@@ -6184,6 +6184,22 @@ static SDValue getOnesVector(EVT VT, SelectionDAG &DAG, const SDLoc &dl) {
6184
6184
return DAG.getBitcast(VT, Vec);
6185
6185
}
6186
6186
6187
+ // Convert *_EXTEND_VECTOR_INREG to *_EXTEND opcode.
6188
+ static unsigned getOpcode_EXTEND(unsigned Opcode) {
6189
+ switch (Opcode) {
6190
+ case ISD::ANY_EXTEND:
6191
+ case ISD::ANY_EXTEND_VECTOR_INREG:
6192
+ return ISD::ANY_EXTEND;
6193
+ case ISD::ZERO_EXTEND:
6194
+ case ISD::ZERO_EXTEND_VECTOR_INREG:
6195
+ return ISD::ZERO_EXTEND;
6196
+ case ISD::SIGN_EXTEND:
6197
+ case ISD::SIGN_EXTEND_VECTOR_INREG:
6198
+ return ISD::SIGN_EXTEND;
6199
+ }
6200
+ llvm_unreachable("Unknown opcode");
6201
+ }
6202
+
6187
6203
// Convert *_EXTEND to *_EXTEND_VECTOR_INREG opcode.
6188
6204
static unsigned getOpcode_EXTEND_VECTOR_INREG(unsigned Opcode) {
6189
6205
switch (Opcode) {
@@ -49258,6 +49274,7 @@ static SDValue combineEXTEND_VECTOR_INREG(SDNode *N, SelectionDAG &DAG,
49258
49274
EVT VT = N->getValueType(0);
49259
49275
SDValue In = N->getOperand(0);
49260
49276
unsigned Opcode = N->getOpcode();
49277
+ unsigned InOpcode = In.getOpcode();
49261
49278
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
49262
49279
49263
49280
// Try to merge vector loads and extend_inreg to an extload.
@@ -49283,9 +49300,18 @@ static SDValue combineEXTEND_VECTOR_INREG(SDNode *N, SelectionDAG &DAG,
49283
49300
}
49284
49301
49285
49302
// Fold EXTEND_VECTOR_INREG(EXTEND_VECTOR_INREG(X)) -> EXTEND_VECTOR_INREG(X).
49286
- if (Opcode == In.getOpcode() )
49303
+ if (Opcode == InOpcode )
49287
49304
return DAG.getNode(Opcode, SDLoc(N), VT, In.getOperand(0));
49288
49305
49306
+ // Fold EXTEND_VECTOR_INREG(EXTRACT_SUBVECTOR(EXTEND(X),0))
49307
+ // -> EXTEND_VECTOR_INREG(X).
49308
+ // TODO: Handle non-zero subvector indices.
49309
+ if (InOpcode == ISD::EXTRACT_SUBVECTOR && In.getConstantOperandVal(1) == 0 &&
49310
+ In.getOperand(0).getOpcode() == getOpcode_EXTEND(Opcode) &&
49311
+ In.getOperand(0).getOperand(0).getValueSizeInBits() ==
49312
+ In.getValueSizeInBits())
49313
+ return DAG.getNode(Opcode, SDLoc(N), VT, In.getOperand(0).getOperand(0));
49314
+
49289
49315
// Attempt to combine as a shuffle.
49290
49316
// TODO: General ZERO_EXTEND_VECTOR_INREG support.
49291
49317
if (Opcode == ISD::ANY_EXTEND_VECTOR_INREG ||
0 commit comments