[PATCH] Use ScalarEvolution to create tight bounds on the parameters

Johannes Doerfert doerfert at cs.uni-saarland.de
Thu Feb 12 00:03:30 PST 2015


Hi grosser, sebpop, simbuerg, zinob,

http://reviews.llvm.org/D7579

Files:
  lib/Analysis/ScopInfo.cpp
  test/ScopInfo/ranged_parameter.ll

Index: lib/Analysis/ScopInfo.cpp
===================================================================
--- lib/Analysis/ScopInfo.cpp
+++ lib/Analysis/ScopInfo.cpp
@@ -1193,33 +1193,22 @@
 }
 
 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);
+    Context = isl_set_lower_bound_val(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);
+    Context = isl_set_upper_bound_val(Context, isl_dim_param, dim, V);
   }
 }
 
@@ -1271,6 +1260,7 @@
   //   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.
Index: test/ScopInfo/ranged_parameter.ll
===================================================================
--- /dev/null
+++ test/ScopInfo/ranged_parameter.ll
@@ -0,0 +1,38 @@
+; RUN: opt %loadPolly -polly-scops -analyze < %s | FileCheck %s
+;
+; 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 }

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7579.19808.patch
Type: text/x-patch
Size: 3183 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150212/869a985a/attachment.bin>


More information about the llvm-commits mailing list