summaryrefslogtreecommitdiff
path: root/test/Transforms/InstCombine/2008-11-20-DivMulRem.ll
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2008-11-21 07:33:58 +0000
committerNick Lewycky <nicholas@mxc.ca>2008-11-21 07:33:58 +0000
commit0c73079855de925bf08335fe39b0b112f3d9407a (patch)
tree551a778e44dbac57cbe75b020b9fa977080e6019 /test/Transforms/InstCombine/2008-11-20-DivMulRem.ll
parent41e4a59f2f396519e7026011320760c6d0c179c3 (diff)
downloadllvm-0c73079855de925bf08335fe39b0b112f3d9407a.tar.gz
llvm-0c73079855de925bf08335fe39b0b112f3d9407a.tar.bz2
llvm-0c73079855de925bf08335fe39b0b112f3d9407a.tar.xz
Optimize (x/y)*y into x-(x%y) in general. Div and rem are about the same, and
a subtract is cheaper than a multiply. This generalizes an existing transform. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@59800 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Transforms/InstCombine/2008-11-20-DivMulRem.ll')
-rw-r--r--test/Transforms/InstCombine/2008-11-20-DivMulRem.ll34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/Transforms/InstCombine/2008-11-20-DivMulRem.ll b/test/Transforms/InstCombine/2008-11-20-DivMulRem.ll
new file mode 100644
index 0000000000..8c58a2ae7f
--- /dev/null
+++ b/test/Transforms/InstCombine/2008-11-20-DivMulRem.ll
@@ -0,0 +1,34 @@
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis > %t
+; RUN: grep urem %t | count 3
+; RUN: grep srem %t | count 1
+; RUN: grep sub %t | count 2
+; RUN: grep add %t | count 1
+; PR3103
+
+define i8 @test1(i8 %x, i8 %y) {
+ %A = udiv i8 %x, %y
+ %B = mul i8 %A, %y
+ %C = sub i8 %x, %B
+ ret i8 %C
+}
+
+define i8 @test2(i8 %x, i8 %y) {
+ %A = sdiv i8 %x, %y
+ %B = mul i8 %A, %y
+ %C = sub i8 %x, %B
+ ret i8 %C
+}
+
+define i8 @test3(i8 %x, i8 %y) {
+ %A = udiv i8 %x, %y
+ %B = mul i8 %A, %y
+ %C = sub i8 %B, %x
+ ret i8 %C
+}
+
+define i8 @test4(i8 %x) {
+ %A = udiv i8 %x, 3
+ %B = mul i8 %A, -3
+ %C = sub i8 %x, %B
+ ret i8 %C
+}