Assume GetElementPtr offsets to be inbounds
authorTobias Grosser <tobias@grosser.es>
Tue, 25 Nov 2014 10:51:12 +0000 (10:51 +0000)
committerTobias Grosser <tobias@grosser.es>
Tue, 25 Nov 2014 10:51:12 +0000 (10:51 +0000)
commit7b50beebe48e716d8be6bf2456eef65209634f95
treec1e399b32486c841ca354864c5258a82a3fc491b
parent4c8cf4f7bcd60fe86f0b4cc0c03178397ff4e7b0
Assume GetElementPtr offsets to be inbounds

In case a GEP instruction references into a fixed size array e.g., an access
A[i][j] into an array A[100x100], LLVM-IR does not guarantee that the subscripts
always compute values that are within array bounds. We now derive the set of
parameter values for which all accesses are within bounds and add the assumption
that the scop is only every executed with this set of parameter values.

Example:

void foo(float A[][20], long n, long m {
    for (long i = 0; i < n; i++)
      for (long j = 0; j < m; j++)
        A[i][j] = ...

This loop yields out-of-bound accesses if m is at least 20 and at the same time
at least one iteration of the outer loop is executed. Hence, we assume:

  n <= 0 or m <= 20.

Doing so simplifies the dependence analysis problem, allows us to perform
more optimizations and generate better code.

TODO: The location where the GEP instruction is executed is not necessarily the
location where the memory is actually accessed. As a result scanning for GEP[s]
is imprecise. Even though this is not a correctness problem, this imprecision
may result in missed optimizations or non-optimal run-time checks.

In polybench where this mismatch between parametric loop bounds and fixed size
arrays is common, we see with this patch significant reductions in compile time
(up to 50%) and execution time (up to 70%). We see two significant compile time
regressions (fdtd-2d, jacobi-2d-imper), and one execution time regression
(trmm).  Both regressions arise due to additional optimizations that have been
enabled by this patch. They can be addressed in subsequent commits.

http://reviews.llvm.org/D6369

llvm-svn: 222754
polly/include/polly/ScopInfo.h
polly/lib/Analysis/Dependences.cpp
polly/lib/Analysis/ScopInfo.cpp
polly/test/Dependences/sequential_loops.ll
polly/test/Isl/Ast/OpenMP/nested_loop_both_parallel_parametric.ll
polly/test/Isl/Ast/alias_simple_1.ll
polly/test/Isl/Ast/alias_simple_2.ll
polly/test/Isl/Ast/alias_simple_3.ll
polly/test/ScopInfo/assume_gep_bounds.ll [new file with mode: 0644]
polly/test/ScopInfo/assume_gep_bounds_2.ll [new file with mode: 0644]