summaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/IPO/Attributor.cpp
AgeCommit message (Collapse)Author
2025-07-01[Reland][IPO] Added attributor for identifying invariant loads (#146584)zGoldthorpe
Patched and tested the `AAInvariantLoadPointer` attributor from #141800, which identifies pointers whose loads are eligible to be marked as `!invariant.load`. The bug in the attributor was due to `AAMemoryBehavior` always identifying pointers obtained from `alloca`s as having no writes. I'm not entirely sure why `AAMemoryBehavior` behaves this way, but it seems to be beceause it identifies the scope of an `alloca` to be limited to only that instruction (and, certainly, no memory writes occur within the `alloca` instructin). This patch just adds a check to disallow all loads from `alloca` pointers from being marked `!invariant.load` (since any well-defined program will have to write to stack pointers at some point).
2025-06-18Revert "[IPO] Added attributor for identifying invariant loads" (#144808)zGoldthorpe
Reverts llvm/llvm-project#141800 The implementation critically misunderstands the `AAMemoryBehavior` attributor, which it relies on heavily. @shiltian, since I do not have commit permissions.
2025-06-16[IPO] Added attributor for identifying invariant loads (#141800)zGoldthorpe
The attributor conservatively marks pointers whose loads are eligible to be marked as `!invariant.load`. It does so by identifying: 1. Pointers marked `noalias` and `readonly` 2. Pointers whose underlying objects are all eligible for invariant loads. The attributor then manifests this attribute at non-atomic non-volatile load instructions.
2025-06-16[MemoryBuiltins] Support allocas in getInitialValueOfAllocation (NFC)Nikita Popov
2025-06-12[DebugInfo][RemoveDIs] Delete debug-info-format flag (#143746)Jeremy Morse
This flag was used to let us incrementally introduce debug records into LLVM, however everything is now using records. It serves no purpose now, so delete it.
2025-05-23[IPO] Teach AbstractAttribute::getName to return StringRef (NFC) (#141313)Kazu Hirata
This patch addresses clang-tidy's readability-const-return-type by dropping const from the return type while switching to StringRef at the same time because these functions just return string constants.
2025-05-20[Attributor] Don't replace `addrspacecast (ptr null to ptr addrspace(x))` ↵Shilei Tian
with `ptr addrspace(x) null` (#126779) `ConstantPointerNull` represents a pointer with value 0, but it doesn’t necessarily mean a `nullptr`. `ptr addrspace(x) null` is not the same as `addrspacecast (ptr null to ptr addrspace(x))` if the `nullptr` in AS X is not zero. Therefore, we can't simply replace it. Fixes #115083.
2025-05-07[llvm] Drop "const" from "const ArrayRef" (NFC) (#138818)Kazu Hirata
2025-05-02[IR] Do not store Function inside BlockAddress (#137958)Nikita Popov
Currently BlockAddresses store both the Function and the BasicBlock they reference, and the BlockAddress is part of the use list of both the Function and BasicBlock. This is quite awkward, because this is not really a use of the function itself (and walks of function uses generally skip block addresses for that reason). This also has weird implications on function RAUW (as that will replace the function in block addresses in a way that generally doesn't make sense), and causes other peculiar issues, like the ability to have multiple block addresses for one block (with different functions). Instead, I believe it makes more sense to specify only the basic block and let the function be implied by the BB parent. This does mean that we may have block addresses without a function (if the BB is not inserted), but this should only happen during IR construction.
2025-04-18Attributor: Use use_empty instead of getNumUses == 0 (#136339)Matt Arsenault
2025-04-07Attributor: Don't follow uses of ConstantData (#134573)Matt Arsenault
These should not really have uselists, and it's not worth the compile time of looking at all uses of trivial constants. The main observable change of this is it no longer adds align attributes on constant null uses, but those are not useful. Some of these cases should potentially be more aggressive and not look at any Constant users.
2025-03-28[clang][flang][Triple][llvm] Add isOffload function to LangOpts and isGPU ↵Nick Sarnie
function to Triple (#126956) I'm adding support for SPIR-V, so let's consolidate these checks. --------- Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
2025-03-19[Transforms] Use *Set::insert_range (NFC) (#132056)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.
2025-03-03[Attributor] Do not optimize away externally_initialized loads. (#128170)Pierre van Houtryve
Fixes SWDEV-515029
2025-02-27[Attributor][NFC] Clang format (#129163)Johannes Doerfert
2025-01-29[IR] Convert from nocapture to captures(none) (#123181)Nikita Popov
This PR removes the old `nocapture` attribute, replacing it with the new `captures` attribute introduced in #116990. This change is intended to be essentially NFC, replacing existing uses of `nocapture` with `captures(none)` without adding any new analysis capabilities. Making use of non-`none` values is left for a followup. Some notes: * `nocapture` will be upgraded to `captures(none)` by the bitcode reader. * `nocapture` will also be upgraded by the textual IR reader. This is to make it easier to use old IR files and somewhat reduce the test churn in this PR. * Helper APIs like `doesNotCapture()` will check for `captures(none)`. * MLIR import will convert `captures(none)` into an `llvm.nocapture` attribute. The representation in the LLVM IR dialect should be updated separately.
2025-01-14[Attributor][NFC] Performance improvements (#122923)macurtis-amd
` forallInterferingAccesses` is a hotspot and for large modules these changes make a measurable improvement in compilation time. For LTO kernel compilation of 519.clvleaf (SPEChpc 2021) I measured the following: ``` | Measured times (s) | Average | speedup --------------------+------------------------+---------+--------- Baseline | 33.268 33.332 33.275 | 33.292 | 0% Cache "kernel" | 30.543 30.339 30.607 | 30.496 | 9.2% templatize callback | 30.981 30.97 30.964 | 30.972 | 7.5% Both changes | 29.284 29.201 29.053 | 29.179 | 14.1% ```
2024-11-03[IPO] Remove unused includes (NFC) (#114716)Kazu Hirata
Identified with misc-include-cleaner.
2024-09-27[Attributor] Use more appropriate approach to check flat address space (#108713)Shilei Tian
2024-09-10[Attributor] Keep track of reached returns in AAPointerInfo (#107479)Johannes Doerfert
Instead of visiting call sites in Attribute::checkForAllUses, we now keep track of returns in AAPointerInfo and use the call site return information as required. This way, the user of AAPointerInfo(CallSite)Argument can determine if the call return should be visited. We do not collect them as "may accesses" in the AAPointerInfo(CallSite)Argument itself in case a return user is found.
2024-08-14Reapply "[Attributor][AMDGPU] Enable AAIndirectCallInfo for AMDAttributor ↵Shilei Tian
(#100952)" This reverts commit 36467bfe89f231458eafda3edb916c028f1f0619.
2024-08-07Revert "Reapply "[Attributor][AMDGPU] Enable AAIndirectCallInfo for ↵Shilei Tian
AMDAttributor (#100952)"" This reverts commit 7a68449a82ab1c1ab005caa72c1d986ca5deca36. https://lab.llvm.org/buildbot/#/builders/123/builds/3205
2024-08-06Reapply "[Attributor][AMDGPU] Enable AAIndirectCallInfo for AMDAttributor ↵Shilei Tian
(#100952)" This reverts commit 874cd100a076f3b98aaae09f90ef224682501538.
2024-08-02Revert "[Attributor][AMDGPU] Enable AAIndirectCallInfo for AMDAttributor ↵Shilei Tian
(#100952)" This reverts commit ab819d7cf86932e4a47b5bf6aadea9d714a313a9.
2024-08-02[Attributor][AMDGPU] Enable AAIndirectCallInfo for AMDAttributor (#100952)Shilei Tian
2024-07-13Fix a warning in #98362 [-Wunused-but-set-variable]NAKAMURA Takumi
2024-07-12[CallGraphUpdater] Remove some legacy pass manager support (#98362)Arthur Eubanks
We don't have any legacy pass manager CGSCC passes that modify the call graph (we only use it in the codegen pipeline to run function passes in call graph order). This is the beginning of removing CallGraphUpdater and making all the relevant CGSCC passes directly use the new pass manager APIs.
2024-07-02[Transforms] Use range-based for loops (NFC) (#97195)Kazu Hirata
2024-06-18[Attributor] Prevent infinite loop in AAGlobalValueInfoFloating (#94941)Ethan Luis McDonough
Global variables that reference themselves alongside a function that is called indirectly can cause an infinite loop in `AAGlobalValueInfoFloating`. The recursive reference is continually pushed back into the workload, causing the attributor to hang indefinitely.
2024-06-13[llvm-project] Fix typo "seperate" (#95373)Jay Foad
2024-05-23[AttributorLight] Without liveness checks, look at all functions (#91004)Johannes Doerfert
2024-03-05[NFC][RemoveDIs] Insert instruction using iterators in Transforms/Jeremy Morse
As part of the RemoveDIs project we need LLVM to insert instructions using iterators wherever possible, so that the iterators can carry a bit of debug-info. This commit implements some of that by updating the contents of llvm/lib/Transforms/Utils to always use iterator-versions of instruction constructors. There are two general flavours of update: * Almost all call-sites just call getIterator on an instruction * Several make use of an existing iterator (scenarios where the code is actually significant for debug-info) The underlying logic is that any call to getFirstInsertionPt or similar APIs that identify the start of a block need to have that iterator passed directly to the insertion function, without being converted to a bare Instruction pointer along the way. Noteworthy changes: * FindInsertedValue now takes an optional iterator rather than an instruction pointer, as we need to always insert with iterators, * I've added a few iterator-taking versions of some value-tracking and DomTree methods -- they just unwrap the iterator. These are purely convenience methods to avoid extra syntax in some passes. * A few calls to getNextNode become std::next instead (to keep in the theme of using iterators for positions), * SeparateConstOffsetFromGEP has it's insertion-position field changed. Noteworthy because it's not a purely localised spelling change. All this should be NFC.
2024-02-15[ConstantFolding] Do not consider padded-in-memory types as uniform (#81854)Björn Pettersson
Teaching ConstantFoldLoadFromUniformValue that types that are padded in memory can't be considered as uniform. Using the big hammer to prevent optimizations when loading from a constant for which DataLayout::typeSizeEqualsStoreSize would return false. Main problem solved would be something like this: store i17 -1, ptr %p, align 4 %v = load i8, ptr %p, align 1 If for example the i17 occupies 32 bits in memory, then LLVM IR doesn't really tell where the padding goes. And even if we assume that the 15 most significant bits are padding, then they should be considered as undefined (even if LLVM backend typically would pad with zeroes). Anyway, for a big-endian target the load would read those most significant bits, which aren't guaranteed to be one's. So it would be wrong to constant fold the load as returning -1. If LLVM IR had been more explicit about the placement of padding, then we could allow the constant fold of the load in the example, but only for little-endian. Fixes: https://github.com/llvm/llvm-project/issues/81793
2024-01-24[NFC][DebugInfo] Maintain RemoveDIs flag when attributor creates functions ↵Jeremy Morse
(#79143) We're using this flag (IsNewDbgInfoFormat) to detect the boundaries in LLVM of what's treating debug-info as intrinsics (i.e. dbg.value), and what's using DPValue objects (the non-intrinsic replacement). The attributor tends to create new wrapper functions and doesn't insert them into Modules in the usual way, thus we have to manually update that flag to signal what debug-info mode it's using. I've added some --try-experimental-debuginfo-iterators RUN lines to tests that would otherwise crash because of this, so that they're exercised by our new-debuginfo-iterators buildbot. NB: there's an attributor test with a dbg.value in it, however attributes re-order themselves in RemoveDIs mode for various reasons, so we're going to address that in a different patch.
2023-11-10[Attributor] New attribute to identify what byte ranges are alive for an ↵Vidhush Singhal
allocation (#66148) Changes the size of allocations automatically. For now, implements the case when a single range from start of the allocation is alive and the allocation can be reduced.
2023-11-06[Attributor] Avoid use of ConstantExpr::getFPTrunc() (NFC)Nikita Popov
Use the constant folding API instead. For simplificity I'm using the DL-independent API here.
2023-10-20[Attributor][FIX] Interposable constants cannot be propagatedJohannes Doerfert
2023-09-08[Attributor] Look through indirect calls (#65197)Johannes Doerfert
Through the new `Attributor::checkForAllCallees` we can look through indirect calls and visit all potential callees if they are known. Most AAs will do that implicitly now via `AACalleeToCallSite`, thus, most AAs are able to deal with missing callees for call site IR positions. Differential Revision: https://reviews.llvm.org/D112290
2023-08-31[Core] Allow `hasAddressTaken` to ignore "casted direct calls"Johannes Doerfert
A direct call to a function casted to a different type is still not really an address taken event. We allow the user to opt out of these now. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D159149
2023-08-31Attributor: Don't pass ArrayRef by const referenceMatt Arsenault
2023-08-31Attributor: Try to propagate concrete denormal-fp-math{-f32}Matt Arsenault
Allow specialization of functions with "dynamic" denormal modes to a known IEEE or DAZ mode based on callers. This should make it possible to implement a is-denormal-flushing-enabled test using llvm.canonicalize and have it be free after LTO. https://reviews.llvm.org/D156129
2023-08-29[Attributor] Introduce the closed world flagJohannes Doerfert
The Attributor user can now set the closed world flag (`AttributorConfig.IsClosedWorldModule` or `-attributor-assume-closed-world`) in order to specialize call edges based only on available callees. That means, we assume all functions are known and hence all potential callees must be declared/defined in the module. We will use this for GPUs and LTO cases, but for now the user has to set it via a flag.
2023-08-29[Attributor][NFC] Add querying AA to shouldSpecializeCallSiteForCalleeJohannes Doerfert
The callback might require an AA, e.g., to ask other AAs for information in a way that will enfore dependences.
2023-08-25[Attributor] Introduce limit for indirect call specializationJohannes Doerfert
The user can now limit the number of indirect calls specialized for a given call site with `-attributor-max-specializations-per-call-base=N` or the AttributorConfig callback. We further attach the `!callee` metadata if all remaining callees are known.
2023-08-18[Attributor] Introduce AAIndirectCallInfoJohannes Doerfert
AAIndirectCallInfo will collect information and specialize indirect call sites. It is similar to our IndirectCallPromotion but runs as part of the Attributor (so with assumed callee information). It also expands more calls and let's the rest of the pipeline figure out what is UB, for now. We use existing call promotion logic to improve the result, otherwise we rely on the (implicit) function pointer cast. This effectively "fixes" #60327 as it will undo the type punning early enough for the inliner to work with the (now specialized, thus direct) call. Fixes: https://github.com/llvm/llvm-project/issues/60327
2023-08-10[OpenMPOpt][FIX] Ensure a dependence for KernelEnvC queriesJohannes Doerfert
When other AAs query the current value of KernelEnvC via the callback KernelConfigurationSimplifyCB we need to ensure they are now dependent on the AAKernelInfo that is in charge of the KernelEnvC.
2023-08-05[Attributor] Add lightweight version for attribute deduction only.Florian Hahn
This patch adds a lightweight instance of Attributor that only deduces attributes. This is just an initial version with the goal to have a version that only focuses on attributes to replace the function-attrs pass. The initial version has a few open issues pending until default enablement, the main one probably being compile time. The main additional functionality this will provide in general is propagating attributes to call sites. Open issues: * compile time The current version increase O3 +2.67% and ThinLTO +6.18% when replacing FunctionAttr https://llvm-compile-time-tracker.com/compare.php?from=c4bb3e073548cf436d5fa0406e3ae75e94684dec&to=d992630a69c79a2587d736e6a88f448850413bd1&stat=instructions%3Au Both are with an additional change to preserve more analysis, like FunctionAttrs CGSCC run. * some missed attribute inference Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D152081
2023-08-04[Attributor][NFCI] Filter uninteresting accesses earlyJohannes Doerfert
We can prevent the costly interference check if an access is not interesting in the first place. Let the user decide via a callback.
2023-07-26[Attributor][FIX] Swap cases in ternary op to avoid nullptr referenceJohannes Doerfert
The case was wrong before, and somehow I only looked at the condition before.
2023-07-25[Attributor] Improve NonNull deductionJohannes Doerfert
We can improve our deduction if we stop at PHI and select instructions and also iterate the returned values explicitly. The latter helps with isImpliedByIR deductions.