test for a variety of new transformations:
authorChris Lattner <sabre@nondot.org>
Tue, 18 Feb 2003 19:28:47 +0000 (19:28 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 18 Feb 2003 19:28:47 +0000 (19:28 +0000)
  * A & ~A == 0
  * A / (2^c) == A >> c  if unsigned
  * 0 / A == 0
  * 1.0 * A == A
  * A * (2^c) == A << c
  * A ^ ~A == -1
  * A | ~A == -1
  * 0 % X = 0
  * A % (2^c) == A & (c-1) if unsigned
  * A - (A & B) == A & ~B
  * -1 - A == ~A

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5588 91177308-0d34-0410-b5e6-96231b3b80d8

test/Transforms/InstCombine/and.ll
test/Transforms/InstCombine/div.ll
test/Transforms/InstCombine/mul.ll
test/Transforms/InstCombine/or.ll
test/Transforms/InstCombine/rem.ll
test/Transforms/InstCombine/sub.ll

index 4c151bdeeaaa1b3f39bb10aada89a72dadea2aac..7dd3d554b651e92dca1232bd9e61f6b8411245d1 100644 (file)
@@ -38,3 +38,8 @@ bool %test6(bool %A) {
        ret bool %B
 }
 
+int %test7(int %A) {         ; A & ~A == 0
+        %NotA = xor int %A, -1
+        %B = and int %A, %NotA
+        ret int %B
+}
\ No newline at end of file
index 10daccf11c6a3de6008aef252a7f8d5ecf790896..2bcd452c23bd59036d6a87eb436ca9af3c139680 100644 (file)
@@ -12,3 +12,13 @@ int %test1(int %A) {
        %B = div int %A, 1
        ret int %B
 }
+
+uint %test2(uint %A) {
+       %B = div uint %A, 8   ; => Shift
+       ret int %B
+}
+
+int %test3(int %A) {
+       %B = div int 0, %A    ; => 0, don't need to keep traps
+       ret int %B
+}
index 793040e87792670746f395244ad7f5848cf588b3..3f171f4522d73a88f43ba21ca86d876caf3cdde2 100644 (file)
@@ -26,3 +26,12 @@ begin
        ret int %B
 end
 
+double %test4(double %A) {
+       %B = mul double 1.0, %A   ; This is safe for FP
+       ret double %B
+}
+
+int %test5(int %A) {
+       %B = mul int %A, 8
+       ret int %B
+}
index 453df5581cd3152a02b39a7bac2c7a08368b435e..3358715d1f9c695310427e57aa9e402413305cfc 100644 (file)
@@ -58,3 +58,14 @@ int %test10(int %A) {
        ret int %B
 }
 
+int %test11(int %A) {    ; A ^ ~A == -1
+        %NotA = xor int -1, %A
+        %B = xor int %A, %NotA
+        ret int %B
+}
+
+int %test12(int %A) {    ; A | ~A == -1
+        %NotA = xor int -1, %A
+        %B = or int %A, %NotA
+        ret int %B
+}
index 554c059b1f7c59703181be9a0886f8e568147da7..ddc1c4b0c66e1c463c40e996ce6174e507cff8fd 100644 (file)
@@ -8,8 +8,17 @@
 
 implementation
 
-int "test1"(int %A) {
+int %test1(int %A) {
        %B = rem int %A, 1    ; ISA constant 0
        ret int %B
 }
 
+int %test2(int %A) {          ; 0 % X = 0, we don't need ot preserve traps
+       %B = rem int 0, %A
+       ret int %B
+}
+
+uint %test3(uint %A) {
+       %B = rem uint %A, 8   ; & 7
+       ret uint %B
+}
index cf9011573d0f2e868ef425cec2a5122fe3d8d22d..f807d7e042ff6ff5ce23bfdc6f71d869952847c5 100644 (file)
@@ -35,3 +35,15 @@ int "test5"(int %A, int %Bok, int %Cok) {
        %E = sub int %A, %D
        ret int %E
 }
+
+int %test6(int %A, int %B) {
+       %C = and int %A, %B   ; A - (A & B) => A & ~B
+       %D = sub int %A, %C
+       ret int %D
+}
+
+int %test7(int %A) {
+       %B = sub int -1, %A   ; B = ~A
+       ret int %B
+}
+