[polly] r183800 - ScopDetect: check region entering edges are valid.

Sebastian Pop spop at codeaurora.org
Tue Jun 11 15:20:40 PDT 2013


Author: spop
Date: Tue Jun 11 17:20:40 2013
New Revision: 183800

URL: http://llvm.org/viewvc/llvm-project?rev=183800&view=rev
Log:
ScopDetect: check region entering edges are valid.

When a region header is part of a loop, then all entering edges of this region
should not come from the loop but outside the region. Otherwise, the loop may be
only partially part of the region, which would cause troubles in handling
induction variables.

Currently, we can only model induction variables that are either fully part of
the scop (loop induction variable) or induction variables that are scop-
invariant (parameter). A loop that is only partially part of the
scop causes troubles, as there is no good way to handle the induction
variable in the independent blocks pass.

Contributed-by:    Star Tan <tanmx_star at yeah.net>

Added:
    polly/trunk/test/ScopDetect/indvars.ll
      - copied, changed from r183799, polly/trunk/test/IndependentBlocks/indvars.ll
Removed:
    polly/trunk/test/IndependentBlocks/indvars.ll
Modified:
    polly/trunk/lib/Analysis/ScopDetection.cpp

Modified: polly/trunk/lib/Analysis/ScopDetection.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopDetection.cpp?rev=183800&r1=183799&r2=183800&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopDetection.cpp (original)
+++ polly/trunk/lib/Analysis/ScopDetection.cpp Tue Jun 11 17:20:40 2013
@@ -138,6 +138,7 @@ STATISTIC(ValidRegion, "Number of region
 
 BADSCOP_STAT(CFG, "CFG too complex");
 BADSCOP_STAT(IndVar, "Non canonical induction variable in loop");
+BADSCOP_STAT(IndEdge, "Found invalid region entering edges");
 BADSCOP_STAT(LoopBound, "Loop bounds can not be computed");
 BADSCOP_STAT(FuncCall, "Function call with side effects appeared");
 BADSCOP_STAT(AffFunc, "Expression not affine");
@@ -549,9 +550,21 @@ bool ScopDetection::isValidRegion(Detect
   }
 
   if (!R.getEnteringBlock()) {
-    Loop *L = LI->getLoopFor(R.getEntry());
-    if (L && !L->isLoopSimplifyForm())
-      INVALID(SimpleLoop, "Loop not in simplify form is invalid!");
+    BasicBlock *entry = R.getEntry();
+    Loop *L = LI->getLoopFor(entry);
+
+    if (L) {
+      if (!L->isLoopSimplifyForm())
+        INVALID(SimpleLoop, "Loop not in simplify form is invalid!");
+
+      for (pred_iterator PI = pred_begin(entry), PE = pred_end(entry); PI != PE;
+           ++PI) {
+        // Region entering edges come from the same loop but outside the region
+        // are not allowed.
+        if (L->contains(*PI) && !R.contains(*PI))
+          INVALID(IndEdge, "Region has invalid entering edges!");
+      }
+    }
   }
 
   // SCoP cannot contain the entry block of the function, because we need

Removed: polly/trunk/test/IndependentBlocks/indvars.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/IndependentBlocks/indvars.ll?rev=183799&view=auto
==============================================================================
--- polly/trunk/test/IndependentBlocks/indvars.ll (original)
+++ polly/trunk/test/IndependentBlocks/indvars.ll (removed)
@@ -1,39 +0,0 @@
-; RUN: opt %loadPolly -polly-independent -polly-codegen-scev %s | FileCheck %s
-; XFAIL: *
-;
-; Ensure that the independent block pass does not invalidate the induction
-; variable here.
-target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
-target triple = "x86_64-unknown-linux-gnu"
-
-define void @main() nounwind {
-entry:
-  br label %for.i
-
-for.i:
-  %indvar.i = phi i64 [ 0, %entry ], [ %indvar.next.i, %for.i.backedge ]
-  br i1 true, label %for.j.preheader, label %for.j2
-
-for.j.preheader:
-  br label %for.j
-
-for.j:
-  %indvar.j = phi i64 [ %indvar.next.j, %for.j ], [ 0, %for.j.preheader ]
-  %indvar.next.j = add i64 %indvar.j, 1
-  %exitcond.j = icmp eq i64 %indvar.next.j, 0
-  br i1 %exitcond.j, label %for.j2, label %for.j
-
-for.j2:
-  fence seq_cst
-  br label %for.i.backedge
-
-for.i.backedge:
-  %indvar.next.i = add i64 %indvar.i, 1
-  %exitcond.i = icmp eq i64 %indvar.next.i, 2048
-  br i1 %exitcond.i, label %for.i, label %.end
-
-.end:
-  ret void
-}
-
-; CHECK: %indvar.j = phi i64 [ %indvar.next.j, %for.j ], [ 0, %for.j.preheader ]

Copied: polly/trunk/test/ScopDetect/indvars.ll (from r183799, polly/trunk/test/IndependentBlocks/indvars.ll)
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopDetect/indvars.ll?p2=polly/trunk/test/ScopDetect/indvars.ll&p1=polly/trunk/test/IndependentBlocks/indvars.ll&r1=183799&r2=183800&rev=183800&view=diff
==============================================================================
--- polly/trunk/test/IndependentBlocks/indvars.ll (original)
+++ polly/trunk/test/ScopDetect/indvars.ll Tue Jun 11 17:20:40 2013
@@ -1,17 +1,20 @@
-; RUN: opt %loadPolly -polly-independent -polly-codegen-scev %s | FileCheck %s
-; XFAIL: *
+; RUN: opt %loadPolly -analyze -polly-detect -polly-codegen-isl -polly-codegen-scev < %s | FileCheck %s
 ;
-; Ensure that the independent block pass does not invalidate the induction
-; variable here.
+; When a region header is part of a loop, then all entering edges of this region
+; should not come from the loop but outside the region.
+
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
 target triple = "x86_64-unknown-linux-gnu"
 
-define void @main() nounwind {
+define void @main(i64* %A) nounwind {
 entry:
   br label %for.i
 
 for.i:
   %indvar.i = phi i64 [ 0, %entry ], [ %indvar.next.i, %for.i.backedge ]
+  %indvar.next.i = add i64 %indvar.i, 1
+  %scevgep = getelementptr i64* %A, i64 %indvar.i
+  store i64 %indvar.i, i64* %scevgep, align 4
   br i1 true, label %for.j.preheader, label %for.j2
 
 for.j.preheader:
@@ -20,7 +23,7 @@ for.j.preheader:
 for.j:
   %indvar.j = phi i64 [ %indvar.next.j, %for.j ], [ 0, %for.j.preheader ]
   %indvar.next.j = add i64 %indvar.j, 1
-  %exitcond.j = icmp eq i64 %indvar.next.j, 0
+  %exitcond.j = icmp eq i64 %indvar.next.j, 10
   br i1 %exitcond.j, label %for.j2, label %for.j
 
 for.j2:
@@ -28,7 +31,6 @@ for.j2:
   br label %for.i.backedge
 
 for.i.backedge:
-  %indvar.next.i = add i64 %indvar.i, 1
   %exitcond.i = icmp eq i64 %indvar.next.i, 2048
   br i1 %exitcond.i, label %for.i, label %.end
 
@@ -36,4 +38,4 @@ for.i.backedge:
   ret void
 }
 
-; CHECK: %indvar.j = phi i64 [ %indvar.next.j, %for.j ], [ 0, %for.j.preheader ]
+; CHECK: Valid Region for Scop: for.j => for.j2





More information about the llvm-commits mailing list