This is an archive of the discontinued LLVM Phabricator instance.

[IRCE] Relax restrictions on IRCE's latch exit count
ClosedPublic

Authored by mkazantsev on Apr 10 2023, 12:18 AM.

Details

Summary

It seems that existing logic is too strict about latch block exit count.
It is required to be computable, however it is not used in any computations,
and effectively the only thing it is used for is to get the type of computed
exit count.

Sometimes the exit count for latch block is not known, but the loop is still
finite because of other exits, and safe bounds are still computable. In this case,
we miss an opportunity to apply IRCE.
We could instead use a more relaxed version - max symbolic exit count, which,
if exists, is enough to say that the loop is finite, and its type should be good enough.

There is a subtlety with type: we do not support latch count type wider than range
check type. Because of that, we want to have the narrowest type available. So if it
can be computed from latch block immediately, take it. Otherwise, take whatever whole
loop provides and hope that it's type isn't too wide.

Diff Detail

Event Timeline

mkazantsev created this revision.Apr 10 2023, 12:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 10 2023, 12:18 AM
mkazantsev requested review of this revision.Apr 10 2023, 12:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 10 2023, 12:18 AM
mkazantsev edited the summary of this revision. (Show Details)Apr 10 2023, 12:21 AM
mkazantsev planned changes to this revision.Apr 12 2023, 6:07 AM

While discussing this offline, we found a potential problem that loop's max symbolic count type can be wider than what there was before. I'll add a test and update the patch to not pessimize it.

mkazantsev requested review of this revision.Apr 12 2023, 10:53 PM
This comment was removed by mkazantsev.
mkazantsev planned changes to this revision.Apr 12 2023, 11:22 PM
mkazantsev edited the summary of this revision. (Show Details)

Updated according to type wideness concern making sure that https://github.com/llvm/llvm-project/commit/7d7b178d752a9af023714ff3ae0c268d596932e1 does not regress with this change due to wide unrelated exit.

This revision is now accepted and ready to land.Apr 13 2023, 1:16 AM
This revision was landed with ongoing or failed builds.Apr 13 2023, 2:00 AM
This revision was automatically updated to reflect the committed changes.