[llvm] [SelectionDAG] Handle more opcodes in isGuaranteedNotToBeUndefOrPoison (PR #147019)
Björn Pettersson via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 5 08:00:40 PDT 2025
================
@@ -5480,6 +5557,52 @@ bool SelectionDAG::isGuaranteedNotToBeUndefOrPoison(SDValue Op,
return true;
}
+ case ISD::SHL:
+ case ISD::SRL:
+ case ISD::SRA:
+ // Shift amount operand is checked by canCreateUndefOrPoison. So it is
+ // enough to check operand 0 if Op can't create undef/poison.
+ return !canCreateUndefOrPoison(Op, DemandedElts, PoisonOnly,
+ /*ConsiderFlags*/ true, Depth) &&
+ isGuaranteedNotToBeUndefOrPoison(Op.getOperand(0), DemandedElts,
+ PoisonOnly, Depth + 1);
+
+ case ISD::BSWAP:
+ case ISD::CTPOP:
+ case ISD::BITREVERSE:
+ case ISD::AND:
+ case ISD::OR:
+ case ISD::XOR:
+ case ISD::ADD:
+ case ISD::SUB:
+ case ISD::MUL:
+ case ISD::SADDSAT:
+ case ISD::UADDSAT:
+ case ISD::SSUBSAT:
+ case ISD::USUBSAT:
+ case ISD::SSHLSAT:
+ case ISD::USHLSAT:
+ case ISD::SMIN:
+ case ISD::SMAX:
+ case ISD::UMIN:
+ case ISD::UMAX:
+ case ISD::ZERO_EXTEND:
+ case ISD::SIGN_EXTEND:
+ case ISD::ANY_EXTEND:
----------------
bjope wrote:
Including it here merely makes it pass on the DemandedElts in the canCreateUndefOrPoison call (instead of ending up in the default canCreateUndefOrPoison check without DemandedElts at the end). So having it here make sense to me, as it would be correct even if we update canCreateUndefOrPoison in the future.
Btw, maybe canCreateUndefOrPoison actually should be updated handle ANY_EXTEND and return false for PoisonOnly. Not quite sure for the !PoisonOnly situation. The upper bits is undefined, but should the result of ANY_EXTEND really be considered as "Undef"?
https://github.com/llvm/llvm-project/pull/147019
More information about the llvm-commits
mailing list