It's been quite some time the Dependence Analysis (DA) is broken,
as it uses the GEP representation to "identify" multi-dimensional arrays.
It even wrongly detects multi-dimensional arrays in single nested loops:
from test/Analysis/DependenceAnalysis/Coupled.ll, example @couple6
;; for (long int i = 0; i < 50; i++) {
;; A[i][3*i - 6] = i;
;; *B++ = A[i][i];
DA used to detect two subscripts, which makes no sense in the LLVM IR
or in C/C++ semantics, as there are no guarantees as in Fortran of
subscripts not overlapping into a next array dimension:
maximum nesting levels = 1
SrcPtrSCEV = %A
DstPtrSCEV = %A
using GEPs
subscript 0
src = {0,+,1}<nuw><nsw><%for.body>
dst = {0,+,1}<nuw><nsw><%for.body>
class = 1
loops = {1}
subscript 1
src = {-6,+,3}<nsw><%for.body>
dst = {0,+,1}<nuw><nsw><%for.body>
class = 1
loops = {1}
Separable = {}
Coupled = {1}
With the current patch, DA will correctly work on only one dimension:
maximum nesting levels = 1
SrcSCEV = {(-2424 + %A)<nsw>,+,1212}<%for.body>
DstSCEV = {%A,+,404}<%for.body>
subscript 0
src = {(-2424 + %A)<nsw>,+,1212}<%for.body>
dst = {%A,+,404}<%for.body>
class = 1
loops = {1}
Separable = {0}
Coupled = {}
This change removes all uses of GEP from DA, and we now only rely
on the SCEV representation.
The patch does not turn on -da-delinearize by default, and so the DA analysis
will be more conservative in the case of multi-dimensional memory accesses in
nested loops.
I disabled some interchange tests, as the DA is not able to disambiguate
the dependence anymore. To make DA stronger, we may need to
compute a bound on the number of iterations based on the access functions
and array dimensions.
The patch cleans up all the CHECKs in test/Transforms/LoopInterchange/*.ll to
avoid checking for snippets of LLVM IR: this form of checking is very hard to
maintain. Instead, we now check for output of the pass that are more meaningful
than dozens of lines of LLVM IR. Some tests now require -debug messages and thus
only enabled with asserts.
Patch written by Sebastian Pop and Aditya Kumar.
Differential Revision: https://reviews.llvm.org/D35430
llvm-svn: 326837
71 lines
2.5 KiB
LLVM
71 lines
2.5 KiB
LLVM
; REQUIRES: asserts
|
|
; RUN: opt < %s -basicaa -loop-interchange -S -debug 2>&1 | FileCheck %s
|
|
|
|
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
|
target triple = "x86_64-unknown-linux-gnu"
|
|
|
|
@A = common global [100 x [100 x i32]] zeroinitializer
|
|
@C = common global [100 x [100 x i32]] zeroinitializer
|
|
|
|
;; FIXME:
|
|
;; Test for interchange when we have an lcssa phi. This should ideally be interchanged but it is currently not supported.
|
|
;; for(gi=1;gi<N;gi++)
|
|
;; for(gj=1;gj<M;gj++)
|
|
;; A[gj][gi] = A[gj - 1][gi] + C[gj][gi];
|
|
|
|
; CHECK: PHI Nodes in loop nest exit is not handled for now since on failure all loops branch to loop nest exit.
|
|
|
|
@gi = common global i32 0
|
|
@gj = common global i32 0
|
|
|
|
define void @interchange_07(i32 %N, i32 %M){
|
|
entry:
|
|
store i32 1, i32* @gi
|
|
%cmp21 = icmp sgt i32 %N, 1
|
|
br i1 %cmp21, label %for.cond1.preheader.lr.ph, label %for.end16
|
|
|
|
for.cond1.preheader.lr.ph:
|
|
%cmp218 = icmp sgt i32 %M, 1
|
|
%gi.promoted = load i32, i32* @gi
|
|
%0 = add i32 %M, -1
|
|
%1 = sext i32 %gi.promoted to i64
|
|
%2 = sext i32 %N to i64
|
|
%3 = add i32 %gi.promoted, 1
|
|
%4 = icmp slt i32 %3, %N
|
|
%smax = select i1 %4, i32 %N, i32 %3
|
|
br label %for.cond1.preheader
|
|
|
|
for.cond1.preheader:
|
|
%indvars.iv25 = phi i64 [ %1, %for.cond1.preheader.lr.ph ], [ %indvars.iv.next26, %for.inc14 ]
|
|
br i1 %cmp218, label %for.body3, label %for.inc14
|
|
|
|
for.body3:
|
|
%indvars.iv = phi i64 [ %indvars.iv.next, %for.body3 ], [ 1, %for.cond1.preheader ]
|
|
%5 = add nsw i64 %indvars.iv, -1
|
|
%arrayidx5 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @A, i64 0, i64 %5, i64 %indvars.iv25
|
|
%6 = load i32, i32* %arrayidx5
|
|
%arrayidx9 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @C, i64 0, i64 %indvars.iv, i64 %indvars.iv25
|
|
%7 = load i32, i32* %arrayidx9
|
|
%add = add nsw i32 %7, %6
|
|
%arrayidx13 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @A, i64 0, i64 %indvars.iv, i64 %indvars.iv25
|
|
store i32 %add, i32* %arrayidx13
|
|
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
|
|
%lftr.wideiv = trunc i64 %indvars.iv to i32
|
|
%exitcond = icmp eq i32 %lftr.wideiv, %0
|
|
br i1 %exitcond, label %for.inc14, label %for.body3
|
|
|
|
for.inc14:
|
|
%inc.lcssa23 = phi i32 [ 1, %for.cond1.preheader ], [ %M, %for.body3 ]
|
|
%indvars.iv.next26 = add nsw i64 %indvars.iv25, 1
|
|
%cmp = icmp slt i64 %indvars.iv.next26, %2
|
|
br i1 %cmp, label %for.cond1.preheader, label %for.cond.for.end16_crit_edge
|
|
|
|
for.cond.for.end16_crit_edge:
|
|
store i32 %inc.lcssa23, i32* @gj
|
|
store i32 %smax, i32* @gi
|
|
br label %for.end16
|
|
|
|
for.end16:
|
|
ret void
|
|
}
|