#
931b6066 |
| 23-Mar-2021 |
Nikita Popov <nikita.ppv@gmail.com> |
[BasicAA] Handle assumes with operand bundles
This fixes a regression reported on D99022: If a call has operand bundles, then the inaccessiblememonly attribute on the function will be ignored, as op
[BasicAA] Handle assumes with operand bundles
This fixes a regression reported on D99022: If a call has operand bundles, then the inaccessiblememonly attribute on the function will be ignored, as operand bundles can affect modref behavior in the general case. However, for assume operand bundles in particular this is not the case.
Adjust getModRefBehavior() to always report inaccessiblememonly for assumes, regardless of presence of operand bundles.
show more ...
|
#
ca28e323 |
| 20-Mar-2021 |
Nikita Popov <nikita.ppv@gmail.com> |
[IR] Mark assume/annotation as InaccessibleMemOnly
These intrinsics don't need to be marked as arbitrary writing, it's sufficient to write inaccessible memory (aka "side effect") to preserve control
[IR] Mark assume/annotation as InaccessibleMemOnly
These intrinsics don't need to be marked as arbitrary writing, it's sufficient to write inaccessible memory (aka "side effect") to preserve control dependencies. This means less special-casing in BasicAA. This is intended as an alternative to D98925.
Differential Revision: https://reviews.llvm.org/D99022
show more ...
|
#
5698537f |
| 19-Mar-2021 |
Philip Reames <listmail@philipreames.com> |
Update basic deref API to account for possiblity of free [NFC]
This patch is plumbing to support work towards the goal outlined in the recent llvm-dev post "[llvm-dev] RFC: Decomposing deref(N) into
Update basic deref API to account for possiblity of free [NFC]
This patch is plumbing to support work towards the goal outlined in the recent llvm-dev post "[llvm-dev] RFC: Decomposing deref(N) into deref(N) + nofree".
The point of this change is purely to simplify iteration on other pieces on way to making the switch. Rebuilding with a change to Value.h is slow and painful, so I want to get the API change landed. Once that's done, I plan to more closely audit each caller, add the inference rules in their own patch, then post a patch with the langref changes and test diffs. The value of the command line flag is that we can exercise the inference logic in standalone patches without needing the whole switch ready to go just yet.
Differential Revision: https://reviews.llvm.org/D98908
show more ...
|
#
a6074b09 |
| 17-Mar-2021 |
Max Kazantsev <mkazantsev@azul.com> |
[BasicAA] Drop dependency on Loop Info. PR43276
BasicAA stores a reference to LoopInfo inside. This imposes an implicit requirement of keeping it up to date whenever we modify the IR (in particular,
[BasicAA] Drop dependency on Loop Info. PR43276
BasicAA stores a reference to LoopInfo inside. This imposes an implicit requirement of keeping it up to date whenever we modify the IR (in particular, whenever we modify terminators of blocks that belong to loops). Failing to do so leads to incorrect state of the LoopInfo.
Because general AA does not require loop info updates and provides to API to update it properly, the users of AA reasonably assume that there is no need to update the loop info. It may be a reason of bugs, as example in PR43276 shows.
This patch drops dependence of BasicAA on LoopInfo to avoid this problem.
This may potentially pessimize the result of queries to BasicAA.
Differential Revision: https://reviews.llvm.org/D98627 Reviewed By: nikic
show more ...
|
#
83ae4967 |
| 04-Mar-2021 |
Philip Reames <listmail@philipreames.com> |
[basicaa] Recurse through a single phi input
BasicAA knows how to analyze phis, but to control compile time, we're fairly limited in doing so. This patch loosens that restriction just slightly when
[basicaa] Recurse through a single phi input
BasicAA knows how to analyze phis, but to control compile time, we're fairly limited in doing so. This patch loosens that restriction just slightly when there is exactly one phi input (after discounting induction variable increments). The result of this is that we can handle more cases around nested and sibling loops with pointer induction variables.
A few points to note. * This is deliberately extremely restrictive about recursing through at most one input of the phi. There's a known general problem with BasicAA sometimes hitting exponential compile time already, and this patch makes every effort not to compound the problem. Once the root issue is fixed, we can probably loosen the restrictions here a bit. * As seen in the test file, we're still missing cases which aren't *directly* based on phis (e.g. using the indvar increment). I believe this to be a separate problem and am going to explore this in another patch once this one lands. * As seen in the test file, this results in the unfortunate fact that using phivalues sometimes results in worse quality results. I believe this comes down to an oversight in how recursive phi detection was implemented for phivalues. I'm happy to tackle this in a follow up change.
Differential Revision: https://reviews.llvm.org/D97401
show more ...
|
#
c8cf27e3 |
| 03-Mar-2021 |
Philip Reames <listmail@philipreames.com> |
Fix a build warning from ea7d208
|
#
ea7d208b |
| 03-Mar-2021 |
Philip Reames <listmail@philipreames.com> |
[basicaa] Rewrite isGEPBaseAtNegativeOffset in terms of index difference [mostly NFC]
This is almost purely NFC, it just fits more obviously in the flow of the code now that we've standardized on th
[basicaa] Rewrite isGEPBaseAtNegativeOffset in terms of index difference [mostly NFC]
This is almost purely NFC, it just fits more obviously in the flow of the code now that we've standardized on the index different approach. The non-NFC bit is that because of canceling the VariableOffsets in the subtract, we can now handle the case where both sides involve a common variable offset. This isn't an "interesting" improvement; it just happens to fall out of the natural code structure.
One subtle point - the placement of this above the BaseAlias check is important in the original code as this can return NoAlias even when we can't find a relation between the bases otherwise.
Also added some enhancement TODOs noticed while understanding the existing code.
Note: This is slightly different than the LGTMed version. I fixed the "inbounds" issue Nikita noticed with the original code in e6e5ef4 and rebased this to include the same fix.
Differential Revision: https://reviews.llvm.org/D97520
show more ...
|
#
e6e5ef40 |
| 03-Mar-2021 |
Philip Reames <listmail@philipreames.com> |
[basicaa] Fix a latent bug in isGEPBaseAtNegativeOffset
This was pointed out in review of D97520 by Nikita, but existed in the original code as well.
The basic issue is that a decomposed GEP expres
[basicaa] Fix a latent bug in isGEPBaseAtNegativeOffset
This was pointed out in review of D97520 by Nikita, but existed in the original code as well.
The basic issue is that a decomposed GEP expression describes (potentially) more than one getelementptr. The "inbounds" derived UB which justifies this aliasing rule requires that the entire offset be composed of "inbounds" geps. Otherwise, as can be seen in the recently added and changes in this patch test, we can end up with a large commulative offset with only a small sub-offset actually being "inbounds". If that small sub-offset lies within the object, the result was unsound.
We could potentially be fancier here, but for the moment, simply be conservative when any of the GEPs parsed aren't inbounds.
show more ...
|
#
6e967834 |
| 21-Dec-2020 |
dfukalov <daniil.fukalov@amd.com> |
[AA] Cache (optionally) estimated PartialAlias offsets.
For the cases of two clobbering loads and one loaded object is fully contained in the second `BasicAAResult::aliasGEP` returns just `PartialAl
[AA] Cache (optionally) estimated PartialAlias offsets.
For the cases of two clobbering loads and one loaded object is fully contained in the second `BasicAAResult::aliasGEP` returns just `PartialAlias` that is actually more common case of partial overlap, it doesn't say anything about actual overlapping sizes.
AA users such as GVN and DSE have no functionality to estimate aliasing of GEPs with non-constant offsets. The change stores estimated relative offsets so they can be used further.
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D93529
show more ...
|
#
1d9f4903 |
| 18-Feb-2021 |
Nikita Popov <nikita.ppv@gmail.com> |
[BasicAA] Add simple depth limit to avoid stack overflow (PR49151)
This is a simpler variant of D96647. It just adds a straightforward depth limit with a high cutoff, without introducing complex log
[BasicAA] Add simple depth limit to avoid stack overflow (PR49151)
This is a simpler variant of D96647. It just adds a straightforward depth limit with a high cutoff, without introducing complex logic for BatchAA consistency. It accepts that we may cache a sub-optimal result if the depth limit is hit.
Eventually this should be more fully addressed by D96647 or similar, but in the meantime this avoids stack overflows in a cheap way.
Differential Revision: https://reviews.llvm.org/D96996
show more ...
|
#
70e3c9a8 |
| 14-Feb-2021 |
Nikita Popov <nikita.ppv@gmail.com> |
[BasicAA] Always strip single-argument phi nodes
We can always look through single-argument (LCSSA) phi nodes when performing alias analysis. getUnderlyingObject() already does this, but stripPointe
[BasicAA] Always strip single-argument phi nodes
We can always look through single-argument (LCSSA) phi nodes when performing alias analysis. getUnderlyingObject() already does this, but stripPointerCastsAndInvariantGroups() does not. We still look through these phi nodes with the usual aliasPhi() logic, but sometimes get sub-optimal results due to the restrictions on value equivalence when looking through arbitrary phi nodes. I think it's generally beneficial to keep the underlying object logic and the pointer cast stripping logic in sync, insofar as it is possible.
With this patch we get marginally better results:
aa.NumMayAlias | 5010069 | 5009861 aa.NumMustAlias | 347518 | 347674 aa.NumNoAlias | 27201336 | 27201528 ... licm.NumPromoted | 1293 | 1296
I've renamed the relevant strip method to stripPointerCastsForAliasAnalysis(), as we're past the point where we can explicitly spell out everything that's getting stripped.
Differential Revision: https://reviews.llvm.org/D96668
show more ...
|
#
f197cf21 |
| 14-Feb-2021 |
Nikita Popov <nikita.ppv@gmail.com> |
[BasicAA] Merge aliasGEP code paths
At this point, we can treat the case of GEP/GEP aliasing and GEP/non-GEP aliasing in essentially the same way. The only differences are that we need to do an addi
[BasicAA] Merge aliasGEP code paths
At this point, we can treat the case of GEP/GEP aliasing and GEP/non-GEP aliasing in essentially the same way. The only differences are that we need to do an additional negative GEP base check, and that we perform a bailout on unknown sizes for the GEP/non-GEP case (the latter exists only to limit compile-time).
This change is not quite NFC due to the peculiar effect that the DecomposedGEP for V2 can actually be non-trivial even if V2 is not a GEP. The reason for this is that getUnderlyingObject() can look through LCSSA phi nodes, while stripPointerCasts() doesn't. This can lead to slightly better results if single-entry phi nodes occur inside a loop, where looking through the phi node via aliasPhi() would subject it to phi cycle equivalence restrictions. It would probably make sense to adjust pointer cast stripping (for AA) to handle this case, and ensure consistent results.
show more ...
|
#
53ae96d4 |
| 13-Feb-2021 |
Nikita Popov <nikita.ppv@gmail.com> |
[BasicAA] Avoid duplicate query for GEPs with identical offsets (NFCI)
For two GEPs with identical offsets, we currently first perform a base address query without size information, and then if it i
[BasicAA] Avoid duplicate query for GEPs with identical offsets (NFCI)
For two GEPs with identical offsets, we currently first perform a base address query without size information, and then if it is MayAlias, perform another with size information. This is pointless, as the latter query should produce strictly better results.
This was not quite true historically due to the way that NoAlias assumptions were handled, but that issue has since been resolved.
show more ...
|
#
728803ed |
| 14-Feb-2021 |
Nikita Popov <nikita.ppv@gmail.com> |
[BasicAA] Use index difference to detect GEPs with identical indexes
We currently detect GEPs that have exactly the same indexes by comparing the Offsets and VarIndices. However, the latter implicit
[BasicAA] Use index difference to detect GEPs with identical indexes
We currently detect GEPs that have exactly the same indexes by comparing the Offsets and VarIndices. However, the latter implicitly performs equality comparisons between two values, which is not generally legal inside BasicAA, due to the possibility of comparisons across phi cycles.
I believe that in this particular instance this actually ends up being unproblematic, at least I wasn't able to come up with any cases that could result in an incorrect root query result.
In the interest of being defensive, compute GetIndexDifference earlier (which knows how to handle phi cycles properly) and use the result of that to determine whether the offsets are identical.
show more ...
|
#
191e469e |
| 12-Feb-2021 |
Nikita Popov <nikita.ppv@gmail.com> |
[AA] Move Depth member from AAResults to AAQI (NFC)
Rather than storing the query depth in AAResults, store it in AAQI. This makes more sense, as it is a property of the query. This sidesteps the is
[AA] Move Depth member from AAResults to AAQI (NFC)
Rather than storing the query depth in AAResults, store it in AAQI. This makes more sense, as it is a property of the query. This sidesteps the issue of D94363, fixing slightly inaccurate AA statistics. Additionally, I plan to use the Depth from BasicAA in the future, where fetching it from AAResults would be unreliable.
This change is not quite as straightforward as it seems, because we need to preserve the depth when creating a new AAQI for recursive queries across phis. I'm adding a new method for this, as we may need to preserve additional information here in the future.
show more ...
|
#
a3254904 |
| 23-Jan-2021 |
Kazu Hirata <kazu@google.com> |
[Analysis] Use llvm::append_range (NFC)
|
#
6699029b |
| 21-Jan-2021 |
Arthur Eubanks <aeubanks@google.com> |
[NewPM][opt] Run the "default" AA pipeline by default
We tend to assume that the AA pipeline is by default the default AA pipeline and it's confusing when it's empty instead.
PR48779
Initially rev
[NewPM][opt] Run the "default" AA pipeline by default
We tend to assume that the AA pipeline is by default the default AA pipeline and it's confusing when it's empty instead.
PR48779
Initially reverted due to BasicAA running analyses in an unspecified order (multiple function calls as parameters), fixed by fetching analyses before the call to construct BasicAA.
Reviewed By: asbirlea
Differential Revision: https://reviews.llvm.org/D95117
show more ...
|
#
0b84afa5 |
| 10-Nov-2020 |
Nikita Popov <nikita.ppv@gmail.com> |
Reapply [BasicAA] Handle recursive queries more efficiently
There are no changes relative to the original commit. However, an issue this exposed in BasicAA assumption tracking has been fixed in the
Reapply [BasicAA] Handle recursive queries more efficiently
There are no changes relative to the original commit. However, an issue this exposed in BasicAA assumption tracking has been fixed in the previous commit.
-----
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. 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.
Differential Revision: https://reviews.llvm.org/D90094
show more ...
|
#
b1c2f128 |
| 16-Jan-2021 |
Nikita Popov <nikita.ppv@gmail.com> |
[BasicAA] Move assumption tracking into AAQI
D91936 placed the tracking for the assumptions into BasicAA. However, when recursing over phis, we may use fresh AAQI instances. In this case AssumptionB
[BasicAA] Move assumption tracking into AAQI
D91936 placed the tracking for the assumptions into BasicAA. However, when recursing over phis, we may use fresh AAQI instances. In this case AssumptionBasedResults from an inner AAQI can reesult in a removal of an element from the outer AAQI.
To avoid this, move the tracking into AAQI. This generally makes more sense, as the NoAlias assumptions themselves are also stored in AAQI.
The test case only produces an assertion failure with D90094 reapplied. I think the issue exists independently of that change as well, but I wasn't able to come up with a reproducer.
show more ...
|
#
64db296e |
| 15-Jan-2021 |
Reid Kleckner <rnk@google.com> |
Revert "[BasicAA] Handle recursive queries more efficiently"
This reverts commit a3904cc77f181cff7355357688edfc392a236f5d. It causes the compiler to crash while building Harfbuzz for ARM in Chromium
Revert "[BasicAA] Handle recursive queries more efficiently"
This reverts commit a3904cc77f181cff7355357688edfc392a236f5d. It causes the compiler to crash while building Harfbuzz for ARM in Chromium, reduced reproducer forthcoming: https://crbug.com/1167305
show more ...
|
#
a3904cc7 |
| 10-Nov-2020 |
Nikita Popov <nikita.ppv@gmail.com> |
[BasicAA] Handle recursive queries more efficiently
An alias query currently works out roughly like this:
* Look up location pair in cache. * Perform BasicAA logic (including cache lookup and ins
[BasicAA] Handle recursive queries more efficiently
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. 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.
Differential Revision: https://reviews.llvm.org/D90094
show more ...
|
#
675be651 |
| 01-Jan-2021 |
Bjorn Pettersson <bjorn.a.pettersson@ericsson.com> |
Require chained analyses in BasicAA and AAResults to be transitive
This patch fixes a bug that could result in miscompiles (at least in an OOT target). The problem could be seen by adding checks tha
Require chained analyses in BasicAA and AAResults to be transitive
This patch fixes a bug that could result in miscompiles (at least in an OOT target). The problem could be seen by adding checks that the DominatorTree used in BasicAliasAnalysis and ValueTracking was valid (e.g. by adding DT->verify() call before every DT dereference and then running all tests in test/CodeGen).
Problem was that the LegacyPassManager calculated "last user" incorrectly for passes such as the DominatorTree when not telling the pass manager that there was a transitive dependency between the different analyses. And then it could happen that an incorrect dominator tree was used when doing alias analysis (which was a pretty serious bug as the alias analysis result could be invalid).
Fixes: https://bugs.llvm.org/show_bug.cgi?id=48709
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D94138
show more ...
|
#
f6f6f637 |
| 22-Nov-2020 |
Nikita Popov <nikita.ppv@gmail.com> |
[BasicAA] Fix BatchAA results for phi-phi assumptions
Change the way NoAlias assumptions in BasicAA are handled. Instead of handling this inside the phi-phi code, always initially insert a NoAlias r
[BasicAA] Fix BatchAA results for phi-phi assumptions
Change the way NoAlias assumptions in BasicAA are handled. Instead of handling this inside the phi-phi code, always initially insert a NoAlias result into the map and keep track whether it is used. If it is used, then we require that we also get back NoAlias from the recursive queries. Otherwise, the entry is changed to MayAlias.
Additionally, keep track of all location pairs we inserted that may still be based on assumptions higher up. If it turns out one of those assumptions is incorrect, we flush them from the cache.
The compile-time impact for the new implementation is significantly higher than the previous iteration of this patch: https://llvm-compile-time-tracker.com/compare.php?from=c0bb9859de6991cc233e2dedb978dd118da8c382&to=c07112373279143e37568b5bcd293daf81a35973&stat=instructions However, it should avoid the exponential runtime cases we run into if we don't cache assumption-based results entirely.
This also produces better results in some cases, because NoAlias assumptions can now start at any root, rather than just phi-phi pairs. This is not just relevant for analysis quality, but also for BatchAA consistency: Otherwise, results would once again depend on query order, though at least they wouldn't be wrong.
This ended up both more complicated and more expensive than I hoped, but I wasn't able to come up with another solution that satisfies all the constraints.
Differential Revision: https://reviews.llvm.org/D91936
show more ...
|
#
c795dd19 |
| 25-Dec-2020 |
Nikita Popov <nikita.ppv@gmail.com> |
[BasicAA] Pass AC/DT to isKnownNonEqual()
This allows us to handle assumes etc in the recursive isKnownNonZero() checks.
|
#
a3614a31 |
| 25-Dec-2020 |
Nikita Popov <nikita.ppv@gmail.com> |
[BasicAA] Pass context instruction to isKnownNonZero()
This allows us to handle additional cases like assumes.
|