Currently the dependence analysis in LLVM is unable to compute accurate dependence vectors for multi-dimensional fixed size arrays. For example:
#define N 1024 #define M 2048 void foo(int a[N][M]) { for (long i = 0; i < N-1; ++i) for (long j = 2; j < M; ++j) a[i][j] = a[i+1][j-2];
gives the following output for the dependence between the load of a[i+1][j-2] and the store into a[i][j]:
da analyze - anti [< >]!
While the direction vectors are correct, no dependence distances are computed, as we expect:
da analyze - anti [1 -2]!
This is mainly because the delinearization algorithm in scalar evolution relies on parametric terms to be present in the access functions. In the case of fixed size arrays such parametric terms are not present, but we can use the indexes from GEP instructions to recover the subscripts for each dimension of the arrays.
It appears that https://reviews.llvm.org/D35430 removed the capability to look at GEP instructions early in 2018. The justification for that change appears to be related to the concern over subscripts overlapping into next array dimensions in languages like C/C++. Please note that https://reviews.llvm.org/D62610 added a debug option to address this concern.
Removing support for fixed-size array delinearization resulted in over-pissimization of DependenceAnalysis and reduction of test coverage for both DA and LoopInterchange.
I've also noticed that polly tries to recover fixed-size array subscripts for dependence testing as well. In this patch I add support for fixed-size array delinearization (using the same mechanism that polly uses) under the option introduced in D62610. Two follow up revisions succeed this patch:
- In D73995 I've refactored the polly code and moved it to scalar-evolution to make it reuseable by both polly and DA.
- In D73998 I've renamed the option to reflect the fact that it controls more than just the delinearization validity checks.
Quite a few DA and loop interchange test cases improve as a result of this change, and it makes writing tests for new and existing transformations easier.
Is checkSubscript supposed to be public now?