aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2010-11-17 19:11:46 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2010-11-17 19:11:46 +0000
commit1951a5b721187ab85db0b2db55ae39eec3733c20 (patch)
tree8a1c6d468ac64fe45ffd85783f8b576d0a850209
parent2b749870d0488c3b049edf5d0c8875f56f5b1bed (diff)
InstCombine: Add a missing irem identity (X % X -> 0).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119538 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/InstCombine/InstCombineMulDivRem.cpp4
-rw-r--r--test/Transforms/InstCombine/rem.ll5
2 files changed, 9 insertions, 0 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index c2ae4cc637..1433f7bbc9 100644
--- a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -551,6 +551,10 @@ Instruction *InstCombiner::commonIRemTransforms(BinaryOperator &I) {
if (Instruction *common = commonRemTransforms(I))
return common;
+ // X % X == 0
+ if (Op0 == Op1)
+ return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
+
// 0 % X == 0 for integer, we don't need to preserve faults!
if (Constant *LHS = dyn_cast<Constant>(Op0))
if (LHS->isNullValue())
diff --git a/test/Transforms/InstCombine/rem.ll b/test/Transforms/InstCombine/rem.ll
index bac248e58d..b421b7c0e8 100644
--- a/test/Transforms/InstCombine/rem.ll
+++ b/test/Transforms/InstCombine/rem.ll
@@ -81,3 +81,8 @@ define i32 @test12(i32 %i) {
%tmp.5 = srem i32 %tmp.1, 2
ret i32 %tmp.5
}
+
+define i32 @test13(i32 %i) {
+ %x = srem i32 %i, %i
+ ret i32 %x
+}