[llvm] r235281 - [X86][SSE] Fix for getScalarValueForVectorElement to detect scalar sources requiring truncation.

Simon Pilgrim llvm-dev at redking.me.uk
Sun Apr 19 15:16:49 PDT 2015


Author: rksimon
Date: Sun Apr 19 17:16:49 2015
New Revision: 235281

URL: http://llvm.org/viewvc/llvm-project?rev=235281&view=rev
Log:
[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.

Added:
    llvm/trunk/test/CodeGen/X86/fold-vector-shuffle-crash.ll
Modified:
    llvm/trunk/lib/Target/X86/X86ISelLowering.cpp

Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=235281&r1=235280&r2=235281&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Sun Apr 19 17:16:49 2015
@@ -6918,8 +6918,13 @@ static SDValue getScalarValueForVectorEl
     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();
 }

Added: llvm/trunk/test/CodeGen/X86/fold-vector-shuffle-crash.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/fold-vector-shuffle-crash.ll?rev=235281&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/fold-vector-shuffle-crash.ll (added)
+++ llvm/trunk/test/CodeGen/X86/fold-vector-shuffle-crash.ll Sun Apr 19 17:16:49 2015
@@ -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> <i32 8, i32 10, i32 12, i32 14, i32 undef, i32 2, i32 4, i32 undef>
+ 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> <i32 13, i32 15, i32 1, i32 3, i32 5, i32 7, i32 undef, i32 11>
+ 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





More information about the llvm-commits mailing list