This is an archive of the discontinued LLVM Phabricator instance.

Assume GetElementPtr offsets to be inbounds
ClosedPublic

Authored by grosser on Nov 22 2014, 12:43 AM.

Details

Summary

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[10][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 on 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.

Diff Detail

Event Timeline

grosser updated this revision to Diff 16523.Nov 22 2014, 12:43 AM
grosser retitled this revision from to Assume GetElementPtr offsets to be inbounds.
grosser updated this object.
grosser added a subscriber: Unknown Object (MLST).

Here the performance results for this patch:

jdoerfert edited edge metadata.Nov 24 2014, 7:48 PM

Some minor commments, otherwise LGTM

include/polly/ScopInfo.h
476

What about n > 10 and m > 1? Shouldn't that be a violation too?

lib/Analysis/ScopInfo.cpp
850

I would rename Inst to GEP or GEPInst or sth. to make the type clear.

856

Theoretically, we could make this a while and increment the dimension, however I don't think it will ever matter.
However, stripping of structs might be worthwile?

867

1 + Dimension is Operand!

869

Please move Parent.getSE() before the loop

Thanks for the review. I will commit it as soon as our LNT builders are green again.

include/polly/ScopInfo.h
476

The first dimension does not carry any size information. I declared the array as A[][20] to make this clear.

lib/Analysis/ScopInfo.cpp
850

Done.

856

Possibly. I do not have a test case yet. I think we can add it in a subsequent commit if found useful.

867

Fixed.

869

Fixed.

grosser accepted this revision.Nov 25 2014, 2:53 AM
grosser added a reviewer: grosser.

Accept revision to be able to close it.

This revision is now accepted and ready to land.Nov 25 2014, 2:53 AM
grosser closed this revision.Nov 25 2014, 2:53 AM

Committed in 222754.