diff options
author | Andrea Di Biagio <Andrea_DiBiagio@sn.scee.net> | 2015-01-24 11:54:29 +0000 |
---|---|---|
committer | Andrea Di Biagio <Andrea_DiBiagio@sn.scee.net> | 2015-01-24 11:54:29 +0000 |
commit | 8381475a7511c17e046bf25b53185a4d109df467 (patch) | |
tree | a2d8f331cb2d9943e09310a1434cfdc90d5b9e93 /llvm/lib/CodeGen/SelectionDAG | |
parent | 9dea5cdb8ed79adcf44ca6200689cc5467d4ecf2 (diff) | |
download | bcm5719-llvm-8381475a7511c17e046bf25b53185a4d109df467.tar.gz bcm5719-llvm-8381475a7511c17e046bf25b53185a4d109df467.zip |
[DAG] Fix wrong canonicalization performed on shuffle nodes.
This fixes a regression introduced by r226816.
When replacing a splat shuffle node with a constant build_vector,
make sure that the new build_vector has a valid number of elements.
Thanks to Patrik Hagglund for reporting this problem and providing a
small reproducible.
llvm-svn: 227002
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index c354155b035..565e4bbe87a 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -1538,13 +1538,15 @@ SDValue SelectionDAG::getVectorShuffle(EVT VT, SDLoc dl, SDValue N1, if (Splat && Splat.getOpcode() == ISD::UNDEF) return getUNDEF(VT); + bool SameNumElts = + V.getValueType().getVectorNumElements() == VT.getVectorNumElements(); + // We only have a splat which can skip shuffles if there is a splatted // value and no undef lanes rearranged by the shuffle. if (Splat && UndefElements.none()) { // Splat of <x, x, ..., x>, return <x, x, ..., x>, provided that the // number of elements match or the value splatted is a zero constant. - if (V.getValueType().getVectorNumElements() == - VT.getVectorNumElements()) + if (SameNumElts) return N1; if (auto *C = dyn_cast<ConstantSDNode>(Splat)) if (C->isNullValue()) @@ -1553,15 +1555,15 @@ SDValue SelectionDAG::getVectorShuffle(EVT VT, SDLoc dl, SDValue N1, // If the shuffle itself creates a constant splat, build the vector // directly. - if (AllSame) { + if (AllSame && SameNumElts) { 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) { + for (unsigned i = 0; i != NElts; ++i) Ops.push_back(Splatted); - } - SDValue NewBV = getNode(ISD::BUILD_VECTOR, dl, - BV->getValueType(0), Ops); + + 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. |