Skip to content

Commit 3dea42f

Browse files
authored
[TargetLowering] Don't call SelectionDAG::getTargetLoweringInfo() from TargetLowering methods. NFC (#104197)
If we are inside a TargetLowering method, `SelectionDAG::getTargetLoweringInfo()` should be the same as `this`.
1 parent 9325381 commit 3dea42f

File tree

1 file changed

+21
-32
lines changed

1 file changed

+21
-32
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -598,12 +598,11 @@ bool TargetLowering::ShrinkDemandedOp(SDValue Op, unsigned BitWidth,
598598

599599
// Search for the smallest integer type with free casts to and from
600600
// Op's type. For expedience, just check power-of-2 integer types.
601-
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
602601
unsigned DemandedSize = DemandedBits.getActiveBits();
603602
for (unsigned SmallVTBits = llvm::bit_ceil(DemandedSize);
604603
SmallVTBits < BitWidth; SmallVTBits = NextPowerOf2(SmallVTBits)) {
605604
EVT SmallVT = EVT::getIntegerVT(*DAG.getContext(), SmallVTBits);
606-
if (TLI.isTruncateFree(VT, SmallVT) && TLI.isZExtFree(SmallVT, VT)) {
605+
if (isTruncateFree(VT, SmallVT) && isZExtFree(SmallVT, VT)) {
607606
// We found a type with free casts.
608607
SDValue X = DAG.getNode(
609608
Op.getOpcode(), dl, SmallVT,
@@ -1622,9 +1621,8 @@ bool TargetLowering::SimplifyDemandedBits(
16221621
APInt Ones = APInt::getAllOnes(BitWidth);
16231622
Ones = Op0Opcode == ISD::SHL ? Ones.shl(ShiftAmt)
16241623
: Ones.lshr(ShiftAmt);
1625-
const TargetLowering &TLI = TLO.DAG.getTargetLoweringInfo();
16261624
if ((DemandedBits & C->getAPIntValue()) == (DemandedBits & Ones) &&
1627-
TLI.isDesirableToCommuteXorWithShift(Op.getNode())) {
1625+
isDesirableToCommuteXorWithShift(Op.getNode())) {
16281626
// If the xor constant is a demanded mask, do a 'not' before the
16291627
// shift:
16301628
// xor (X << ShiftC), XorC --> (not X) << ShiftC
@@ -3065,8 +3063,7 @@ bool TargetLowering::SimplifyDemandedVectorElts(
30653063

30663064
KnownUndef = KnownZero = APInt::getZero(NumElts);
30673065

3068-
const TargetLowering &TLI = TLO.DAG.getTargetLoweringInfo();
3069-
if (!TLI.shouldSimplifyDemandedVectorElts(Op, TLO))
3066+
if (!shouldSimplifyDemandedVectorElts(Op, TLO))
30703067
return false;
30713068

30723069
// TODO: For now we assume we know nothing about scalable vectors.
@@ -4162,8 +4159,7 @@ SDValue TargetLowering::optimizeSetCCOfSignedTruncationCheck(
41624159

41634160
// We don't want to do this in every single case.
41644161
SelectionDAG &DAG = DCI.DAG;
4165-
if (!DAG.getTargetLoweringInfo().shouldTransformSignedTruncationCheck(
4166-
XVT, KeptBits))
4162+
if (!shouldTransformSignedTruncationCheck(XVT, KeptBits))
41674163
return SDValue();
41684164

41694165
// Unfold into: sext_inreg(%x) cond %x
@@ -4187,10 +4183,9 @@ SDValue TargetLowering::optimizeSetCCByHoistingAndByConstFromLogicalShift(
41874183
SDValue X, C, Y;
41884184

41894185
SelectionDAG &DAG = DCI.DAG;
4190-
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
41914186

41924187
// Look for '(C l>>/<< Y)'.
4193-
auto Match = [&NewShiftOpcode, &X, &C, &Y, &TLI, &DAG](SDValue V) {
4188+
auto Match = [&NewShiftOpcode, &X, &C, &Y, &DAG, this](SDValue V) {
41944189
// The shift should be one-use.
41954190
if (!V.hasOneUse())
41964191
return false;
@@ -4216,7 +4211,7 @@ SDValue TargetLowering::optimizeSetCCByHoistingAndByConstFromLogicalShift(
42164211

42174212
ConstantSDNode *XC =
42184213
isConstOrConstSplat(X, /*AllowUndefs=*/true, /*AllowTruncation=*/true);
4219-
return TLI.shouldProduceAndByConstByHoistingConstFromShiftsLHSOfAnd(
4214+
return shouldProduceAndByConstByHoistingConstFromShiftsLHSOfAnd(
42204215
X, XC, CC, Y, OldShiftOpcode, NewShiftOpcode, DAG);
42214216
};
42224217

@@ -5114,7 +5109,6 @@ SDValue TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
51145109
// Back to non-vector simplifications.
51155110
// TODO: Can we do these for vector splats?
51165111
if (auto *N1C = dyn_cast<ConstantSDNode>(N1.getNode())) {
5117-
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
51185112
const APInt &C1 = N1C->getAPIntValue();
51195113
EVT ShValTy = N0.getValueType();
51205114

@@ -5132,7 +5126,7 @@ SDValue TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
51325126
// Perform the xform if the AND RHS is a single bit.
51335127
unsigned ShCt = AndRHS->getAPIntValue().logBase2();
51345128
if (AndRHS->getAPIntValue().isPowerOf2() &&
5135-
!TLI.shouldAvoidTransformToShift(ShValTy, ShCt)) {
5129+
!shouldAvoidTransformToShift(ShValTy, ShCt)) {
51365130
return DAG.getNode(
51375131
ISD::TRUNCATE, dl, VT,
51385132
DAG.getNode(ISD::SRL, dl, ShValTy, N0,
@@ -5142,8 +5136,7 @@ SDValue TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
51425136
// (X & 8) == 8 --> (X & 8) >> 3
51435137
// Perform the xform if C1 is a single bit.
51445138
unsigned ShCt = C1.logBase2();
5145-
if (C1.isPowerOf2() &&
5146-
!TLI.shouldAvoidTransformToShift(ShValTy, ShCt)) {
5139+
if (C1.isPowerOf2() && !shouldAvoidTransformToShift(ShValTy, ShCt)) {
51475140
return DAG.getNode(
51485141
ISD::TRUNCATE, dl, VT,
51495142
DAG.getNode(ISD::SRL, dl, ShValTy, N0,
@@ -5162,7 +5155,7 @@ SDValue TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
51625155
const APInt &AndRHSC = AndRHS->getAPIntValue();
51635156
if (AndRHSC.isNegatedPowerOf2() && C1.isSubsetOf(AndRHSC)) {
51645157
unsigned ShiftBits = AndRHSC.countr_zero();
5165-
if (!TLI.shouldAvoidTransformToShift(ShValTy, ShiftBits)) {
5158+
if (!shouldAvoidTransformToShift(ShValTy, ShiftBits)) {
51665159
SDValue Shift = DAG.getNode(
51675160
ISD::SRL, dl, ShValTy, N0.getOperand(0),
51685161
DAG.getShiftAmountConstant(ShiftBits, ShValTy, dl));
@@ -5191,7 +5184,7 @@ SDValue TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
51915184
NewC.lshrInPlace(ShiftBits);
51925185
if (ShiftBits && NewC.getSignificantBits() <= 64 &&
51935186
isLegalICmpImmediate(NewC.getSExtValue()) &&
5194-
!TLI.shouldAvoidTransformToShift(ShValTy, ShiftBits)) {
5187+
!shouldAvoidTransformToShift(ShValTy, ShiftBits)) {
51955188
SDValue Shift =
51965189
DAG.getNode(ISD::SRL, dl, ShValTy, N0,
51975190
DAG.getShiftAmountConstant(ShiftBits, ShValTy, dl));
@@ -6234,8 +6227,7 @@ SDValue TargetLowering::BuildSDIVPow2(SDNode *N, const APInt &Divisor,
62346227
SelectionDAG &DAG,
62356228
SmallVectorImpl<SDNode *> &Created) const {
62366229
AttributeList Attr = DAG.getMachineFunction().getFunction().getAttributes();
6237-
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
6238-
if (TLI.isIntDivCheap(N->getValueType(0), Attr))
6230+
if (isIntDivCheap(N->getValueType(0), Attr))
62396231
return SDValue(N, 0); // Lower SDIV as SDIV
62406232
return SDValue();
62416233
}
@@ -6245,8 +6237,7 @@ TargetLowering::BuildSREMPow2(SDNode *N, const APInt &Divisor,
62456237
SelectionDAG &DAG,
62466238
SmallVectorImpl<SDNode *> &Created) const {
62476239
AttributeList Attr = DAG.getMachineFunction().getFunction().getAttributes();
6248-
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
6249-
if (TLI.isIntDivCheap(N->getValueType(0), Attr))
6240+
if (isIntDivCheap(N->getValueType(0), Attr))
62506241
return SDValue(N, 0); // Lower SREM as SREM
62516242
return SDValue();
62526243
}
@@ -11746,35 +11737,34 @@ bool TargetLowering::LegalizeSetCCCondCode(SelectionDAG &DAG, EVT VT,
1174611737
SDValue EVL, bool &NeedInvert,
1174711738
const SDLoc &dl, SDValue &Chain,
1174811739
bool IsSignaling) const {
11749-
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
1175011740
MVT OpVT = LHS.getSimpleValueType();
1175111741
ISD::CondCode CCCode = cast<CondCodeSDNode>(CC)->get();
1175211742
NeedInvert = false;
1175311743
assert(!EVL == !Mask && "VP Mask and EVL must either both be set or unset");
1175411744
bool IsNonVP = !EVL;
11755-
switch (TLI.getCondCodeAction(CCCode, OpVT)) {
11745+
switch (getCondCodeAction(CCCode, OpVT)) {
1175611746
default:
1175711747
llvm_unreachable("Unknown condition code action!");
1175811748
case TargetLowering::Legal:
1175911749
// Nothing to do.
1176011750
break;
1176111751
case TargetLowering::Expand: {
1176211752
ISD::CondCode InvCC = ISD::getSetCCSwappedOperands(CCCode);
11763-
if (TLI.isCondCodeLegalOrCustom(InvCC, OpVT)) {
11753+
if (isCondCodeLegalOrCustom(InvCC, OpVT)) {
1176411754
std::swap(LHS, RHS);
1176511755
CC = DAG.getCondCode(InvCC);
1176611756
return true;
1176711757
}
1176811758
// Swapping operands didn't work. Try inverting the condition.
1176911759
bool NeedSwap = false;
1177011760
InvCC = getSetCCInverse(CCCode, OpVT);
11771-
if (!TLI.isCondCodeLegalOrCustom(InvCC, OpVT)) {
11761+
if (!isCondCodeLegalOrCustom(InvCC, OpVT)) {
1177211762
// If inverting the condition is not enough, try swapping operands
1177311763
// on top of it.
1177411764
InvCC = ISD::getSetCCSwappedOperands(InvCC);
1177511765
NeedSwap = true;
1177611766
}
11777-
if (TLI.isCondCodeLegalOrCustom(InvCC, OpVT)) {
11767+
if (isCondCodeLegalOrCustom(InvCC, OpVT)) {
1177811768
CC = DAG.getCondCode(InvCC);
1177911769
NeedInvert = true;
1178011770
if (NeedSwap)
@@ -11788,18 +11778,18 @@ bool TargetLowering::LegalizeSetCCCondCode(SelectionDAG &DAG, EVT VT,
1178811778
default:
1178911779
llvm_unreachable("Don't know how to expand this condition!");
1179011780
case ISD::SETUO:
11791-
if (TLI.isCondCodeLegal(ISD::SETUNE, OpVT)) {
11781+
if (isCondCodeLegal(ISD::SETUNE, OpVT)) {
1179211782
CC1 = ISD::SETUNE;
1179311783
CC2 = ISD::SETUNE;
1179411784
Opc = ISD::OR;
1179511785
break;
1179611786
}
11797-
assert(TLI.isCondCodeLegal(ISD::SETOEQ, OpVT) &&
11787+
assert(isCondCodeLegal(ISD::SETOEQ, OpVT) &&
1179811788
"If SETUE is expanded, SETOEQ or SETUNE must be legal!");
1179911789
NeedInvert = true;
1180011790
[[fallthrough]];
1180111791
case ISD::SETO:
11802-
assert(TLI.isCondCodeLegal(ISD::SETOEQ, OpVT) &&
11792+
assert(isCondCodeLegal(ISD::SETOEQ, OpVT) &&
1180311793
"If SETO is expanded, SETOEQ must be legal!");
1180411794
CC1 = ISD::SETOEQ;
1180511795
CC2 = ISD::SETOEQ;
@@ -11812,9 +11802,8 @@ bool TargetLowering::LegalizeSetCCCondCode(SelectionDAG &DAG, EVT VT,
1181211802
// of SETOGT/SETOLT to be legal, the other can be emulated by swapping
1181311803
// the operands.
1181411804
CC2 = ((unsigned)CCCode & 0x8U) ? ISD::SETUO : ISD::SETO;
11815-
if (!TLI.isCondCodeLegal(CC2, OpVT) &&
11816-
(TLI.isCondCodeLegal(ISD::SETOGT, OpVT) ||
11817-
TLI.isCondCodeLegal(ISD::SETOLT, OpVT))) {
11805+
if (!isCondCodeLegal(CC2, OpVT) && (isCondCodeLegal(ISD::SETOGT, OpVT) ||
11806+
isCondCodeLegal(ISD::SETOLT, OpVT))) {
1181811807
CC1 = ISD::SETOGT;
1181911808
CC2 = ISD::SETOLT;
1182011809
Opc = ISD::OR;

0 commit comments

Comments
 (0)