[DAG] Improved target independent vector shuffle folding logic.

This patch teaches the DAGCombiner how to combine shuffles according to rules:
   shuffle(shuffle(A, Undef, M0), B, M1) -> shuffle(B, A, M2)
   shuffle(shuffle(A, B, M0), B, M1) -> shuffle(B, A, M2)
   shuffle(shuffle(A, B, M0), A, M1) -> shuffle(B, A, M2)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222090 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Andrea Di Biagio
2014-11-15 22:56:25 +00:00
parent 01e39346f3
commit 37f645cb34
2 changed files with 40 additions and 44 deletions

View File

@ -11239,6 +11239,26 @@ SDValue DAGCombiner::visitVECTOR_SHUFFLE(SDNode *N) {
return DAG.getVectorShuffle(VT, SDLoc(N), SV0, N1, &Mask[0]);
return DAG.getVectorShuffle(VT, SDLoc(N), SV0, SV1, &Mask[0]);
}
// Compute the commuted shuffle mask.
for (unsigned i = 0; i != NumElts; ++i) {
int idx = Mask[i];
if (idx < 0)
continue;
else if (idx < (int)NumElts)
Mask[i] = idx + NumElts;
else
Mask[i] = idx - NumElts;
}
if (TLI.isShuffleMaskLegal(Mask, VT)) {
if (IsSV1Undef)
// shuffle(shuffle(A, Undef, M0), B, M1) -> shuffle(B, A, M2)
return DAG.getVectorShuffle(VT, SDLoc(N), N1, SV0, &Mask[0]);
// shuffle(shuffle(A, B, M0), B, M1) -> shuffle(B, A, M2)
// shuffle(shuffle(A, B, M0), A, M1) -> shuffle(B, A, M2)
return DAG.getVectorShuffle(VT, SDLoc(N), SV1, SV0, &Mask[0]);
}
}
return SDValue();