[PATCH] D24565: [InstCombine] PR30366 : Teach the udiv folding logic how to handle constant expressions.

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 23 14:04:43 PDT 2016


spatel accepted this revision.
spatel added a comment.
This revision is now accepted and ready to land.

LGTM. See inline comments for a couple of nits.


================
Comment at: lib/Transforms/InstCombine/InstCombineMulDivRem.cpp:993
@@ -992,3 +992,3 @@
 
 // X udiv (C1 << N), where C1 is "1<<C2"  -->  X >> (N+C2)
 static Instruction *foldUDivShl(Value *Op0, Value *Op1, const BinaryOperator &I,
----------------
It would be helpful to add a comment about the optional zext that we are pattern matching.

================
Comment at: lib/Transforms/InstCombine/InstCombineMulDivRem.cpp:996
@@ -995,12 +995,3 @@
                                 InstCombiner &IC) {
-  Instruction *ShiftLeft = cast<Instruction>(Op1);
-  if (isa<ZExtInst>(ShiftLeft))
-    ShiftLeft = cast<Instruction>(ShiftLeft->getOperand(0));
-
-  const APInt &CI =
-      cast<Constant>(ShiftLeft->getOperand(0))->getUniqueInteger();
-  Value *N = ShiftLeft->getOperand(1);
-  if (CI != 1)
-    N = IC.Builder->CreateAdd(N, ConstantInt::get(N->getType(), CI.logBase2()));
-  if (ZExtInst *Z = dyn_cast<ZExtInst>(Op1))
-    N = IC.Builder->CreateZExt(N, Z->getDestTy());
+  Value *ShiftLeft = nullptr;
+  if (!match(Op1, m_ZExt(m_Value(ShiftLeft))))
----------------
Unnecessary to initialize to nullptr here?


https://reviews.llvm.org/D24565





More information about the llvm-commits mailing list