[polly] r295349 - [ScopInfo] Always derive upper and lower bounds for parameters

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 16 10:39:14 PST 2017


Author: grosser
Date: Thu Feb 16 12:39:14 2017
New Revision: 295349

URL: http://llvm.org/viewvc/llvm-project?rev=295349&view=rev
Log:
[ScopInfo] Always derive upper and lower bounds for parameters

Commit r230230 introduced the use of range metadata to derive bounds for
parameters, instead of just looking at the type of the parameter. As part of
this commit support for wrapping ranges was added, where the lower bound of a
parameter is larger than the upper bound:

  { 255 < p || p < 0 }

However, at the same time, for wrapping ranges support for adding bounds given
by the size of the containing type has acidentally been dropped. As a result,
the range of the parameters was not guaranteed to be bounded any more. This
change makes sure we always add the bounds given by the size of the type and
then additionally add bounds based on signed wrapping, if available. For a
parameter p with a type size of 32 bit, the valid range is then:

  { -2147483648 <= p <= 2147483647 and (255 < p or p < 0) }

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

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=295349&r1=295348&r2=295349&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Thu Feb 16 12:39:14 2017
@@ -145,21 +145,30 @@ static __isl_give isl_set *addRangeBound
   isl_val *V;
   isl_ctx *ctx = isl_set_get_ctx(S);
 
-  bool useLowerUpperBound = Range.isSignWrappedSet() && !Range.isFullSet();
-  const auto LB = useLowerUpperBound ? Range.getLower() : Range.getSignedMin();
-  V = isl_valFromAPInt(ctx, LB, true);
-  isl_set *SLB = isl_set_lower_bound_val(isl_set_copy(S), type, dim, V);
-
-  const auto UB = useLowerUpperBound ? Range.getUpper() : Range.getSignedMax();
-  V = isl_valFromAPInt(ctx, UB, true);
-  if (useLowerUpperBound)
+  // The upper and lower bound for a parameter value is derived either from
+  // the data type of the parameter or from the - possibly more restrictive -
+  // range metadata.
+  V = isl_valFromAPInt(ctx, Range.getSignedMin(), true);
+  S = isl_set_lower_bound_val(S, type, dim, V);
+  V = isl_valFromAPInt(ctx, Range.getSignedMax(), true);
+  S = isl_set_upper_bound_val(S, type, dim, V);
+
+  if (Range.isFullSet())
+    return S;
+
+  // In case of signed wrapping, we can refine the set of valid values by
+  // excluding the part not covered by the wrapping range.
+  if (Range.isSignWrappedSet()) {
+    V = isl_valFromAPInt(ctx, Range.getLower(), true);
+    isl_set *SLB = isl_set_lower_bound_val(isl_set_copy(S), type, dim, V);
+
+    V = isl_valFromAPInt(ctx, Range.getUpper(), true);
     V = isl_val_sub_ui(V, 1);
-  isl_set *SUB = isl_set_upper_bound_val(S, type, dim, V);
+    isl_set *SUB = isl_set_upper_bound_val(S, type, dim, V);
+    S = isl_set_union(SLB, SUB);
+  }
 
-  if (useLowerUpperBound)
-    return isl_set_union(SLB, SUB);
-  else
-    return isl_set_intersect(SLB, SUB);
+  return S;
 }
 
 static const ScopArrayInfo *identifyBasePtrOriginSAI(Scop *S, Value *BasePtr) {

Modified: polly/trunk/test/ScopInfo/ranged_parameter_wrap.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/ranged_parameter_wrap.ll?rev=295349&r1=295348&r2=295349&view=diff
==============================================================================
--- polly/trunk/test/ScopInfo/ranged_parameter_wrap.ll (original)
+++ polly/trunk/test/ScopInfo/ranged_parameter_wrap.ll Thu Feb 16 12:39:14 2017
@@ -4,7 +4,7 @@
 ; __wrapping__ range metadata (see bottom of the file) are present:
 ;
 ; CHECK: Context:
-; CHECK:   [tmp] -> {  : tmp >= 256 or tmp < 0 }
+; CHECK:   [tmp] -> {  : -2147483648 <= tmp <= 2147483647 and (tmp >= 256 or tmp < 0) }
 ;
 ;    void jd(int *A, int *p /* in [256, 0) */) {
 ;      for (int i = 0; i < 1024; i++)




More information about the llvm-commits mailing list