[llvm-commits] [llvm] r162899 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineMulDivRem.cpp test/Transforms/InstCombine/2012-08-28-udiv_ashl.ll

Nadav Rotem nrotem at apple.com
Thu Aug 30 04:23:20 PDT 2012


Author: nadav
Date: Thu Aug 30 06:23:20 2012
New Revision: 162899

URL: http://llvm.org/viewvc/llvm-project?rev=162899&view=rev
Log:
It is illegal to transform (sdiv (ashr X c1) c2)  -> (sdiv x (2^c1 * c2)),
because C always rounds towards zero.

Thanks Dirk and Ben.


Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
    llvm/trunk/test/Transforms/InstCombine/2012-08-28-udiv_ashl.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp?rev=162899&r1=162898&r2=162899&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Thu Aug 30 06:23:20 2012
@@ -543,16 +543,6 @@
                                           ConstantExpr::getNeg(RHS));
   }
 
-  // Sdiv ((Ashl x, C1) , C2) ->  x / (C2 * 1<<C1);
-  if (ConstantInt *C2 = dyn_cast<ConstantInt>(Op1)) {
-    Value *X;
-    ConstantInt *C1;
-    if (match(Op0, m_AShr(m_Value(X), m_ConstantInt(C1)))) {
-      APInt NC = C2->getValue().shl(C1->getLimitedValue(C1->getBitWidth()-1));
-      return BinaryOperator::CreateSDiv(X, Builder->getInt(NC));
-    }
-  }
-
   // If the sign bits of both operands are zero (i.e. we can prove they are
   // unsigned inputs), turn this into a udiv.
   if (I.getType()->isIntegerTy()) {

Modified: llvm/trunk/test/Transforms/InstCombine/2012-08-28-udiv_ashl.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/2012-08-28-udiv_ashl.ll?rev=162899&r1=162898&r2=162899&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/2012-08-28-udiv_ashl.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/2012-08-28-udiv_ashl.ll Thu Aug 30 06:23:20 2012
@@ -15,15 +15,6 @@
   ret i32 %div1
 }
 
-; CHECK: @sdiv400
-; CHECK: sdiv i32 %x, 400
-; CHECK: ret
-define i32 @sdiv400(i32 %x) {
-entry:
-  %div = ashr i32 %x, 2
-  %div1 = sdiv i32 %div, 100
-  ret i32 %div1
-}
 
 ; CHECK: @udiv400_no
 ; CHECK: ashr
@@ -59,22 +50,6 @@
   ret i80 %div1
 }
 
-; CHECK: @sdiv_i80
-; CHECK: sdiv i80 %x, 400
-; CHECK: ret
-define i80 @sdiv_i80(i80 %x) {
-  %div = ashr i80 %x, 2
-  %div1 = sdiv i80 %div, 100
-  ret i80 %div1
-}
-
-
-define i32 @no_crash_notconst_sdiv(i32 %x, i32 %notconst) {
-  %div = ashr i32 %x, %notconst
-  %div1 = sdiv i32 %div, 100
-  ret i32 %div1
-}
-
 define i32 @no_crash_notconst_udiv(i32 %x, i32 %notconst) {
   %div = lshr i32 %x, %notconst
   %div1 = udiv i32 %div, 100





More information about the llvm-commits mailing list