DA: remove uses of GEP, only ask SCEV
authorSebastian Pop <sebpop@gmail.com>
Tue, 6 Mar 2018 21:55:59 +0000 (21:55 +0000)
committerSebastian Pop <sebpop@gmail.com>
Tue, 6 Mar 2018 21:55:59 +0000 (21:55 +0000)
commitbf6e1c26cf185445d2150580106afee9f7131907
tree7041db09f530711d309b5906ddbeb14421d19fe6
parent4289f4cecf673808f870f66074bfc7a24eb5f580
DA: remove uses of GEP, only ask SCEV

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
30 files changed:
llvm/lib/Analysis/DependenceAnalysis.cpp
llvm/lib/Transforms/Scalar/LoopInterchange.cpp
llvm/test/Analysis/DependenceAnalysis/Coupled.ll
llvm/test/Analysis/DependenceAnalysis/ExactSIV.ll
llvm/test/Analysis/DependenceAnalysis/GCD.ll
llvm/test/Analysis/DependenceAnalysis/Invariant.ll
llvm/test/Analysis/DependenceAnalysis/NonCanonicalizedSubscript.ll
llvm/test/Analysis/DependenceAnalysis/Preliminary.ll
llvm/test/Analysis/DependenceAnalysis/Propagating.ll
llvm/test/Analysis/DependenceAnalysis/Separability.ll
llvm/test/Analysis/DependenceAnalysis/StrongSIV.ll
llvm/test/Analysis/DependenceAnalysis/SymbolicSIV.ll
llvm/test/Transforms/LoopInterchange/call-instructions.ll
llvm/test/Transforms/LoopInterchange/current-limitations-lcssa.ll
llvm/test/Transforms/LoopInterchange/currentLimitation.ll
llvm/test/Transforms/LoopInterchange/interchange-flow-dep-outer.ll
llvm/test/Transforms/LoopInterchange/interchange-insts-between-indvar.ll
llvm/test/Transforms/LoopInterchange/interchange-latch-no-exit.ll [deleted file]
llvm/test/Transforms/LoopInterchange/interchange-no-deps.ll
llvm/test/Transforms/LoopInterchange/interchange-not-profitable.ll
llvm/test/Transforms/LoopInterchange/interchange-output-dependencies.ll
llvm/test/Transforms/LoopInterchange/interchange-simple-count-down.ll
llvm/test/Transforms/LoopInterchange/interchange-simple-count-up.ll
llvm/test/Transforms/LoopInterchange/loop-interchange-optimization-remarks.ll
llvm/test/Transforms/LoopInterchange/not-interchanged-dependencies-1.ll
llvm/test/Transforms/LoopInterchange/not-interchanged-loop-nest-3.ll
llvm/test/Transforms/LoopInterchange/not-interchanged-tightly-nested.ll
llvm/test/Transforms/LoopInterchange/phi-ordering.ll
llvm/test/Transforms/LoopInterchange/profitability.ll
llvm/test/Transforms/LoopInterchange/reductions.ll