[llvm] r217937 - InstSimplify: ((X % Y) % Y) -> (X % Y)

David Majnemer david.majnemer at gmail.com
Tue Sep 16 20:34:35 PDT 2014


Author: majnemer
Date: Tue Sep 16 22:34:34 2014
New Revision: 217937

URL: http://llvm.org/viewvc/llvm-project?rev=217937&view=rev
Log:
InstSimplify: ((X % Y) % Y) -> (X % Y)

Patch by Sonam Kumari!

Differential Revision: http://reviews.llvm.org/D5350

Modified:
    llvm/trunk/lib/Analysis/InstructionSimplify.cpp
    llvm/trunk/test/Transforms/InstSimplify/rem.ll

Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=217937&r1=217936&r2=217937&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Tue Sep 16 22:34:34 2014
@@ -1171,6 +1171,11 @@ static Value *SimplifyRem(Instruction::B
   if (Op0 == Op1)
     return Constant::getNullValue(Op0->getType());
 
+  // ((X % Y) % Y) -> (X % Y)
+  if (match(Op0, m_SRem(m_Value(), m_Specific(Op1)))) {
+    return Op0;
+  }
+
   // If the operation is with the result of a select instruction, check whether
   // operating on either branch of the select always yields the same value.
   if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))

Modified: llvm/trunk/test/Transforms/InstSimplify/rem.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/rem.ll?rev=217937&r1=217936&r2=217937&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/rem.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/rem.ll Tue Sep 16 22:34:34 2014
@@ -15,3 +15,12 @@ define i32 @select2(i32 %x, i1 %b) {
   ret i32 %rem
 ; CHECK: ret i32 0
 }
+
+define i32 @select3(i32 %x, i32 %n) {
+; CHECK-LABEL: @select3(
+; CHECK-NEXT: %mod = srem i32 %x, %n
+; CHECK-NEXT: ret i32 %mod
+ %mod = srem i32 %x, %n
+ %mod1 = srem i32 %mod, %n
+ ret i32 %mod1
+}





More information about the llvm-commits mailing list