[llvm] r207835 - Allow SelectionDAG::FoldConstantArithmetic to work when it's called with a vector VT but scalar values.

Benjamin Kramer benny.kra at googlemail.com
Fri May 2 05:35:23 PDT 2014


Author: d0k
Date: Fri May  2 07:35:22 2014
New Revision: 207835

URL: http://llvm.org/viewvc/llvm-project?rev=207835&view=rev
Log:
Allow SelectionDAG::FoldConstantArithmetic to work when it's called with a vector VT but scalar values.

Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
    llvm/trunk/test/CodeGen/X86/vector-idiv.ll

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=207835&r1=207834&r2=207835&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Fri May  2 07:35:22 2014
@@ -2924,11 +2924,17 @@ SDValue SelectionDAG::FoldConstantArithm
     }
   }
 
+  assert((Scalar1 && Scalar2) ||
+         VT.getVectorNumElements() == Outputs.size() && "No scalar or vector!");
+
   // Handle the scalar case first.
-  if (Scalar1 && Scalar2)
+  if (!VT.isVector())
     return Outputs.back();
 
-  // Otherwise build a big vector out of the scalar elements we generated.
+  // We may have a vector type but a scalar result. Create a splat.
+  Outputs.resize(VT.getVectorNumElements(), Outputs.back());
+
+  // Build a big vector out of the scalar elements we generated.
   return getNode(ISD::BUILD_VECTOR, SDLoc(), VT, Outputs);
 }
 

Modified: llvm/trunk/test/CodeGen/X86/vector-idiv.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/vector-idiv.ll?rev=207835&r1=207834&r2=207835&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/vector-idiv.ll (original)
+++ llvm/trunk/test/CodeGen/X86/vector-idiv.ll Fri May  2 07:35:22 2014
@@ -205,3 +205,13 @@ define <8 x i32> @test11(<8 x i32> %a) {
 ; AVX: vpadd
 ; AVX: vpmulld
 }
+
+define <2 x i16> @test12() {
+  %I8 = insertelement <2 x i16> zeroinitializer, i16 -1, i32 0
+  %I9 = insertelement <2 x i16> %I8, i16 -1, i32 1
+  %B9 = urem <2 x i16> %I9, %I9
+  ret <2 x i16> %B9
+
+; AVX-LABEL: test12:
+; AVX: xorps
+}





More information about the llvm-commits mailing list