[PATCH] Fix instruction creation in scalarizePHI

Joey Gouly joey.gouly at arm.com
Fri May 24 05:01:56 PDT 2013


Using IRBuilder<> in this part of the function can place instructions in the incorrect block, and they will not dominate all uses.

http://llvm-reviews.chandlerc.com/D857

Files:
  lib/Transforms/InstCombine/InstCombineVectorOps.
  test/Transforms/InstCombine/vec_phi_extract.ll

Index: lib/Transforms/InstCombine/InstCombineVectorOps.
===================================================================
--- lib/Transforms/InstCombine/InstCombineVectorOps.
+++ lib/Transforms/InstCombine/InstCombineVectorOps.
@@ -146,8 +146,9 @@
       // 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 = ExtractElementInst::Create(
+          B0->getOperand(opId), Elt, B0->getOperand(opId)->getName() + ".Elt",
+          B0);
       Value *newPHIUser = InsertNewInstWith(
         BinaryOperator::Create(B0->getOpcode(), scalarPHI,Op),
         *B0);
Index: test/Transforms/InstCombine/vec_phi_extract.ll
===================================================================
--- test/Transforms/InstCombine/vec_phi_extract.ll
+++ test/Transforms/InstCombine/vec_phi_extract.ll
@@ -25,3 +25,26 @@
   ret void
 }
 
+define i1 @g(<3 x i32> %input_2) {
+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
+
+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
+}
+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D857.1.patch
Type: text/x-patch
Size: 1722 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130524/c53ebe56/attachment.bin>


More information about the llvm-commits mailing list