This is an archive of the discontinued LLVM Phabricator instance.

[getUnderlyingOjbects] Analyze loop PHIs further to remove false positives
ClosedPublic

Authored by anemet on Apr 15 2015, 10:50 AM.

Details

Summary

Specifically, if a pointer accesses different underlying objects in each
iteration, don't look through the phi node defining the pointer.

The motivating case is the underlyling-objects-2.ll testcase. Consider
the loop nest:

int **A;
for (i)
  for (j)
     A[i][j] = A[i-1][j] * B[j]

This loop is transformed by Load-PRE to stash away A[i] for the next
iteration of the outer loop:

Curr = A[0];          // Prev_0
for (i: 1..N) {
  Prev = Curr;        // Prev = PHI (Prev_0, Curr)
  Curr = A[i];
  for (j: 0..N)
     Curr[j] = Prev[j] * B[j]
}

Since A[i] and A[i-1] are likely to be independent pointers,
getUnderlyingObjects should not assume that Curr and Prev share the same
underlying object in the inner loop.

If it did we would try to dependence-analyze Curr and Prev and the
analysis of the corresponding SCEVs would fail with non-constant
distance.

To fix this, the getUnderlyingObjects API is extended with an optional
LoopInfo parameter. This is effectively what controls whether we want
the above behavior or the original. Currently, I only changed to use
this approach for LoopAccessAnalysis.

The other testcase is to guard the opposite case where we do want to
look through the loop PHI. If we step through an array by incrementing
a pointer, the underlying object is the incoming value of the phi as the
loop is entered.

Diff Detail

Event Timeline

anemet updated this revision to Diff 23784.Apr 15 2015, 10:50 AM
anemet retitled this revision from to [getUnderlyingOjbects] Analyze loop PHIs further to remove false positives.
anemet updated this object.
anemet edited the test plan for this revision. (Show Details)
anemet added reviewers: hfinkel, aschwaighofer, nadav.
anemet added a subscriber: Unknown Object (MLST).
aschwaighofer edited edge metadata.Apr 22 2015, 3:16 PM

This LGTM though I think we should add an example to the documentation in the header similar to what is in the implementation.

Makes sense. Will add a sketch of the example there. Thanks for the review!

anemet accepted this revision.Apr 23 2015, 1:16 PM
anemet added a reviewer: anemet.
This revision is now accepted and ready to land.Apr 23 2015, 1:16 PM
anemet closed this revision.Apr 23 2015, 1:17 PM

Committed as r235634.