[polly] r245294 - Fix Codegen adding a second exit out of region
Michael Kruse via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 18 06:14:42 PDT 2015
Author: meinersbur
Date: Tue Aug 18 08:14:42 2015
New Revision: 245294
URL: http://llvm.org/viewvc/llvm-project?rev=245294&view=rev
Log:
Fix Codegen adding a second exit out of region
executeScopConditionally would destroy a predecessor region if it the
scop's entry was the region's exit block by forking it to polly.start
and thus creating a secnd exit out of the region. This patch "shrinks"
the predecessor region s.t. polly.split_new_and_old is not the
region's exit anymore.
Added:
polly/trunk/test/Isl/CodeGen/split_edge_of_exit.ll
Modified:
polly/trunk/lib/CodeGen/Utils.cpp
Modified: polly/trunk/lib/CodeGen/Utils.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/Utils.cpp?rev=245294&r1=245293&r2=245294&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/Utils.cpp (original)
+++ polly/trunk/lib/CodeGen/Utils.cpp Tue Aug 18 08:14:42 2015
@@ -103,6 +103,18 @@ BasicBlock *polly::executeScopConditiona
splitEdge(EnteringBB, EntryBB, ".split_new_and_old", &DT, &LI, &RI);
SplitBlock->setName("polly.split_new_and_old");
+ // If EntryBB is the exit block of the region that includes Prev, exclude
+ // SplitBlock from that region by making it itself the exit block. This is
+ // trivially possible because there is just one edge to EnteringBB.
+ // This is necessary because we will add an outgoing edge from SplitBlock,
+ // which would violate the single exit block requirement of PrevRegion.
+ Region *PrevRegion = RI.getRegionFor(EnteringBB);
+ while (PrevRegion->getExit() == EntryBB) {
+ PrevRegion->replaceExit(SplitBlock);
+ PrevRegion = PrevRegion->getParent();
+ }
+ RI.setRegionFor(SplitBlock, PrevRegion);
+
// Create a join block
BasicBlock *ExitingBB = R.getExitingBlock();
BasicBlock *ExitBB = R.getExit();
Added: polly/trunk/test/Isl/CodeGen/split_edge_of_exit.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/split_edge_of_exit.ll?rev=245294&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/split_edge_of_exit.ll (added)
+++ polly/trunk/test/Isl/CodeGen/split_edge_of_exit.ll Tue Aug 18 08:14:42 2015
@@ -0,0 +1,31 @@
+; RUN: opt %loadPolly -polly-detect-unprofitable -polly-no-early-exit -polly-detect -analyze < %s | FileCheck %s
+; RUN: opt %loadPolly -polly-detect-unprofitable -polly-no-early-exit -polly-codegen -verify-region-info -analyze < %s
+;
+; This is a scop directly precedented by a region, i.e. the scop's entry is the
+; region's exit block. This test is to ensure that the RegionInfo is correctly
+; preserved.
+;
+; CHECK: Valid Region for Scop: region2 => return
+;
+define void @f1(i64* %A, i64 %N) nounwind {
+entry:
+ br label %region1
+
+region1:
+ %indvar1 = phi i64 [ 0, %entry ], [ %indvar1.next, %region1 ]
+ fence seq_cst
+ %indvar1.next = add nsw i64 %indvar1, 1
+ %exitcond1 = icmp eq i64 %indvar1.next, %N
+ br i1 %exitcond1, label %region2, label %region1
+
+region2:
+ %indvar2 = phi i64 [ 0, %region1 ], [ %indvar2.next, %region2 ]
+ %scevgep2 = getelementptr i64, i64* %A, i64 %indvar2
+ store i64 %indvar2, i64* %scevgep2
+ %indvar2.next = add nsw i64 %indvar2, 1
+ %exitcond2 = icmp eq i64 %indvar2.next, %N
+ br i1 %exitcond2, label %return, label %region2
+
+return:
+ ret void
+}
More information about the llvm-commits
mailing list