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
67 lines
2.8 KiB
LLVM
67 lines
2.8 KiB
LLVM
; REQUIRES: asserts
|
|
; RUN: opt < %s -loop-interchange -verify-dom-info -S -debug 2>&1 | FileCheck %s
|
|
;; Checks the order of the inner phi nodes does not cause havoc.
|
|
;; The inner loop has a reduction into c. The IV is not the first phi.
|
|
|
|
; CHECK: Not interchanging loops. Cannot prove legality.
|
|
|
|
target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
|
|
target triple = "armv8--linux-gnueabihf"
|
|
|
|
; Function Attrs: norecurse nounwind
|
|
define void @test(i32 %T, [90 x i32]* noalias nocapture %C, i16* noalias nocapture readonly %A, i16* noalias nocapture readonly %B) local_unnamed_addr #0 {
|
|
entry:
|
|
%cmp45 = icmp sgt i32 %T, 0
|
|
br i1 %cmp45, label %for.body3.lr.ph.preheader, label %for.end21
|
|
|
|
for.body3.lr.ph.preheader: ; preds = %entry
|
|
br label %for.body3.lr.ph
|
|
|
|
for.body3.lr.ph: ; preds = %for.body3.lr.ph.preheader, %for.inc19
|
|
%i.046 = phi i32 [ %inc20, %for.inc19 ], [ 0, %for.body3.lr.ph.preheader ]
|
|
%mul = mul nsw i32 %i.046, %T
|
|
br label %for.body6.lr.ph
|
|
|
|
for.body6.lr.ph: ; preds = %for.inc16, %for.body3.lr.ph
|
|
%j.043 = phi i32 [ 0, %for.body3.lr.ph ], [ %inc17, %for.inc16 ]
|
|
%arrayidx14 = getelementptr inbounds [90 x i32], [90 x i32]* %C, i32 %i.046, i32 %j.043
|
|
%arrayidx14.promoted = load i32, i32* %arrayidx14, align 4
|
|
br label %for.body6
|
|
|
|
for.body6: ; preds = %for.body6, %for.body6.lr.ph
|
|
%add1541 = phi i32 [ %arrayidx14.promoted, %for.body6.lr.ph ], [ %add15, %for.body6 ]
|
|
%k.040 = phi i32 [ 0, %for.body6.lr.ph ], [ %inc, %for.body6 ]
|
|
%add = add nsw i32 %k.040, %mul
|
|
%arrayidx = getelementptr inbounds i16, i16* %A, i32 %add
|
|
%0 = load i16, i16* %arrayidx, align 2
|
|
%conv = sext i16 %0 to i32
|
|
%mul7 = mul nsw i32 %k.040, %T
|
|
%add8 = add nsw i32 %mul7, %j.043
|
|
%arrayidx9 = getelementptr inbounds i16, i16* %B, i32 %add8
|
|
%1 = load i16, i16* %arrayidx9, align 2
|
|
%conv10 = sext i16 %1 to i32
|
|
%mul11 = mul nsw i32 %conv10, %conv
|
|
%add15 = add nsw i32 %mul11, %add1541
|
|
%inc = add nuw nsw i32 %k.040, 1
|
|
%exitcond = icmp eq i32 %inc, %T
|
|
br i1 %exitcond, label %for.inc16, label %for.body6
|
|
|
|
for.inc16: ; preds = %for.body6
|
|
%add15.lcssa = phi i32 [ %add15, %for.body6 ]
|
|
store i32 %add15.lcssa, i32* %arrayidx14, align 4
|
|
%inc17 = add nuw nsw i32 %j.043, 1
|
|
%exitcond47 = icmp eq i32 %inc17, %T
|
|
br i1 %exitcond47, label %for.inc19, label %for.body6.lr.ph
|
|
|
|
for.inc19: ; preds = %for.inc16
|
|
%inc20 = add nuw nsw i32 %i.046, 1
|
|
%exitcond48 = icmp eq i32 %inc20, %T
|
|
br i1 %exitcond48, label %for.end21.loopexit, label %for.body3.lr.ph
|
|
|
|
for.end21.loopexit: ; preds = %for.inc19
|
|
br label %for.end21
|
|
|
|
for.end21: ; preds = %for.end21.loopexit, %entry
|
|
ret void
|
|
}
|