forked from OSchip/llvm-project
[FIX] Handle error blocks in non-affine regions correctly
llvm-svn: 247545
This commit is contained in:
parent
40fa56f59f
commit
e114dc024e
|
@ -1663,6 +1663,15 @@ getDomainForBlock(BasicBlock *BB, DenseMap<BasicBlock *, isl_set *> &DomainMap,
|
|||
return getDomainForBlock(R->getEntry(), DomainMap, RI);
|
||||
}
|
||||
|
||||
static bool containsErrorBlock(RegionNode *RN) {
|
||||
if (!RN->isSubRegion())
|
||||
return isErrorBlock(*RN->getNodeAs<BasicBlock>());
|
||||
for (BasicBlock *BB : RN->getNodeAs<Region>()->blocks())
|
||||
if (isErrorBlock(*BB))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void Scop::propagateDomainConstraints(Region *R, LoopInfo &LI,
|
||||
ScopDetection &SD, DominatorTree &DT) {
|
||||
// Iterate over the region R and propagate the domain constrains from the
|
||||
|
@ -1751,7 +1760,7 @@ void Scop::propagateDomainConstraints(Region *R, LoopInfo &LI,
|
|||
Domain = isl_set_intersect(Domain, PredDom);
|
||||
|
||||
// Add assumptions for error blocks.
|
||||
if (isErrorBlock(*BB)) {
|
||||
if (containsErrorBlock(RN)) {
|
||||
IsOptimized = true;
|
||||
isl_set *DomPar = isl_set_params(isl_set_copy(Domain));
|
||||
addAssumption(isl_set_complement(DomPar));
|
||||
|
|
|
@ -1032,9 +1032,17 @@ void RegionGenerator::copyStmt(ScopStmt &Stmt, LoopToScevMapT <S,
|
|||
// region control flow by hand after all blocks have been copied.
|
||||
for (BasicBlock *BB : SeenBlocks) {
|
||||
|
||||
BranchInst *BI = cast<BranchInst>(BB->getTerminator());
|
||||
|
||||
BasicBlock *BBCopy = BlockMap[BB];
|
||||
TerminatorInst *TI = BB->getTerminator();
|
||||
if (isa<UnreachableInst>(TI)) {
|
||||
while (!BBCopy->empty())
|
||||
BBCopy->begin()->eraseFromParent();
|
||||
new UnreachableInst(BBCopy->getContext(), BBCopy);
|
||||
continue;
|
||||
}
|
||||
|
||||
BranchInst *BI = cast<BranchInst>(TI);
|
||||
|
||||
Instruction *BICopy = BBCopy->getTerminator();
|
||||
|
||||
ValueMapT &RegionMap = RegionMaps[BBCopy];
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
; RUN: opt %loadPolly -S -polly-codegen -polly-detect-unprofitable -polly-no-early-exit < %s | FileCheck %s
|
||||
;
|
||||
; CHECK-LABEL: polly.stmt.if.then:
|
||||
; CHECK-NEXT: unreachable
|
||||
;
|
||||
; void f(int *A, int N) {
|
||||
; for (int i = 0; i < 1024; i++)
|
||||
; if (i == N) {
|
||||
; if (A[i])
|
||||
; abort();
|
||||
; else
|
||||
; A[i] = i;
|
||||
; }
|
||||
; }
|
||||
;
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
|
||||
define void @f(i32* %A, i64 %N) {
|
||||
entry:
|
||||
br label %for.cond
|
||||
|
||||
for.cond: ; preds = %for.inc, %entry
|
||||
%indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]
|
||||
%cmp = icmp slt i64 %indvars.iv, 1024
|
||||
br i1 %cmp, label %for.body, label %for.end
|
||||
|
||||
for.body: ; preds = %for.cond
|
||||
%arrayidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
|
||||
%tmp = load i32, i32* %arrayidx, align 4
|
||||
%cmp.outer = icmp eq i64 %indvars.iv, %N
|
||||
br i1 %cmp.outer, label %if.then.outer, label %for.inc
|
||||
|
||||
if.then.outer:
|
||||
%tobool = icmp eq i32 %tmp, 0
|
||||
br i1 %tobool, label %if.else, label %if.then
|
||||
|
||||
if.then: ; preds = %for.body
|
||||
call void @abort()
|
||||
unreachable
|
||||
|
||||
if.else: ; preds = %for.body
|
||||
%arrayidx2 = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
|
||||
%tmp1 = trunc i64 %indvars.iv to i32
|
||||
store i32 %tmp1, i32* %arrayidx2, align 4
|
||||
br label %if.end
|
||||
|
||||
if.end: ; preds = %if.else
|
||||
br label %for.inc
|
||||
|
||||
for.inc: ; preds = %if.end
|
||||
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
|
||||
br label %for.cond
|
||||
|
||||
for.end: ; preds = %for.cond
|
||||
ret void
|
||||
}
|
||||
|
||||
declare void @abort()
|
Loading…
Reference in New Issue