diff options
Diffstat (limited to 'test/Transforms/InstSimplify')
-rw-r--r-- | test/Transforms/InstSimplify/2010-12-20-Distribute.ll | 62 | ||||
-rw-r--r-- | test/Transforms/InstSimplify/apint-or.ll | 37 | ||||
-rw-r--r-- | test/Transforms/InstSimplify/compare.ll | 30 |
3 files changed, 67 insertions, 62 deletions
diff --git a/test/Transforms/InstSimplify/2010-12-20-Distribute.ll b/test/Transforms/InstSimplify/2010-12-20-Distribute.ll deleted file mode 100644 index 9ea0a5e..0000000 --- a/test/Transforms/InstSimplify/2010-12-20-Distribute.ll +++ /dev/null @@ -1,62 +0,0 @@ -; RUN: opt < %s -instsimplify -S | FileCheck %s - -define i32 @factorize(i32 %x, i32 %y) { -; CHECK-LABEL: @factorize( -; (X | 1) & (X | 2) -> X | (1 & 2) -> X - %l = or i32 %x, 1 - %r = or i32 %x, 2 - %z = and i32 %l, %r - ret i32 %z -; CHECK: ret i32 %x -} - -define i32 @factorize2(i32 %x) { -; CHECK-LABEL: @factorize2( -; 3*X - 2*X -> X - %l = mul i32 3, %x - %r = mul i32 2, %x - %z = sub i32 %l, %r - ret i32 %z -; CHECK: ret i32 %x -} - -define i32 @factorize3(i32 %x, i32 %a, i32 %b) { -; CHECK-LABEL: @factorize3( -; (X | (A|B)) & (X | B) -> X | ((A|B) & B) -> X | B - %aORb = or i32 %a, %b - %l = or i32 %x, %aORb - %r = or i32 %x, %b - %z = and i32 %l, %r - ret i32 %z -; CHECK: ret i32 %r -} - -define i32 @factorize4(i32 %x, i32 %y) { -; CHECK-LABEL: @factorize4( - %sh = shl i32 %y, 1 - %ml = mul i32 %sh, %x - %mr = mul i32 %x, %y - %s = sub i32 %ml, %mr - ret i32 %s -; CHECK: ret i32 %mr -} - -define i32 @factorize5(i32 %x, i32 %y) { -; CHECK-LABEL: @factorize5( - %sh = mul i32 %y, 2 - %ml = mul i32 %sh, %x - %mr = mul i32 %x, %y - %s = sub i32 %ml, %mr - ret i32 %s -; CHECK: ret i32 %mr -} - -define i32 @expand(i32 %x) { -; CHECK-LABEL: @expand( -; ((X & 1) | 2) & 1 -> ((X & 1) & 1) | (2 & 1) -> (X & 1) | 0 -> X & 1 - %a = and i32 %x, 1 - %b = or i32 %a, 2 - %c = and i32 %b, 1 - ret i32 %c -; CHECK: ret i32 %a -} diff --git a/test/Transforms/InstSimplify/apint-or.ll b/test/Transforms/InstSimplify/apint-or.ll new file mode 100644 index 0000000..5d314db --- /dev/null +++ b/test/Transforms/InstSimplify/apint-or.ll @@ -0,0 +1,37 @@ +; RUN: opt < %s -instsimplify -S | not grep or + +; Test the case where integer BitWidth <= 64 && BitWidth % 2 != 0. +define i39 @test1(i39 %V, i39 %M) { + ;; 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 +; CHECK-LABEL @test1 +; CHECK-NEXT: and {{.*}}, -274877906944 +; CHECK-NEXT: add +; CHECK-NEXT: ret +} + +; Test the case where Integer BitWidth > 64 && BitWidth <= 1024. +define i399 @test2(i399 %V, i399 %M) { + ;; 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 +; CHECK-LABEL @test2 +; CHECK-NEXT: and {{.*}}, 18446742974197923840 +; CHECK-NEXT: add +; CHECK-NEXT: ret +} diff --git a/test/Transforms/InstSimplify/compare.ll b/test/Transforms/InstSimplify/compare.ll index 105e244..7d0cd9c 100644 --- a/test/Transforms/InstSimplify/compare.ll +++ b/test/Transforms/InstSimplify/compare.ll @@ -883,3 +883,33 @@ define i1 @returns_nonnull() { ; CHECK: ret i1 false } +; If a bit is known to be zero for A and known to be one for B, +; then A and B cannot be equal. +define i1 @icmp_eq_const(i32 %a) nounwind { + %b = mul nsw i32 %a, -2 + %c = icmp eq i32 %b, 1 + ret i1 %c + +; CHECK-LABEL: @icmp_eq_const +; CHECK-NEXT: ret i1 false +} + +define i1 @icmp_ne_const(i32 %a) nounwind { + %b = mul nsw i32 %a, -2 + %c = icmp ne i32 %b, 1 + ret i1 %c + +; CHECK-LABEL: @icmp_ne_const +; CHECK-NEXT: ret i1 true +} + +define i1 @icmp_sdiv_int_min(i32 %a) { + %div = sdiv i32 -2147483648, %a + %cmp = icmp ne i32 %div, -1073741824 + ret i1 %cmp + +; CHECK-LABEL: @icmp_sdiv_int_min +; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 -2147483648, %a +; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[DIV]], -1073741824 +; CHECK-NEXT: ret i1 [[CMP]] +} |