Skip to content

Commit

Permalink
[DAG] Make it clear mul(x,x) knownbits bit[1] == 0 check should be fo…
Browse files Browse the repository at this point in the history
…r x is undef only

As raised on rGffd0e464b4b9, if x is poison, this fold is still ok.
  • Loading branch information
RKSimon committed Feb 1, 2022
1 parent f131d4d commit d83a96f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/X86/combine-mul.ll
Expand Up @@ -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:
Expand Down

0 comments on commit d83a96f

Please sign in to comment.