[polly] r230230 - Use ScalarEvolution to create tight bounds on the parameters

Johannes Doerfert doerfert at cs.uni-saarland.de
Mon Feb 23 08:15:51 PST 2015


Author: jdoerfert
Date: Mon Feb 23 10:15:51 2015
New Revision: 230230

URL: http://llvm.org/viewvc/llvm-project?rev=230230&view=rev
Log:
Use ScalarEvolution to create tight bounds on the parameters

Added:
    polly/trunk/test/ScopInfo/ranged_parameter.ll
    polly/trunk/test/ScopInfo/ranged_parameter_wrap.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=230230&r1=230229&r2=230230&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Mon Feb 23 10:15:51 2015
@@ -1187,33 +1187,29 @@ void Scop::buildContext() {
 }
 
 void Scop::addParameterBounds() {
-  for (unsigned i = 0; i < isl_set_dim(Context, isl_dim_param); ++i) {
+  for (const auto &ParamID : ParameterIds) {
     isl_val *V;
-    isl_id *Id;
-    const SCEV *Scev;
-    const IntegerType *T;
-    int Width;
-
-    Id = isl_set_get_dim_id(Context, isl_dim_param, i);
-    Scev = (const SCEV *)isl_id_get_user(Id);
-    isl_id_free(Id);
+    int dim = ParamID.second;
 
-    T = dyn_cast<IntegerType>(Scev->getType());
+    ConstantRange SRange = SE->getSignedRange(ParamID.first);
 
-    if (!T)
+    // TODO: Find a case where the full set is actually helpful.
+    if (SRange.isFullSet())
       continue;
 
-    Width = T->getBitWidth();
-
-    V = isl_val_int_from_si(IslCtx, Width - 1);
-    V = isl_val_2exp(V);
-    V = isl_val_neg(V);
-    Context = isl_set_lower_bound_val(Context, isl_dim_param, i, V);
+    V = isl_valFromAPInt(IslCtx, SRange.getLower(), true);
+    isl_set *ContextLB =
+        isl_set_lower_bound_val(isl_set_copy(Context), isl_dim_param, dim, V);
 
-    V = isl_val_int_from_si(IslCtx, Width - 1);
-    V = isl_val_2exp(V);
+    V = isl_valFromAPInt(IslCtx, SRange.getUpper(), true);
     V = isl_val_sub_ui(V, 1);
-    Context = isl_set_upper_bound_val(Context, isl_dim_param, i, V);
+    isl_set *ContextUB =
+        isl_set_upper_bound_val(Context, isl_dim_param, dim, V);
+
+    if (SRange.isSignWrappedSet())
+      Context = isl_set_union(ContextLB, ContextUB);
+    else
+      Context = isl_set_intersect(ContextLB, ContextUB);
   }
 }
 
@@ -1265,6 +1261,7 @@ void Scop::simplifyAssumedContext() {
   //   only executed for the case m >= 0, it is sufficient to assume p >= 0.
   AssumedContext =
       isl_set_gist_params(AssumedContext, isl_union_set_params(getDomains()));
+  AssumedContext = isl_set_gist_params(AssumedContext, getContext());
 }
 
 /// @brief Add the minimal/maximal access in @p Set to @p User.

Added: polly/trunk/test/ScopInfo/ranged_parameter.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/ranged_parameter.ll?rev=230230&view=auto
==============================================================================
--- polly/trunk/test/ScopInfo/ranged_parameter.ll (added)
+++ polly/trunk/test/ScopInfo/ranged_parameter.ll Mon Feb 23 10:15:51 2015
@@ -0,0 +1,41 @@
+; RUN: opt %loadPolly -polly-detect-unprofitable -polly-scops -analyze < %s | FileCheck %s
+;
+; Check that the contstraints on the paramater derived from the
+; range metadata (see bottom of the file) are present:
+;
+; CHECK: Context:
+; CHECK:   [p_0] -> {  : p_0 >= 0 and p_0 <= 255 }
+;
+;    void jd(int *A, int *p /* in [0,256) */) {
+;      for (int i = 0; i < 1024; i++)
+;        A[i + *p] = i;
+;    }
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @jd(i32* %A, i32* %p) {
+entry:
+  %tmp = load i32* %p, align 4, !range !0
+  br label %for.cond
+
+for.cond:                                         ; preds = %for.inc, %entry
+  %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
+  %exitcond = icmp ne i32 %i.0, 1024
+  br i1 %exitcond, label %for.body, label %for.end
+
+for.body:                                         ; preds = %for.cond
+  %add = add i32 %i.0, %tmp
+  %idxprom = sext i32 %add to i64
+  %arrayidx = getelementptr inbounds i32* %A, i64 %idxprom
+  store i32 %i.0, i32* %arrayidx, align 4
+  br label %for.inc
+
+for.inc:                                          ; preds = %for.body
+  %inc = add nsw i32 %i.0, 1
+  br label %for.cond
+
+for.end:                                          ; preds = %for.cond
+  ret void
+}
+
+!0 =  !{ i32 0, i32 256 }

Added: polly/trunk/test/ScopInfo/ranged_parameter_wrap.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/ranged_parameter_wrap.ll?rev=230230&view=auto
==============================================================================
--- polly/trunk/test/ScopInfo/ranged_parameter_wrap.ll (added)
+++ polly/trunk/test/ScopInfo/ranged_parameter_wrap.ll Mon Feb 23 10:15:51 2015
@@ -0,0 +1,41 @@
+; RUN: opt %loadPolly -polly-detect-unprofitable -polly-scops -analyze < %s | FileCheck %s
+;
+; Check that the contstraints on the paramater derived from the
+; __wrapping__ range metadata (see bottom of the file) are present:
+;
+; CHECK: Context:
+; CHECK:   [tmp] -> {  : tmp >= 256 or tmp <= -1 }
+;
+;    void jd(int *A, int *p /* in [256, 0) */) {
+;      for (int i = 0; i < 1024; i++)
+;        A[i + *p] = i;
+;    }
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @jd(i32* %A, i32* %p) {
+entry:
+  %tmp = load i32* %p, align 4, !range !0
+  br label %for.cond
+
+for.cond:                                         ; preds = %for.inc, %entry
+  %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
+  %exitcond = icmp ne i32 %i.0, 1024
+  br i1 %exitcond, label %for.body, label %for.end
+
+for.body:                                         ; preds = %for.cond
+  %add = add i32 %i.0, %tmp
+  %idxprom = sext i32 %add to i64
+  %arrayidx = getelementptr inbounds i32* %A, i64 %idxprom
+  store i32 %i.0, i32* %arrayidx, align 4
+  br label %for.inc
+
+for.inc:                                          ; preds = %for.body
+  %inc = add nsw i32 %i.0, 1
+  br label %for.cond
+
+for.end:                                          ; preds = %for.cond
+  ret void
+}
+
+!0 =  !{ i32 256, i32 0 }





More information about the llvm-commits mailing list