Skip to content

Commit

Permalink
scalarizePHI needs to insert the next ExtractElement in the same block
Browse files Browse the repository at this point in the history
as the BinaryOperator, *not* in the block where the IRBuilder is currently
inserting into. Fixes a bug where scalarizePHI would create instructions
that would not dominate all uses.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@182639 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
jgouly committed May 24, 2013
1 parent 77226a0 commit 4a94131
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/Transforms/InstCombine/InstCombineVectorOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,10 @@ Instruction *InstCombiner::scalarizePHI(ExtractElementInst &EI, PHINode *PN) {
// vector operand.
BinaryOperator *B0 = cast<BinaryOperator>(PHIUser);
unsigned opId = (B0->getOperand(0) == PN) ? 1: 0;
Value *Op = Builder->CreateExtractElement(
B0->getOperand(opId), Elt, B0->getOperand(opId)->getName()+".Elt");
Value *Op = InsertNewInstWith(
ExtractElementInst::Create(B0->getOperand(opId), Elt,
B0->getOperand(opId)->getName() + ".Elt"),
*B0);
Value *newPHIUser = InsertNewInstWith(
BinaryOperator::Create(B0->getOpcode(), scalarPHI,Op),
*B0);
Expand Down
25 changes: 25 additions & 0 deletions test/Transforms/InstCombine/vec_phi_extract.ll
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,28 @@ ret:
ret void
}

define i1 @g(<3 x i32> %input_2) {
; CHECK: extractelement
entry:
br label %for.cond

for.cond:
; CHECK: phi i32
%input_2.addr.0 = phi <3 x i32> [ %input_2, %entry ], [ %div45, %for.body ]
%input_1.addr.1 = phi <3 x i32> [ undef, %entry ], [ %dec43, %for.body ]
br i1 undef, label %for.end, label %for.body

; CHECK extractelement
for.body:
%dec43 = add <3 x i32> %input_1.addr.1, <i32 -1, i32 -1, i32 -1>
%sub44 = sub <3 x i32> zeroinitializer, %dec43
%div45 = sdiv <3 x i32> %input_2.addr.0, %sub44
br label %for.cond

for.end:
%0 = extractelement <3 x i32> %input_2.addr.0, i32 0
%.89 = select i1 false, i32 0, i32 %0
%tobool313 = icmp eq i32 %.89, 0
ret i1 %tobool313
}

0 comments on commit 4a94131

Please sign in to comment.