This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Calculate PHI range based on its underlying values instead of just its inputs
Needs RevisionPublic

Authored by dmakogon on Sep 19 2022, 5:42 AM.

Details

Summary

This teaches SCEV to calculate range of a PHI as a union of its underlying values ranges.
Currently we do it by uniting ranges of its inputs, but there are cases where two or more PHIs
are cycled so such approach would give the full range.
This uses PhiValues analysis to get underlying values for PHIs and then unite their ranges.

Diff Detail

Event Timeline

dmakogon created this revision.Sep 19 2022, 5:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 19 2022, 5:42 AM
dmakogon requested review of this revision.Sep 19 2022, 5:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 19 2022, 5:42 AM

Need to carefully think how to invalidate it correctly. I guess you need updates in forgetValue and maybe somewhere else.

mkazantsev added inline comments.Sep 19 2022, 5:54 AM
llvm/lib/CodeGen/SafeStack.cpp
920

Can we reuse cached result from analysis?

@nikic this is not a final solution, but could you please evaluate CT impact of this one? Just for reference.

nikic added a comment.Sep 19 2022, 7:20 AM

@nikic this is not a final solution, but could you please evaluate CT impact of this one? Just for reference.

Unfortunately there is a crash when building test-suite: http://llvm-compile-time-tracker.com/show_error.php?commit=d1ebd749bf430527616aab33a7340f9fd2736228

Note that to make this change viable, every pass that preserves SCEV must also preserve PhiValues -- I doubt this is worth the effort or complexity.

mkazantsev added a comment.EditedSep 19 2022, 10:42 PM

Likely this is due to missing invalidation. @dmakogon pls fix the known issue and run more extensive fuzz testing to find what else is missing.

@nikic it shouldn't be a problem. If I'm reading this correctly, PhiValues makes computation lazily by request and supports by-value invalidation. If we have preserved SCEV => we have forgotten all values in SCEV that need to be forgotten => we have also invalidated them in PhiValues. This automatically gives what we want, no?

nikic requested changes to this revision.Sep 21 2022, 1:04 AM

Marking as changes requested for now due to known issues.

@nikic it shouldn't be a problem. If I'm reading this correctly, PhiValues makes computation lazily by request and supports by-value invalidation. If we have preserved SCEV => we have forgotten all values in SCEV that need to be forgotten => we have also invalidated them in PhiValues. This automatically gives what we want, no?

I'm not sure this is true, because PhiValues will also contain phis that are outside loops, and those may not get invalidated by SCEVs invalidation mechanisms, right?

This revision now requires changes to proceed.Sep 21 2022, 1:04 AM