summaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/MemorySSA.cpp
AgeCommit message (Collapse)Author
2025-10-14[llvm] Replace LLVM_ATTRIBUTE_UNUSED with [[maybe_unused]] (NFC) (#163330)Kazu Hirata
This patch replaces LLVM_ATTRIBUTE_UNUSED with [[maybe_unused]] where we do not need to move the position of [[maybe_unused]] within declarations. Notes: - [[maybe_unused]] is a standard feature of C++17. - The compiler is far more lenient about the placement of __attribute__((unused)) than that of [[maybe_unused]]. I'll follow up with another patch to finish up the rest.
2025-05-26[llvm] Value-initialize values with *Map::try_emplace (NFC) (#141522)Kazu Hirata
try_emplace value-initializes values, so we do not need to pass nullptr to try_emplace when the value types are raw pointers or std::unique_ptr<T>.
2025-04-21[LLVM] Cleanup pass initialization for Analysis passes (#135858)Rahul Joshi
- 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
2025-03-20[llvm] Use *Set::insert_range (NFC) (#132325)Kazu Hirata
DenseSet, SmallPtrSet, SmallSet, SetVector, and StringSet recently gained C++23-style insert_range. This patch replaces: Dest.insert(Src.begin(), Src.end()); with: Dest.insert_range(Src); This patch does not touch custom begin like succ_begin for now.
2024-08-13[LLVM] Don't peek through bitcast on pointers and gep with zero indices. ↵Yingwei Zheng
NFC. (#102889) Since we are using opaque pointers now, we don't need to peek through bitcast on pointers and gep with zero indices.
2024-05-02[LoopUnroll] Add CSE to remove redundant loads after unrolling. (#83860)Florian Hahn
This patch adds loadCSE support to simplifyLoopAfterUnroll. It is based on EarlyCSE's implementation using ScopeHashTable and is using SCEV for accessed pointers to check to find redundant loads after unrolling. This applies to the late unroll pass only, for full unrolling those redundant loads will be cleaned up by the regular pipeline. The current approach constructs MSSA on-demand per-loop, but there is still small but notable compile-time impact: stage1-O3 +0.04% stage1-ReleaseThinLTO +0.06% stage1-ReleaseLTO-g +0.05% stage1-O0-g +0.02% stage2-O3 +0.09% stage2-O0-g +0.04% stage2-clang +0.02% https://llvm-compile-time-tracker.com/compare.php?from=c089fa5a729e217d0c0d4647656386dac1a1b135&to=ec7c0f27cb5c12b600d9adfc8543d131765ec7be&stat=instructions:u This benefits some workloads with runtime-unrolling disabled, where users use pragmas to force unrolling, as well as with runtime unrolling enabled. On SPEC/MultiSource, this removes a number of loads after unrolling on AArch64 with runtime unrolling enabled. ``` External/S...te/526.blender_r/526.blender_r 96 MultiSourc...rks/mediabench/gsm/toast/toast 39 SingleSource/Benchmarks/Misc/ffbench 4 External/SPEC/CINT2006/403.gcc/403.gcc 18 MultiSourc.../Applications/JM/ldecod/ldecod 4 MultiSourc.../mediabench/jpeg/jpeg-6a/cjpeg 6 MultiSourc...OE-ProxyApps-C/miniGMG/miniGMG 9 MultiSourc...e/Applications/ClamAV/clamscan 4 MultiSourc.../MallocBench/espresso/espresso 3 MultiSourc...dence-flt/LinearDependence-flt 2 MultiSourc...ch/office-ispell/office-ispell 4 MultiSourc...ch/consumer-jpeg/consumer-jpeg 6 MultiSourc...ench/security-sha/security-sha 11 MultiSourc...chmarks/McCat/04-bisect/bisect 3 SingleSour...tTests/2020-01-06-coverage-009 12 MultiSourc...ench/telecomm-gsm/telecomm-gsm 39 MultiSourc...lds-flt/CrossingThresholds-flt 24 MultiSourc...dence-dbl/LinearDependence-dbl 2 External/S...C/CINT2006/445.gobmk/445.gobmk 6 MultiSourc...enchmarks/mafft/pairlocalalign 53 External/S...31.deepsjeng_r/531.deepsjeng_r 3 External/S...rate/510.parest_r/510.parest_r 58 External/S...NT2006/464.h264ref/464.h264ref 29 External/S...NT2017rate/502.gcc_r/502.gcc_r 45 External/S...C/CINT2006/456.hmmer/456.hmmer 6 External/S...te/538.imagick_r/538.imagick_r 18 External/S.../CFP2006/447.dealII/447.dealII 4 MultiSourc...OE-ProxyApps-C++/miniFE/miniFE 12 External/S...2017rate/525.x264_r/525.x264_r 36 MultiSourc...Benchmarks/7zip/7zip-benchmark 33 MultiSourc...hmarks/ASC_Sequoia/AMGmk/AMGmk 2 MultiSourc...chmarks/VersaBench/8b10b/8b10b 1 MultiSourc.../Applications/JM/lencod/lencod 116 MultiSourc...lds-dbl/CrossingThresholds-dbl 24 MultiSource/Benchmarks/McCat/05-eks/eks 15 ``` PR: https://github.com/llvm/llvm-project/pull/83860
2024-03-31[memoryssa] Exclude llvm.allow.{runtime,ubsan}.check() (#86066)Vitaly Buka
RFC: https://discourse.llvm.org/t/rfc-add-llvm-experimental-hot-intrinsic-or-llvm-hot/77641
2024-01-24[Analysis] Use llvm::pred_size (NFC)Kazu Hirata
2023-08-10[MemorySSA] Handle queries with empty memory location.Alina Sbirlea
2023-07-06[MemorySSA] Always perform MemoryUses liveOnEntry optimization on MSSA ↵Arthur Eubanks
construction Fixes invariant memory regressions in future DSE patches. Also add a flag to print<memoryssa> to not ensure optimized uses to test this. Noticeable compile time regression [1], but a future DSE change that depends on this more than makes up for it. [1] https://llvm-compile-time-tracker.com/compare.php?from=9d5466849a770eeab222d5a5890376d3596e8ad6&to=95682dbe11d76a3342870437377216e96b167504&stat=instructions:u Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D152859
2023-06-13[Passes] Remove some legacy printer passesArthur Eubanks
MemDepPrinter doesn't have a new PM equivalent, but MemDep is soft deprecated anyway and adding one should be easy if somebody wants to.
2023-03-02[DebugInfo] Remove `dbg.addr` from AnalysisJ. Ryan Stinnett
Part of `dbg.addr` removal Discussed in https://discourse.llvm.org/t/what-is-the-status-of-dbg-addr/62898 Differential Revision: https://reviews.llvm.org/D144799
2023-01-12[MemorySSA] Don't check def set when cloning memoryaccessesluxufan
For internal functions, globals-aa returns different ModRefInfo results if they are inlined and are no longer called by external functions. This causes an assertion failure when cloning memoryssa accesses. Fixes: https://github.com/llvm/llvm-project/issues/59546 Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D141185
2022-12-20[llvm] Remove redundant initialization of std::optional (NFC)Kazu Hirata
2022-12-14Don't include Optional.hKazu Hirata
These files no longer use llvm::Optional.
2022-12-14[Analysis] llvm::Optional => std::optionalFangrui Song
2022-12-06[ADT] Don't including None.h (NFC)Kazu Hirata
These source files no longer use None, so they do not need to include None.h. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-06[MemorySSA] Use BatchAA for clobber walkerNikita Popov
While MemorySSA use optimization was already using BatchAA, the publicly exposed MSSA walkers were using plain AAResults. This is not great, because it is expected that clobber walking will make repeated AA queries. This patch makes the clobber API accept a BatchAAResults instance. The plain APIs are kept as wrappers and will create a BatchAAResults instance for the duration of the query. In the future, the explicit BatchAAResults arguments will be used to share AA results across queries, not just within one query. Differential Revision: https://reviews.llvm.org/D136164
2022-12-04[llvm] Use std::nullopt instead of None in comments (NFC)Kazu Hirata
This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-02[Analysis] Use std::nullopt instead of None (NFC)Kazu Hirata
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-28[Analysis] Remove unused fields in MemorySSA.cpp (NFC)Kazu Hirata
The last uses of AR were removed on July 28, 2022 in commit f96ea53e892e0dfc1ee778868c1ed33616b95a82. Differential Revision: https://reviews.llvm.org/D138730
2022-11-17[MemorySSA] Relax assert condition in createDefinedAccessluxufan
If globals-aa is enabled, because of the deletion of memory instructions, there may be call instruction that is not in ModOrRefSet but is a MemoryUseOrDef. This causes the crash in the process of cloning uses and defs. Fixes https://github.com/llvm/llvm-project/issues/58719 Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D137553
2022-10-31[AliasAnalysis] Introduce getModRefInfoMask() as a generalization of ↵Patrick Walton
pointsToConstantMemory(). The pointsToConstantMemory() method returns true only if the memory pointed to by the memory location is globally invariant. However, the LLVM memory model also has the semantic notion of *locally-invariant*: memory that is known to be invariant for the life of the SSA value representing that pointer. The most common example of this is a pointer argument that is marked readonly noalias, which the Rust compiler frequently emits. It'd be desirable for LLVM to treat locally-invariant memory the same way as globally-invariant memory when it's safe to do so. This patch implements that, by introducing the concept of a *ModRefInfo mask*. A ModRefInfo mask is a bound on the Mod/Ref behavior of an instruction that writes to a memory location, based on the knowledge that the memory is globally-constant memory (in which case the mask is NoModRef) or locally-constant memory (in which case the mask is Ref). ModRefInfo values for an instruction can be combined with the ModRefInfo mask by simply using the & operator. Where appropriate, this patch has modified uses of pointsToConstantMemory() to instead examine the mask. The most notable optimization change I noticed with this patch is that now redundant loads from readonly noalias pointers can be eliminated across calls, even when the pointer is captured. Internally, before this patch, AliasAnalysis was assigning Ref to reads from constant memory; now AA can assign NoModRef, which is a tighter bound. Differential Revision: https://reviews.llvm.org/D136659
2022-09-21[MemorySSA] Remove PerformedPhiTranslation flagNikita Popov
I believe this is no longer necessary, as the underlying problem has been fixed in a different way: Nowadays, we will adjust the location size to beforeOrAfterPointer() if the pointer is not loop invariant. This makes merging results translated across loop backedges safe. The two tests in phi-translation.ll show an improvement while still being correct: The loads in the loop no longer alias with noalias pointers, but still alias with the store in the entry block (which they originally did not -- this is the bug that PerformedPhiTranslation originally fixed). Differential Revision: https://reviews.llvm.org/D133404
2022-09-20[MemorySSA][NFC] Use const whenever possibleluxufan
Differential Revision: https://reviews.llvm.org/D134162
2022-08-01[MSSA] Fix expensive checks buildNikita Popov
2022-08-01[AA] Do not track Must in ModRefInfoNikita Popov
getModRefInfo() queries currently track whether the result is a MustAlias on a best-effort basis. The only user of this functionality is the optimized memory access type in MemorySSA -- which in turn has no users. Given that this functionality has not found a user since it was introduced five years ago (in D38862), I think we should drop it again. The context is that I'm working to separate FunctionModRefBehavior to track mod/ref for different location kinds (like argmem or inaccessiblemem) separately, and the fact that ModRefInfo also has an unrelated Must flag makes this quite awkward, especially as this means that NoModRef is not a zero value. If we want to retain the functionality, I would probably split getModRefInfo() results into a part that just contains the ModRef information, and a separate part containing a (best-effort) AliasResult. Differential Revision: https://reviews.llvm.org/D130713
2022-06-26[llvm] Use Optional::has_value instead of Optional::hasValue (NFC)Kazu Hirata
This patch replaces x.hasValue() with x.has_value() where x is not contextually convertible to bool.
2022-06-25[llvm] Don't use Optional::hasValue (NFC)Kazu Hirata
This patch replaces Optional::hasValue with the implicit cast to bool in conditionals only.
2022-06-25Revert "Don't use Optional::hasValue (NFC)"Kazu Hirata
This reverts commit aa8feeefd3ac6c78ee8f67bf033976fc7d68bc6d.
2022-06-25Don't use Optional::hasValue (NFC)Kazu Hirata
2022-04-06[MSSA] Print memory phis when inspecting walker.Alina Sbirlea
This makes the MemorySSA and MemorySSA Walker printers consistent. Invokation `-print<memoryssa-walker>` should also have the MemoryPhis.
2022-03-18[MemorySSA] Don't optimize uses during constructionNikita Popov
This changes MemorySSA to be constructed in unoptimized form. MemorySSA::ensureOptimizedUses() can be called to optimize all uses (once). This should be done by passes where having optimized uses is beneficial, either because we're going to query all uses anyway, or because we're doing def-use walks. This should help reduce the compile-time impact of MemorySSA for some use cases (the reason why I started looking into this is D117926), which can avoid optimizing all uses upfront, and instead only optimize those that are actually queried. Actually, we have an existing use-case for this, which is EarlyCSE. Disabling eager use optimization there gives a significant compile-time improvement, because EarlyCSE will generally only query clobbers for a subset of all uses (this change is not included in this patch). Differential Revision: https://reviews.llvm.org/D121381
2022-03-01Cleanup includes: LLVMAnalysisserge-sans-paille
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
2022-02-06[llvm] Use = default (NFC)Kazu Hirata
2022-02-04[NFC] Remove unnecessary #includesBill Wendling
An attempt to reduce the number of files that are recompiled due to a change. Differential Revision: https://reviews.llvm.org/D119055
2022-01-23[Analysis] Use default member initialization (NFC)Kazu Hirata
Identified with modernize-use-default-member-init.
2021-10-12[CSSPGO] Unblock optimizations with pseudo probe instrumentation part 3.Hongtao Yu
This patch continues unblocking optimizations that are blocked by pseudo probe instrumentation. Not exactly like DbgIntrinsics, PseudoProbe intrinsic has other attributes (such as mayread, maywrite, mayhaveSideEffect) that can block optimizations. The issues fixed are: - Flipped default param of getFirstNonPHIOrDbg API to skip pseudo probes - Unblocked CSE by avoiding pseudo probe from clobbering memory SSA - Unblocked induction variable simpliciation - Allow empty loop deletion by treating probe intrinsic isDroppable - Some refactoring. Reviewed By: wenlei Differential Revision: https://reviews.llvm.org/D110847
2021-09-15[MemorySSA] Fix "set but not used" warningsKazu Hirata
2021-09-15[MemorySSA] Add verification levels to MemorySSA. [NFC]Alina Sbirlea
Add two levels of verification for MemorySSA: Fast and Full. The defaults are kept the same. Full verification always occurs under EXPENSIVE_CHECKS, but now it can also be requested in a specific pass for debugging purposes.
2021-09-08[MemorySSA] Support invariant.group metadataArthur Eubanks
The implementation is mostly copied from MemDepAnalysis. We want to look at all loads and stores to the same pointer operand. Bitcasts and zero GEPs of a pointer are considered the same pointer value. We choose the most dominating instruction. Since updating MemorySSA with invariant.group is non-trivial, for now handling of invariant.group is not cached in any way, so it's part of the walker. The number of loads/stores with invariant.group is small for now anyway. We can revisit if this actually noticeably affects compile times. To avoid invariant.group affecting optimized uses, we need to have optimizeUsesInBlock() not use invariant.group in any way. Co-authored-by: Piotr Padlewski <prazek@google.com> Reviewed By: asbirlea, nikic, Prazek Differential Revision: https://reviews.llvm.org/D109134
2021-09-02[MemorySSA] Properly handle liveOnEntry in the walker printerArthur Eubanks
Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D109177
2021-09-01Reland [MemorySSA] Add pass to print results of MemorySSA walkerArthur Eubanks
Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D109028
2021-09-01Revert "[MemorySSA] Add pass to print results of MemorySSA walker"Arthur Eubanks
This reverts commit 8f98477c2d2bcbf5b6aa36278b59bf2a861426a1. Breaks bots
2021-09-01[MemorySSA] Add pass to print results of MemorySSA walkerArthur Eubanks
Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D109028
2021-08-16[MemorySSA] Remove -enable-mssa-loop-dependency optionNikita Popov
This option has been enabled by default for quite a while now. The practical impact of removing the option is that MSSA use cannot be disabled in default pipelines (both LPM and NPM) and in manual LPM invocations. NPM can still choose to enable/disable MSSA using loop vs loop-mssa. The next step will be to require MSSA for LICM and drop the AST-based implementation entirely. Differential Revision: https://reviews.llvm.org/D108075
2021-05-15[IR] Add BasicBlock::isEntryBlock() (NFC)Nikita Popov
This is a recurring and somewhat awkward pattern. Add a helper method for it.
2021-04-09[AA][NFC] Convert AliasResult to class containing offset for PartialAlias case.dfukalov
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.dfukalov
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-03-23[MSSA] Extending IsGuaranteedLoopInvariant to support an instruction defined ↵Matteo Favaro
in the entry block As mentioned in [[ https://reviews.llvm.org/D96979 | D96979 ]], I'm extending the **IsGuaranteedLoopInvariant** check also to the `MemorySSA.cpp` file. @fhahn For now I didn't unify the function into `MemorySSA.h` because, as you mentioned, it's not directly MSSA related. I'm open to suggestions to find a better place so we can improve the unification process. Reviewed By: fhahn Differential Revision: https://reviews.llvm.org/D97155