summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
diff options
context:
space:
mode:
authorMichael Kuperstein <michael.m.kuperstein@intel.com>2015-01-22 12:37:23 +0000
committerMichael Kuperstein <michael.m.kuperstein@intel.com>2015-01-22 12:37:23 +0000
commit84fad3e5c9f75710ad1f43198c6e136e7cdb46b4 (patch)
tree04d9c0d679cd5d5c911e13c5b9350e472055cdcb /llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
parentfebfd3453ec975887ef2370fa4b9a6a9a6757950 (diff)
downloadbcm5719-llvm-84fad3e5c9f75710ad1f43198c6e136e7cdb46b4.tar.gz
bcm5719-llvm-84fad3e5c9f75710ad1f43198c6e136e7cdb46b4.zip
[DAGCombine] Produce better code for constant splats
This solves PR22276. Splats of constants would sometimes produce redundant shuffles, sometimes ridiculously so (see the PR for details). Fold these shuffles into BUILD_VECTORs early on instead. Differential Revision: http://reviews.llvm.org/D7093 llvm-svn: 226811
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp')
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index f75d5f4b2bd..c5ef77a3195 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -1513,9 +1513,10 @@ SDValue SelectionDAG::getVectorShuffle(EVT VT, SDLoc dl, SDValue N1,
return getUNDEF(VT);
// If Identity shuffle return that node.
- bool Identity = true;
+ bool Identity = true, AllSame = true;
for (unsigned i = 0; i != NElts; ++i) {
if (MaskVec[i] >= 0 && MaskVec[i] != (int)i) Identity = false;
+ if (MaskVec[i] != MaskVec[0]) AllSame = false;
}
if (Identity && NElts)
return N1;
@@ -1549,6 +1550,26 @@ SDValue SelectionDAG::getVectorShuffle(EVT VT, SDLoc dl, SDValue N1,
if (C->isNullValue())
return N1;
}
+
+ // If the shuffle itself creates a constant splat, build the vector
+ // directly.
+ if (AllSame) {
+ const SDValue &Splatted = BV->getOperand(MaskVec[0]);
+ if (isa<ConstantSDNode>(Splatted) || isa<ConstantFPSDNode>(Splatted)) {
+ SmallVector<SDValue, 8> Ops;
+ for (unsigned i = 0; i != NElts; ++i) {
+ Ops.push_back(Splatted);
+ }
+ SDValue &NewBV = getNode(ISD::BUILD_VECTOR, dl,
+ BV->getValueType(0), Ops);
+
+ // We may have jumped through bitcasts, so the type of the
+ // BUILD_VECTOR may not match the type of the shuffle.
+ if (BV->getValueType(0) != VT)
+ NewBV = getNode(ISD::BITCAST, dl, VT, NewBV);
+ return NewBV;
+ }
+ }
}
}
OpenPOWER on IntegriCloud