518 Commits

Author SHA1 Message Date
Johannes Doerfert
3e19416e4e [Attributor][FIX] Initialize variable 2023-08-18 21:47:57 -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
361b536bbc [Attributor] Simplify switches with more than one potential condition
Before, we allowed the condition to be simplified to a simple constant
only, otherwise we assumed all successors are live. Now we allow
multiple constants, and mark the default successor as dead accordingly.
2023-08-17 22:42:38 -07:00
Johannes Doerfert
bfa1afb81c [OpenMPOpt] Improve __kmpc_alloc_shared handling
We know that __kmpc_alloc_shared is by construction matched with a
unique __kmpc_free_shared. Making the compiler aware of these facts
helps to avoid mallocs/allocas.

Fixes: https://github.com/llvm/llvm-project/issues/64551
2023-08-17 19:25:32 -07:00
Johannes Doerfert
5a406b63e9 [Attributor][FIX] Stores capture, even for readonly functions
If we end up visiting a store use, we couldn't follow to the "reloads".
The capture effect of a store is more than memory as the reloads are
unknown.

Fixes: https://github.com/llvm/llvm-project/issues/64613
2023-08-11 14:17:33 -07: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
78daab0a85 [Attributor][NFCI] Compute ReachabilityQueryInfo hash once and on demand 2023-08-03 00:12:46 -07:00
Johannes Doerfert
2a20c64a73 [Attributor][NFCI] Use DominatorTree to short circuit reachability queries
If we do not have exlusion blocks and the target is live, we only need
to reach a dominating block.
2023-08-03 00:12:46 -07:00
Johannes Doerfert
4fd9874696 [Attributor][NFCI] Exit reachability queries early if the target is not live 2023-08-03 00:12:45 -07:00
Johannes Doerfert
578ab3312f [Attributor][NFCI] Use a uniform necessary query to avoid a unique one
If we cannot reach the target from the entry of a function without
exclusion set, we cannot reach it at all. This can allow us to filter
unique queries based on a uniform one.
2023-08-03 00:12:45 -07:00
Bjorn Pettersson
e6e9a87534 Drop some typed pointer handling
Differential Revision: https://reviews.llvm.org/D156739
2023-08-02 12:08:37 +02:00
Johannes Doerfert
a598e39063 [AAInterFnReachabilityFunction][NFC] Remove unused members 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
88b5d23021 [Attributor] Allow multiple LHS/RHS values when simplifying comparisons
We use to deal with multiple values but not in the handleCmp function.
Now we also allow multiple simplified operands there.
2023-07-25 20:31:21 -07:00
Johannes Doerfert
0cd8a28941 [Attributor][FIX] No IntraFnReachability does not mean unreachable
Also, first check inter fn reachability as it seems to be cheaper in
practise.
2023-07-25 17:47:33 -07:00
Johannes Doerfert
ba0be698c5 [Attributor][NFC] Rename variable to be less confusing 2023-07-25 17:47:33 -07:00
Johannes Doerfert
e31724f1a6 [Attributor] Check readonly call sites for nosync in AANoSync
See @nosync_convergent_callee_test() in nosync.ll. The other changes are
call sites now annotated with `nosync`.
2023-07-25 17:47:33 -07:00
Johannes Doerfert
c3f30687b5 [Attributor][NFCI] Add a shortcut for constants 2023-07-19 10:27:01 -07:00
Alexander Batashev
17508cbcc6 [NFC] Fix builds on recent GCC with C++20 enabled
The following pattern fails on recent GCC versions with -std=c++20 flag passed
and succeeds with -std=c++17. Such behavior is not observed on Clang 16.0.

```c++
template <typename T>
struct Foo {
    Foo<T>(int a) {}
};
```

