[PATCH] Added InstCombine transform for pattern " ((X % Z) + (Y % Z)) % Z -> (X + Y) % Z ".

David Majnemer david.majnemer at gmail.com
Wed Sep 17 11:47:32 PDT 2014


================
Comment at: lib/Transforms/InstCombine/InstCombineMulDivRem.cpp:1338-1340
@@ +1337,5 @@
+                       m_SRem(m_Value(Y), m_Specific(Z))))) {
+    Instruction *I1 = dyn_cast<Instruction>(Op0);
+    I1->setOperand(0, X);
+    I1->setOperand(1, Y);
+    if (WillNotOverflowSignedAdd(X, Y, I1)) {
----------------
Why are you mutating the LHS of I?  This is unsafe if it has any other users.

================
Comment at: test/Transforms/InstCombine/rem.ll:229-243
@@ +228,16 @@
+
+define i2 @test22(i2 %c) {
+ %lhs = srem i2 3, %c
+ %rhs = srem i2 2, %c
+ %add = add i2 %lhs, %rhs
+ %mod = srem i2 %add, %c
+ ret i2 %mod
+}
+
+define i4 @test23(i4 %c) {
+ %lhs = srem i4 3, %c
+ %rhs = srem i4 2, %c
+ %add = add i4 %lhs, %rhs
+ %mod = srem i4 %add, %c
+ ret i4 %mod
+}
----------------
You don't have any CHECK statements here.

http://reviews.llvm.org/D5351






More information about the llvm-commits mailing list