forked from OSchip/llvm-project
Use ScalarEvolution to create tight bounds on the parameters
llvm-svn: 230230
This commit is contained in:
parent
1cacda086f
commit
4f8ac3d123
|
@ -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;
|
||||
int dim = ParamID.second;
|
||||
|
||||
Id = isl_set_get_dim_id(Context, isl_dim_param, i);
|
||||
Scev = (const SCEV *)isl_id_get_user(Id);
|
||||
isl_id_free(Id);
|
||||
ConstantRange SRange = SE->getSignedRange(ParamID.first);
|
||||
|
||||
T = dyn_cast<IntegerType>(Scev->getType());
|
||||
|
||||
if (!T)
|
||||
// TODO: Find a case where the full set is actually helpful.
|
||||
if (SRange.isFullSet())
|
||||
continue;
|
||||
|
||||
Width = T->getBitWidth();
|
||||
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_val_neg(V);
|
||||
Context = isl_set_lower_bound_val(Context, isl_dim_param, i, 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.
|
||||
|
|
|
@ -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 }
|
|
@ -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 }
|
Loading…
Reference in New Issue