From: Benjamin Kramer Date: Fri, 2 May 2014 12:35:22 +0000 (+0000) Subject: Allow SelectionDAG::FoldConstantArithmetic to work when it's called with a vector... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=bcf15018398f0c9303d66f4dabdfdd9006555170;p=oota-llvm.git Allow SelectionDAG::FoldConstantArithmetic to work when it's called with a vector VT but scalar values. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207835 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index bf311226cd9..7058c4e95ae 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -2924,11 +2924,17 @@ SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, EVT VT, } } + 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); } diff --git a/test/CodeGen/X86/vector-idiv.ll b/test/CodeGen/X86/vector-idiv.ll index 5738c94e37b..4c30184a542 100644 --- a/test/CodeGen/X86/vector-idiv.ll +++ b/test/CodeGen/X86/vector-idiv.ll @@ -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 +}