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

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 5 14:05:30 PDT 2016


spatel 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
----------------
OK, then:
  if (match(II->getArgOperand(1), m_Zero()))
    II->setArgOperand(1, ConstantInt::getTrue(II->getContext()));



https://reviews.llvm.org/D23134





More information about the llvm-commits mailing list