[polly] r247545 - [FIX] Handle error blocks in non-affine regions correctly

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 14 04:15:58 PDT 2015


Author: jdoerfert
Date: Mon Sep 14 06:15:58 2015
New Revision: 247545

URL: http://llvm.org/viewvc/llvm-project?rev=247545&view=rev
Log:
[FIX] Handle error blocks in non-affine regions correctly

Added:
    polly/trunk/test/Isl/CodeGen/error-stmt-in-non-affine-region.ll
Modified:
    polly/trunk/lib/Analysis/ScopInfo.cpp
    polly/trunk/lib/CodeGen/BlockGenerators.cpp

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=247545&r1=247544&r2=247545&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Mon Sep 14 06:15:58 2015
@@ -1663,6 +1663,15 @@ getDomainForBlock(BasicBlock *BB, DenseM
   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(Re
     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));

Modified: polly/trunk/lib/CodeGen/BlockGenerators.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/BlockGenerators.cpp?rev=247545&r1=247544&r2=247545&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/BlockGenerators.cpp (original)
+++ polly/trunk/lib/CodeGen/BlockGenerators.cpp Mon Sep 14 06:15:58 2015
@@ -1032,9 +1032,17 @@ void RegionGenerator::copyStmt(ScopStmt
   // 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];

Added: polly/trunk/test/Isl/CodeGen/error-stmt-in-non-affine-region.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/error-stmt-in-non-affine-region.ll?rev=247545&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/error-stmt-in-non-affine-region.ll (added)
+++ polly/trunk/test/Isl/CodeGen/error-stmt-in-non-affine-region.ll Mon Sep 14 06:15:58 2015
@@ -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()




More information about the llvm-commits mailing list