1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 19:12:56 +02:00

[InstSimplify] add tests for logic-of-icmp with min/max constant; NFC

See PR45510:
https://bugs.llvm.org/show_bug.cgi?id=45510

We had partial coverage for some of these patterns, so removing duplicate tests
with the complete set in the new test file.
This commit is contained in:
Sanjay Patel 2020-04-17 14:05:04 -04:00
parent 9c786576c7
commit 07f4aa11d2
3 changed files with 1274 additions and 236 deletions

View File

@ -383,112 +383,6 @@ define i32 @neg_nuw(i32 %x) {
ret i32 %neg
}
define i1 @and_icmp1(i32 %x, i32 %y) {
; CHECK-LABEL: @and_icmp1(
; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[TMP1]]
;
%1 = icmp ult i32 %x, %y
%2 = icmp ne i32 %y, 0
%3 = and i1 %1, %2
ret i1 %3
}
define i1 @and_icmp2(i32 %x, i32 %y) {
; CHECK-LABEL: @and_icmp2(
; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[TMP1]]
;
%1 = icmp ugt i32 %x, %y
%2 = icmp ne i32 %x, 0
%3 = and i1 %1, %2
ret i1 %3
}
define i1 @and_icmp3(i32 %x, i32 %y) {
; CHECK-LABEL: @and_icmp3(
; CHECK-NEXT: ret i1 false
;
%1 = icmp ult i32 %x, %y
%2 = icmp eq i32 %y, 0
%3 = and i1 %1, %2
ret i1 %3
}
define i1 @and_icmp4(i32 %x, i32 %y) {
; CHECK-LABEL: @and_icmp4(
; CHECK-NEXT: ret i1 false
;
%1 = icmp ugt i32 %x, %y
%2 = icmp eq i32 %x, 0
%3 = and i1 %1, %2
ret i1 %3
}
define i1 @or_icmp1(i32 %x, i32 %y) {
; CHECK-LABEL: @or_icmp1(
; CHECK-NEXT: [[TMP1:%.*]] = icmp ne i32 [[Y:%.*]], 0
; CHECK-NEXT: ret i1 [[TMP1]]
;
%1 = icmp ult i32 %x, %y
%2 = icmp ne i32 %y, 0
%3 = or i1 %1, %2
ret i1 %3
}
define i1 @or_icmp2(i32 %x, i32 %y) {
; CHECK-LABEL: @or_icmp2(
; CHECK-NEXT: [[TMP1:%.*]] = icmp ne i32 [[X:%.*]], 0
; CHECK-NEXT: ret i1 [[TMP1]]
;
%1 = icmp ugt i32 %x, %y
%2 = icmp ne i32 %x, 0
%3 = or i1 %1, %2
ret i1 %3
}
define i1 @or_icmp3(i32 %x, i32 %y) {
; CHECK-LABEL: @or_icmp3(
; CHECK-NEXT: ret i1 true
;
%1 = icmp uge i32 %x, %y
%2 = icmp ne i32 %y, 0
%3 = or i1 %1, %2
ret i1 %3
}
define i1 @or_icmp4(i32 %x, i32 %y) {
; CHECK-LABEL: @or_icmp4(
; CHECK-NEXT: ret i1 true
;
%1 = icmp ule i32 %x, %y
%2 = icmp ne i32 %x, 0
%3 = or i1 %1, %2
ret i1 %3
}
define i1 @or_icmp5(i32 %x, i32 %y) {
; CHECK-LABEL: @or_icmp5(
; CHECK-NEXT: [[TMP1:%.*]] = icmp uge i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[TMP1]]
;
%1 = icmp uge i32 %x, %y
%2 = icmp eq i32 %y, 0
%3 = or i1 %1, %2
ret i1 %3
}
define i1 @or_icmp6(i32 %x, i32 %y) {
; CHECK-LABEL: @or_icmp6(
; CHECK-NEXT: [[TMP1:%.*]] = icmp ule i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[TMP1]]
;
%1 = icmp ule i32 %x, %y
%2 = icmp eq i32 %x, 0
%3 = or i1 %1, %2
ret i1 %3
}
; PR27869 - Look through casts to eliminate cmps and bitwise logic.
define i32 @and_of_zexted_icmps(i32 %i) {
@ -581,6 +475,8 @@ define <2 x i3> @and_of_different_cast_icmps_vec(<2 x i8> %i, <2 x i16> %j) {
ret <2 x i3> %and
}
; limit
define i32 @or_of_zexted_icmps(i32 %i) {
; CHECK-LABEL: @or_of_zexted_icmps(
; CHECK-NEXT: ret i32 1

File diff suppressed because it is too large Load Diff

View File

@ -1,130 +0,0 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt %s -instsimplify -S | FileCheck %s
; Here we add unsigned two values, check that addition did not underflow AND
; that the result is non-zero. This can be simplified just to a comparison
; between the base and negated offset.
; If we are checking that the result is not null or no underflow happened,
; it is tautological (always-true).
define i1 @t1(i8 %x, i8 %y) {
; CHECK-LABEL: @t1(
; CHECK-NEXT: ret i1 true
;
%not_null = icmp ne i8 %y, 0
%no_underflow = icmp ule i8 %y, %x
%r = or i1 %not_null, %no_underflow
ret i1 %r
}
define i1 @t2_commutative(i8 %x, i8 %y) {
; CHECK-LABEL: @t2_commutative(
; CHECK-NEXT: ret i1 true
;
%not_null = icmp ne i8 %y, 0
%no_underflow = icmp uge i8 %x, %y ; swapped
%r = or i1 %not_null, %no_underflow
ret i1 %r
}
define i1 @t3_commutative(i8 %x, i8 %y) {
; CHECK-LABEL: @t3_commutative(
; CHECK-NEXT: ret i1 true
;
%not_null = icmp ne i8 %y, 0
%no_underflow = icmp ule i8 %y, %x
%r = or i1 %no_underflow, %not_null ; swapped
ret i1 %r
}
define i1 @t4_commutative(i8 %x, i8 %y) {
; CHECK-LABEL: @t4_commutative(
; CHECK-NEXT: ret i1 true
;
%not_null = icmp ne i8 %y, 0
%no_underflow = icmp uge i8 %x, %y ; swapped
%r = or i1 %no_underflow, %not_null ; swapped
ret i1 %r
}
; If we are checking that the result is null and underflow happened,
; it is tautological (always-false).
define i1 @t5(i8 %x, i8 %y) {
; CHECK-LABEL: @t5(
; CHECK-NEXT: ret i1 false
;
%not_null = icmp eq i8 %y, 0
%no_underflow = icmp ugt i8 %y, %x
%r = and i1 %not_null, %no_underflow
ret i1 %r
}
define i1 @t6_commutative(i8 %x, i8 %y) {
; CHECK-LABEL: @t6_commutative(
; CHECK-NEXT: ret i1 false
;
%not_null = icmp eq i8 %y, 0
%no_underflow = icmp ult i8 %x, %y ; swapped
%r = and i1 %not_null, %no_underflow
ret i1 %r
}
; We only need to know that any of the 'add' operands is non-zero,
; not necessarily the one used in the comparison.
define i1 @t7(i8 %x, i8 %y) {
; CHECK-LABEL: @t7(
; CHECK-NEXT: ret i1 true
;
%cmp = icmp slt i8 %y, 0
%not_null = icmp ne i8 %y, 0
%no_underflow = icmp ule i8 %y, %x
%r = or i1 %not_null, %no_underflow
ret i1 %r
}
; If we check that no underflow happened and that the result is null,
; we can just check for null.
define i1 @t8(i8 %x, i8 %y) {
; CHECK-LABEL: @t8(
; CHECK-NEXT: [[NOT_NULL:%.*]] = icmp eq i8 [[Y:%.*]], 0
; CHECK-NEXT: ret i1 [[NOT_NULL]]
;
%not_null = icmp eq i8 %y, 0
%no_underflow = icmp ule i8 %y, %x
%r = and i1 %not_null, %no_underflow
ret i1 %r
}
; Likewise, if we check that result is non-null or underflow happened,
; we can just check for null.
define i1 @t9(i8 %x, i8 %y) {
; CHECK-LABEL: @t9(
; CHECK-NEXT: [[NOT_NULL:%.*]] = icmp ne i8 [[Y:%.*]], 0
; CHECK-NEXT: ret i1 [[NOT_NULL]]
;
%not_null = icmp ne i8 %y, 0
%no_underflow = icmp ugt i8 %y, %x
%r = or i1 %not_null, %no_underflow
ret i1 %r
}
; If we check that no underflow happened or that the result is not null,
; we can just check for lack of underflow.
define i1 @t10(i8 %x, i8 %y) {
; CHECK-LABEL: @t10(
; CHECK-NEXT: [[NO_UNDERFLOW:%.*]] = icmp ule i8 [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: ret i1 [[NO_UNDERFLOW]]
;
%not_null = icmp eq i8 %y, 0
%no_underflow = icmp ule i8 %y, %x
%r = or i1 %not_null, %no_underflow
ret i1 %r
}
; Likewise, if we check that underflow happened and that the result is not null,
; we can just check for lack of underflow.
define i1 @t11(i8 %x, i8 %y) {
; CHECK-LABEL: @t11(
; CHECK-NEXT: [[NO_UNDERFLOW:%.*]] = icmp ugt i8 [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: ret i1 [[NO_UNDERFLOW]]
;
%not_null = icmp ne i8 %y, 0
%no_underflow = icmp ugt i8 %y, %x
%r = and i1 %not_null, %no_underflow
ret i1 %r
}