[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
Fri Aug 5 10:36:10 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:
> Can't this function simplify to one line of code?
>   II->setArgOperand(1, ConstantInt::getTrue(II->getContext()));
> 
> Ie, you don't even need to check the current value of the undef operand. If it's already true, setting it again does nothing.
No, you want to patch this only once, not every time, or it'll never terminate.


https://reviews.llvm.org/D23134





More information about the llvm-commits mailing list