@@ -2503,6 +2503,31 @@ SDValue DAGCombiner::visitADD(SDNode *N) {
2503
2503
return DAG.getNode(ISD::ADD, DL, VT, N0.getOperand(0), VS);
2504
2504
}
2505
2505
2506
+ // Fold (add step_vector(c1), step_vector(c2) to step_vector(c1+c2))
2507
+ if (N0.getOpcode() == ISD::STEP_VECTOR &&
2508
+ N1.getOpcode() == ISD::STEP_VECTOR) {
2509
+ const APInt &C0 = N0->getConstantOperandAPInt(0);
2510
+ const APInt &C1 = N1->getConstantOperandAPInt(0);
2511
+ EVT SVT = N0.getOperand(0).getValueType();
2512
+ SDValue NewStep = DAG.getConstant(C0 + C1, DL, SVT);
2513
+ return DAG.getStepVector(DL, VT, NewStep);
2514
+ }
2515
+
2516
+ // Fold a + step_vector(c1) + step_vector(c2) to a + step_vector(c1+c2)
2517
+ if ((N0.getOpcode() == ISD::ADD) &&
2518
+ (N0.getOperand(1).getOpcode() == ISD::STEP_VECTOR) &&
2519
+ (N1.getOpcode() == ISD::STEP_VECTOR)) {
2520
+ const APInt &SV0 = N0.getOperand(1)->getConstantOperandAPInt(0);
2521
+ const APInt &SV1 = N1->getConstantOperandAPInt(0);
2522
+ EVT SVT = N1.getOperand(0).getValueType();
2523
+ assert(N1.getOperand(0).getValueType() ==
2524
+ N0.getOperand(1)->getOperand(0).getValueType() &&
2525
+ "Different operand types of STEP_VECTOR.");
2526
+ SDValue NewStep = DAG.getConstant(SV0 + SV1, DL, SVT);
2527
+ SDValue SV = DAG.getStepVector(DL, VT, NewStep);
2528
+ return DAG.getNode(ISD::ADD, DL, VT, N0.getOperand(0), SV);
2529
+ }
2530
+
2506
2531
return SDValue();
2507
2532
}
2508
2533
@@ -3893,6 +3918,17 @@ SDValue DAGCombiner::visitMUL(SDNode *N) {
3893
3918
return DAG.getVScale(SDLoc(N), VT, C0 * C1);
3894
3919
}
3895
3920
3921
+ // Fold (mul step_vector(C0), C1) to (step_vector(C0 * C1)).
3922
+ APInt MulVal;
3923
+ if (N0.getOpcode() == ISD::STEP_VECTOR)
3924
+ if (ISD::isConstantSplatVector(N1.getNode(), MulVal)) {
3925
+ const APInt &C0 = N0.getConstantOperandAPInt(0);
3926
+ EVT SVT = N0.getOperand(0).getValueType();
3927
+ SDValue NewStep = DAG.getConstant(
3928
+ C0 * MulVal.sextOrTrunc(SVT.getSizeInBits()), SDLoc(N), SVT);
3929
+ return DAG.getStepVector(SDLoc(N), VT, NewStep);
3930
+ }
3931
+
3896
3932
// Fold ((mul x, 0/undef) -> 0,
3897
3933
// (mul x, 1) -> x) -> x)
3898
3934
// -> and(x, mask)
@@ -8381,6 +8417,17 @@ SDValue DAGCombiner::visitSHL(SDNode *N) {
8381
8417
return DAG.getVScale(SDLoc(N), VT, C0 << C1);
8382
8418
}
8383
8419
8420
+ // Fold (shl step_vector(C0), C1) to (step_vector(C0 << C1)).
8421
+ APInt ShlVal;
8422
+ if (N0.getOpcode() == ISD::STEP_VECTOR)
8423
+ if (ISD::isConstantSplatVector(N1.getNode(), ShlVal)) {
8424
+ const APInt &C0 = N0.getConstantOperandAPInt(0);
8425
+ EVT SVT = N0.getOperand(0).getValueType();
8426
+ SDValue NewStep = DAG.getConstant(
8427
+ C0 << ShlVal.sextOrTrunc(SVT.getSizeInBits()), SDLoc(N), SVT);
8428
+ return DAG.getStepVector(SDLoc(N), VT, NewStep);
8429
+ }
8430
+
8384
8431
return SDValue();
8385
8432
}
8386
8433
0 commit comments