summaryrefslogtreecommitdiff
path: root/test/Transforms/InstSimplify
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2011-01-28 16:51:11 +0000
committerDuncan Sands <baldrick@free.fr>2011-01-28 16:51:11 +0000
commit593faa53fa6d89841e601cc4571d143a6a05f0b4 (patch)
tree0b119c1a312e445ae9c0ece500f9e574daf47818 /test/Transforms/InstSimplify
parentabcae24d991844ac6ac33b773b1007e2e901575c (diff)
downloadllvm-593faa53fa6d89841e601cc4571d143a6a05f0b4.tar.gz
llvm-593faa53fa6d89841e601cc4571d143a6a05f0b4.tar.bz2
llvm-593faa53fa6d89841e601cc4571d143a6a05f0b4.tar.xz
My auto-simplifier noticed that ((X/Y)*Y)/Y occurs several times in SPEC
benchmarks, and that it can be simplified to X/Y. (In general you can only simplify (Z*Y)/Y to Z if the multiplication did not overflow; if Z has the form "X/Y" then this is the case). This patch implements that transform and moves some Div logic out of instcombine and into InstructionSimplify. Unfortunately instcombine gets in the way somewhat, since it likes to change (X/Y)*Y into X-(X rem Y), so I had to teach instcombine about this too. Finally, thanks to the NSW/NUW flags, sometimes we know directly that "Z*Y" does not overflow, because the flag says so, so I added that logic too. This eliminates a bunch of divisions and subtractions in 447.dealII, and has good effects on some other benchmarks too. It seems to have quite an effect on tramp3d-v4 but it's hard to say if it's good or bad because inlining decisions changed, resulting in massive changes all over. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124487 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Transforms/InstSimplify')
-rw-r--r--test/Transforms/InstSimplify/2010-12-20-Reassociate.ll56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/Transforms/InstSimplify/2010-12-20-Reassociate.ll b/test/Transforms/InstSimplify/2010-12-20-Reassociate.ll
index 1e2f7fae43..13724669d7 100644
--- a/test/Transforms/InstSimplify/2010-12-20-Reassociate.ll
+++ b/test/Transforms/InstSimplify/2010-12-20-Reassociate.ll
@@ -90,3 +90,59 @@ define i32 @sub3(i32 %x, i32 %y) {
ret i32 %r
; CHECK: ret i32 %x
}
+
+define i32 @sdiv1(i32 %x, i32 %y) {
+; CHECK: @sdiv1
+; (no overflow X * Y) / Y -> X
+ %mul = mul nsw i32 %x, %y
+ %r = sdiv i32 %mul, %y
+ ret i32 %r
+; CHECK: ret i32 %x
+}
+
+define i32 @sdiv2(i32 %x, i32 %y) {
+; CHECK: @sdiv2
+; (((X / Y) * Y) / Y) -> X / Y
+ %div = sdiv i32 %x, %y
+ %mul = mul i32 %div, %y
+ %r = sdiv i32 %mul, %y
+ ret i32 %r
+; CHECK: ret i32 %div
+}
+
+define i32 @sdiv3(i32 %x, i32 %y) {
+; CHECK: @sdiv3
+; (X rem Y) / Y -> 0
+ %rem = srem i32 %x, %y
+ %div = sdiv i32 %rem, %y
+ ret i32 %div
+; CHECK: ret i32 0
+}
+
+define i32 @udiv1(i32 %x, i32 %y) {
+; CHECK: @udiv1
+; (no overflow X * Y) / Y -> X
+ %mul = mul nuw i32 %x, %y
+ %r = udiv i32 %mul, %y
+ ret i32 %r
+; CHECK: ret i32 %x
+}
+
+define i32 @udiv2(i32 %x, i32 %y) {
+; CHECK: @udiv2
+; (((X / Y) * Y) / Y) -> X / Y
+ %div = udiv i32 %x, %y
+ %mul = mul i32 %div, %y
+ %r = udiv i32 %mul, %y
+ ret i32 %r
+; CHECK: ret i32 %div
+}
+
+define i32 @udiv3(i32 %x, i32 %y) {
+; CHECK: @udiv3
+; (X rem Y) / Y -> 0
+ %rem = urem i32 %x, %y
+ %div = udiv i32 %rem, %y
+ ret i32 %div
+; CHECK: ret i32 0
+}