Skip to content

Commit

Permalink
[X86] SimplifyDemandedBits - move MaskedValueIsZero as late as possib…
Browse files Browse the repository at this point in the history
…le to avoid unnecessary (recursive) analysis costs. NFC.

Mentioned on D155472 for the SHL equivalent
  • Loading branch information
RKSimon committed Aug 18, 2023
1 parent a834b79 commit bd9bf9c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1886,15 +1886,15 @@ bool TargetLowering::SimplifyDemandedBits(

// Narrow shift to lower half - similar to ShrinkDemandedOp.
// (srl i64:x, K) -> (i64 zero_extend (srl (i32 (trunc i64:x)), K))
if ((BitWidth % 2) == 0 && !VT.isVector() &&
((InDemandedMask.countLeadingZeros() >= (BitWidth / 2)) ||
TLO.DAG.MaskedValueIsZero(
Op0, APInt::getHighBitsSet(BitWidth, BitWidth / 2)))) {
if ((BitWidth % 2) == 0 && !VT.isVector()) {
APInt HiBits = APInt::getHighBitsSet(BitWidth, BitWidth / 2);
EVT HalfVT = EVT::getIntegerVT(*TLO.DAG.getContext(), BitWidth / 2);
if (isNarrowingProfitable(VT, HalfVT) &&
isTypeDesirableForOp(ISD::SRL, HalfVT) &&
isTruncateFree(VT, HalfVT) && isZExtFree(HalfVT, VT) &&
(!TLO.LegalOperations() || isOperationLegal(ISD::SRL, VT))) {
(!TLO.LegalOperations() || isOperationLegal(ISD::SRL, VT)) &&
((InDemandedMask.countLeadingZeros() >= (BitWidth / 2)) ||
TLO.DAG.MaskedValueIsZero(Op0, HiBits))) {
SDValue NewOp = TLO.DAG.getNode(ISD::TRUNCATE, dl, HalfVT, Op0);
SDValue NewShiftAmt = TLO.DAG.getShiftAmountConstant(
ShAmt, HalfVT, dl, TLO.LegalTypes());
Expand Down

0 comments on commit bd9bf9c

Please sign in to comment.