aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/AssumptionCache.cpp
AgeCommit message (Collapse)AuthorFilesLines
4 days[DropUnnecessaryAssumes] Add support for operand bundles (#160311)Nikita Popov1-11/+20
This extends the DropUnnecessaryAssumes pass to also handle operand bundle assumes. For this purpose, export the affected value analysis for operand bundles from AssumptionCache. If the bundle only affects ephemeral values, drop it. If all bundles on an assume are dropped, drop the whole assume.
5 days[AssumptionCache] Don't use ResultElem for assumption list (NFC) (#160462)Nikita Popov1-2/+2
ResultElem stores a weak handle of an assume, plus an index for referring to a specific operand bundle. This makes sense for the results of assumptionsFor(), which refers to specific operands of assumes. However, assumptions() is a plain list of assumes. It does *not* contain separate entries for each operand bundles. The operand bundle index is always ExprResultIdx. As such, we should be directly using WeakVH for this case, without the additional wrapper.
2025-04-21[LLVM] Cleanup pass initialization for Analysis passes (#135858)Rahul Joshi1-3/+1
- Do not call pass initialization from pass constructors. - Instead, pass initialization should happen in the `initializeAnalysis` function. - https://github.com/llvm/llvm-project/issues/111767
2024-10-12[Analysis] Simplify code with DenseMap::operator[] (NFC) (#112082)Kazu Hirata1-3/+1
2024-03-04[Analysis] Share `findAffectedValues` between DomConditionCache and ↵Noah Goldstein1-60/+13
AssumptionCache; NFC
2024-01-03[AssumptionCache] Add affected values for separate_storage (#76806)Nikita Popov1-3/+10
Add the underlying object of both separate_storage arguments as affected values. This allows us to use assumptionsFor() in BasicAA, which will be more efficient if there are many assumes in the function.
2023-11-28[AssumptionCache] Remove unnecessary bitcast/not handlingNikita Popov1-2/+3
We only handle not for the top level value of the condition, so move it there instead of trying to look through not at all leafs. Also remove bitcast handling entirely -- we don't do anything special wrt bitcasts, this is probably a leftover from pointer types.
2023-11-27[InstCombine] Remove over-generalization from computeKnownBitsFromCmp() (#72637)Nikita Popov1-21/+11
For most practical purposes, the only KnownBits patterns we care about are those involving a constant comparison RHS and constant mask. However, the actual implementation is written in a very general way -- and of course, with basically no test coverage of those generalizations. This patch reduces the implementation to only handle cases with constant operands. The test changes are all in "make sure we don't crash" tests. The motivation for this change is an upcoming patch to handling dominating conditions in computeKnownBits(). Handling non-constant RHS would add significant additional compile-time overhead in that case, without any significant impact on optimization quality.
2023-11-17[ValueTracking] Remove handling of KnownBits assumptions with invertNikita Popov1-7/+1
For all practical purposes, we only care about comparisons with constant RHS in this code. In that case, an invert will be canonicalized into the constant and it will be handled by other cases. Given the complete lack of test coverage, I'm removing this code.
2023-10-24[ADT] Rename llvm::erase_value to llvm::erase (NFC) (#70156)Kazu Hirata1-1/+1
C++20 comes with std::erase to erase a value from std::vector. This patch renames llvm::erase_value to llvm::erase for consistency with C++20. We could make llvm::erase more similar to std::erase by having it return the number of elements removed, but I'm not doing that for now because nobody seems to care about that in our code base. Since there are only 50 occurrences of erase_value in our code base, this patch replaces all of them with llvm::erase and deprecates llvm::erase_value.
2023-09-06[AssumptionCache] Track GlobalValues as affected values. (#65425)Tyler Lanphear1-1/+1
Fixes a corner case of the analysis: previously GlobalValues could be affected by assumptions, but were not tracked within AffectedValues. This patch allows assumptions which affect a given GlobalValue to be looked up via `assumptionsFor()`. A small update to llvm/test/Analysis/ScalarEvolution/ranges.ll was necessary due to knowledge about a global value now being propagated from AssumptionCache -> ValueTracking -> ScalarEvolution.
2023-03-17Attributor: Assume handling for nofpclassMatt Arsenault1-1/+12
2023-02-20Revert "[AssumptionCache] caches @llvm.experimental.guard's"Max Kazantsev1-11/+11
This reverts commit f9599bbc7a3f831e1793a549d8a7a19265f3e504. For some reason it caused us a huge compile time regression in downstream workloads. Not sure whether the source of it is in upstream code ir not. Temporarily reverting until investigated. Differential Revision: https://reviews.llvm.org/D142330
2023-01-24[AssumptionCache] caches @llvm.experimental.guard'sJoshua Cao1-11/+11
As discussed in https://github.com/llvm/llvm-project/issues/59901 This change is not NFC. There is one SCEV and EarlyCSE test that have an improved analysis/optimization case. Rest of the tests are not failing. I've mostly only added cleanup to SCEV since that is where this issue started. As a follow up, I believe there is more cleanup opportunity in SCEV and other affected passes. There could be cases where there are missed registerAssumption of guards, but this case is not so bad because there will be no miscompilation. AssumptionCacheTracker should take care of deleted guards. Differential Revision: https://reviews.llvm.org/D142330
2023-01-11[InstCombine] Handle assume(X & Pow2 != 0) in computeKnownBits()Noah Goldstein1-9/+16
If we know that X & Pow2 != 0, then the bit at that position is known one. Differential Revision: https://reviews.llvm.org/D140851
2022-03-01Cleanup includes: LLVMAnalysisserge-sans-paille1-3/+1
Number of lines output by preprocessor: before: 1065940348 after: 1065307662 Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D120659
2021-11-08[InferAddressSpaces] Support assumed addrspaces from addrspace predicates.Michael Liao1-4/+22
- CUDA cannot associate memory space with pointer types. Even though Clang could add extra attributes to specify the address space explicitly on a pointer type, it breaks the portability between Clang and NVCC. - This change proposes to assume the address space from a pointer from the assumption built upon target-specific address space predicates, such as `__isGlobal` from CUDA. E.g., ``` foo(float *p) { __builtin_assume(__isGlobal(p)); // From there, we could assume p is a global pointer instead of a // generic one. } ``` This makes the code portable without introducing the implementation-specific features. Note that NVCC starts to support __builtin_assume from version 11. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D112041
2021-10-24Use llvm::any_of and llvm::none_of (NFC)Kazu Hirata1-2/+2
2021-04-06Use AssumeInst in a few more places [nfc]Philip Reames1-3/+3
Follow up to a6d2a8d6f5. These were found by simply grepping for "::assume", and are the subset of that result which looked cleaner to me using the isa/dyn_cast patterns.
2021-04-06Add a subclass of IntrinsicInst for llvm.assume [nfc]Philip Reames1-8/+5
Add the subclass, update a few places which check for the intrinsic to use idiomatic dyn_cast, and update the public interface of AssumptionCache to use the new class. A follow up change will do the same for the newer assumption query/bundle mechanisms.
2021-02-11Revert "[AssumptionCache] Avoid dangling llvm.assume calls in the cache"Michael Kruse1-17/+23
This reverts commit b7d870eae7fdadcf10d0f177faa7409c2e37d776 and the subsequent fix "[Polly] Fix build after AssumptionCache change (D96168)" (commit e6810cab09fcbc87b6e5e4d226de0810e2f2ea38). It caused indeterminism in the output, such that e.g. the polly-x86_64-linux buildbot failed accasionally.
2021-02-06[AssumptionCache] Avoid dangling llvm.assume calls in the cacheJohannes Doerfert1-23/+17
PR49043 exposed a problem when it comes to RAUW llvm.assumes. While D96106 would fix it for GVNSink, it seems a more general concern. To avoid future problems this patch moves away from the vector of weak reference model used in the assumption cache. Instead, we track the llvm.assume calls with a callback handle which will remove itself from the cache if the call is deleted. Fixes PR49043. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D96168
2021-01-03[llvm] Call *(Set|Map)::erase directly (NFC)Kazu Hirata1-3/+1
We can erase an item in a set or map without checking its membership first.
2020-12-14[Analysis] Use llvm::erase_value (NFC)Kazu Hirata1-3/+1
2020-12-13[AC] Handle (X+C1)<C2 assumes (PR48408)Nikita Popov1-0/+8
InstCombine canonicalizes X>C && X<C' style comparisons into (X+C1)<C2. This type of expression is recognized by some analyses like LVI, but currently not when used inside assumptions, because AssumptionCache does not track affected values for it.
2020-10-13[Analysis] findAffectedValues - remove unused ConstantInt argument. NFCI.Simon Pilgrim1-2/+1
We can use m_ConstantInt without a result value as we don't ever use it.
2020-07-27Use llvm::is_contained where appropriate (NFC)Kazu Hirata1-1/+1
Summary: This patch replaces std::find with llvm::is_contained where appropriate. Reviewers: efriedma, nhaehnle Reviewed By: nhaehnle Subscribers: arsenm, jvesely, nhaehnle, hiraditya, rogfer01, kerbowa, llvm-commits, vkmr Tags: #llvm Differential Revision: https://reviews.llvm.org/D84489
2020-05-11[NFC][DwarfDebug] Add test for variables with a single location whichOCHyams1-1/+1
don't span their entire scope. The previous commit (6d1c40c171e) is an older version of the test. Reviewed By: aprantl, vsk Differential Revision: https://reviews.llvm.org/D79573
2020-04-13[AssumeBundles] adapt Assumption cache to assume bundlesTyker1-20/+44
Summary: change assumption cache to store an assume along with an index to the operand bundle containing the knowledge. Reviewers: jdoerfert, hfinkel Reviewed By: jdoerfert Subscribers: hiraditya, mgrang, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77402
2019-11-13Sink all InitializePasses.h includesReid Kleckner1-0/+1
This file lists every pass in LLVM, and is included by Pass.h, which is very popular. Every time we add, remove, or rename a pass in LLVM, it caused lots of recompilation. I found this fact by looking at this table, which is sorted by the number of times a file was changed over the last 100,000 git commits multiplied by the number of object files that depend on it in the current checkout: recompiles touches affected_files header 342380 95 3604 llvm/include/llvm/ADT/STLExtras.h 314730 234 1345 llvm/include/llvm/InitializePasses.h 307036 118 2602 llvm/include/llvm/ADT/APInt.h 213049 59 3611 llvm/include/llvm/Support/MathExtras.h 170422 47 3626 llvm/include/llvm/Support/Compiler.h 162225 45 3605 llvm/include/llvm/ADT/Optional.h 158319 63 2513 llvm/include/llvm/ADT/Triple.h 140322 39 3598 llvm/include/llvm/ADT/StringRef.h 137647 59 2333 llvm/include/llvm/Support/Error.h 131619 73 1803 llvm/include/llvm/Support/FileSystem.h Before this change, touching InitializePasses.h would cause 1345 files to recompile. After this change, touching it only causes 550 compiles in an incremental rebuild. Reviewers: bkramer, asbirlea, bollu, jdoerfert Differential Revision: https://reviews.llvm.org/D70211
2019-10-02Fix: Actually erase remove the elements from AssumeHandlesAditya Kumar1-1/+4
Reviewers: sdmitriev, tejohnson Reviewed by: tejohnson Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68318 llvm-svn: 373494
2019-08-16AssumptionCache: remove old affected values after RAUW.Tim Northover1-2/+3
If they're left in the cache then they can't be removed efficiently when the cache is notified to unlink a @llvm.assume call, and that can lead to values from different functions entirely remaining there. llvm-svn: 369091
2019-08-15[llvm] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere1-1/+1
Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. llvm-svn: 369013
2019-02-08[CodeExtractor] Update function's assumption cache after extracting blocks ↵Sergey Dmitriev1-2/+26
from it Summary: Assumption cache's self-updating mechanism does not correctly handle the case when blocks are extracted from the function by the CodeExtractor. As a result function's assumption cache may have stale references to the llvm.assume calls that were moved to the outlined function. This patch fixes this problem by removing extracted llvm.assume calls from the function’s assumption cache. Reviewers: hfinkel, vsk, fhahn, davidxl, sanjoy Reviewed By: hfinkel, vsk Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D57215 llvm-svn: 353500
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2017-09-01[Analysis, Transforms] Fix some Clang-tidy modernize and Include What You ↵Eugene Zelenko1-6/+19
Use warnings; other minor fixes (NFC). llvm-svn: 312383
2017-06-24[IR][AssumptionCache] Add m_Shift and m_BitwiseLogic matchers to replace a ↵Craig Topper1-9/+2
couple m_CombineOr Summary: m_CombineOr isn't very efficient. The code using it is also quite verbose. This patch adds m_Shift and m_BitwiseLogic matchers to make the using code more concise and improve the match efficiency. Reviewers: spatel, davide Reviewed By: davide Subscribers: davide, llvm-commits Differential Revision: https://reviews.llvm.org/D34593 llvm-svn: 306206
2017-05-01Rename WeakVH to WeakTrackingVH; NFCSanjoy Das1-3/+4
This relands r301424. llvm-svn: 301812
2017-04-26Reverts commit r301424, r301425 and r301426Sanjoy Das1-4/+3
Commits were: "Use WeakVH instead of WeakTrackingVH in AliasSetTracker's UnkownInsts" "Add a new WeakVH value handle; NFC" "Rename WeakVH to WeakTrackingVH; NFC" The changes assumed pointers are 8 byte aligned on all architectures. llvm-svn: 301429
2017-04-26Rename WeakVH to WeakTrackingVH; NFCSanjoy Das1-3/+4
Summary: I plan to use WeakVH to mean "nulls itself out on deletion, but does not track RAUW" in a subsequent commit. Reviewers: dblaikie, davide Reviewed By: davide Subscribers: arsenm, mehdi_amini, mcrosier, mzolotukhin, jfb, llvm-commits, nhaehnle Differential Revision: https://reviews.llvm.org/D32266 llvm-svn: 301424
2017-02-15AssumptionCache: Disable the verifier by default, move it behind a hidden ↵Peter Collingbourne1-5/+15
cl::opt and verify from releaseMemory(). This is a short term solution to the problem that many passes currently fail to update the assumption cache. In the long term the verifier should not be controllable with a flag. We should either fix all passes to correctly update the assumption cache and enable the verifier unconditionally or somehow arrange for the assumption list to be updated automatically by passes. Differential Revision: https://reviews.llvm.org/D30003 llvm-svn: 295236
2017-01-17[ValueTracking] recognize a 'not' of an assumed condition as falseSanjay Patel1-3/+5
Also, add the corresponding match to the AssumptionCache's 'Affected Values' list. Differential Revision: https://reviews.llvm.org/D28485 llvm-svn: 292239
2017-01-16Fix use-after-free bug in AffectedValueCallbackVH::allUsesReplacedWithHal Finkel1-10/+17
When transferring affected values in the cache from an old value, identified by the value of the current callback, to the specified new value we might need to insert a new entry into the DenseMap which constitutes the cache. Doing so might delete the current callback object. Move the copying logic into a new function, a member of the assumption cache itself, so that we don't run into UB should the callback handle itself be removed mid-copy. Differential Revision: https://reviews.llvm.org/D28749 llvm-svn: 292133
2017-01-11Make processing @llvm.assume more efficient - Add affected values to the ↵Hal Finkel1-0/+109
assumption cache Here's my second try at making @llvm.assume processing more efficient. My previous attempt, which leveraged operand bundles, r289755, didn't end up working: it did make assume processing more efficient but eliminating the assumption cache made ephemeral value computation too expensive. This is a more-targeted change. We'll keep the assumption cache, but extend it to keep a map of affected values (i.e. values about which an assumption might provide some information) to the corresponding assumption intrinsics. This allows ValueTracking and LVI to find assumptions relevant to the value being queried without scanning all assumptions in the function. The fact that ValueTracking started doing O(number of assumptions in the function) work, for every known-bits query, has become prohibitively expensive in some cases. As discussed during the review, this is a pragmatic fix that, longer term, will likely be replaced by a more-principled solution (perhaps based on an extended SSA form). Differential Revision: https://reviews.llvm.org/D28459 llvm-svn: 291671
2016-12-19Add files I seem to have dropped in my revert (r290086).Daniel Jasper1-0/+140
Sorry! llvm-svn: 290087
2016-12-15Remove the AssumptionCacheHal Finkel1-140/+0
After r289755, the AssumptionCache is no longer needed. Variables affected by assumptions are now found by using the new operand-bundle-based scheme. This new scheme is more computationally efficient, and also we need much less code... llvm-svn: 289756
2016-11-23[PM] Change the static object whose address is used to uniquely identifyChandler Carruth1-1/+1
analyses to have a common type which is enforced rather than using a char object and a `void *` type when used as an identifier. This has a number of advantages. First, it at least helps some of the confusion raised in Justin Lebar's code review of why `void *` was being used everywhere by having a stronger type that connects to documentation about this. However, perhaps more importantly, it addresses a serious issue where the alignment of these pointer-like identifiers was unknown. This made it hard to use them in pointer-like data structures. We were already dodging this in dangerous ways to create the "all analyses" entry. In a subsequent patch I attempted to use these with TinyPtrVector and things fell apart in a very bad way. And it isn't just a compile time or type system issue. Worse than that, the actual alignment of these pointer-like opaque identifiers wasn't guaranteed to be a useful alignment as they were just characters. This change introduces a type to use as the "key" object whose address forms the opaque identifier. This both forces the objects to have proper alignment, and provides type checking that we get it right everywhere. It also makes the types somewhat less mysterious than `void *`. We could go one step further and introduce a truly opaque pointer-like type to return from the `ID()` static function rather than returning `AnalysisKey *`, but that didn't seem to be a clear win so this is just the initial change to get to a reliably typed and aligned object serving is a key for all the analyses. Thanks to Richard Smith and Justin Lebar for helping pick plausible names and avoid making this refactoring many times. =] And thanks to Sean for the super fast review! While here, I've tried to move away from the "PassID" nomenclature entirely as it wasn't really helping and is overloaded with old pass manager constructs. Now we have IDs for analyses, and key objects whose address can be used as IDs. Where possible and clear I've shortened this to just "ID". In a few places I kept "AnalysisID" to make it clear what was being identified. Differential Revision: https://reviews.llvm.org/D27031 llvm-svn: 287783
2016-08-09Consistently use FunctionAnalysisManagerSean Silva1-1/+1
Besides a general consistently benefit, the extra layer of indirection allows the mechanical part of https://reviews.llvm.org/D23256 that requires touching every transformation and analysis to be factored out cleanly. Thanks to David for the suggestion. llvm-svn: 278077
2016-03-11[PM] Make the AnalysisManager parameter to run methods a reference.Chandler Carruth1-2/+2
This was originally a pointer to support pass managers which didn't use AnalysisManagers. However, that doesn't realistically come up much and the complexity of supporting it doesn't really make sense. In fact, *many* parts of the pass manager were just assuming the pointer was never null already. This at least makes it much more explicit and clear. llvm-svn: 263219
2016-03-11[PM] Implement the final conclusion as to how the analysis IDs shouldChandler Carruth1-1/+1
work in the face of the limitations of DLLs and templated static variables. This requires passes that use the AnalysisBase mixin provide a static variable themselves. So as to keep their APIs clean, I've made these private and befriended the CRTP base class (which is the common practice). I've added documentation to AnalysisBase for why this is necessary and at what point we can go back to the much simpler system. This is clearly a better pattern than the extern template as it caught *numerous* places where the template magic hadn't been applied and things were "just working" but would eventually have broken mysteriously. llvm-svn: 263216