Skip to content

Commit c8dc6b5

Browse files
authored
[SDAG] Improve SimplifyDemandedBits for mul (#90034)
If the RHS is a constant with X trailing zeros, then the X MSBs of the LHS are not demanded. Alive2: https://alive2.llvm.org/ce/z/F5CyJW Fixes #56645.
1 parent 831d143 commit c8dc6b5

File tree

10 files changed

+513
-370
lines changed

10 files changed

+513
-370
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2814,10 +2814,16 @@ bool TargetLowering::SimplifyDemandedBits(
28142814
unsigned DemandedBitsLZ = DemandedBits.countl_zero();
28152815
APInt LoMask = APInt::getLowBitsSet(BitWidth, BitWidth - DemandedBitsLZ);
28162816
KnownBits KnownOp0, KnownOp1;
2817-
if (SimplifyDemandedBits(Op0, LoMask, DemandedElts, KnownOp0, TLO,
2818-
Depth + 1) ||
2819-
SimplifyDemandedBits(Op1, LoMask, DemandedElts, KnownOp1, TLO,
2817+
auto GetDemandedBitsLHSMask = [&](APInt Demanded,
2818+
const KnownBits &KnownRHS) {
2819+
if (Op.getOpcode() == ISD::MUL)
2820+
Demanded.clearHighBits(KnownRHS.countMinTrailingZeros());
2821+
return Demanded;
2822+
};
2823+
if (SimplifyDemandedBits(Op1, LoMask, DemandedElts, KnownOp1, TLO,
28202824
Depth + 1) ||
2825+
SimplifyDemandedBits(Op0, GetDemandedBitsLHSMask(LoMask, KnownOp1),
2826+
DemandedElts, KnownOp0, TLO, Depth + 1) ||
28212827
// See if the operation should be performed at a smaller bit width.
28222828
ShrinkDemandedOp(Op, BitWidth, DemandedBits, TLO)) {
28232829
if (Flags.hasNoSignedWrap() || Flags.hasNoUnsignedWrap()) {

0 commit comments

Comments
 (0)