Skip to content

Commit af1b7eb

Browse files
committed
[TargetLowering] Move a few hasOneUse() tests later to reduce unnecessary computations. NFC.
Many of these cases, an early-out on the much cheaper getOpcode() check will avoid us needing to call hasOneUse() entirely.
1 parent ef906f2 commit af1b7eb

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,7 @@ bool TargetLowering::SimplifyDemandedBits(
17451745
// aren't demanded (as above) and that the shifted upper c1 bits of
17461746
// x aren't demanded.
17471747
// TODO - support non-uniform vector amounts.
1748-
if (Op0.hasOneUse() && InnerOp.getOpcode() == ISD::SRL &&
1748+
if (InnerOp.getOpcode() == ISD::SRL && Op0.hasOneUse() &&
17491749
InnerOp.hasOneUse()) {
17501750
if (const APInt *SA2 =
17511751
TLO.DAG.getValidShiftAmountConstant(InnerOp, DemandedElts)) {
@@ -2375,18 +2375,18 @@ bool TargetLowering::SimplifyDemandedBits(
23752375

23762376
// If the input is only used by this truncate, see if we can shrink it based
23772377
// on the known demanded bits.
2378-
if (Src.getNode()->hasOneUse()) {
2379-
switch (Src.getOpcode()) {
2380-
default:
2378+
switch (Src.getOpcode()) {
2379+
default:
2380+
break;
2381+
case ISD::SRL:
2382+
// Shrink SRL by a constant if none of the high bits shifted in are
2383+
// demanded.
2384+
if (TLO.LegalTypes() && !isTypeDesirableForOp(ISD::SRL, VT))
2385+
// Do not turn (vt1 truncate (vt2 srl)) into (vt1 srl) if vt1 is
2386+
// undesirable.
23812387
break;
2382-
case ISD::SRL:
2383-
// Shrink SRL by a constant if none of the high bits shifted in are
2384-
// demanded.
2385-
if (TLO.LegalTypes() && !isTypeDesirableForOp(ISD::SRL, VT))
2386-
// Do not turn (vt1 truncate (vt2 srl)) into (vt1 srl) if vt1 is
2387-
// undesirable.
2388-
break;
23892388

2389+
if (Src.getNode()->hasOneUse()) {
23902390
const APInt *ShAmtC =
23912391
TLO.DAG.getValidShiftAmountConstant(Src, DemandedElts);
23922392
if (!ShAmtC || ShAmtC->uge(BitWidth))
@@ -2408,8 +2408,8 @@ bool TargetLowering::SimplifyDemandedBits(
24082408
return TLO.CombineTo(
24092409
Op, TLO.DAG.getNode(ISD::SRL, dl, VT, NewTrunc, NewShAmt));
24102410
}
2411-
break;
24122411
}
2412+
break;
24132413
}
24142414

24152415
assert(!Known.hasConflict() && "Bits known to be one AND zero?");

0 commit comments

Comments
 (0)