This patch removes template parameter from constructor in two occurences to
make the following command complete successfully:
bazel build -c fastbuild --cxxopt=-std=c++20 --host_cxxopt=-std=c++20 @llvm-project//llvm/...

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D154782
2023-07-18 19:44:06 +03:00
Nikita Popov
7be7f23269 [llvm] Remove uses of getWithSamePointeeType() (NFC) 2023-07-18 12:07:09 +02:00
Johannes Doerfert
cd69b0cc88 [Attributor][FIX] Initialize out parameters 2023-07-17 16:26:32 -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
a5d194e975 [Attributor][NFC] Improve debug message 2023-07-17 10:43:22 -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
Shilei Tian
f3bd221adc [NFC] clang-format attributor related files 2023-07-09 22:37:30 -04:00
Johannes Doerfert
ab513fe63b [Attributor] Ensure call sites with missing callees are tracked 2023-07-09 19:25:09 -07:00
Kazu Hirata
60db0b8d3a [IPO] Fix uused-variable warnings
This patch fixes:

  llvm/lib/Transforms/IPO/AttributorAttributes.cpp:2038:10: error:
  unused variable 'IsKnown' [-Werror,-Wunused-variable]
2023-07-09 17:54:30 -07: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
7e77e812ab [Attributor][FIX] Require the store to be aligned for value propagation 2023-07-07 16:38:34 -07:00
Johannes Doerfert
d081296212 [Attributor] Check all NoFPClass attributes found in the IR 2023-07-06 21:30:04 -07:00
Johannes Doerfert
3b04d119b2 [Attributor][NFCI] Use AA::hasAssumedIRAttr for NoSync 2023-07-06 21:30:04 -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
Johannes Doerfert
f086f383d8 [Attributor][NFCI] Move attribute collection and manifest to Attributor
Before, we checked and manifested attributes right in the IR. This was
bad as we modified the IR before the manifest stage. Now we can
add/remove/inspect attributes w/o going to the IR (except for the
initial query).
2023-07-03 11:57:30 -07:00
Johannes Doerfert
77dbd1d712 [Attributor][NFCI] Manifest assumption attributes explicitly
We had some custom manifest for assumption attributes but we use the
generic manifest logic. If we later decide to curb duplication (of
attributes on the call site and callee), we can do that at a single
location and for all attributes.

The test changes basically add known `llvm.assume` callee information to
the call sites.
2023-07-03 11:57:29 -07:00
Johannes Doerfert
b672c602c7 [Attributor][NFCI] Merge MemoryEffects explicitly
We had some custom handling for existing MemoryEffects but we now move
it to the place we check other existing attributes before we manifest
new ones. If we later decide to curb duplication (of attributes on the
call site and callee), we can do that at a single location and for all
attributes.

The test changes basically add known `memory` callee information to the
call sites.
2023-07-03 11:57:29 -07:00
Johannes Doerfert
41086f38ec [Attributor][NFC] Check for the Explorer first to avoid traversing uses 2023-07-03 10:07:03 -07:00
Johannes Doerfert
d6fa3b374f [Attributor] Remove now obsolete initialization code
With the helpers in place to judge AAs [1] we can remove the custom
rolled initialization checking code. This exposed a minor oversight in
the AAMemoryLocation where we did not check the IR before we gave up for
a declaration.

[1] d33bca840a
2023-06-29 13:32:06 -07:00
Elliot Goodrich
b0abd4893f [llvm] Add missing StringExtras.h includes
In preparation for removing the `#include "llvm/ADT/StringExtras.h"`
from the header to source file of `llvm/Support/Error.h`, first add in
all the missing includes that were previously included transitively
through this header.
2023-06-25 15:42:22 +01:00
Johannes Doerfert
339a1f3ce3 [Attributor] Avoid more AAs through IR implication 2023-06-24 00:35:31 -07:00
Johannes Doerfert
7d16a35c83 [Attributor][FIX] Do not ignore refinement for IPO
This is just a cleanup commit, a follow up will make this way more
structured.
2023-06-23 20:10:12 -07:00