This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Cache operands used in BEInfo
ClosedPublic

Authored by nikic on May 19 2021, 11:58 AM.

Details

Summary

When memoized values for a SCEV expressions are dropped, we also drop all BECounts that make use of the SCEV expression. This is done by iterating over all the ExitNotTaken counts and (recursively) checking whether they use the SCEV expression. If there are many exits, this will take a lot of time.

This patch improves the situation by pre-computing a set of all used operands, so that we can determine whether a certain BEInfo needs to be invalidated using a simple set lookup. Will still need to loop over all BEInfos though.

This makes for a mild improvement on non-degenerate cases: https://llvm-compile-time-tracker.com/compare.php?from=b661a55a253f4a1cf5a0fbcb86e5ba7b9fb1387b&to=be1393f450e594c53f0ad7e62339a6bc831b16f6&stat=instructions

For the degenerate case from https://bugs.llvm.org/show_bug.cgi?id=50384, for n=128 I'm seeing run time drop from 1.6s to 1.1s.

Diff Detail

Event Timeline

nikic created this revision.May 19 2021, 11:58 AM
nikic requested review of this revision.May 19 2021, 11:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 19 2021, 11:58 AM

This is great.
I, however, wonder if we are missing some more global caching for the ScalarEvolution::isSCEVExprNeverPoison(const Instruction *) itself.
For example, can we simply cache the entire result of that function?
When would it need to be invalidated?

nikic added a comment.May 21 2021, 1:46 PM

This is great.
I, however, wonder if we are missing some more global caching for the ScalarEvolution::isSCEVExprNeverPoison(const Instruction *) itself.
For example, can we simply cache the entire result of that function?
When would it need to be invalidated?

I don't think these things are related: This is addressing a problem where the process of invalidation itself is expensive, while performance issues in isSCEVExprNeverPoison() would appear either during initial SCEV construction or after invalidation. Caching isSCEVExprNeverPoison() results shouldn't have an impact on the performance of invalidation itself.

reames accepted this revision.May 24 2021, 2:59 PM

LGTM, seems like a worthwhile improvement.

You might consider using a small set variant. Not sure how many operands exist in the common case.

This revision is now accepted and ready to land.May 24 2021, 2:59 PM
This revision was automatically updated to reflect the committed changes.