[llvm-commits] [llvm] r124994 - in /llvm/trunk: lib/Analysis/InstructionSimplify.cpp test/Transforms/InstSimplify/reassociate.ll

Chris Lattner sabre at nondot.org
Sun Feb 6 14:05:31 PST 2011


Author: lattner
Date: Sun Feb  6 16:05:31 2011
New Revision: 124994

URL: http://llvm.org/viewvc/llvm-project?rev=124994&view=rev
Log:
teach instsimplify to transform (X / Y) * Y to X
when the div is an exact udiv.

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

Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=124994&r1=124993&r2=124994&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Sun Feb  6 16:05:31 2011
@@ -735,9 +735,11 @@
   // (X / Y) * Y -> X if the division is exact.
   Value *X = 0, *Y = 0;
   if ((match(Op0, m_SDiv(m_Value(X), m_Value(Y))) && Y == Op1) || // (X / Y) * Y
-      (match(Op1, m_SDiv(m_Value(X), m_Value(Y))) && Y == Op0)) { // Y * (X / Y)
-    BinaryOperator *SDiv = cast<BinaryOperator>(Y == Op1 ? Op0 : Op1);
-    if (SDiv->isExact())
+      (match(Op0, m_UDiv(m_Value(X), m_Value(Y))) && Y == Op1) ||
+      (match(Op1, m_SDiv(m_Value(X), m_Value(Y))) && Y == Op0) || // Y * (X / Y)
+      (match(Op1, m_UDiv(m_Value(X), m_Value(Y))) && Y == Op0)) {
+    BinaryOperator *Div = cast<BinaryOperator>(Y == Op1 ? Op0 : Op1);
+    if (Div->isExact())
       return X;
   }
 

Modified: llvm/trunk/test/Transforms/InstSimplify/reassociate.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/reassociate.ll?rev=124994&r1=124993&r2=124994&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/reassociate.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/reassociate.ll Sun Feb  6 16:05:31 2011
@@ -137,6 +137,7 @@
 ; CHECK: ret i32 %x
 }
 
+
 define i32 @udiv1(i32 %x, i32 %y) {
 ; CHECK: @udiv1
 ; (no overflow X * Y) / Y -> X
@@ -164,3 +165,22 @@
   ret i32 %div
 ; CHECK: ret i32 0
 }
+
+define i32 @udiv4(i32 %x, i32 %y) {
+; CHECK: @udiv4
+; (X / Y) * Y -> X if the division is exact
+  %div = udiv exact i32 %x, %y
+  %mul = mul i32 %div, %y
+  ret i32 %mul
+; CHECK: ret i32 %x
+}
+
+define i32 @udiv5(i32 %x, i32 %y) {
+; CHECK: @udiv5
+; Y * (X / Y) -> X if the division is exact
+  %div = udiv exact i32 %x, %y
+  %mul = mul i32 %y, %div
+  ret i32 %mul
+; CHECK: ret i32 %x
+}
+





More information about the llvm-commits mailing list