This is an archive of the discontinued LLVM Phabricator instance.

[LCSSA] Compute SCEV of LCSSA phi if original instruction had SCEV
ClosedPublic

Authored by nikic on Jun 16 2023, 8:21 AM.

Details

Summary

The backstory here is that the LCSSA invalidation we perform here is not really necessary from a SCEV perspective. However, other code may rely on the fact that invalidating only LCSSA phi nodes is sufficient for transforms like loop peeling (see https://reviews.llvm.org/D149331#4398582 for more details).

However, performing invalidation during LCSSA construction also means that SCEV expansion (which may need to construct LCSSA) can invalidate SCEV, which is somewhat unexpected and code may not be prepared to deal with it (see the added test case, reported at https://reviews.llvm.org/D149435#4428219).

Instead of invalidating SCEV, ensure that the LCSSA phi node also has cached SCEV if the original instruction did. This means that later invalidation of LCSSA phi nodes will work as expected. This should avoid both the above issues and be more efficient.

Diff Detail

Event Timeline

nikic created this revision.Jun 16 2023, 8:21 AM
nikic requested review of this revision.Jun 16 2023, 8:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 16 2023, 8:21 AM

I've verified that this fixes the problem I saw in https://reviews.llvm.org/D149435#4428219

Thanks!

fhahn accepted this revision.Jun 26 2023, 3:18 AM

LGTM, thanks!

This revision is now accepted and ready to land.Jun 26 2023, 3:18 AM
This revision was landed with ongoing or failed builds.Jun 26 2023, 5:43 AM
This revision was automatically updated to reflect the committed changes.