[DAG] Make it clear mul(x,x) knownbits bit[1] == 0 check should be for x is undef only

As raised on rGffd0e464b4b9, if x is poison, this fold is still ok.
This commit is contained in:
Simon Pilgrim 2022-02-01 11:31:42 +00:00
parent f131d4d0d0
commit d83a96f59f
2 changed files with 2 additions and 1 deletions

View File

@ -3082,6 +3082,7 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
Known = computeKnownBits(Op.getOperand(1), DemandedElts, Depth + 1);
Known2 = computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
bool SelfMultiply = Op.getOperand(0) == Op.getOperand(1);
// TODO: SelfMultiply can be poison, but not undef.
SelfMultiply &= isGuaranteedNotToBeUndefOrPoison(
Op.getOperand(0), DemandedElts, false, Depth + 1);
Known = KnownBits::mul(Known, Known2, SelfMultiply);

View File

@ -393,7 +393,7 @@ define <4 x i32> @combine_mul_self_knownbits_vector(<4 x i32> %x) {
ret <4 x i32> %2
}
; mul(x,x) - bit[1] is 0, but if demanding the other bits the source must not be undef/poison
; mul(x,x) - bit[1] is 0, but if demanding the other bits the source must not be undef
define i64 @combine_mul_self_demandedbits(i64 %x) {
; SSE-LABEL: combine_mul_self_demandedbits: