[PATCH] D90094: [BasicAA] Handle recursive queries more efficiently (NFCI)

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 24 03:55:52 PDT 2020


nikic created this revision.
nikic added reviewers: asbirlea, fhahn, dmgreen, hfinkel.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
nikic requested review of this revision.

An alias query currently works out roughly like this:

- Look up location pair in cache.
- Perform BasicAA logic (including cache lookup and insertion...)
- Perform a recursive query using BestAAResults.
  - Look up location pair in cache (and thus do not recurse into BasicAA)
  - Query all the other AA providers.
- Query all the other AA providers.

This is a lot of unnecessary work, all ultimately caused by the BestAAResults query at the end of aliasCheck(). The reason we perform it, is that aliasCheck() is getting called recursively, and we of course want those recursive queries to also make use of other AA providers, not just BasicAA. We can solve this by making the recursive queries directly use BestAAResults (which will check both BasicAA and other providers), rather than recursing into aliasCheck().

There are some tradeoffs:

- We can no longer pass through the precomputed underlying object to aliasCheck(). This is not a major concern, because nowadays getUnderlyingObject() is quite cheap.
- Results from other AA providers are no longer cached inside BasicAA. The way this worked was already a bit iffy, in that a result could be cached, but if it was MayAlias, we'd still end up re-querying other providers anyway. If we want to cache non-BasicAA results, we should do that in a more principled manner.

In any case, despite those tradeoffs, this works out to be a decent compile-time improvment: https://llvm-compile-time-tracker.com/compare.php?from=1a7a9efec3cf872dcf3e1a6e6fe39e797c4d9fc6&to=93127a4d7350261ed9ee2ccaa9c369eda2b60198&stat=instructions I think it also simplifies the mental model of how BasicAA works. It took me quite a while to fully understand how these things interact.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90094

Files:
  llvm/include/llvm/Analysis/BasicAliasAnalysis.h
  llvm/lib/Analysis/BasicAliasAnalysis.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90094.300470.patch
Type: text/x-patch
Size: 12080 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201024/b3985fc4/attachment.bin>


More information about the llvm-commits mailing list