[llvm] [DAG] canCreateUndefOrPoison - add handling for CTTZ/CTLZ nodes (PR #146361)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 30 08:09:10 PDT 2025


================
@@ -5618,6 +5620,14 @@ bool SelectionDAG::canCreateUndefOrPoison(SDValue Op, const APInt &DemandedElts,
                                              PoisonOnly, Depth + 1) ||
            !getValidMaximumShiftAmount(Op, DemandedElts, Depth + 1);
 
+  case ISD::CTTZ_ZERO_UNDEF:
+  case ISD::CTLZ_ZERO_UNDEF:
+    // If the amount is zero then the result will be poison.
+    // TODO: Add isKnownNeverZero DemandedElts handling.
+    return !isGuaranteedNotToBeUndefOrPoison(Op.getOperand(0), DemandedElts,
+                                             PoisonOnly, Depth + 1) ||
----------------
nikic wrote:

canCreateUndefOrPoison() shouldn't be checking isGuaranteedNotToBeUndefOrPoison(). If the operand is already poison, then it's not creating new poison. If it's undef, then it's not known non-zero. (Also applies to shift handling above.)

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


More information about the llvm-commits mailing list