diff options
author | Andrea Di Biagio <Andrea_DiBiagio@sn.scee.net> | 2014-11-15 22:56:25 +0000 |
---|---|---|
committer | Andrea Di Biagio <Andrea_DiBiagio@sn.scee.net> | 2014-11-15 22:56:25 +0000 |
commit | e13a0b81f416e3e5353e5c72e06db9a9171adc82 (patch) | |
tree | a85eecfe707054a12fd2ab6ffd6f7d5fab113362 /llvm/lib | |
parent | d1c12e65cd58581a48a2e3ad48a07d202415a638 (diff) | |
download | bcm5719-llvm-e13a0b81f416e3e5353e5c72e06db9a9171adc82.tar.gz bcm5719-llvm-e13a0b81f416e3e5353e5c72e06db9a9171adc82.zip |
[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)
llvm-svn: 222090
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 530ced6e532..342a4278adf 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -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(); |