Fix dominance when subregion exit is outside scop

The dominance of the generated non-affine subregion block was based on
the scop's merge block, therefore resulted in an invalid DominanceTree.
It resulted in some values as assumed to be unusable in the actual
generated exit block.

We detect the case that the exit block has been moved and decide
dominance using the BB at the original exit. If we create another exit
node, that exit nodes is dominated by the one generated from where the
original exit resides. This fixes llvm.org/PR25438 and part of
llvm.org/PR25439.

llvm-svn: 252526
This commit is contained in:
Michael Kruse 2015-11-09 23:07:38 +00:00
parent 1ad0146498
commit d6fb6f1b0c
4 changed files with 53 additions and 6 deletions

View File

@ -1012,6 +1012,8 @@ void RegionGenerator::copyStmt(ScopStmt &Stmt, LoopToScevMapT &LTS,
assert(Stmt.isRegionStmt() &&
"Only region statements can be copied by the region generator");
Scop *S = Stmt.getParent();
// Forget all old mappings.
BlockMap.clear();
RegionMaps.clear();
@ -1037,6 +1039,17 @@ void RegionGenerator::copyStmt(ScopStmt &Stmt, LoopToScevMapT &LTS,
if (!R->contains(*PI))
BlockMap[*PI] = EntryBBCopy;
// Determine the original exit block of this subregion. If it the exit block
// is also the scop's exit, it it has been changed to polly.merge_new_and_old.
// We move one block back to find the original block. This only happens if the
// scop required simplification.
// If the whole scop consists of only this non-affine region, then they share
// the same Region object, such that we cannot change the exit of one and not
// the other.
BasicBlock *ExitBB = R->getExit();
if (!S->hasSingleExitEdge() && ExitBB == S->getRegion().getExit())
ExitBB = *(++pred_begin(ExitBB));
// Iterate over all blocks in the region in a breadth-first search.
std::deque<BasicBlock *> Blocks;
SmallPtrSet<BasicBlock *, 8> SeenBlocks;
@ -1078,7 +1091,7 @@ void RegionGenerator::copyStmt(ScopStmt &Stmt, LoopToScevMapT &LTS,
Blocks.push_back(*SI);
// Remember value in case it is visible after this subregion.
if (DT.dominates(BB, R->getExit()))
if (DT.dominates(BB, ExitBB))
ValueMap.insert(RegionMap.begin(), RegionMap.end());
}
@ -1088,7 +1101,10 @@ void RegionGenerator::copyStmt(ScopStmt &Stmt, LoopToScevMapT &LTS,
ExitBBCopy->setName("polly.stmt." + R->getExit()->getName() + ".exit");
BlockMap[R->getExit()] = ExitBBCopy;
repairDominance(R->getExit(), ExitBBCopy);
if (ExitBB == R->getExit())
repairDominance(ExitBB, ExitBBCopy);
else
DT.changeImmediateDominator(ExitBBCopy, BlockMap.lookup(ExitBB));
// As the block generator doesn't handle control flow we need to add the
// region control flow by hand after all blocks have been copied.

View File

@ -0,0 +1,30 @@
; RUN: opt %loadPolly -polly-codegen -S < %s | FileCheck %s
;
; llvm.org/PR25439
; The dominance of the generated non-affine subregion block was based on the
; scop's merge block, therefore resulted in an invalid DominanceTree.
; It resulted in some values as assumed to be unusable in the actual generated
; exit block. Here we check whether the value %escaping is taken from the
; generated block.
;
; CHECK-LABEL: polly.stmt.subregion_entry:
; CHECK: %p_escaping = select i1 undef, i32 undef, i32 undef
;
; CHECK-LABEL: polly.stmt.polly.merge_new_and_old.exit:
; CHECK: store i32 %p_escaping, i32* %escaping.s2a
define i32 @func() {
entry:
br label %subregion_entry
subregion_entry:
%escaping = select i1 undef, i32 undef, i32 undef
%cond = or i1 undef, undef
br i1 %cond, label %subregion_exit, label %subregion_if
subregion_if:
br label %subregion_exit
subregion_exit:
ret i32 %escaping
}

View File

@ -1,5 +1,5 @@
; RUN: opt %loadPolly -polly-codegen -S < %s | FileCheck %s
; XFAIL: *
;
; llvm.org/PR25438
; After loop versioning, a dominance check of a non-affine subregion's exit node
; causes the dominance check to always fail any block in the scop. The
@ -13,7 +13,7 @@
; CHECK: a.phiops.reload = load i32, i32* %a.phiops
;
; CHECK-LABEL: polly.stmt.polly.merge_new_and_old.exit:
; CHECK: store i32 %a.phiops.reload, i32* %a.s2a
; CHECK: store i32 %polly.a, i32* %a.s2a
define void @func() {
entry:

View File

@ -6,10 +6,11 @@
; CHECK-LABEL: polly.stmt.if.then.862:
; CHECK: %[[R1:[0-9]+]] = add i32 %tmp, 1
; CHECK: store i32 %0, i32* %curr.3.s2a
; CHECK: br label
; CHECK-LABEL: polly.stmt.while.body.740.region_exiting:
; CHECK: %polly.curr.3.ph = phi i32 [ undef, %polly.stmt.if.else.864 ], [ %[[R1]], %polly.stmt.if.then.862 ]
; CHECK-LABEL: polly.stmt.polly.merge_new_and_old.exit:
; CHECK: %curr.3.ph.final_reload = load i32, i32* %curr.3.s2a
; CHECK: br label