649 Commits

Author SHA1 Message Date
Johannes Doerfert
56a033462e
[Attributor] Keep track of reached returns in AAPointerInfo (#107479)
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-09-10 08:13:21 -07:00
Shilei Tian
1ca9fe6db3 Reapply "[Attributor][AMDGPU] Enable AAIndirectCallInfo for AMDAttributor (#100952)"
This reverts commit 36467bfe89f231458eafda3edb916c028f1f0619.
2024-08-14 17:16:47 -04:00
Shilei Tian
36467bfe89 Revert "Reapply "[Attributor][AMDGPU] Enable AAIndirectCallInfo for AMDAttributor (#100952)""
This reverts commit 7a68449a82ab1c1ab005caa72c1d986ca5deca36.

https://lab.llvm.org/buildbot/#/builders/123/builds/3205
2024-08-07 09:22:48 -04:00
Shilei Tian
7a68449a82 Reapply "[Attributor][AMDGPU] Enable AAIndirectCallInfo for AMDAttributor (#100952)"
This reverts commit 874cd100a076f3b98aaae09f90ef224682501538.
2024-08-06 22:46:32 -04:00
Shilei Tian
874cd100a0 Revert "[Attributor][AMDGPU] Enable AAIndirectCallInfo for AMDAttributor (#100952)"
This reverts commit ab819d7cf86932e4a47b5bf6aadea9d714a313a9.
2024-08-02 18:31:21 -04:00
Shilei Tian
ab819d7cf8
[Attributor][AMDGPU] Enable AAIndirectCallInfo for AMDAttributor (#100952) 2024-08-02 17:23:18 -04:00
NAKAMURA Takumi
c8f2ee77d2 Fix a warning in #98362 [-Wunused-but-set-variable] 2024-07-13 20:57:09 +09:00
Arthur Eubanks
58bc98cd3a
[CallGraphUpdater] Remove some legacy pass manager support (#98362)
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-12 10:02:50 -07:00
Kazu Hirata
4b28b3fae4
[Transforms] Use range-based for loops (NFC) (#97195) 2024-07-02 16:20:44 -07:00
Ethan Luis McDonough
b629d4b912
[Attributor] Prevent infinite loop in AAGlobalValueInfoFloating (#94941)
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-18 09:36:42 -07:00
Jay Foad
d4a0154902
[llvm-project] Fix typo "seperate" (#95373) 2024-06-13 20:20:27 +01:00
Johannes Doerfert
5ec91b392d
[AttributorLight] Without liveness checks, look at all functions (#91004) 2024-05-23 07:28:07 +02:00
Jeremy Morse
2fe81edef6 [NFC][RemoveDIs] Insert instruction using iterators in Transforms/
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-03-05 15:12:22 +00:00
Björn Pettersson
7677453886
[ConstantFolding] Do not consider padded-in-memory types as uniform (#81854)
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-02-15 15:40:21 +01:00
Jeremy Morse
0065d06760
[NFC][DebugInfo] Maintain RemoveDIs flag when attributor creates functions (#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.
2024-01-24 15:20:05 +00:00
Vidhush Singhal
754b93e466
[Attributor] New attribute to identify what byte ranges are alive for an 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-10 16:26:37 -08:00
Nikita Popov
16a595e398 [Attributor] Avoid use of ConstantExpr::getFPTrunc() (NFC)
Use the constant folding API instead. For simplificity I'm using
the DL-independent API here.
2023-11-06 15:27:01 +01:00
Johannes Doerfert
499fb1b8d8 [Attributor][FIX] Interposable constants cannot be propagated 2023-10-20 19:28:09 -07:00
Johannes Doerfert
73a836a464
[Attributor] Look through indirect calls (#65197)
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-09-08 12:14:38 -07:00
Johannes Doerfert
209496b766 [Core] Allow hasAddressTaken to ignore "casted direct calls"
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-31 19:32:52 -07:00
Matt Arsenault
9536bbe464 Attributor: Don't pass ArrayRef by const reference 2023-08-31 08:41:08 -04:00
Matt Arsenault
850ec7bbb1 Attributor: Try to propagate concrete denormal-fp-math{-f32}
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-31 08:26:32 -04:00
Johannes Doerfert
498887ae8a [Attributor] Introduce the closed world flag
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 22:35:17 -07:00
Johannes Doerfert
936661084c [Attributor][NFC] Add querying AA to shouldSpecializeCallSiteForCallee
The callback might require an AA, e.g., to ask other AAs for information
in a way that will enfore dependences.
2023-08-29 22:35:16 -07:00
Johannes Doerfert
d0b5523632 [Attributor] Introduce limit for indirect call specialization
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-25 14:36:42 -07:00
Johannes Doerfert
9c08e76f3e [Attributor] Introduce AAIndirectCallInfo
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-18 16:44:05 -07:00
Johannes Doerfert
dfc821ae89 [OpenMPOpt][FIX] Ensure a dependence for KernelEnvC queries
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-10 23:16:25 -07:00
Florian Hahn
400fde9296
[Attributor] Add lightweight version for attribute deduction only.
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-05 11:47:28 +01:00
Johannes Doerfert
d70ab63bc2 [Attributor][NFCI] Filter uninteresting accesses early
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-08-04 11:36:58 -07:00
Johannes Doerfert
2f7ef7be1f [Attributor][FIX] Swap cases in ternary op to avoid nullptr reference
The case was wrong before, and somehow I only looked at the condition
before.
2023-07-26 00:03:06 -07:00
Johannes Doerfert
b3fec1067a [Attributor] Improve NonNull deduction
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.
2023-07-25 20:31:21 -07:00
Johannes Doerfert
4223c9b354 [Attributor] Always deduce nosync from readonly + non-convergent
This adds the deduction also if the function is not IPO amendable.
2023-07-25 17:47:33 -07:00
Johannes Doerfert
ae6ad31763 [Attributor] Try to remove argmem effects after signature rewrite
If the new signature has only readnone pointers we can remove any argmem
effect from the function signature.
2023-07-25 17:47:33 -07:00
Matt Arsenault
e93ae281db Attributor: Fix typo 2023-07-25 07:25:11 -04:00
Johannes Doerfert
dae52dd07d [Attributor][FIX] Initialize variable. 2023-07-17 22:48:03 -07:00
Johannes Doerfert
f26d05d306 [Attributor] Replace AAReturnedValues with AAPotentialValuesReturned
The very first AA, at least the first one in order, is not necessary
anymore. `AAReturnedValues` was from a different time; one might say, a
simpler time.

It was rewriten once to use `Attribute::getAssumedSimplifiedValues`,
which is what the replacement, `AAPotentialValuesReturned`, does too.
To match the old behavior we needed to avoid the helper
`AAReturnedFromReturnedValues` and iterate the return instructions
explicitly, however, it is still less complexity than it was before.
`AAReturnedFromReturnedValues` and `getAssumedSimplifiedValues` now
allow users to stop at PHI and select nodes or to ignore those and look
through. `AANoFPClass` will stop at select and phi nodes to read the
fast math flags.

Fixes: https://github.com/llvm/llvm-project/issues/63404

Differential Revision: https://reviews.llvm.org/D154917
2023-07-17 10:43:23 -07:00
Johannes Doerfert
55544518c6 [Attributor] Allow IR-attr deduction for non-IPO amendable functions
If the function is non-IPO amendable we do skip most attributes/AAs.
However, if an AA has a isImpliedByIR that can deduce the attribute from
other attributes, we can run those. For now, we manually enable them,
if we have more later we can use some automation/flag.
2023-07-14 13:54:04 -07:00
Shilei Tian
bcba20b5d0 [Attributor] Add AAAddressSpace to deduce address spaces
This patch adds initial support for the `AAAddressSpace` abstract
attributor interface to deduce and query address space information for a
pointer. We simply query the underlying objects that a pointer can point
to and find a common address space if they exist. This is the minimal
support for the interface, we currently manifest changes on loads and
stores. Additionally we should use the target transform information to
deduce if an address space transformation is a no-op for the target
machine when calculating compatibility.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D120586
2023-07-12 15:47:41 -04:00
Johannes Doerfert
ba7cc56782 [Attributor] Port AANoRecurse to the isImpliedByIR interface 2023-07-09 16:04:22 -07:00
Johannes Doerfert
18d9f7ebba [Attributor] Port AANoReturn to the isImpliedByIR interface 2023-07-09 16:04:22 -07:00
Johannes Doerfert
c272728624 [Attributor] Port AANoSync to the isImpliedByIR interface 2023-07-09 16:04:21 -07:00
Johannes Doerfert
c33fa5a6f8 [Attributor] Port AANoUnwind to the isImpliedByIR interface 2023-07-09 16:04:21 -07:00
Johannes Doerfert
6e7eb729c0 [Attributor] Port AAMustProgress to the checkAndQueryIRAttr interface 2023-07-09 16:04:21 -07:00
Johannes Doerfert
0348652cb0 [Attributor] Port AAWillReturn to the checkAndQueryIRAttr interface 2023-07-09 16:04:21 -07:00
Johannes Doerfert
5163779232 [Attributor] Port AANoFree to the isImpliedByIR interface 2023-07-09 16:04:20 -07:00
Johannes Doerfert
ebec3dd1bf [Attributor] Port AANoCapture to the isImpliedByIR interface
AANoCapture is now the first non-boolean AA that is always queried via
the new APIs and not created manually.

We explicitly do not manifest nocapture for `null` and `undef` anymore.
2023-07-09 16:04:20 -07:00
Johannes Doerfert
59fd610558 [Attributor] Port AANoUndef to the isImpliedByIR interface 2023-07-09 16:04:20 -07:00
Johannes Doerfert
aae749b275 [Attributor] Port AANoAlias to the isImpliedByIR interface
As part of this we do not annotate literal `null` and `undef/poison` as
`noalias` anymore. This was not really needed anyway.
2023-07-09 16:04:20 -07:00
Johannes Doerfert
02a4fcec6b [Attributor] Port AANonNull to the isImpliedByIR interface
AANonNull is now the first AA that is always queried via the new APIs
and not created manually. Others will follow shortly to avoid trivial
AAs whenever possible.

This commit introduced some helper logic that will make it simpler to
port the next one. It also untangles AADereferenceable and AANonNull
such that the former does not keep a handle on the latter. Finally,
we stop deducing `nonnull` for `undef`, which was incorrect.
2023-07-09 16:04:19 -07:00
Johannes Doerfert
aafdc9ea26 [Attributor] Make isImpliedByIR and hasAssumedIRAttr more useful
Checking more than one attribute kind was never done and we want to
later check the IR w/o creating an AA as fallback.
2023-07-03 16:05:16 -07:00