Skip to content

Commit 7c422dd

Browse files
committed
[X86] shuffle combines - share the same SDLoc argument instead of recreating it over and over again.
1 parent 0636309 commit 7c422dd

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7404,17 +7404,16 @@ static int getUnderlyingExtractedFromVec(SDValue &ExtractedFromVec,
74047404
return Idx;
74057405
}
74067406

7407-
static SDValue buildFromShuffleMostly(SDValue Op, SelectionDAG &DAG) {
7407+
static SDValue buildFromShuffleMostly(SDValue Op, const SDLoc &DL,
7408+
SelectionDAG &DAG) {
74087409
MVT VT = Op.getSimpleValueType();
74097410

74107411
// Skip if insert_vec_elt is not supported.
74117412
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
74127413
if (!TLI.isOperationLegalOrCustom(ISD::INSERT_VECTOR_ELT, VT))
74137414
return SDValue();
74147415

7415-
SDLoc DL(Op);
74167416
unsigned NumElems = Op.getNumOperands();
7417-
74187417
SDValue VecIn1;
74197418
SDValue VecIn2;
74207419
SmallVector<unsigned, 4> InsertIndices;
@@ -9021,7 +9020,7 @@ X86TargetLowering::LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const {
90219020
assert(Values.size() > 1 && "Expected non-undef and non-splat vector");
90229021

90239022
// Check for a build vector from mostly shuffle plus few inserting.
9024-
if (SDValue Sh = buildFromShuffleMostly(Op, DAG))
9023+
if (SDValue Sh = buildFromShuffleMostly(Op, dl, DAG))
90259024
return Sh;
90269025

90279026
// For SSE 4.1, use insertps to put the high elements into the low element.
@@ -39519,12 +39518,12 @@ static SmallVector<int, 4> getPSHUFShuffleMask(SDValue N) {
3951939518
/// We walk up the chain and look for a combinable shuffle, skipping over
3952039519
/// shuffles that we could hoist this shuffle's transformation past without
3952139520
/// altering anything.
39522-
static SDValue
39523-
combineRedundantDWordShuffle(SDValue N, MutableArrayRef<int> Mask,
39524-
SelectionDAG &DAG) {
39521+
static SDValue combineRedundantDWordShuffle(SDValue N,
39522+
MutableArrayRef<int> Mask,
39523+
const SDLoc &DL,
39524+
SelectionDAG &DAG) {
3952539525
assert(N.getOpcode() == X86ISD::PSHUFD &&
3952639526
"Called with something other than an x86 128-bit half shuffle!");
39527-
SDLoc DL(N);
3952839527

3952939528
// Walk up a single-use chain looking for a combinable shuffle. Keep a stack
3953039529
// of the shuffles in the chain so that we can form a fresh chain to replace
@@ -39922,10 +39921,10 @@ static SDValue canonicalizeLaneShuffleWithRepeatedOps(SDValue V,
3992239921
}
3992339922

3992439923
/// Try to combine x86 target specific shuffles.
39925-
static SDValue combineTargetShuffle(SDValue N, SelectionDAG &DAG,
39924+
static SDValue combineTargetShuffle(SDValue N, const SDLoc &DL,
39925+
SelectionDAG &DAG,
3992639926
TargetLowering::DAGCombinerInfo &DCI,
3992739927
const X86Subtarget &Subtarget) {
39928-
SDLoc DL(N);
3992939928
MVT VT = N.getSimpleValueType();
3993039929
SmallVector<int, 4> Mask;
3993139930
unsigned Opcode = N.getOpcode();
@@ -40653,7 +40652,7 @@ static SDValue combineTargetShuffle(SDValue N, SelectionDAG &DAG,
4065340652
break;
4065440653

4065540654
case X86ISD::PSHUFD:
40656-
if (SDValue NewN = combineRedundantDWordShuffle(N, Mask, DAG))
40655+
if (SDValue NewN = combineRedundantDWordShuffle(N, Mask, DL, DAG))
4065740656
return NewN;
4065840657

4065940658
break;
@@ -40762,7 +40761,7 @@ static bool isAddSubOrSubAdd(SDNode *N, const X86Subtarget &Subtarget,
4076240761
}
4076340762

4076440763
/// Combine shuffle of two fma nodes into FMAddSub or FMSubAdd.
40765-
static SDValue combineShuffleToFMAddSub(SDNode *N,
40764+
static SDValue combineShuffleToFMAddSub(SDNode *N, const SDLoc &DL,
4076640765
const X86Subtarget &Subtarget,
4076740766
SelectionDAG &DAG) {
4076840767
// We only handle target-independent shuffles.
@@ -40796,7 +40795,6 @@ static SDValue combineShuffleToFMAddSub(SDNode *N,
4079640795
return SDValue();
4079740796

4079840797
// FMAddSub takes zeroth operand from FMSub node.
40799-
SDLoc DL(N);
4080040798
bool IsSubAdd = Op0Even ? Op0 == FMAdd : Op1 == FMAdd;
4080140799
unsigned Opcode = IsSubAdd ? X86ISD::FMSUBADD : X86ISD::FMADDSUB;
4080240800
return DAG.getNode(Opcode, DL, VT, FMAdd.getOperand(0), FMAdd.getOperand(1),
@@ -40805,10 +40803,10 @@ static SDValue combineShuffleToFMAddSub(SDNode *N,
4080540803

4080640804
/// Try to combine a shuffle into a target-specific add-sub or
4080740805
/// mul-add-sub node.
40808-
static SDValue combineShuffleToAddSubOrFMAddSub(SDNode *N,
40806+
static SDValue combineShuffleToAddSubOrFMAddSub(SDNode *N, const SDLoc &DL,
4080940807
const X86Subtarget &Subtarget,
4081040808
SelectionDAG &DAG) {
40811-
if (SDValue V = combineShuffleToFMAddSub(N, Subtarget, DAG))
40809+
if (SDValue V = combineShuffleToFMAddSub(N, DL, Subtarget, DAG))
4081240810
return V;
4081340811

4081440812
SDValue Opnd0, Opnd1;
@@ -40817,7 +40815,6 @@ static SDValue combineShuffleToAddSubOrFMAddSub(SDNode *N,
4081740815
return SDValue();
4081840816

4081940817
MVT VT = N->getSimpleValueType(0);
40820-
SDLoc DL(N);
4082140818

4082240819
// Try to generate X86ISD::FMADDSUB node here.
4082340820
SDValue Opnd2;
@@ -40847,7 +40844,8 @@ static SDValue combineShuffleToAddSubOrFMAddSub(SDNode *N,
4084740844
// We are looking for a shuffle where both sources are concatenated with undef
4084840845
// and have a width that is half of the output's width. AVX2 has VPERMD/Q, so
4084940846
// if we can express this as a single-source shuffle, that's preferable.
40850-
static SDValue combineShuffleOfConcatUndef(SDNode *N, SelectionDAG &DAG,
40847+
static SDValue combineShuffleOfConcatUndef(SDNode *N, const SDLoc &DL,
40848+
SelectionDAG &DAG,
4085140849
const X86Subtarget &Subtarget) {
4085240850
if (!Subtarget.hasAVX2() || !isa<ShuffleVectorSDNode>(N))
4085340851
return SDValue();
@@ -40879,11 +40877,10 @@ static SDValue combineShuffleOfConcatUndef(SDNode *N, SelectionDAG &DAG,
4087940877
SmallVector<int, 8> Mask;
4088040878
int NumElts = VT.getVectorNumElements();
4088140879

40882-
ShuffleVectorSDNode *SVOp = cast<ShuffleVectorSDNode>(N);
40880+
auto *SVOp = cast<ShuffleVectorSDNode>(N);
4088340881
for (int Elt : SVOp->getMask())
4088440882
Mask.push_back(Elt < NumElts ? Elt : (Elt - NumElts / 2));
4088540883

40886-
SDLoc DL(N);
4088740884
SDValue Concat = DAG.getNode(ISD::CONCAT_VECTORS, DL, VT, N0.getOperand(0),
4088840885
N1.getOperand(0));
4088940886
return DAG.getVectorShuffle(VT, DL, Concat, DAG.getUNDEF(VT), Mask);
@@ -40935,7 +40932,8 @@ static SDValue combineShuffle(SDNode *N, SelectionDAG &DAG,
4093540932
EVT VT = N->getValueType(0);
4093640933
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
4093740934
if (TLI.isTypeLegal(VT) && !isSoftF16(VT, Subtarget))
40938-
if (SDValue AddSub = combineShuffleToAddSubOrFMAddSub(N, Subtarget, DAG))
40935+
if (SDValue AddSub =
40936+
combineShuffleToAddSubOrFMAddSub(N, dl, Subtarget, DAG))
4093940937
return AddSub;
4094040938

4094140939
// Attempt to combine into a vector load/broadcast.
@@ -40949,12 +40947,12 @@ static SDValue combineShuffle(SDNode *N, SelectionDAG &DAG,
4094940947
// Into:
4095040948
// (vector_shuffle <mask> (concat_vectors t1, t2), undef)
4095140949
// Since the latter can be efficiently lowered with VPERMD/VPERMQ
40952-
if (SDValue ShufConcat = combineShuffleOfConcatUndef(N, DAG, Subtarget))
40950+
if (SDValue ShufConcat = combineShuffleOfConcatUndef(N, dl, DAG, Subtarget))
4095340951
return ShufConcat;
4095440952

4095540953
if (isTargetShuffle(N->getOpcode())) {
4095640954
SDValue Op(N, 0);
40957-
if (SDValue Shuffle = combineTargetShuffle(Op, DAG, DCI, Subtarget))
40955+
if (SDValue Shuffle = combineTargetShuffle(Op, dl, DAG, DCI, Subtarget))
4095840956
return Shuffle;
4095940957

4096040958
// Try recursively combining arbitrary sequences of x86 shuffle

0 commit comments

Comments
 (0)