InstCombine: Add a missing irem identity (X % X -> 0).
authorBenjamin Kramer <benny.kra@googlemail.com>
Wed, 17 Nov 2010 19:11:46 +0000 (19:11 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Wed, 17 Nov 2010 19:11:46 +0000 (19:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119538 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
test/Transforms/InstCombine/rem.ll

index c2ae4cc6371d4c87a528fc07700cbcb33ee84a32..1433f7bbc943bf844345d298fb001bb2f4093f19 100644 (file)
@@ -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())
index bac248e58d7ab393cba86325304aa447bb011e1d..b421b7c0e8b4a7d629d938b5c432089094ca25c2 100644 (file)
@@ -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
+}