[polly] r250693 - Synthesize phi arguments in incoming block

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 19 02:19:29 PDT 2015


Author: meinersbur
Date: Mon Oct 19 04:19:25 2015
New Revision: 250693

URL: http://llvm.org/viewvc/llvm-project?rev=250693&view=rev
Log:
Synthesize phi arguments in incoming block

New values were always synthesized in the block of the instruction
that needed them. This is incorrect for PHI node whose' value must be
defined in the respective incoming block. This patch temporarily moves
the builder's insert point to the incoming block while synthesizing phi
node arguments. 

This fixes PR25241 (http://llvm.org/bugs/show_bug.cgi?id=25241)


Added:
    polly/trunk/test/Isl/CodeGen/pr25241.ll
Modified:
    polly/trunk/lib/CodeGen/BlockGenerators.cpp

Modified: polly/trunk/lib/CodeGen/BlockGenerators.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/BlockGenerators.cpp?rev=250693&r1=250692&r2=250693&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/BlockGenerators.cpp (original)
+++ polly/trunk/lib/CodeGen/BlockGenerators.cpp Mon Oct 19 04:19:25 2015
@@ -1181,7 +1181,11 @@ void RegionGenerator::addOperandToPHI(Sc
     ValueMapT &BBCopyMap = RegionMaps[BBCopy];
 
     Value *Op = PHI->getIncomingValueForBlock(IncomingBB);
+
+    auto OldIP = Builder.GetInsertPoint();
+    Builder.SetInsertPoint(BBCopy->getTerminator());
     OpCopy = getNewValue(Stmt, Op, BBCopyMap, LTS, getLoopForInst(PHI));
+    Builder.SetInsertPoint(OldIP);
   } else {
 
     if (PHICopy->getBasicBlockIndex(BBCopy) >= 0)

Added: polly/trunk/test/Isl/CodeGen/pr25241.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/pr25241.ll?rev=250693&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/pr25241.ll (added)
+++ polly/trunk/test/Isl/CodeGen/pr25241.ll Mon Oct 19 04:19:25 2015
@@ -0,0 +1,61 @@
+; RUN: opt %loadPolly -polly-codegen -S < %s | FileCheck %s
+
+; PR25241 (https://llvm.org/bugs/show_bug.cgi?id=25241)
+; Ensure that synthesized values of a PHI node argument are generated in the
+; incoming block, not in the PHI's block.
+
+; CHECK-LABEL: polly.stmt.if.then.862:
+; CHECK:         %[[R1:[0-9]+]] = add i32 %tmp, 1
+; CHECK:         br label
+
+; CHECK-LABEL: polly.stmt.while.body.740.region_exiting:
+; CHECKL         %polly.curr.3.ph = phi i32 [ undef, %polly.stmt.if.else.864 ], [ %[[R1]], %polly.stmt.if.then.862 ]
+; CHECK:         br label
+
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; Function Attrs: nounwind uwtable
+define void @BZ2_decompress() #0 {
+entry:
+  %tmp = load i32, i32* undef, align 4, !tbaa !1
+  switch i32 undef, label %save_state_and_return [
+    i32 34, label %sw.bb.748
+    i32 35, label %if.then.813
+  ]
+
+while.body.740:                                   ; preds = %if.else.864, %if.then.862
+  %curr.3 = phi i32 [ %inc863, %if.then.862 ], [ undef, %if.else.864 ]
+  unreachable
+
+sw.bb.748:                                        ; preds = %entry
+  unreachable
+
+if.then.813:                                      ; preds = %entry
+  %conv823903 = and i32 undef, undef
+  %cmp860 = icmp eq i32 %conv823903, 0
+  br i1 %cmp860, label %if.then.862, label %if.else.864
+
+if.then.862:                                      ; preds = %if.then.813
+  %inc863 = add nsw i32 %tmp, 1
+  br label %while.body.740
+
+if.else.864:                                      ; preds = %if.then.813
+  br label %while.body.740
+
+save_state_and_return:                            ; preds = %entry
+  ret void
+}
+
+attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
+
+!llvm.ident = !{!0}
+
+!0 = !{!"clang version 3.8.0 (trunk 250010) (llvm/trunk 250018)"}
+!1 = !{!2, !6, i64 64092}
+!2 = !{!"", !3, i64 0, !6, i64 8, !4, i64 12, !6, i64 16, !4, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40, !4, i64 44, !6, i64 48, !6, i64 52, !6, i64 56, !6, i64 60, !6, i64 64, !4, i64 68, !6, i64 1092, !4, i64 1096, !4, i64 2124, !3, i64 3152, !3, i64 3160, !3, i64 3168, !6, i64 3176, !6, i64 3180, !6, i64 3184, !6, i64 3188, !6, i64 3192, !4, i64 3196, !4, i64 3452, !4, i64 3468, !4, i64 3724, !4, i64 7820, !4, i64 7884, !4, i64 25886, !4, i64 43888, !4, i64 45436, !4, i64 51628, !4, i64 57820, !4, i64 64012, !6, i64 64036, !6, i64 64040, !6, i64 64044, !6, i64 64048, !6, i64 64052, !6, i64 64056, !6, i64 64060, !6, i64 64064, !6, i64 64068, !6, i64 64072, !6, i64 64076, !6, i64 64080, !6, i64 64084, !6, i64 64088, !6, i64 64092, !6, i64 64096, !6, i64 64100, !6, i64 64104, !6, i64 64108, !6, i64 64112, !6, i64 64116, !3, i64 64120, !3, i64 64128, !3, i64 64136}
+!3 = !{!"any pointer", !4, i64 0}
+!4 = !{!"omnipotent char", !5, i64 0}
+!5 = !{!"Simple C/C++ TBAA"}
+!6 = !{!"int", !4, i64 0}




More information about the llvm-commits mailing list