llvm-project/polly/test/ScopInfo/invariant_loads_cyclic_depe...

64 lines
2.3 KiB
LLVM
Raw Normal View History

; RUN: opt %loadPolly -analyze -polly-scops -polly-invariant-load-hoisting=true < %s | FileCheck %s
Allow invariant loads in the SCoP description This patch allows invariant loads to be used in the SCoP description, e.g., as loop bounds, conditions or in memory access functions. First we collect "required invariant loads" during SCoP detection that would otherwise make an expression we care about non-affine. To this end a new level of abstraction was introduced before SCEVValidator::isAffineExpr() namely ScopDetection::isAffine() and ScopDetection::onlyValidRequiredInvariantLoads(). Here we can decide if we want a load inside the region to be optimistically assumed invariant or not. If we do, it will be marked as required and in the SCoP generation we bail if it is actually not invariant. If we don't it will be a non-affine expression as before. At the moment we optimistically assume all "hoistable" (namely non-loop-carried) loads to be invariant. This causes us to expand some SCoPs and dismiss them later but it also allows us to detect a lot we would dismiss directly if we would ask e.g., AliasAnalysis::canBasicBlockModify(). We also allow potential aliases between optimistically assumed invariant loads and other pointers as our runtime alias checks are sound in case the loads are actually invariant. Together with the invariant checks this combination allows to handle a lot more than LICM can. The code generation of the invariant loads had to be extended as we can now have dependences between parameters and invariant (hoisted) loads as well as the other way around, e.g., test/Isl/CodeGen/invariant_load_parameters_cyclic_dependence.ll First, it is important to note that we cannot have real cycles but only dependences from a hoisted load to a parameter and from another parameter to that hoisted load (and so on). To handle such cases we materialize llvm::Values for parameters that are referred by a hoisted load on demand and then materialize the remaining parameters. Second, there are new kinds of dependences between hoisted loads caused by the constraints on their execution. If a hoisted load is conditionally executed it might depend on the value of another hoisted load. To deal with such situations we sort them already in the ScopInfo such that they can be generated in the order they are listed in the Scop::InvariantAccesses list (see compareInvariantAccesses). The dependences between hoisted loads caused by indirect accesses are handled the same way as before. llvm-svn: 249607
2015-10-08 04:17:36 +08:00
;
; Negative test. If we assume UB[*V] to be invariant we get a cyclic
; dependence in the invariant loads that needs to be resolved by
; ignoring the actual accessed address and focusing on the fact
; that the access happened. However, at the moment we assume UB[*V]
; not to be loop invariant, thus reject this region.
;
; CHECK-NOT: Statements
;
;
; void f(int *restrict V, int *restrict UB, int *restrict A) {
; for (int i = 0; i < 100; i++) {
; int j = 0;
; int x = 0;
; do {
; x = /* invariant load dependent on UB[*V] */ *V;
; A[j + i]++;
; } while (j++ < /* invariant load dependent on *V */ UB[x]);
; }
; }
;
target datalayout = "e-m:e-i32:64-f80:128-n8:16:32:64-S128"
define void @f(i32* noalias %V, i32* noalias %UB, i32* noalias %A) {
entry:
br label %for.cond
for.cond: ; preds = %for.inc, %entry
%indvars.iv2 = phi i32 [ %indvars.iv.next3, %for.inc ], [ 0, %entry ]
%exitcond = icmp ne i32 %indvars.iv2, 100
br i1 %exitcond, label %for.body, label %for.end
for.body: ; preds = %for.cond
br label %do.body
do.body: ; preds = %do.cond, %for.body
%indvars.iv = phi i32 [ %indvars.iv.next, %do.cond ], [ 0, %for.body ]
%tmp = load i32, i32* %V, align 4
%tmp4 = add nuw nsw i32 %indvars.iv, %indvars.iv2
%arrayidx = getelementptr inbounds i32, i32* %A, i32 %tmp4
%tmp5 = load i32, i32* %arrayidx, align 4
%inc = add nsw i32 %tmp5, 1
store i32 %inc, i32* %arrayidx, align 4
br label %do.cond
do.cond: ; preds = %do.body
%indvars.iv.next = add nuw nsw i32 %indvars.iv, 1
%arrayidx3 = getelementptr inbounds i32, i32* %UB, i32 %tmp
%tmp6 = load i32, i32* %arrayidx3, align 4
%cmp4 = icmp slt i32 %indvars.iv, %tmp6
br i1 %cmp4, label %do.body, label %do.end
do.end: ; preds = %do.cond
br label %for.inc
for.inc: ; preds = %do.end
%indvars.iv.next3 = add nuw nsw i32 %indvars.iv2, 1
br label %for.cond
for.end: ; preds = %for.cond
ret void
}