aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/BasicAliasAnalysis.cpp
AgeCommit message (Collapse)AuthorFilesLines
2021-07-01[BasicAA] Fix typo ScaleForGDC -> ScaleForGCD.Florian Hahn1-4/+4
2021-06-30[BasicAA] Use separate scale variable for GCD.Florian Hahn1-4/+5
Use separate variable for adjusted scale used for GCD computations. This fixes an issue where we incorrectly determined that all indices are non-negative and returned noalias because of that. Follow up to 91fa3565da16.
2021-06-29[BasicAA] Be more careful with modulo ops on VariableGEPIndex.Florian Hahn1-22/+37
(V * Scale) % X may not produce the same result for any possible value of V, e.g. if the multiplication overflows. This means we currently incorrectly determine NoAlias in some cases. This patch updates LinearExpression to track whether the expression has NSW and uses that to adjust the scale used for alias checks. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D99424
2021-06-07[BasicAA] Handle PHIs without incoming values gracefullyDaniil Suchkov1-0/+2
Fix a bug introduced by f6f6f6375d1a4bced8a6e79a78726ab32b8dd879. Now for empty PHIs, instead of crashing on assert(hasVal()) in Optional's internals, we'll return NoAlias, as we did before that patch. Differential Revision: https://reviews.llvm.org/D103831
2021-05-07BasicAA: Recognize inttoptr as isEscapeSourceJoseph Tremoulet1-0/+8
Pointers escape when converted to integers, so a pointer produced by converting an integer to a pointer must not be a local non-escaping object. Reviewed By: nikic, nlopes, aqjune Differential Revision: https://reviews.llvm.org/D101541
2021-04-15[AA] Updates for D95543.dfukalov1-2/+2
Addressing latter comments in D95543: - `AliasResult::Result` renamed to `AliasResult::Kind` - Offset printing added for `PartialAlias` case in `-aa-eval` - Removed VisitedPhiBBs check from BasicAA' Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D100454
2021-04-09[AA][NFC] Convert AliasResult to class containing offset for PartialAlias case.dfukalov1-12/+20
Add an ability to store `Offset` between partially aliased location. Use this storage within returned `ResultAlias` instead of caching it in `AAQueryInfo`. Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D98718
2021-04-09[NFC][AA] Prepare to convert AliasResult to class with PartialAlias offset.dfukalov1-62/+65
Main reason is preparation to transform AliasResult to class that contains offset for PartialAlias case. Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D98027
2021-04-03[BasicAA] Don't store AATags in cache key (NFC)Nikita Popov1-2/+1
The AAMDNodes part of the MemoryLocation is not used by the BasicAA cache, so don't store it. This reduces the size of each cache entry from 112 bytes to 48 bytes.
2021-04-03[BasicAA] Don't pass through AA metadata (NFCI)Nikita Popov1-46/+32
BasicAA itself doesn't make use of AA metadata, but passes it through to recursive queries and makes it part of the cache key. Aliasing decisions that are based on AA metadata (i.e. TBAA and ScopedAA) are based *only* on AA metadata, so checking them with different pointer values or sizes is not useful, the result will always be the same. While this change is a mild compile-time improvement by itself, the actual goal here is to reduce the size of AA cache keys in a followup change. Differential Revision: https://reviews.llvm.org/D90098
2021-03-28[BasicAA] Make sure types match in constant offset heuristicNikita Popov1-1/+1
This can only happen if offset types that are larger than the pointer size are involved. The previous implementation did not assert in this case because it initialized the APInts to the width of one of the variables -- though I strongly suspect it did not compute correct results in this case. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=32621 reported by fhahn.
2021-03-28[BasicAA] Handle gep with unknown sizes earlier (NFCI)Nikita Popov1-5/+14
If the sizes of both memory locations are unknown, we can only perform a check on the underlying objects. There's no point in going through GEP decomposition in this case.
2021-03-27[BasicAA] Refactor linear expression decompositionNikita Popov1-177/+142
The current linear expression decomposition handles zext/sext by decomposing the casted operand, and then checking NUW/NSW flags to determine whether the extension can be distributed. This has some disadvantages: First, it is not possible to perform a partial decomposition. If we have zext((x + C1) +<nuw> C2) then we will fail to decompose the expression entirely, even though it would be safe and profitable to decompose it to zext(x + C1) +<nuw> zext(C2) Second, we may end up performing unnecessary decompositions, which will later be discarded because they lack nowrap flags necessary for extensions. Third, correctness of the code is not entirely obvious: At a high level, we encounter zext(x -<nuw> C) in the form of a zext on the linear expression x + (-C) with nuw flag set. Notably, this case must be treated as zext(x) + -zext(C) rather than zext(x) + zext(-C). The code handles this correctly by speculatively zexting constants to the final bitwidth, and performing additional fixup if the actual extension turns out to be an sext. This was not immediately obvious to me. This patch inverts the approach: An ExtendedValue represents a zext(sext(V)), and linear expression decomposition will try to decompose V further, either by absorbing another sext/zext into the ExtendedValue, or by distributing zext(sext(x op C)) over a binary operator with appropriate nsw/nuw flags. At each step we can determine whether distribution is legal and abort with a partial decomposition if not. We also know which extensions we need to apply to constants, and don't need to speculate or fixup.
2021-03-27[BasicAA] Correct handle implicit sext in decompositionNikita Popov1-54/+61
While explicit sext instructions were handled correctly, the implicit sext that occurs if the offset is smaller than the pointer size blindly assumed that sext(X * Scale + Offset) is the same as sext(X) * Scale + Offset, which is obviously not correct. Fix this by extracting the code that handles linear expression extension and reusing it for the implicit sext as well.
2021-03-27[BasicAA] Clarify entry values of GetLinearExpression() (NFC)Nikita Popov1-1/+4
A number of variables need to be correctly initialized on entry to GetLinearExpression() for the implementation to behave reasonably. The fact that SExtBits can currenlty be non-zero on entry is a bug, as demonstrated by the added test: For implicit sexts by the GEP, we do currently skip legality checks.
2021-03-27[BasicAA] Bail out earlier for invalid shift amountNikita Popov1-3/+2
Currently, we'd produce an incorrect decomposition, because we already recursively called GetLinearExpression(), so the Scale=1, Offset=0 will not necessarily be relative to the shl itself. Now, this doesn't actually matter for functional correctness, because such a shift is poison anyway, so its okay to return an incorrect decomposition. It's still unnecessarily confusing though, and we can easily avoid this by checking the bitwidth earlier.
2021-03-27[BasicAA] Retain shl nowrap flags in GetLinearExpression()Nikita Popov1-4/+1
Nowrap flags between mul and shl differ in that mul nsw allows multiplication of 1 * INT_MIN, while shl nsw does not. This means that it is always fine to transfer shl nowrap flags to muls, but not necessarily the other way around. In this case the NUW/NSW results refer to mul/add operations, so it's fine to retain the flags from the shl.
2021-03-25[IR] Lift attribute handling for assume bundles into CallBaseNikita Popov1-5/+0
Rather than special-casing assume in BasicAA getModRefBehavior(), do this one level higher, in the attribute handling of CallBase. For assumes with operand bundles, the inaccessiblememonly attribute applies regardless of operand bundles.
2021-03-23[BasicAA] Handle assumes with operand bundlesNikita Popov1-5/+10
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.
2021-03-22[IR] Mark assume/annotation as InaccessibleMemOnlyNikita Popov1-19/+6
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
2021-03-19Update basic deref API to account for possiblity of free [NFC]Philip Reames1-2/+4
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
2021-03-17[BasicAA] Drop dependency on Loop Info. PR43276Max Kazantsev1-7/+2
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
2021-03-04[basicaa] Recurse through a single phi inputPhilip Reames1-6/+17
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
2021-03-03Fix a build warning from ea7d208Philip Reames1-1/+1
2021-03-03[basicaa] Rewrite isGEPBaseAtNegativeOffset in terms of index difference ↵Philip Reames1-69/+26
[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
2021-03-03[basicaa] Fix a latent bug in isGEPBaseAtNegativeOffsetPhilip Reames1-1/+8
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.
2021-03-02[AA] Cache (optionally) estimated PartialAlias offsets.dfukalov1-12/+31
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
2021-02-19[BasicAA] Add simple depth limit to avoid stack overflow (PR49151)Nikita Popov1-0/+7
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
2021-02-18[BasicAA] Always strip single-argument phi nodesNikita Popov1-2/+2
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
2021-02-14[BasicAA] Merge aliasGEP code pathsNikita Popov1-52/+25
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.
2021-02-14[BasicAA] Avoid duplicate query for GEPs with identical offsets (NFCI)Nikita Popov1-11/+7
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.
2021-02-14[BasicAA] Use index difference to detect GEPs with identical indexesNikita Popov1-8/+8
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.
2021-02-12[AA] Move Depth member from AAResults to AAQI (NFC)Nikita Popov1-1/+1
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.
2021-01-22[Analysis] Use llvm::append_range (NFC)Kazu Hirata1-2/+1
2021-01-21[NewPM][opt] Run the "default" AA pipeline by defaultArthur Eubanks1-7/+6
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
2021-01-17Reapply [BasicAA] Handle recursive queries more efficientlyNikita Popov1-64/+45
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
2021-01-17[BasicAA] Move assumption tracking into AAQINikita Popov1-8/+8
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.
2021-01-15Revert "[BasicAA] Handle recursive queries more efficiently"Reid Kleckner1-45/+64
This reverts commit a3904cc77f181cff7355357688edfc392a236f5d. It causes the compiler to crash while building Harfbuzz for ARM in Chromium, reduced reproducer forthcoming: https://crbug.com/1167305
2021-01-14[BasicAA] Handle recursive queries more efficientlyNikita Popov1-64/+45
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
2021-01-11Require chained analyses in BasicAA and AAResults to be transitiveBjorn Pettersson1-3/+3
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
2021-01-06[BasicAA] Fix BatchAA results for phi-phi assumptionsNikita Popov1-49/+73
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
2020-12-25[BasicAA] Pass AC/DT to isKnownNonEqual()Nikita Popov1-1/+1
This allows us to handle assumes etc in the recursive isKnownNonZero() checks.
2020-12-25[BasicAA] Pass context instruction to isKnownNonZero()Nikita Popov1-1/+1
This allows us to handle additional cases like assumes.
2020-12-25[BasicAA] Make sure context instruction is symmetricNikita Popov1-4/+5
D71264 started using a context instruction in a computeKnownBits() call. However, if aliasing between two GEPs is checked, then the choice of context instruction will be different for alias(GEP1, GEP2) and alias(GEP2, GEP1), which is not supposed to happen. Resolve this by remembering which GEP a certain VarIndex belongs to, and use that as the context instruction. This makes the choice of context instruction predictable and symmetric. It should be noted that this choice of context instruction is non-optimal (just like the previous choice): The AA query result is only valid at points that are reachable from *both* instructions. Using either one of them is conservatively correct, but a larger context may also be valid to use. Differential Revision: https://reviews.llvm.org/D93183
2020-12-18Revert "[BasicAA] Handle two unknown sizes for GEPs"Florian Hahn1-16/+4
Temporarily revert commit 8b1c4e310c2f9686cad925ad81d8e2be10a1ef3c. After 8b1c4e310c2f the compile-time for `MultiSource/Benchmarks/MiBench/consumer-lame` dramatically increases with -O3 & LTO, causing issues for builders with that configuration. I filed PR48553 with a smallish reproducer that shows a 10-100x compile time increase.
2020-12-13[BasicAA] Handle known non-zero variable indexNikita Popov1-2/+6
BasicAA currently handles cases like Scale*V0 + (-Scale)*V1 where V0 != V1, but does not handle the simpler case of Scale*V with V != 0. Add it based on an isKnownNonZero() call. I'm not passing a context instruction for now, because the existing approach of always using GEP1 for context could result in symmetry issues. Differential Revision: https://reviews.llvm.org/D93162
2020-12-12[BasicAA] Make non-equal index handling simpler to extend (NFC)Nikita Popov1-18/+21
2020-12-11[BasicAA] Handle two unknown sizes for GEPsNikita Popov1-4/+16
If we have two unknown sizes and one GEP operand and one non-GEP operand, then we currently simply return MayAlias. The comment says we can't do anything useful ... but we can! We can still check that the underlying objects are different (and do so for the GEP-GEP case). To reduce the compile-time impact, this a) checks this early, before doing the relatively expensive GEP decomposition that will not be used and b) doesn't do the check if the other operand is a phi or select. In that case, the phi/select will already recurse, so this would just do two slightly different recursive walks that arrive at the same roots. Compile-time is still a bit of a mixed bag: https://llvm-compile-time-tracker.com/compare.php?from=624af932a808b363a888139beca49f57313d9a3b&to=845356e14adbe651a553ed11318ddb5e79a24bcd&stat=instructions On average this is a small improvement, but sqlite with ThinLTO has a 0.5% regression (lencod has a 1% improvement). The BasicAA test case checks this by using two memsets with unknown size. However, the more interesting case where this is useful is the LoopVectorize test case, as analysis of accesses in loops tends to always us unknown sizes. Differential Revision: https://reviews.llvm.org/D92401
2020-12-06[BasicAA] Migrate "same base pointer" logic to decomposed GEPsNikita Popov1-123/+26
BasicAA has some special bit of logic for "same base pointer" GEPs that performs a structural comparison: It only looks at two GEPs with the same base (as opposed to two GEP chains with a MustAlias base) and compares their indexes in a limited way. I generalized part of this code in D91027, and this patch merges the remainder into the normal decomposed GEP logic. What this code ultimately wants to do is to determine that gep %base, %idx1 and gep %base, %idx2 don't alias if %idx1 != %idx2, and the access size fits within the stride. We can express this in terms of a decomposed GEP expression with two indexes scale*%idx1 + -scale*%idx2 where %idx1 != %idx2, and some appropriate checks for sizes and offsets. This makes the reasoning slightly more powerful, and more importantly brings all the GEP logic under a common umbrella. Differential Revision: https://reviews.llvm.org/D92723
2020-12-05[BasicAA] Fix a bug with relational reasoning across iterationsPhilip Reames1-21/+9
Due to the recursion through phis basicaa does, the code needs to be extremely careful not to reason about equality between values which might represent distinct iterations. I'm generally skeptical of the correctness of the whole scheme, but this particular patch fixes one particular instance which is demonstrateable incorrect. Interestingly, this appears to be the second attempted fix for the same issue. The former fix is incomplete and doesn't address the actual issue. Differential Revision: https://reviews.llvm.org/D92694