[llvm] [InstCombine] Set zero_is_poison for ctlz/cttz if they are only used as shift amounts (PR #85035)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 13 01:46:00 PDT 2024


================
@@ -1948,11 +1948,20 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
     break;
 
   case Intrinsic::cttz:
-  case Intrinsic::ctlz:
+  case Intrinsic::ctlz: {
+    // If ctlz/cttz is only used as a shift amount, set is_zero_poison to true.
+    bool Changed = false;
+    if (II->hasOneUse() && match(II->getArgOperand(1), m_Zero()) &&
+        match(II->user_back(), m_Shift(m_Value(), m_Specific(II)))) {
+      replaceOperand(*II, 1, Builder.getTrue());
+      Changed = true;
+    }
----------------
dtcxzyw wrote:

Done.

https://github.com/llvm/llvm-project/pull/85035


More information about the llvm-commits mailing list