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 +}