[polly] r247291 - [FIX] Do not assume only one loop can be left at a time

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 10 08:53:59 PDT 2015


Author: jdoerfert
Date: Thu Sep 10 10:53:59 2015
New Revision: 247291

URL: http://llvm.org/viewvc/llvm-project?rev=247291&view=rev
Log:
[FIX] Do not assume only one loop can be left at a time

Added:
    polly/trunk/test/ScopInfo/multiple_exiting_blocks_two_loop.ll
Modified:
    polly/trunk/lib/Analysis/ScopInfo.cpp

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=247291&r1=247290&r2=247291&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Thu Sep 10 10:53:59 2015
@@ -1601,13 +1601,17 @@ void Scop::buildDomainsWithBranchConstra
         // adjust the dimensionality accordingly. Lastly, if we leave a loop
         // and enter a new one we need to drop the old constraints.
         int SuccBBLoopDepth = getRelativeLoopDepth(SuccBBLoop);
-        assert(std::abs(BBLoopDepth - SuccBBLoopDepth) <= 1);
+        unsigned LoopDepthDiff = std::abs(BBLoopDepth - SuccBBLoopDepth);
         if (BBLoopDepth > SuccBBLoopDepth) {
-          CondSet = isl_set_project_out(CondSet, isl_dim_set, BBLoopDepth, 1);
+          CondSet = isl_set_project_out(CondSet, isl_dim_set,
+                                        isl_set_n_dim(CondSet) - LoopDepthDiff,
+                                        LoopDepthDiff);
         } else if (SuccBBLoopDepth > BBLoopDepth) {
+          assert(LoopDepthDiff == 1);
           CondSet = isl_set_add_dims(CondSet, isl_dim_set, 1);
           CondSet = addDomainDimId(CondSet, SuccBBLoopDepth, SuccBBLoop);
         } else if (BBLoopDepth >= 0) {
+          assert(LoopDepthDiff <= 1);
           CondSet = isl_set_project_out(CondSet, isl_dim_set, BBLoopDepth, 1);
           CondSet = isl_set_add_dims(CondSet, isl_dim_set, 1);
           CondSet = addDomainDimId(CondSet, SuccBBLoopDepth, SuccBBLoop);
@@ -1714,15 +1718,19 @@ void Scop::propagateDomainConstraints(Re
           PredBBLoop = PredBBLoop->getParentLoop();
 
         int PredBBLoopDepth = getRelativeLoopDepth(PredBBLoop);
-        assert(std::abs(BBLoopDepth - PredBBLoopDepth) <= 1);
+        unsigned LoopDepthDiff = std::abs(BBLoopDepth - PredBBLoopDepth);
         if (BBLoopDepth < PredBBLoopDepth)
-          PredBBDom =
-              isl_set_project_out(PredBBDom, isl_dim_set, PredBBLoopDepth, 1);
-        else if (PredBBLoopDepth < BBLoopDepth)
+          PredBBDom = isl_set_project_out(
+              PredBBDom, isl_dim_set, isl_set_n_dim(PredBBDom) - LoopDepthDiff,
+              LoopDepthDiff);
+        else if (PredBBLoopDepth < BBLoopDepth) {
+          assert(LoopDepthDiff == 1);
           PredBBDom = isl_set_add_dims(PredBBDom, isl_dim_set, 1);
-        else if (BBLoop != PredBBLoop && BBLoopDepth >= 0)
+        } else if (BBLoop != PredBBLoop && BBLoopDepth >= 0) {
+          assert(LoopDepthDiff <= 1);
           PredBBDom = isl_set_drop_constraints_involving_dims(
               PredBBDom, isl_dim_set, BBLoopDepth, 1);
+        }
       }
 
       PredDom = isl_set_union(PredDom, PredBBDom);

Added: polly/trunk/test/ScopInfo/multiple_exiting_blocks_two_loop.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/multiple_exiting_blocks_two_loop.ll?rev=247291&view=auto
==============================================================================
--- polly/trunk/test/ScopInfo/multiple_exiting_blocks_two_loop.ll (added)
+++ polly/trunk/test/ScopInfo/multiple_exiting_blocks_two_loop.ll Thu Sep 10 10:53:59 2015
@@ -0,0 +1,78 @@
+; RUN: opt %loadPolly -polly-scops -polly-detect-unprofitable -analyze < %s | FileCheck %s
+;
+;    void foo(long n, float A[100]) {
+;      for (long j = 0; j < n; j++) {
+;        for (long i = j; i < n; i++) {
+;          if (i < 0)
+;            goto end;
+;
+;          if (i >= 100)
+;            goto end;
+;
+;          A[i] += i;
+;        }
+;      }
+;    end:
+;      return;
+;    }
+;
+; CHECK: Domain :=
+; CHECK:  [n] -> { Stmt_if_end_7[i0, i1] : i0 >= 0 and i1 <= 99 - i0 and i1 >= 0 and i1 <= -1 + n - i0 };
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @foo(i64 %n, float* %A) {
+entry:
+  br label %for.cond
+
+for.cond:                                         ; preds = %for.inc.8, %entry
+  %j.0 = phi i64 [ 0, %entry ], [ %inc9, %for.inc.8 ]
+  %cmp = icmp slt i64 %j.0, %n
+  br i1 %cmp, label %for.body, label %for.end.10
+
+for.body:                                         ; preds = %for.cond
+  br label %for.cond.1
+
+for.cond.1:                                       ; preds = %for.inc, %for.body
+  %i.0 = phi i64 [ %j.0, %for.body ], [ %inc, %for.inc ]
+  %cmp2 = icmp slt i64 %i.0, %n
+  br i1 %cmp2, label %for.body.3, label %for.end
+
+for.body.3:                                       ; preds = %for.cond.1
+  br i1 false, label %if.then, label %if.end
+
+if.then:                                          ; preds = %for.body.3
+  br label %end
+
+if.end:                                           ; preds = %for.body.3
+  %cmp5 = icmp sgt i64 %i.0, 99
+  br i1 %cmp5, label %if.then.6, label %if.end.7
+
+if.then.6:                                        ; preds = %if.end
+  br label %end
+
+if.end.7:                                         ; preds = %if.end
+  %conv = sitofp i64 %i.0 to float
+  %arrayidx = getelementptr inbounds float, float* %A, i64 %i.0
+  %tmp = load float, float* %arrayidx, align 4
+  %add = fadd float %tmp, %conv
+  store float %add, float* %arrayidx, align 4
+  br label %for.inc
+
+for.inc:                                          ; preds = %if.end.7
+  %inc = add nuw nsw i64 %i.0, 1
+  br label %for.cond.1
+
+for.end:                                          ; preds = %for.cond.1
+  br label %for.inc.8
+
+for.inc.8:                                        ; preds = %for.end
+  %inc9 = add nuw nsw i64 %j.0, 1
+  br label %for.cond
+
+for.end.10:                                       ; preds = %for.cond
+  br label %end
+
+end:                                              ; preds = %for.end.10, %if.then.6, %if.then
+  ret void
+}




More information about the llvm-commits mailing list