@@ -20799,26 +20799,35 @@ SDValue DAGCombiner::visitVECTOR_SHUFFLE(SDNode *N) {
20799
20799
}
20800
20800
}
20801
20801
20802
- // Canonicalize shuffles according to rules:
20803
- // shuffle(A, shuffle(A, B)) -> shuffle(shuffle(A,B), A)
20804
- // shuffle(B, shuffle(A, B)) -> shuffle(shuffle(A,B), B)
20805
- // shuffle(B, shuffle(A, Undef)) -> shuffle(shuffle(A, Undef), B)
20806
- if (N1.getOpcode() == ISD::VECTOR_SHUFFLE &&
20807
- N0.getOpcode() != ISD::VECTOR_SHUFFLE && Level < AfterLegalizeDAG &&
20808
- TLI.isTypeLegal(VT)) {
20809
- // The incoming shuffle must be of the same type as the result of the
20810
- // current shuffle.
20811
- assert(N1->getOperand(0).getValueType() == VT &&
20812
- "Shuffle types don't match");
20813
-
20814
- SDValue SV0 = N1->getOperand(0);
20815
- SDValue SV1 = N1->getOperand(1);
20816
- bool HasSameOp0 = N0 == SV0;
20817
- bool IsSV1Undef = SV1.isUndef();
20818
- if (HasSameOp0 || IsSV1Undef || N0 == SV1)
20819
- // Commute the operands of this shuffle so that next rule
20820
- // will trigger.
20802
+ if (Level < AfterLegalizeDAG && TLI.isTypeLegal(VT)) {
20803
+ // Canonicalize shuffles according to rules:
20804
+ // shuffle(A, shuffle(A, B)) -> shuffle(shuffle(A,B), A)
20805
+ // shuffle(B, shuffle(A, B)) -> shuffle(shuffle(A,B), B)
20806
+ // shuffle(B, shuffle(A, Undef)) -> shuffle(shuffle(A, Undef), B)
20807
+ if (N1.getOpcode() == ISD::VECTOR_SHUFFLE &&
20808
+ N0.getOpcode() != ISD::VECTOR_SHUFFLE) {
20809
+ // The incoming shuffle must be of the same type as the result of the
20810
+ // current shuffle.
20811
+ assert(N1->getOperand(0).getValueType() == VT &&
20812
+ "Shuffle types don't match");
20813
+
20814
+ SDValue SV0 = N1->getOperand(0);
20815
+ SDValue SV1 = N1->getOperand(1);
20816
+ bool HasSameOp0 = N0 == SV0;
20817
+ bool IsSV1Undef = SV1.isUndef();
20818
+ if (HasSameOp0 || IsSV1Undef || N0 == SV1)
20819
+ // Commute the operands of this shuffle so merging below will trigger.
20820
+ return DAG.getCommutedVectorShuffle(*SVN);
20821
+ }
20822
+
20823
+ // Canonicalize splat shuffles to the RHS to improve merging below.
20824
+ // shuffle(splat(A,u), shuffle(C,D)) -> shuffle'(shuffle(C,D), splat(A,u))
20825
+ if (N0.getOpcode() == ISD::VECTOR_SHUFFLE &&
20826
+ N1.getOpcode() == ISD::VECTOR_SHUFFLE &&
20827
+ cast<ShuffleVectorSDNode>(N0)->isSplat() &&
20828
+ !cast<ShuffleVectorSDNode>(N1)->isSplat()) {
20821
20829
return DAG.getCommutedVectorShuffle(*SVN);
20830
+ }
20822
20831
}
20823
20832
20824
20833
// Compute the combined shuffle mask for a shuffle with SV0 as the first
0 commit comments