Skip to content

Commit 2bcd160

Browse files
RKSimonPhilippRados
authored andcommitted
[DAG] SimplifyDemandedBits - ignore SRL node if we're just demanding known sign bits (llvm#114805)
Check to see if we are only demanding (shifted) signbits from a SRL node that are also signbits in the source node. We can't demand any upper zero bits that the SRL will shift in (up to max shift amount), and the lower demanded bits bound must already be all signbits. Same fold as llvm#114389 which added this for SimplifyMultipleUseDemandedBits
1 parent 0ae38d1 commit 2bcd160

File tree

2 files changed

+305
-313
lines changed

2 files changed

+305
-313
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,6 +2030,21 @@ bool TargetLowering::SimplifyDemandedBits(
20302030
Known = TLO.DAG.computeKnownBits(Op, DemandedElts, Depth);
20312031
}
20322032

2033+
// If we are only demanding sign bits then we can use the shift source
2034+
// directly.
2035+
if (std::optional<uint64_t> MaxSA =
2036+
TLO.DAG.getValidMaximumShiftAmount(Op, DemandedElts, Depth + 1)) {
2037+
unsigned ShAmt = *MaxSA;
2038+
// Must already be signbits in DemandedBits bounds, and can't demand any
2039+
// shifted in zeroes.
2040+
if (DemandedBits.countl_zero() >= ShAmt) {
2041+
unsigned NumSignBits =
2042+
TLO.DAG.ComputeNumSignBits(Op0, DemandedElts, Depth + 1);
2043+
if (DemandedBits.countr_zero() >= (BitWidth - NumSignBits))
2044+
return TLO.CombineTo(Op, Op0);
2045+
}
2046+
}
2047+
20332048
// Try to match AVG patterns (after shift simplification).
20342049
if (SDValue AVG = combineShiftToAVG(Op, TLO, *this, DemandedBits,
20352050
DemandedElts, Depth + 1))

0 commit comments

Comments
 (0)