Skip to content

Commit

Permalink
[SDAG] Improve SimplifyDemandedBits for mul (#90034)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dtcxzyw committed May 22, 2024
1 parent 831d143 commit c8dc6b5
Show file tree
Hide file tree
Showing 10 changed files with 513 additions and 370 deletions.
12 changes: 9 additions & 3 deletions llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2814,10 +2814,16 @@ bool TargetLowering::SimplifyDemandedBits(
unsigned DemandedBitsLZ = DemandedBits.countl_zero();
APInt LoMask = APInt::getLowBitsSet(BitWidth, BitWidth - DemandedBitsLZ);
KnownBits KnownOp0, KnownOp1;
if (SimplifyDemandedBits(Op0, LoMask, DemandedElts, KnownOp0, TLO,
Depth + 1) ||
SimplifyDemandedBits(Op1, LoMask, DemandedElts, KnownOp1, TLO,
auto GetDemandedBitsLHSMask = [&](APInt Demanded,
const KnownBits &KnownRHS) {
if (Op.getOpcode() == ISD::MUL)
Demanded.clearHighBits(KnownRHS.countMinTrailingZeros());
return Demanded;
};
if (SimplifyDemandedBits(Op1, LoMask, DemandedElts, KnownOp1, TLO,
Depth + 1) ||
SimplifyDemandedBits(Op0, GetDemandedBitsLHSMask(LoMask, KnownOp1),
DemandedElts, KnownOp0, TLO, Depth + 1) ||
// See if the operation should be performed at a smaller bit width.
ShrinkDemandedOp(Op, BitWidth, DemandedBits, TLO)) {
if (Flags.hasNoSignedWrap() || Flags.hasNoUnsignedWrap()) {
Expand Down
Loading

0 comments on commit c8dc6b5

Please sign in to comment.