Skip to content

Commit bd76824

Browse files
committed
[DAG] replaceShuffleOfInsert - convert INSERT_VECTOR_ELT matching to use SDPatternMatch helpers. NFC.
1 parent e470826 commit bd76824

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26160,26 +26160,27 @@ static SDValue replaceShuffleOfInsert(ShuffleVectorSDNode *Shuf,
2616026160
// could be an operand of SCALAR_TO_VECTOR, BUILD_VECTOR, or a constant.
2616126161
assert(Mask[ShufOp0Index] >= 0 && Mask[ShufOp0Index] < (int)Mask.size() &&
2616226162
"Shuffle mask value must be from operand 0");
26163-
if (Op0.getOpcode() != ISD::INSERT_VECTOR_ELT)
26164-
return SDValue();
2616526163

26166-
auto *InsIndexC = dyn_cast<ConstantSDNode>(Op0.getOperand(2));
26167-
if (!InsIndexC || InsIndexC->getSExtValue() != Mask[ShufOp0Index])
26168-
return SDValue();
26164+
SDValue Elt;
26165+
if (sd_match(Op0, m_InsertElt(m_Value(), m_Value(Elt),
26166+
m_SpecificInt(Mask[ShufOp0Index])))) {
26167+
// There's an existing insertelement with constant insertion index, so we
26168+
// don't need to check the legality/profitability of a replacement operation
26169+
// that differs at most in the constant value. The target should be able to
26170+
// lower any of those in a similar way. If not, legalization will expand
26171+
// this to a scalar-to-vector plus shuffle.
26172+
//
26173+
// Note that the shuffle may move the scalar from the position that the
26174+
// insert element used. Therefore, our new insert element occurs at the
26175+
// shuffle's mask index value, not the insert's index value.
26176+
//
26177+
// shuffle (insertelt v1, x, C), v2, mask --> insertelt v2, x, C'
26178+
SDValue NewInsIndex = DAG.getVectorIdxConstant(ShufOp0Index, SDLoc(Shuf));
26179+
return DAG.getNode(ISD::INSERT_VECTOR_ELT, SDLoc(Shuf), Op0.getValueType(),
26180+
Op1, Elt, NewInsIndex);
26181+
}
2616926182

26170-
// There's an existing insertelement with constant insertion index, so we
26171-
// don't need to check the legality/profitability of a replacement operation
26172-
// that differs at most in the constant value. The target should be able to
26173-
// lower any of those in a similar way. If not, legalization will expand this
26174-
// to a scalar-to-vector plus shuffle.
26175-
//
26176-
// Note that the shuffle may move the scalar from the position that the insert
26177-
// element used. Therefore, our new insert element occurs at the shuffle's
26178-
// mask index value, not the insert's index value.
26179-
// shuffle (insertelt v1, x, C), v2, mask --> insertelt v2, x, C'
26180-
SDValue NewInsIndex = DAG.getVectorIdxConstant(ShufOp0Index, SDLoc(Shuf));
26181-
return DAG.getNode(ISD::INSERT_VECTOR_ELT, SDLoc(Shuf), Op0.getValueType(),
26182-
Op1, Op0.getOperand(1), NewInsIndex);
26183+
return SDValue();
2618326184
}
2618426185

2618526186
/// If we have a unary shuffle of a shuffle, see if it can be folded away

0 commit comments

Comments
 (0)