[llvm] r182639 - scalarizePHI needs to insert the next ExtractElement in the same block
Joey Gouly
joey.gouly at arm.com
Fri May 24 05:29:54 PDT 2013
Author: joey
Date: Fri May 24 07:29:54 2013
New Revision: 182639
URL: http://llvm.org/viewvc/llvm-project?rev=182639&view=rev
Log:
scalarizePHI needs to insert the next ExtractElement in the same block
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.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
llvm/trunk/test/Transforms/InstCombine/vec_phi_extract.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp?rev=182639&r1=182638&r2=182639&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp Fri May 24 07:29:54 2013
@@ -146,8 +146,10 @@ Instruction *InstCombiner::scalarizePHI(
// 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);
Modified: llvm/trunk/test/Transforms/InstCombine/vec_phi_extract.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/vec_phi_extract.ll?rev=182639&r1=182638&r2=182639&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/vec_phi_extract.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/vec_phi_extract.ll Fri May 24 07:29:54 2013
@@ -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
+}
+
More information about the llvm-commits
mailing list