@@ -26160,26 +26160,27 @@ static SDValue replaceShuffleOfInsert(ShuffleVectorSDNode *Shuf,
26160
26160
// could be an operand of SCALAR_TO_VECTOR, BUILD_VECTOR, or a constant.
26161
26161
assert(Mask[ShufOp0Index] >= 0 && Mask[ShufOp0Index] < (int)Mask.size() &&
26162
26162
"Shuffle mask value must be from operand 0");
26163
- if (Op0.getOpcode() != ISD::INSERT_VECTOR_ELT)
26164
- return SDValue();
26165
26163
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
+ }
26169
26182
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();
26183
26184
}
26184
26185
26185
26186
/// If we have a unary shuffle of a shuffle, see if it can be folded away
0 commit comments