620 Commits

Author SHA1 Message Date
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
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
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
24fc579f57 [Attributor][NFC] Exit manifestAttrs early if there are no attributes 2023-07-03 10:07:03 -07:00
Johannes Doerfert
7b330fa80b [Attributor][NFCI] Avoid creating unnecessary AAs
If the IR has a boolean attribute, or the function is not IPO amendable,
we can avoid creating AAs that would just be forced into a trivial
fixpoint anyway. Since we check boolean IR attributes via
`AA::hasAssumedIRAttr`, we don't need AAs even if they would be fixed
optimistic right away. The only change is in the dependency graph
ordering as we move AAs around to simplify the code flow. There is no
reason for the order we seed AAs, so this order is just as fine.
2023-06-29 23:08:11 -07:00
Johannes Doerfert
5186c2f9f8 [Attributor][NFC] Introduce IRP helpers for Attr and Arg handling 2023-06-29 13:32:06 -07:00
Johannes Doerfert
1716924ccf [Attributor][NFC] Introduce a flag to skip liveness checks
While we can disallow AAs, liveness checks are everywhere and if the
user doesn't want them it is costly to go through just to find out
everything is assumed live.
2023-06-29 09:18:36 -07:00
Johannes Doerfert
339a1f3ce3 [Attributor] Avoid more AAs through IR implication 2023-06-24 00:35:31 -07:00
Johannes Doerfert
732bdb6073 [Attributor] Avoid the type check in getCalledFunction
We now consistently use `CallBase::getCalledOperand` rather than
`getCalledFunction`, as we do not want the type checked performed by the
latter. This exposed various missing checks to handle mismatches
properly, but it is good to have them explicit now.

In a follow up we might want to flag certain calls as UB, but for now,
we allow everything to cut down on unexpected differences.
2023-06-23 20:10:12 -07:00
Johannes Doerfert
e9fc399db3 [Attributor][NFCI] Use pointers to pass around AAs
This will make it easier to create less trivial AAs in the future as we
can simply return `nullptr` rather than an AA with in invalid state.
2023-06-23 17:21:20 -07:00
Johannes Doerfert
767e429a80 [Attributor][NFC] Allow to restrict the Attributor to cached passes
If the user wants to avoid running additional passes, they can now
initialize the AnalysisGetter accordingly.
2023-06-23 16:32:36 -07:00
Johannes Doerfert
23dafbb1e5 [Attributor] Remove the iteration count verification
It was never really useful to track #iterations, though it helped during
the initial development. What we should track, in a follow up, are
potentially #updates. That is also what we should restrict instead of
the #iterations.
2023-06-23 16:32:36 -07:00
Johannes Doerfert
bed6a6e7e0 [Attributor][NFC] Make the MustBeExecutedContextExplorer optional
For a lightweight pass we do not want to instantiate or use the
MustBeExecutedContextExplorer. This simply allows such a configuration.
While at it, the explorer is now allocated with the bump allocator.
2023-06-13 16:49:56 -07:00
Johannes Doerfert
dbbe9b3776 [Attributor] Create AAMustProgress for the mustprogress attribute
Derive the mustprogress attribute based on the willreturn attribute
or the fact that all callers are mustprogress.

Differential Revision: https://reviews.llvm.org/D94740
2023-06-05 16:33:52 -07:00
Johannes Doerfert
d037b237de [Attributor] Teach AAMemoryLocation about constant GPU memory
AS(4), when targeting GPUs, is constant. Accesses to constant memory are
(historically) not treated as "memory accesses", hence we should deduce
`memory(none)` for those.
2023-05-18 13:27:43 -07:00
Shilei Tian
e0ea44720d [Attributor] Set up a dedicated simplification call back map for GlobalVariable
Currently we don't check call backs for global variable simplification.
What's more, the only way that we can register a simplification call back for
global variable is through its initializer (essentially a `Constant *`). It might
not correspond to the right global variable. In this patch, we set up a dedicated
simplification map for `GlobalVariable`.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D144749
2023-04-21 00:08:35 -04:00
Bjorn Pettersson
a20f7efbc5 Remove several no longer needed includes. NFCI
Mostly removing includes of InitializePasses.h and Pass.h in
passes that no longer has support for the legacy PM.
2023-04-17 13:54:19 +02:00
Ishaan Gandhi
aead502b11 [Attributor] Add convergent abstract attribute
This patch adds the AANonConvergent abstract attribute. It removes the
convergent attribute from functions that only call non-convergent
functions.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D143228
2023-03-20 22:33:50 -07:00
Johannes Doerfert
19529458c4 [Attributor][NFC] Reduce output verbosity 2023-03-20 17:44:23 -07:00
Matt Arsenault
94026ce56d Attributor: Start inferring nofpclass
Some of this is boilerplate which doesn't do anything yet.
2023-03-16 23:19:34 -04:00
Arthur Eubanks
773d663e47 [IPO] Remove various legacy passes
These are part of the optimization pipeline, of which the legacy pass manager version is deprecated and being removed.
2023-02-27 19:06:08 -08:00
Johannes Doerfert
7495a2e51b [Attributor][FIX] Ensure we adjust types properly
When we simplify loads we need to adjust types (esp. null-values)
properly to avoid inconsinstencies down the line. Add a cast and an
error message.

Fixes: https://github.com/llvm/llvm-project/issues/60788
2023-02-16 17:45:56 -08:00
Johannes Doerfert
1763c63254 [Attributor][NFCI] Use a set to track dependences 2023-02-10 11:56:09 -06:00
Johannes Doerfert
76a1919026 [Attributor][NFC] Avoid unnecessary string operations
This caused multiple string operations which we don't need if we do not
create a profile.
2023-02-10 11:56:09 -06:00
Johannes Doerfert
bf9964fb13 [Attributor][NFCI] Create a AAIsDead for the function eagerly 2023-02-10 11:56:09 -06:00
Johannes Doerfert
63b02271a8 [Attributor][NFCI] Avoid spending time resolving kernel reachability queries
We know kernels (generally) cannot be called from within the module. Thus,
for reachability we would need to step back from a kernel which would allow
us to reach anything anyway. Even if a kernel is invoked from another
kernel, values like allocas and shared memory are not accessible. We
implicitly check for this situation to avoid costly lookups.
2023-02-02 13:59:58 -08:00
Johannes Doerfert
c4ad24deee [Attributor][NCFI] Explicitly state what interfering accesses to look for
We used to check the query instructions for effects but that does not
work well with complex accesses we will probably support in the future.
Now we simply let the user decide what accesses to look for.
2023-02-02 13:59:57 -08:00
Johannes Doerfert
1771d81475 [Attributor] Allow to delete (assume) intrinsics outside the SCC 2023-01-23 20:32:07 -08:00
Johannes Doerfert
75728b41f8 [Attributor][FIX] Reachability needs to process the entire worklist 2023-01-23 20:32:06 -08:00
Johannes Doerfert
43c1c59f73 [OpenMP] Merge barrier elimination into AAExecutionDomain
With this patch we track aligned barriers in AAExecutionDomain and also
delete unnecessary barriers there. This allows us to eliminate barriers
across blocks, across functions, and in the presence of complex accesses
that do not force a barrier. Further, we can use the collected
information to enable store-load forwarding in a threaded environment
(follow up patch).

Differential Revision: https://reviews.llvm.org/D140463
2023-01-22 16:34:59 -08:00