[PATCH] D23134: Make cltz and cttz zero undef when the operand cannot be zero in InstCombine

Amaury SECHET via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 8 00:53:16 PDT 2016


deadalnix added inline comments.

================
Comment at: lib/Transforms/InstCombine/InstCombineCalls.cpp:1240-1253
@@ -1239,2 +1239,16 @@
 
+static void makeCttzCtlzZeroUndef(InstCombiner &IC, IntrinsicInst *II) {
+  assert((II->getIntrinsicID() == Intrinsic::cttz ||
+          II->getIntrinsicID() == Intrinsic::ctlz) &&
+         "Expected cttz or ctlz intrinsic");
+  bool IsZeroUndef = false;
+  Value *Op1 = II->getArgOperand(1);
+  if (auto *Op1C = dyn_cast<ConstantInt>(Op1))
+    IsZeroUndef = Op1C->getZExtValue() != 0;
+  if (!IsZeroUndef) {
+    IC.Worklist.Add(II);
+    II->setOperand(1, ConstantInt::getAllOnesValue(Op1->getType()));
+  }
+}
+
 /// CallInst simplification. This mostly only handles folding of intrinsic
----------------
spatel wrote:
> deadalnix wrote:
> > spatel wrote:
> > > OK, then:
> > >   if (match(II->getArgOperand(1), m_Zero()))
> > >     II->setArgOperand(1, ConstantInt::getTrue(II->getContext()));
> > > 
> > I'd rather match everything that is NOT true, just in case.
> Sorry - I don't see the difference between the 'm_Zero' version and this?
> 
> Note that I checked in the refactoring in rL277883. We have too many LLVM bugs due to code duplication, and this function may continue to grow over time.
Alright, I'll rebase on top of it.

Not all value are true or false, so matching what is NOT true is not the same as matching false.


https://reviews.llvm.org/D23134





More information about the llvm-commits mailing list