From ca3e6fafc8a071a6654e546bd5e05ed7a6966dfa Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Sun, 19 Apr 2015 22:16:49 +0000 Subject: [PATCH] [X86][SSE] Fix for getScalarValueForVectorElement to detect scalar sources requiring truncation. The fix ensures that scalar sources inserted into a vector are the correct bit size. Integer scalar sources from BUILD_VECTOR and SCALAR_TO_VECTOR nodes may require truncation that this function doesn't currently support. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235281 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/X86ISelLowering.cpp | 9 +++++++-- test/CodeGen/X86/fold-vector-shuffle-crash.ll | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 test/CodeGen/X86/fold-vector-shuffle-crash.ll diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index c32412a741c..fd7a60d7d04 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -6918,8 +6918,13 @@ static SDValue getScalarValueForVectorElement(SDValue V, int Idx, return SDValue(); if (V.getOpcode() == ISD::BUILD_VECTOR || - (Idx == 0 && V.getOpcode() == ISD::SCALAR_TO_VECTOR)) - return DAG.getNode(ISD::BITCAST, SDLoc(V), EltVT, V.getOperand(Idx)); + (Idx == 0 && V.getOpcode() == ISD::SCALAR_TO_VECTOR)) { + // Ensure the scalar operand is the same size as the destination. + // FIXME: Add support for scalar truncation where possible. + SDValue S = V.getOperand(Idx); + if (EltVT.getSizeInBits() == S.getSimpleValueType().getSizeInBits()) + return DAG.getNode(ISD::BITCAST, SDLoc(V), EltVT, S); + } return SDValue(); } diff --git a/test/CodeGen/X86/fold-vector-shuffle-crash.ll b/test/CodeGen/X86/fold-vector-shuffle-crash.ll new file mode 100644 index 00000000000..0bb150bfa86 --- /dev/null +++ b/test/CodeGen/X86/fold-vector-shuffle-crash.ll @@ -0,0 +1,16 @@ +; RUN: llc < %s -mtriple=x86_64-unknown -mcpu=corei7 + +define void @autogen_SD13708(i32) { +BB: + %Shuff7 = shufflevector <8 x i32> zeroinitializer, <8 x i32> zeroinitializer, <8 x i32> + br label %CF + +CF: + %Tr = trunc <8 x i64> zeroinitializer to <8 x i32> + %Shuff20 = shufflevector <8 x i32> %Shuff7, <8 x i32> %Tr, <8 x i32> + br i1 undef, label %CF, label %CF247 + +CF247: + %I171 = insertelement <8 x i32> %Shuff20, i32 %0, i32 0 + br i1 undef, label %CF, label %CF247 +} \ No newline at end of file -- 2.34.1