[llvm] r227002 - [DAG] Fix wrong canonicalization performed on shuffle nodes.
Andrea Di Biagio
Andrea_DiBiagio at sn.scee.net
Sat Jan 24 03:54:29 PST 2015
Author: adibiagio
Date: Sat Jan 24 05:54:29 2015
New Revision: 227002
URL: http://llvm.org/viewvc/llvm-project?rev=227002&view=rev
Log:
[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.
Added:
llvm/trunk/test/CodeGen/X86/selectiondag-crash.ll
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=227002&r1=227001&r2=227002&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Sat Jan 24 05:54:29 2015
@@ -1538,13 +1538,15 @@ SDValue SelectionDAG::getVectorShuffle(E
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(E
// 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.
Added: llvm/trunk/test/CodeGen/X86/selectiondag-crash.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/selectiondag-crash.ll?rev=227002&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/selectiondag-crash.ll (added)
+++ llvm/trunk/test/CodeGen/X86/selectiondag-crash.ll Sat Jan 24 05:54:29 2015
@@ -0,0 +1,15 @@
+; RUN: llc -mtriple=x86_64-unknown-unknown -mcpu=corei7 < %s
+
+; Check that llc doesn't crash in the attempt to fold a shuffle with
+; a splat mask into a constant build_vector.
+
+define <8 x i8> @autogen_SD26299(i8) {
+BB:
+ %Shuff = shufflevector <8 x i32> <i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1>, <8 x i32> zeroinitializer, <8 x i32> <i32 2, i32 undef, i32 6, i32 8, i32 undef, i32 12, i32 14, i32 0>
+ %Shuff14 = shufflevector <8 x i32> %Shuff, <8 x i32> %Shuff, <8 x i32> <i32 7, i32 9, i32 11, i32 undef, i32 undef, i32 1, i32 3, i32 5>
+ %Shuff35 = shufflevector <8 x i32> %Shuff14, <8 x i32> %Shuff, <8 x i32> <i32 undef, i32 1, i32 3, i32 5, i32 7, i32 9, i32 11, i32 13>
+ %I42 = insertelement <8 x i32> %Shuff35, i32 88608, i32 0
+ %Shuff48 = shufflevector <8 x i32> %Shuff35, <8 x i32> %I42, <8 x i32> <i32 4, i32 6, i32 8, i32 10, i32 12, i32 14, i32 0, i32 2>
+ %Tr59 = trunc <8 x i32> %Shuff48 to <8 x i8>
+ ret <8 x i8> %Tr59
+}
More information about the llvm-commits
mailing list