Skip to content

Commit

Permalink
Allow SelectionDAG::FoldConstantArithmetic to work when it's called w…
Browse files Browse the repository at this point in the history
…ith a vector VT but scalar values.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207835 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
d0k committed May 2, 2014
1 parent 74e9519 commit bcf1501
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
10 changes: 10 additions & 0 deletions test/CodeGen/X86/vector-idiv.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit bcf1501

Please sign in to comment.