diff options
Diffstat (limited to 'test/Transforms/InstSimplify')
-rw-r--r-- | test/Transforms/InstSimplify/AndOrXor.ll | 173 | ||||
-rw-r--r-- | test/Transforms/InstSimplify/apint-or.ll | 72 | ||||
-rw-r--r-- | test/Transforms/InstSimplify/compare.ll | 7 | ||||
-rw-r--r-- | test/Transforms/InstSimplify/or.ll | 181 |
4 files changed, 359 insertions, 74 deletions
diff --git a/test/Transforms/InstSimplify/AndOrXor.ll b/test/Transforms/InstSimplify/AndOrXor.ll index e059d77f1fa8..427ea655fcb2 100644 --- a/test/Transforms/InstSimplify/AndOrXor.ll +++ b/test/Transforms/InstSimplify/AndOrXor.ll @@ -628,3 +628,176 @@ define i32 @test46_commuted_and(i32 %a, i32 %b) { %or = or i32 %xor, %and ret i32 %or } + +; (~A ^ B) | (A & B) -> ~A ^ B + +define i32 @test47(i32 %a, i32 %b) { +; CHECK-LABEL: @test47( +; CHECK-NEXT: [[NEGA:%.*]] = xor i32 [[A:%.*]], -1 +; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[NEGA]], [[B:%.*]] +; CHECK-NEXT: ret i32 [[XOR]] +; + %nega = xor i32 %a, -1 + %and = and i32 %a, %b + %xor = xor i32 %nega, %b + %or = or i32 %xor, %and + ret i32 %or +} + +define i32 @test48(i32 %a, i32 %b) { +; CHECK-LABEL: @test48( +; CHECK-NEXT: [[NEGA:%.*]] = xor i32 [[A:%.*]], -1 +; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[B:%.*]], [[NEGA]] +; CHECK-NEXT: ret i32 [[XOR]] +; + %nega = xor i32 %a, -1 + %and = and i32 %a, %b + %xor = xor i32 %b, %nega + %or = or i32 %xor, %and + ret i32 %or +} + +define i32 @test49(i32 %a, i32 %b) { +; CHECK-LABEL: @test49( +; CHECK-NEXT: [[NEGA:%.*]] = xor i32 [[A:%.*]], -1 +; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[B:%.*]], [[NEGA]] +; CHECK-NEXT: ret i32 [[XOR]] +; + %nega = xor i32 %a, -1 + %and = and i32 %b, %a + %xor = xor i32 %b, %nega + %or = or i32 %xor, %and + ret i32 %or +} + +define i32 @test50(i32 %a, i32 %b) { +; CHECK-LABEL: @test50( +; CHECK-NEXT: [[NEGA:%.*]] = xor i32 [[A:%.*]], -1 +; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[NEGA]], [[B:%.*]] +; CHECK-NEXT: ret i32 [[XOR]] +; + %nega = xor i32 %a, -1 + %and = and i32 %b, %a + %xor = xor i32 %nega, %b + %or = or i32 %xor, %and + ret i32 %or +} + +define i32 @test51(i32 %a, i32 %b) { +; CHECK-LABEL: @test51( +; CHECK-NEXT: [[NEGA:%.*]] = xor i32 [[A:%.*]], -1 +; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[NEGA]], [[B:%.*]] +; CHECK-NEXT: ret i32 [[XOR]] +; + %nega = xor i32 %a, -1 + %and = and i32 %a, %b + %xor = xor i32 %nega, %b + %or = or i32 %and, %xor + ret i32 %or +} + +define i32 @test52(i32 %a, i32 %b) { +; CHECK-LABEL: @test52( +; CHECK-NEXT: [[NEGA:%.*]] = xor i32 [[A:%.*]], -1 +; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[B:%.*]], [[NEGA]] +; CHECK-NEXT: ret i32 [[XOR]] +; + %nega = xor i32 %a, -1 + %and = and i32 %a, %b + %xor = xor i32 %b, %nega + %or = or i32 %and, %xor + ret i32 %or +} + +define i32 @test53(i32 %a, i32 %b) { +; CHECK-LABEL: @test53( +; CHECK-NEXT: [[NEGA:%.*]] = xor i32 [[A:%.*]], -1 +; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[B:%.*]], [[NEGA]] +; CHECK-NEXT: ret i32 [[XOR]] +; + %nega = xor i32 %a, -1 + %and = and i32 %b, %a + %xor = xor i32 %b, %nega + %or = or i32 %and, %xor + ret i32 %or +} + +define i32 @test54(i32 %a, i32 %b) { +; CHECK-LABEL: @test54( +; CHECK-NEXT: [[NEGA:%.*]] = xor i32 [[A:%.*]], -1 +; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[NEGA]], [[B:%.*]] +; CHECK-NEXT: ret i32 [[XOR]] +; + %nega = xor i32 %a, -1 + %and = and i32 %b, %a + %xor = xor i32 %nega, %b + %or = or i32 %and, %xor + ret i32 %or +} + +define i8 @lshr_perfect_mask(i8 %x) { +; CHECK-LABEL: @lshr_perfect_mask( +; CHECK-NEXT: [[SH:%.*]] = lshr i8 %x, 5 +; CHECK-NEXT: [[MASK:%.*]] = and i8 [[SH]], 7 +; CHECK-NEXT: ret i8 [[MASK]] +; + %sh = lshr i8 %x, 5 + %mask = and i8 %sh, 7 ; 0x07 + ret i8 %mask +} + +define <2 x i8> @lshr_oversized_mask_splat(<2 x i8> %x) { +; CHECK-LABEL: @lshr_oversized_mask_splat( +; CHECK-NEXT: [[SH:%.*]] = lshr <2 x i8> %x, <i8 5, i8 5> +; CHECK-NEXT: [[MASK:%.*]] = and <2 x i8> [[SH]], <i8 -121, i8 -121> +; CHECK-NEXT: ret <2 x i8> [[MASK]] +; + %sh = lshr <2 x i8> %x, <i8 5, i8 5> + %mask = and <2 x i8> %sh, <i8 135, i8 135> ; 0x87 + ret <2 x i8> %mask +} + +define i8 @lshr_undersized_mask(i8 %x) { +; CHECK-LABEL: @lshr_undersized_mask( +; CHECK-NEXT: [[SH:%.*]] = lshr i8 %x, 5 +; CHECK-NEXT: [[MASK:%.*]] = and i8 [[SH]], -2 +; CHECK-NEXT: ret i8 [[MASK]] +; + %sh = lshr i8 %x, 5 + %mask = and i8 %sh, -2 ; 0xFE + ret i8 %mask +} + +define <2 x i8> @shl_perfect_mask_splat(<2 x i8> %x) { +; CHECK-LABEL: @shl_perfect_mask_splat( +; CHECK-NEXT: [[SH:%.*]] = shl <2 x i8> %x, <i8 6, i8 6> +; CHECK-NEXT: [[MASK:%.*]] = and <2 x i8> [[SH]], <i8 -64, i8 -64> +; CHECK-NEXT: ret <2 x i8> [[MASK]] +; + %sh = shl <2 x i8> %x, <i8 6, i8 6> + %mask = and <2 x i8> %sh, <i8 192, i8 192> ; 0xC0 + ret <2 x i8> %mask +} + +define i8 @shl_oversized_mask(i8 %x) { +; CHECK-LABEL: @shl_oversized_mask( +; CHECK-NEXT: [[SH:%.*]] = shl i8 %x, 6 +; CHECK-NEXT: [[MASK:%.*]] = and i8 [[SH]], -61 +; CHECK-NEXT: ret i8 [[MASK]] +; + %sh = shl i8 %x, 6 + %mask = and i8 %sh, 195 ; 0xC3 + ret i8 %mask +} + +define <2 x i8> @shl_undersized_mask_splat(<2 x i8> %x) { +; CHECK-LABEL: @shl_undersized_mask_splat( +; CHECK-NEXT: [[SH:%.*]] = shl <2 x i8> [[X:%.*]], <i8 6, i8 6> +; CHECK-NEXT: [[MASK:%.*]] = and <2 x i8> [[SH]], <i8 -120, i8 -120> +; CHECK-NEXT: ret <2 x i8> [[MASK]] +; + %sh = shl <2 x i8> %x, <i8 6, i8 6> + %mask = and <2 x i8> %sh, <i8 136, i8 136> ; 0x88 + ret <2 x i8> %mask +} + diff --git a/test/Transforms/InstSimplify/apint-or.ll b/test/Transforms/InstSimplify/apint-or.ll deleted file mode 100644 index e3dc2c48fb40..000000000000 --- a/test/Transforms/InstSimplify/apint-or.ll +++ /dev/null @@ -1,72 +0,0 @@ -; NOTE: Assertions have been autogenerated by update_test_checks.py -; RUN: opt < %s -instsimplify -S | FileCheck %s - -; Test the case where integer BitWidth <= 64 && BitWidth % 2 != 0. -define i39 @test1(i39 %V, i39 %M) { -; CHECK-LABEL: @test1( -; CHECK: [[N:%.*]] = and i39 %M, -274877906944 -; CHECK-NEXT: [[A:%.*]] = add i39 %V, [[N]] -; CHECK-NEXT: ret i39 [[A]] -; - ;; If we have: ((V + N) & C1) | (V & C2) - ;; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0 - ;; replace with V+N. - %C1 = xor i39 274877906943, -1 ;; C2 = 274877906943 - %N = and i39 %M, 274877906944 - %A = add i39 %V, %N - %B = and i39 %A, %C1 - %D = and i39 %V, 274877906943 - %R = or i39 %B, %D - ret i39 %R -} - -define i7 @test2(i7 %X) { -; CHECK-LABEL: @test2( -; CHECK: ret i7 %X -; - %Y = or i7 %X, 0 - ret i7 %Y -} - -define i17 @test3(i17 %X) { -; CHECK-LABEL: @test3( -; CHECK: ret i17 -1 -; - %Y = or i17 %X, -1 - ret i17 %Y -} - -; Test the case where Integer BitWidth > 64 && BitWidth <= 1024. -define i399 @test4(i399 %V, i399 %M) { -; CHECK-LABEL: @test4( -; CHECK: [[N:%.*]] = and i399 %M, 18446742974197923840 -; CHECK-NEXT: [[A:%.*]] = add i399 %V, [[N]] -; CHECK-NEXT: ret i399 [[A]] -; - ;; If we have: ((V + N) & C1) | (V & C2) - ;; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0 - ;; replace with V+N. - %C1 = xor i399 274877906943, -1 ;; C2 = 274877906943 - %N = and i399 %M, 18446742974197923840 - %A = add i399 %V, %N - %B = and i399 %A, %C1 - %D = and i399 %V, 274877906943 - %R = or i399 %B, %D - ret i399 %R -} - -define i777 @test5(i777 %X) { -; CHECK-LABEL: @test5( -; CHECK: ret i777 %X -; - %Y = or i777 %X, 0 - ret i777 %Y -} - -define i117 @test6(i117 %X) { -; CHECK-LABEL: @test6( -; CHECK: ret i117 -1 -; - %Y = or i117 %X, -1 - ret i117 %Y -} diff --git a/test/Transforms/InstSimplify/compare.ll b/test/Transforms/InstSimplify/compare.ll index 883bf31ff77a..d6f1b634102f 100644 --- a/test/Transforms/InstSimplify/compare.ll +++ b/test/Transforms/InstSimplify/compare.ll @@ -598,11 +598,14 @@ define i1 @sdiv_exact_equality(i32 %Z) { ret i1 %C } -; FIXME: But not other preds: PR32949 - https://bugs.llvm.org/show_bug.cgi?id=32949 +; But not other preds: PR32949 - https://bugs.llvm.org/show_bug.cgi?id=32949 define i1 @sdiv_exact_not_equality(i32 %Z) { ; CHECK-LABEL: @sdiv_exact_not_equality( -; CHECK-NEXT: ret i1 true +; CHECK-NEXT: [[A:%.*]] = sdiv exact i32 10, %Z +; CHECK-NEXT: [[B:%.*]] = sdiv exact i32 20, %Z +; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[A]], [[B]] +; CHECK-NEXT: ret i1 [[C]] ; %A = sdiv exact i32 10, %Z %B = sdiv exact i32 20, %Z diff --git a/test/Transforms/InstSimplify/or.ll b/test/Transforms/InstSimplify/or.ll new file mode 100644 index 000000000000..2c5b6181bc6c --- /dev/null +++ b/test/Transforms/InstSimplify/or.ll @@ -0,0 +1,181 @@ +; RUN: opt < %s -instsimplify -S | FileCheck %s + +define i32 @test1(i32 %A) { +; CHECK-LABEL: @test1( +; CHECK-NEXT: ret i32 %A +; + %B = or i32 %A, 0 + ret i32 %B +} + +define i32 @test2(i32 %A) { +; CHECK-LABEL: @test2( +; CHECK-NEXT: ret i32 -1 +; + %B = or i32 %A, -1 + ret i32 %B +} + +define i8 @test2a(i8 %A) { +; CHECK-LABEL: @test2a( +; CHECK-NEXT: ret i8 -1 +; + %B = or i8 %A, -1 + ret i8 %B +} + +define i1 @test3(i1 %A) { +; CHECK-LABEL: @test3( +; CHECK-NEXT: ret i1 %A +; + %B = or i1 %A, false + ret i1 %B +} + +define i1 @test4(i1 %A) { +; CHECK-LABEL: @test4( +; CHECK-NEXT: ret i1 true +; + %B = or i1 %A, true + ret i1 %B +} + +define i1 @test5(i1 %A) { +; CHECK-LABEL: @test5( +; CHECK-NEXT: ret i1 %A +; + %B = or i1 %A, %A + ret i1 %B +} + +define i32 @test6(i32 %A) { +; CHECK-LABEL: @test6( +; CHECK-NEXT: ret i32 %A +; + %B = or i32 %A, %A + ret i32 %B +} + +; A | ~A == -1 +define i32 @test7(i32 %A) { +; CHECK-LABEL: @test7( +; CHECK-NEXT: ret i32 -1 +; + %NotA = xor i32 %A, -1 + %B = or i32 %A, %NotA + ret i32 %B +} + +define i8 @test8(i8 %A) { +; CHECK-LABEL: @test8( +; CHECK-NEXT: ret i8 -1 +; + %B = or i8 %A, -2 + %C = or i8 %B, 1 + ret i8 %C +} + +; Test that (A|c1)|(B|c2) == (A|B)|(c1|c2) +define i8 @test9(i8 %A, i8 %B) { +; CHECK-LABEL: @test9( +; CHECK-NEXT: ret i8 -1 +; + %C = or i8 %A, 1 + %D = or i8 %B, -2 + %E = or i8 %C, %D + ret i8 %E +} + +define i8 @test10(i8 %A) { +; CHECK-LABEL: @test10( +; CHECK-NEXT: ret i8 -2 +; + %B = or i8 %A, 1 + %C = and i8 %B, -2 + ; (X & C1) | C2 --> (X | C2) & (C1|C2) + %D = or i8 %C, -2 + ret i8 %D +} + +define i8 @test11(i8 %A) { +; CHECK-LABEL: @test11( +; CHECK-NEXT: ret i8 -1 +; + %B = or i8 %A, -2 + %C = xor i8 %B, 13 + ; (X ^ C1) | C2 --> (X | C2) ^ (C1&~C2) + %D = or i8 %C, 1 + %E = xor i8 %D, 12 + ret i8 %E +} + +; Test the case where integer BitWidth <= 64 && BitWidth % 2 != 0. +define i39 @test1_apint(i39 %V, i39 %M) { +; CHECK-LABEL: @test1_apint( +; CHECK: [[N:%.*]] = and i39 %M, -274877906944 +; CHECK-NEXT: [[A:%.*]] = add i39 %V, [[N]] +; CHECK-NEXT: ret i39 [[A]] +; + ;; If we have: ((V + N) & C1) | (V & C2) + ;; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0 + ;; replace with V+N. + %C1 = xor i39 274877906943, -1 ;; C2 = 274877906943 + %N = and i39 %M, 274877906944 + %A = add i39 %V, %N + %B = and i39 %A, %C1 + %D = and i39 %V, 274877906943 + %R = or i39 %B, %D + ret i39 %R +} + +define i7 @test2_apint(i7 %X) { +; CHECK-LABEL: @test2_apint( +; CHECK: ret i7 %X +; + %Y = or i7 %X, 0 + ret i7 %Y +} + +define i17 @test3_apint(i17 %X) { +; CHECK-LABEL: @test3_apint( +; CHECK: ret i17 -1 +; + %Y = or i17 %X, -1 + ret i17 %Y +} + +; Test the case where Integer BitWidth > 64 && BitWidth <= 1024. +define i399 @test4_apint(i399 %V, i399 %M) { +; CHECK-LABEL: @test4_apint( +; CHECK: [[N:%.*]] = and i399 %M, 18446742974197923840 +; CHECK-NEXT: [[A:%.*]] = add i399 %V, [[N]] +; CHECK-NEXT: ret i399 [[A]] +; + ;; If we have: ((V + N) & C1) | (V & C2) + ;; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0 + ;; replace with V+N. + %C1 = xor i399 274877906943, -1 ;; C2 = 274877906943 + %N = and i399 %M, 18446742974197923840 + %A = add i399 %V, %N + %B = and i399 %A, %C1 + %D = and i399 %V, 274877906943 + %R = or i399 %B, %D + ret i399 %R +} + +define i777 @test5_apint(i777 %X) { +; CHECK-LABEL: @test5_apint( +; CHECK: ret i777 %X +; + %Y = or i777 %X, 0 + ret i777 %Y +} + +define i117 @test6_apint(i117 %X) { +; CHECK-LABEL: @test6_apint( +; CHECK: ret i117 -1 +; + %Y = or i117 %X, -1 + ret i117 %Y +} + |