From 5640f333313f63ac709e99e57ae455e49ccb8fc6 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 18 Feb 2003 19:28:47 +0000 Subject: [PATCH] test for a variety of new transformations: * 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 | 5 +++++ test/Transforms/InstCombine/div.ll | 10 ++++++++++ test/Transforms/InstCombine/mul.ll | 9 +++++++++ test/Transforms/InstCombine/or.ll | 11 +++++++++++ test/Transforms/InstCombine/rem.ll | 11 ++++++++++- test/Transforms/InstCombine/sub.ll | 12 ++++++++++++ 6 files changed, 57 insertions(+), 1 deletion(-) diff --git a/test/Transforms/InstCombine/and.ll b/test/Transforms/InstCombine/and.ll index 4c151bdeeaa..7dd3d554b65 100644 --- a/test/Transforms/InstCombine/and.ll +++ b/test/Transforms/InstCombine/and.ll @@ -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 diff --git a/test/Transforms/InstCombine/div.ll b/test/Transforms/InstCombine/div.ll index 10daccf11c6..2bcd452c23b 100644 --- a/test/Transforms/InstCombine/div.ll +++ b/test/Transforms/InstCombine/div.ll @@ -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 +} diff --git a/test/Transforms/InstCombine/mul.ll b/test/Transforms/InstCombine/mul.ll index 793040e8779..3f171f4522d 100644 --- a/test/Transforms/InstCombine/mul.ll +++ b/test/Transforms/InstCombine/mul.ll @@ -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 +} diff --git a/test/Transforms/InstCombine/or.ll b/test/Transforms/InstCombine/or.ll index 453df5581cd..3358715d1f9 100644 --- a/test/Transforms/InstCombine/or.ll +++ b/test/Transforms/InstCombine/or.ll @@ -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 +} diff --git a/test/Transforms/InstCombine/rem.ll b/test/Transforms/InstCombine/rem.ll index 554c059b1f7..ddc1c4b0c66 100644 --- a/test/Transforms/InstCombine/rem.ll +++ b/test/Transforms/InstCombine/rem.ll @@ -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 +} diff --git a/test/Transforms/InstCombine/sub.ll b/test/Transforms/InstCombine/sub.ll index cf9011573d0..f807d7e042f 100644 --- a/test/Transforms/InstCombine/sub.ll +++ b/test/Transforms/InstCombine/sub.ll @@ -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 +} +