]> granicus.if.org Git - llvm/commitdiff
[InstCombine] refactor sdiv by APInt transforms (NFC)
authorSanjay Patel <spatel@rotateright.com>
Mon, 27 Jun 2016 18:38:40 +0000 (18:38 +0000)
committerSanjay Patel <spatel@rotateright.com>
Mon, 27 Jun 2016 18:38:40 +0000 (18:38 +0000)
There's at least one more fold to do here:
https://llvm.org/bugs/show_bug.cgi?id=28153

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273904 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineMulDivRem.cpp

index d7bd80261ab506705c7391bbf0538f840e9adf16..4e5bf7859db628a6c539f4aa3d1e17573c32d3e7 100644 (file)
@@ -1139,16 +1139,17 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) {
   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)) {