Skip to content

Commit 7d4733a

Browse files
committed
[X86] LowerBUILD_VECTOR - share the same SDLoc argument instead of recreating it over and over again.
1 parent a643ab8 commit 7d4733a

File tree

1 file changed

+42
-45
lines changed

1 file changed

+42
-45
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7135,6 +7135,7 @@ static bool isFoldableUseOfShuffle(SDNode *N) {
71357135
/// The VBROADCAST node is returned when a pattern is found,
71367136
/// or SDValue() otherwise.
71377137
static SDValue lowerBuildVectorAsBroadcast(BuildVectorSDNode *BVOp,
7138+
const SDLoc &dl,
71387139
const X86Subtarget &Subtarget,
71397140
SelectionDAG &DAG) {
71407141
// VBROADCAST requires AVX.
@@ -7145,8 +7146,6 @@ static SDValue lowerBuildVectorAsBroadcast(BuildVectorSDNode *BVOp,
71457146

71467147
MVT VT = BVOp->getSimpleValueType(0);
71477148
unsigned NumElts = VT.getVectorNumElements();
7148-
SDLoc dl(BVOp);
7149-
71507149
assert((VT.is128BitVector() || VT.is256BitVector() || VT.is512BitVector()) &&
71517150
"Unsupported vector type for broadcast.");
71527151

@@ -7492,14 +7491,13 @@ static SDValue LowerBUILD_VECTORvXbf16(SDValue Op, SelectionDAG &DAG,
74927491
}
74937492

74947493
// Lower BUILD_VECTOR operation for v8i1 and v16i1 types.
7495-
static SDValue LowerBUILD_VECTORvXi1(SDValue Op, SelectionDAG &DAG,
7494+
static SDValue LowerBUILD_VECTORvXi1(SDValue Op, const SDLoc &dl,
7495+
SelectionDAG &DAG,
74967496
const X86Subtarget &Subtarget) {
74977497

74987498
MVT VT = Op.getSimpleValueType();
74997499
assert((VT.getVectorElementType() == MVT::i1) &&
75007500
"Unexpected type in LowerBUILD_VECTORvXi1!");
7501-
7502-
SDLoc dl(Op);
75037501
if (ISD::isBuildVectorAllZeros(Op.getNode()) ||
75047502
ISD::isBuildVectorAllOnes(Op.getNode()))
75057503
return Op;
@@ -7618,7 +7616,7 @@ LLVM_ATTRIBUTE_UNUSED static bool isHorizOp(unsigned Opcode) {
76187616
/// See the corrected implementation in isHopBuildVector(). Can we reduce this
76197617
/// code because it is only used for partial h-op matching now?
76207618
static bool isHorizontalBinOpPart(const BuildVectorSDNode *N, unsigned Opcode,
7621-
SelectionDAG &DAG,
7619+
const SDLoc &DL, SelectionDAG &DAG,
76227620
unsigned BaseIdx, unsigned LastIdx,
76237621
SDValue &V0, SDValue &V1) {
76247622
EVT VT = N->getValueType(0);
@@ -7928,6 +7926,7 @@ static bool isFMAddSubOrFMSubAdd(const X86Subtarget &Subtarget,
79287926
/// 'fsubadd' operation accordingly to X86ISD::ADDSUB or X86ISD::FMADDSUB or
79297927
/// X86ISD::FMSUBADD node.
79307928
static SDValue lowerToAddSubOrFMAddSub(const BuildVectorSDNode *BV,
7929+
const SDLoc &DL,
79317930
const X86Subtarget &Subtarget,
79327931
SelectionDAG &DAG) {
79337932
SDValue Opnd0, Opnd1;
@@ -7938,7 +7937,6 @@ static SDValue lowerToAddSubOrFMAddSub(const BuildVectorSDNode *BV,
79387937
return SDValue();
79397938

79407939
MVT VT = BV->getSimpleValueType(0);
7941-
SDLoc DL(BV);
79427940

79437941
// Try to generate X86ISD::FMADDSUB node here.
79447942
SDValue Opnd2;
@@ -8057,22 +8055,22 @@ static bool isHopBuildVector(const BuildVectorSDNode *BV, SelectionDAG &DAG,
80578055
}
80588056

80598057
static SDValue getHopForBuildVector(const BuildVectorSDNode *BV,
8060-
SelectionDAG &DAG, unsigned HOpcode,
8061-
SDValue V0, SDValue V1) {
8058+
const SDLoc &DL, SelectionDAG &DAG,
8059+
unsigned HOpcode, SDValue V0, SDValue V1) {
80628060
// If either input vector is not the same size as the build vector,
80638061
// extract/insert the low bits to the correct size.
80648062
// This is free (examples: zmm --> xmm, xmm --> ymm).
80658063
MVT VT = BV->getSimpleValueType(0);
80668064
unsigned Width = VT.getSizeInBits();
80678065
if (V0.getValueSizeInBits() > Width)
8068-
V0 = extractSubVector(V0, 0, DAG, SDLoc(BV), Width);
8066+
V0 = extractSubVector(V0, 0, DAG, DL, Width);
80698067
else if (V0.getValueSizeInBits() < Width)
8070-
V0 = insertSubVector(DAG.getUNDEF(VT), V0, 0, DAG, SDLoc(BV), Width);
8068+
V0 = insertSubVector(DAG.getUNDEF(VT), V0, 0, DAG, DL, Width);
80718069

80728070
if (V1.getValueSizeInBits() > Width)
8073-
V1 = extractSubVector(V1, 0, DAG, SDLoc(BV), Width);
8071+
V1 = extractSubVector(V1, 0, DAG, DL, Width);
80748072
else if (V1.getValueSizeInBits() < Width)
8075-
V1 = insertSubVector(DAG.getUNDEF(VT), V1, 0, DAG, SDLoc(BV), Width);
8073+
V1 = insertSubVector(DAG.getUNDEF(VT), V1, 0, DAG, DL, Width);
80768074

80778075
unsigned NumElts = VT.getVectorNumElements();
80788076
APInt DemandedElts = APInt::getAllOnes(NumElts);
@@ -8084,17 +8082,17 @@ static SDValue getHopForBuildVector(const BuildVectorSDNode *BV,
80848082
unsigned HalfNumElts = NumElts / 2;
80858083
if (VT.is256BitVector() && DemandedElts.lshr(HalfNumElts) == 0) {
80868084
MVT HalfVT = VT.getHalfNumVectorElementsVT();
8087-
V0 = extractSubVector(V0, 0, DAG, SDLoc(BV), 128);
8088-
V1 = extractSubVector(V1, 0, DAG, SDLoc(BV), 128);
8089-
SDValue Half = DAG.getNode(HOpcode, SDLoc(BV), HalfVT, V0, V1);
8090-
return insertSubVector(DAG.getUNDEF(VT), Half, 0, DAG, SDLoc(BV), 256);
8085+
V0 = extractSubVector(V0, 0, DAG, DL, 128);
8086+
V1 = extractSubVector(V1, 0, DAG, DL, 128);
8087+
SDValue Half = DAG.getNode(HOpcode, DL, HalfVT, V0, V1);
8088+
return insertSubVector(DAG.getUNDEF(VT), Half, 0, DAG, DL, 256);
80918089
}
80928090

8093-
return DAG.getNode(HOpcode, SDLoc(BV), VT, V0, V1);
8091+
return DAG.getNode(HOpcode, DL, VT, V0, V1);
80948092
}
80958093

80968094
/// Lower BUILD_VECTOR to a horizontal add/sub operation if possible.
8097-
static SDValue LowerToHorizontalOp(const BuildVectorSDNode *BV,
8095+
static SDValue LowerToHorizontalOp(const BuildVectorSDNode *BV, const SDLoc &DL,
80988096
const X86Subtarget &Subtarget,
80998097
SelectionDAG &DAG) {
81008098
// We need at least 2 non-undef elements to make this worthwhile by default.
@@ -8114,7 +8112,7 @@ static SDValue LowerToHorizontalOp(const BuildVectorSDNode *BV,
81148112
unsigned HOpcode;
81158113
SDValue V0, V1;
81168114
if (isHopBuildVector(BV, DAG, HOpcode, V0, V1))
8117-
return getHopForBuildVector(BV, DAG, HOpcode, V0, V1);
8115+
return getHopForBuildVector(BV, DL, DAG, HOpcode, V0, V1);
81188116
}
81198117

81208118
// Try harder to match 256-bit ops by using extract/concat.
@@ -8134,22 +8132,21 @@ static SDValue LowerToHorizontalOp(const BuildVectorSDNode *BV,
81348132
if (BV->getOperand(i)->isUndef())
81358133
NumUndefsHI++;
81368134

8137-
SDLoc DL(BV);
81388135
SDValue InVec0, InVec1;
81398136
if (VT == MVT::v8i32 || VT == MVT::v16i16) {
81408137
SDValue InVec2, InVec3;
81418138
unsigned X86Opcode;
81428139
bool CanFold = true;
81438140

8144-
if (isHorizontalBinOpPart(BV, ISD::ADD, DAG, 0, Half, InVec0, InVec1) &&
8145-
isHorizontalBinOpPart(BV, ISD::ADD, DAG, Half, NumElts, InVec2,
8141+
if (isHorizontalBinOpPart(BV, ISD::ADD, DL, DAG, 0, Half, InVec0, InVec1) &&
8142+
isHorizontalBinOpPart(BV, ISD::ADD, DL, DAG, Half, NumElts, InVec2,
81468143
InVec3) &&
81478144
((InVec0.isUndef() || InVec2.isUndef()) || InVec0 == InVec2) &&
81488145
((InVec1.isUndef() || InVec3.isUndef()) || InVec1 == InVec3))
81498146
X86Opcode = X86ISD::HADD;
8150-
else if (isHorizontalBinOpPart(BV, ISD::SUB, DAG, 0, Half, InVec0,
8147+
else if (isHorizontalBinOpPart(BV, ISD::SUB, DL, DAG, 0, Half, InVec0,
81518148
InVec1) &&
8152-
isHorizontalBinOpPart(BV, ISD::SUB, DAG, Half, NumElts, InVec2,
8149+
isHorizontalBinOpPart(BV, ISD::SUB, DL, DAG, Half, NumElts, InVec2,
81538150
InVec3) &&
81548151
((InVec0.isUndef() || InVec2.isUndef()) || InVec0 == InVec2) &&
81558152
((InVec1.isUndef() || InVec3.isUndef()) || InVec1 == InVec3))
@@ -8179,15 +8176,16 @@ static SDValue LowerToHorizontalOp(const BuildVectorSDNode *BV,
81798176
if (VT == MVT::v8f32 || VT == MVT::v4f64 || VT == MVT::v8i32 ||
81808177
VT == MVT::v16i16) {
81818178
unsigned X86Opcode;
8182-
if (isHorizontalBinOpPart(BV, ISD::ADD, DAG, 0, NumElts, InVec0, InVec1))
8179+
if (isHorizontalBinOpPart(BV, ISD::ADD, DL, DAG, 0, NumElts, InVec0,
8180+
InVec1))
81838181
X86Opcode = X86ISD::HADD;
8184-
else if (isHorizontalBinOpPart(BV, ISD::SUB, DAG, 0, NumElts, InVec0,
8182+
else if (isHorizontalBinOpPart(BV, ISD::SUB, DL, DAG, 0, NumElts, InVec0,
81858183
InVec1))
81868184
X86Opcode = X86ISD::HSUB;
8187-
else if (isHorizontalBinOpPart(BV, ISD::FADD, DAG, 0, NumElts, InVec0,
8185+
else if (isHorizontalBinOpPart(BV, ISD::FADD, DL, DAG, 0, NumElts, InVec0,
81888186
InVec1))
81898187
X86Opcode = X86ISD::FHADD;
8190-
else if (isHorizontalBinOpPart(BV, ISD::FSUB, DAG, 0, NumElts, InVec0,
8188+
else if (isHorizontalBinOpPart(BV, ISD::FSUB, DL, DAG, 0, NumElts, InVec0,
81918189
InVec1))
81928190
X86Opcode = X86ISD::FHSUB;
81938191
else
@@ -8218,10 +8216,9 @@ static SDValue LowerShift(SDValue Op, const X86Subtarget &Subtarget,
82188216
/// NOTE: Its not in our interest to start make a general purpose vectorizer
82198217
/// from this, but enough scalar bit operations are created from the later
82208218
/// legalization + scalarization stages to need basic support.
8221-
static SDValue lowerBuildVectorToBitOp(BuildVectorSDNode *Op,
8219+
static SDValue lowerBuildVectorToBitOp(BuildVectorSDNode *Op, const SDLoc &DL,
82228220
const X86Subtarget &Subtarget,
82238221
SelectionDAG &DAG) {
8224-
SDLoc DL(Op);
82258222
MVT VT = Op->getSimpleValueType(0);
82268223
unsigned NumElems = VT.getVectorNumElements();
82278224
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
@@ -8296,9 +8293,9 @@ static SDValue lowerBuildVectorToBitOp(BuildVectorSDNode *Op,
82968293
/// Create a vector constant without a load. SSE/AVX provide the bare minimum
82978294
/// functionality to do this, so it's all zeros, all ones, or some derivation
82988295
/// that is cheap to calculate.
8299-
static SDValue materializeVectorConstant(SDValue Op, SelectionDAG &DAG,
8296+
static SDValue materializeVectorConstant(SDValue Op, const SDLoc &DL,
8297+
SelectionDAG &DAG,
83008298
const X86Subtarget &Subtarget) {
8301-
SDLoc DL(Op);
83028299
MVT VT = Op.getSimpleValueType();
83038300

83048301
// Vectors containing all zeros can be matched by pxor and xorps.
@@ -8322,7 +8319,7 @@ static SDValue materializeVectorConstant(SDValue Op, SelectionDAG &DAG,
83228319
/// from a vector of source values and a vector of extraction indices.
83238320
/// The vectors might be manipulated to match the type of the permute op.
83248321
static SDValue createVariablePermute(MVT VT, SDValue SrcVec, SDValue IndicesVec,
8325-
SDLoc &DL, SelectionDAG &DAG,
8322+
const SDLoc &DL, SelectionDAG &DAG,
83268323
const X86Subtarget &Subtarget) {
83278324
MVT ShuffleVT = VT;
83288325
EVT IndicesVT = EVT(VT).changeVectorElementTypeToInteger();
@@ -8590,7 +8587,8 @@ static SDValue createVariablePermute(MVT VT, SDValue SrcVec, SDValue IndicesVec,
85908587
// TODO: Utilize pshufb and zero mask blending to support more efficient
85918588
// construction of vectors with constant-0 elements.
85928589
static SDValue
8593-
LowerBUILD_VECTORAsVariablePermute(SDValue V, SelectionDAG &DAG,
8590+
LowerBUILD_VECTORAsVariablePermute(SDValue V, const SDLoc &DL,
8591+
SelectionDAG &DAG,
85948592
const X86Subtarget &Subtarget) {
85958593
SDValue SrcVec, IndicesVec;
85968594
// Check for a match of the permute source vector and permute index elements.
@@ -8629,7 +8627,6 @@ LowerBUILD_VECTORAsVariablePermute(SDValue V, SelectionDAG &DAG,
86298627
return SDValue();
86308628
}
86318629

8632-
SDLoc DL(V);
86338630
MVT VT = V.getSimpleValueType();
86348631
return createVariablePermute(VT, SrcVec, IndicesVec, DL, DAG, Subtarget);
86358632
}
@@ -8645,14 +8642,14 @@ X86TargetLowering::LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const {
86458642

86468643
// Generate vectors for predicate vectors.
86478644
if (VT.getVectorElementType() == MVT::i1 && Subtarget.hasAVX512())
8648-
return LowerBUILD_VECTORvXi1(Op, DAG, Subtarget);
8645+
return LowerBUILD_VECTORvXi1(Op, dl, DAG, Subtarget);
86498646

86508647
if (VT.getVectorElementType() == MVT::bf16 &&
86518648
(Subtarget.hasAVXNECONVERT() || Subtarget.hasBF16()))
86528649
return LowerBUILD_VECTORvXbf16(Op, DAG, Subtarget);
86538650

8654-
if (SDValue VectorConstant = materializeVectorConstant(Op, DAG, Subtarget))
8655-
return VectorConstant;
8651+
if (SDValue VectorCst = materializeVectorConstant(Op, dl, DAG, Subtarget))
8652+
return VectorCst;
86568653

86578654
unsigned EVTBits = EltVT.getSizeInBits();
86588655
APInt UndefMask = APInt::getZero(NumElems);
@@ -8747,13 +8744,13 @@ X86TargetLowering::LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const {
87478744
}
87488745
}
87498746

8750-
if (SDValue AddSub = lowerToAddSubOrFMAddSub(BV, Subtarget, DAG))
8747+
if (SDValue AddSub = lowerToAddSubOrFMAddSub(BV, dl, Subtarget, DAG))
87518748
return AddSub;
8752-
if (SDValue HorizontalOp = LowerToHorizontalOp(BV, Subtarget, DAG))
8749+
if (SDValue HorizontalOp = LowerToHorizontalOp(BV, dl, Subtarget, DAG))
87538750
return HorizontalOp;
8754-
if (SDValue Broadcast = lowerBuildVectorAsBroadcast(BV, Subtarget, DAG))
8751+
if (SDValue Broadcast = lowerBuildVectorAsBroadcast(BV, dl, Subtarget, DAG))
87558752
return Broadcast;
8756-
if (SDValue BitOp = lowerBuildVectorToBitOp(BV, Subtarget, DAG))
8753+
if (SDValue BitOp = lowerBuildVectorToBitOp(BV, dl, Subtarget, DAG))
87578754
return BitOp;
87588755

87598756
unsigned NumZero = ZeroMask.popcount();
@@ -8901,8 +8898,8 @@ X86TargetLowering::LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const {
89018898
if (IsAllConstants)
89028899
return SDValue();
89038900

8904-
if (SDValue V = LowerBUILD_VECTORAsVariablePermute(Op, DAG, Subtarget))
8905-
return V;
8901+
if (SDValue V = LowerBUILD_VECTORAsVariablePermute(Op, dl, DAG, Subtarget))
8902+
return V;
89068903

89078904
// See if we can use a vector load to get all of the elements.
89088905
{

0 commit comments

Comments
 (0)