[llvm] r273904 - [InstCombine] refactor sdiv by APInt transforms (NFC)

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 27 11:38:40 PDT 2016


Author: spatel
Date: Mon Jun 27 13:38:40 2016
New Revision: 273904

URL: http://llvm.org/viewvc/llvm-project?rev=273904&view=rev
Log:
[InstCombine] refactor sdiv by APInt transforms (NFC)

There's at least one more fold to do here:
https://llvm.org/bugs/show_bug.cgi?id=28153

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp?rev=273904&r1=273903&r2=273904&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Mon Jun 27 13:38:40 2016
@@ -1139,16 +1139,17 @@ Instruction *InstCombiner::visitSDiv(Bin
   if (Instruction *Common = commonIDivTransforms(I))
     return Common;
 
-  // sdiv X, -1 == -X
-  if (match(Op1, m_AllOnes()))
-    return BinaryOperator::CreateNeg(Op0);
-
-  // sdiv exact X, C  -->  ashr exact X, log2(C)
   const APInt *Op1C;
-  if (match(Op1, m_APInt(Op1C)) && I.isExact() && Op1C->isNonNegative() &&
-      Op1C->isPowerOf2()) {
-    Value *ShAmt = ConstantInt::get(Op1->getType(), Op1C->exactLogBase2());
-    return BinaryOperator::CreateExactAShr(Op0, ShAmt, I.getName());
+  if (match(Op1, m_APInt(Op1C))) {
+    // sdiv X, -1 == -X
+    if (Op1C->isAllOnesValue())
+      return BinaryOperator::CreateNeg(Op0);
+
+    // sdiv exact X, C  -->  ashr exact X, log2(C)
+    if (I.isExact() && Op1C->isNonNegative() && Op1C->isPowerOf2()) {
+      Value *ShAmt = ConstantInt::get(Op1->getType(), Op1C->exactLogBase2());
+      return BinaryOperator::CreateExactAShr(Op0, ShAmt, I.getName());
+    }
   }
 
   if (Constant *RHS = dyn_cast<Constant>(Op1)) {




More information about the llvm-commits mailing list