Commit Graph

460 Commits

Author SHA1 Message Date
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
Kazu Hirata
1ca0cb717a [llvm] Replace None with std::nullopt in comments (NFC)
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
2023-04-25 23:53:32 -07:00
Doru Bercea
1a58c3d601 Avoid capping heap to stack optimization for __kmpc_alloc_shared allocations.
Review: https://reviews.llvm.org/D148849
2023-04-21 09:27:53 -04:00
Johannes Doerfert
119a94b5ae [Attributor][FIX] Ensure to cache all intra procedural AA queries
We failed to cache queries without an exclusion set that resulted in
non-reachable results. That is obviously bad as changes to liveness can
influence the result.

Fixes: https://github.com/llvm/llvm-project/issues/61883
2023-04-17 18:01:04 -07:00
Nikita Popov
9fe78db4cd [FunctionAttrs] Fix nounwind inference for landingpads
Currently, FunctionAttrs treats landingpads as non-throwing, and
will infer nounwind for functions with landingpads (assuming they
can't unwind in some other way, e.g. via resum). There are two
problems with this:

* Non-cleanup landingpads with catch/filter clauses do not
  necessarily catch all exceptions. Unless there are catch ptr null
  or filter [0 x ptr] zeroinitializer clauses, we should assume
  that we may unwind past this landingpad. This seems like an
  outright bug.
* Cleanup landingpads are skipped during phase one unwinding, so
  we effectively need to support unwinding past them. Marking these
  nounwind is technically correct, but not compatible with how
  unwinding works in reality.

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

Differential Revision: https://reviews.llvm.org/D147694
2023-04-14 11:46:00 +02:00
Nikita Popov
c508e93327 [InstSimplify] Remove unused ORE argument (NFC) 2023-04-14 10:38:32 +02:00
Johannes Doerfert
7ccf4d1ad7 [Attributor][FIX] Account for blocks w/o predecessors 2023-03-27 21:30:23 -07: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
c0f3a3d7b5 [Attributor][FIX] Avoid H2S on GPUs if the pointer can be shared
If the stack is not accessible by other threads, e.g., on a GPU, we need
to ensure heap-2-stack will not create a stack version of a pointer that
might be passed to another thread. Since passing through memory is by
default transparent, we need to register a callback and inspect stores
we might look through explicitly.
2023-03-20 17:44:24 -07:00
Johannes Doerfert
b89558a2ae [OpenMP][FIX] Properly track and lookup Execution Domains
This is a two part fix. First, we need two Execution Domains (ED) to
track the values of a function. One for incoming values and one for
outgoing values. This was conflated before. Second, at the function
entry we need to look at the incoming information from call sites not
iterate over non-existing predecessors.
2023-03-20 17:44:24 -07:00
Johannes Doerfert
0fc63d4e64 [Attributor][FIX] Ensure loop PHI replacements are dynamically unique
Similar to loads, PHIs can be used to introduce non-dynamically unique
values into the simplification "algorithm". We need to check that PHIs
do not carry such a value from one iteration into the next as can cause
downstream reasoning to fail, e.g., downstream could think a comparison
is equal because the simplified values are equal while they are defined
in different loop iterations. Similarly, instructions in cycles are now
conservatively treated as non-dynamically unique. We could do better but
I'll leave that for the future.

The change in AAUnderlyingObjects allows us to ignore dynamically unique
when we simply look for underlying objects. The user of that AA should
be aware that the result might not be a dynamically unique value.
2023-03-20 17:44:24 -07:00
Matt Arsenault
221512e7b2 Revert "Attributor: Add isAtFixpoint part of nofpclass handling"
This reverts commit 78313e8531.

Accidentally pushed
2023-03-17 08:15:28 -04:00
Matt Arsenault
d2404ea6ce Attributor: Assume handling for nofpclass 2023-03-17 07:39:40 -04:00
Matt Arsenault
78313e8531 Attributor: Add isAtFixpoint part of nofpclass handling 2023-03-17 07:02:47 -04:00
Matt Arsenault
6705f634f6 Attributor: Start looking at uses when inferring nofpclass
Pretty much just copy pasted from noundef handling
2023-03-17 07:02:41 -04: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
Johannes Doerfert
86cce90e21 [Attributor][NFCI] Avoid AAIntraFnReachability updates if possible
Even if liveness changed, we only care about certain dead edges in
AAIntraFnReachability. If those are still dead, we can avoid an update.
2023-02-10 11:56:09 -06:00
Johannes Doerfert
a9557aacd1 [Attributor][NFCI] Use queries without exclusion set whenever possible
If a query uses an exclusion set but we haven't used it to determine the
result, we can cache the query without exclusion set too. When we lookup
a cached result we can check for the non-exclusion set version first.
2023-02-10 11:56:09 -06:00
Johannes Doerfert
8bc0bee2f8 [Attributor][NFCI] Avoid a temporary vector and exit early
This change simply avoids the temporary vector and processes the elments
right away.
2023-02-10 11:56:09 -06: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
e67f148023 [Attributor][NFC] Improve debug messages 2023-02-02 02:28:15 -08:00
Johannes Doerfert
18a2975b57 [Attributor][FIX] Ensure we use the right AAExecutionDomain
Before we might have ended up queriying the AAExecutionDomain of a
different function, which resulted in wrong optimistic results.

Partially fixes https://github.com/llvm/llvm-project/issues/60425
2023-02-02 02:27:54 -08:00
Johannes Doerfert
a51ad873bf [OpenMP][FIX] Properly check assume only uses
We improved our simplification and this exposed a bug in the store
elimination. A load that had dead uses and assume uses was thought to be
used by assumes only. Consequently we also deleted the "dead use users".
This was a problem because a dead use just means we will not use the
load there. The user might still be needed.

Exposed by OvO, reported by @ye-luo.
2023-01-31 06:13:54 -08:00
Kazu Hirata
f20b5071f3 [llvm] Use llvm::bit_floor instead of llvm::PowerOf2Floor (NFC) 2023-01-28 09:06:31 -08:00
Johannes Doerfert
5238df7ed5 [Attributor] Allow (inter-procedural) "CFG" reasoning for aligned regions
If an instruction is executed in an aligned region we can ignore
threading effects and use CFG reasoning (dominance and reachability).
This is true because all threads are together in an aligned region and
there cannot be one waiting for a signal at a place not connected via
the control flow.

More dedicated tests will follow.

More details can be found here:
"Co-Designing an OpenMP GPU Runtime and Optimizations for Near-Zero
Overhead Execution", IPDPS 2022,
https://www.osti.gov/servlets/purl/1890094
2023-01-23 22:45:48 -08:00
Johannes Doerfert
fedbc689e1 [Attributor] Check assumptions to improve isAlignedBarrier queries 2023-01-23 20:34:26 -08:00
Johannes Doerfert
2f6fce8bba [Attributor][FIX] Ensure not to run new queries during manifest
If we modified the IR during manifest, e.g., SPMDzation, we might end up
with un-cached reachability queries. This is not good as the result is
going to be optimistic. We now cache the updateImpl result and use it
during manifest.

Bug was exposed in a follow up extension.
2023-01-23 20:32:06 -08:00
Johannes Doerfert
9f0f84f140 [Attributor][FIX] Replace typo with something more sane 2023-01-23 20:32:05 -08:00
Johannes Doerfert
f341807ea5 [Attributor] Add initial support for vectors in AAPointerInfo
While full support requires more work (see TODOs), this allows us to
handle vector writes with a single constant value properly. For now,
we can handle the same constant values stored to all elements if
everything is of a fixed size.
2023-01-22 23:20:32 -08:00
Johannes Doerfert
538cd2e883 [Attributor] Multi-range accesses can be exact
Even if we have multiple access ranges, the access can be exact. It is
not a MUST access but that is taken care of elsewhere. The tests were
wrong as they contained uninitialized memory. When the memory is
initialized it works as expected.
2023-01-22 23:18:55 -08:00
Johannes Doerfert
129faec711 [OpenMP] Identify non-aligned barriers executed in an aligned context
Even if a barrier does not enforce aligned execution, it will
effectively be like an aligned barrier if it is executed by all threads
in an aligned way. We lack control flow divergence analysis here so we
can only do (basic block) local reasoning for now.
2023-01-22 21:42:07 -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
Johannes Doerfert
82ba958ca2 [Attributor] Handle constant icmp expressions in AAPotentialValues
A `ConstantExpr` ICmp is pretty much the same thing as an ICmpInst when
we want to simplify it. We just need to be less restrictive wrt. the
type and use the static helper functions directly.

Fixes: https://github.com/llvm/llvm-project/issues/59767
2023-01-22 01:15:38 -08:00
Johannes Doerfert
8b4e1287ac [Attributor][FIX] Consistently use the access/remote instruction
We use the actual access (=remote) instruction when reasoning about
accesses, except for one leftover use case of the local instruction.
This caused us to potentially ignore the dominating write if the read
and write were in a different function than the (stack) allocation.

Reported by @ye-luo
2023-01-12 15:21:34 -08:00
Johannes Doerfert
2d9f44512e [Attributor] Make AAIsDeadFunction lazy 2023-01-12 00:14:06 -08:00
Guillaume Chatelet
8fd5558b29 [NFC] Use TypeSize::geFixedValue() instead of TypeSize::getFixedSize()
This change is one of a series to implement the discussion from
https://reviews.llvm.org/D141134.
2023-01-11 16:49:38 +00:00
Johannes Doerfert
b84ea7a475 [Attributor] Improve use of dominating writes during reasoning
This resolves a recent regression introduced by a bug fix and allows us
to use dominating write information (formerly HasBeenWrittenTo
information) to skip potential interfering accesses.

Generally, there are two changes here:
1) If we have dominating writes they form a chain and we can look at the
   least one to minimize the distance between the write and the (read)
   access in question.
2) If such a least dominating write exists, we can ignore writes in
   other functions as long as they cannot be reached from code between
   this write and the (read) access in question.

We have all the tools available to make such queries and the positive
tests show the result. Note that the negative test from the bug fix is
still in tree and not affected.

As a side-effect, we can remove the (arbitrary) treshold now on the
number of interfering accesses since we do not iterate over dominating
ones anymore.
2023-01-10 14:21:53 -08:00
Johannes Doerfert
31ad4dbcb9 Reapply "[Attributor] Introduce AA[Intra/Inter]Reachability"
This reverts commit e425a4c456 after the
memory leak has been fixed.
2023-01-10 12:29:24 -08:00
Johannes Doerfert
1b9ba5856a [Attributor] Allow cfg reasoning for thread-local objects
If an object (=memory) is thread-local we do not need to worry about
threading effects.
2023-01-09 16:40:20 -08:00
Caroline Tice
2700d0d13a [AAUnderlyingObjects] Initialize an uninitialized boolean.
Recent commit introducing AA for getting underluying objects of a
pointer created an uninitialized boolean, which causes tests to fail
when built unter asan/ubsan. This initialized that variable.
2023-01-09 15:46:15 -08:00
Shilei Tian
acd22b2751 [AAUnderlyingObjects] Introduce an AA for getting underlying objects of a pointer
This patch introduces a new AA `AAUnderlyingObjects`. It is basically like a wrapper
AA of the function `AA::getAssumedUnderlyingObjects`, but it can recursively do
query if the underlying object is an indirect access, such as a phi node or a select
instruction.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D141164
2023-01-08 16:45:50 -05:00
Sameer Sahasrabuddhe
a73e0c306c [AAPointerInfo] fix assertion at the pass-through use of a pointer
HandlePassthroughUser may sometimes create a new entry for the OffsetInfo of a
user in the OffsetInfoMap. This can invalidate outstanding references into the
map, including the one which needs to be copied into the new entry. This
produces invalid offset info that can trigger assertions.

Fixed this by not using references at this point. The bug was originally
introduced in commit ID 0dc0a44132.

Reviewed By: ronlieb

Differential Revision: https://reviews.llvm.org/D140837
2023-01-04 16:53:55 +05:30
Johannes Doerfert
b0cee1f4ba [Attributor][FIX] Treat undef as zero offset in AAPointerInfoFloating 2023-01-03 13:09:23 -08:00
Sameer Sahasrabuddhe
e467a42943 [Attributor] potential constant values for PHI and Load
AAPotentialConstantValues now works for PHI and Load by simply examinig
AAPotentialValues for the instruction itself.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D140371
2022-12-21 15:59:00 +05:30
Johannes Doerfert
4e0f464ce2 Reapply "[OpenMP][FIX] Restrict more unsound assmptions about threading"
This reverts commit 3b05255812.

This patch got reverted due to an unrelated memory leak that has been
fixed.
2022-12-19 18:27:52 -08:00
Sameer Sahasrabuddhe
9c1b82599d [AAPointerInfo] handle multiple offsets in PHI
Previously reverted in 8b446ea2ba

Reapplying because this commit is NOT DEPENDENT on the reverted commit
fc21f2d7ba, which broke the ASAN buildbot.
See https://reviews.llvm.org/rGfc21f2d7bae2e0be630470cc7ca9323ed5859892 for
more information.

The arguments to a PHI may represent a recurrence by eventually using the output
of the PHI itself. This is now handled by checking for cycles in the control
flow. If a PHI is not in a recurrence, it is now able to report multiple offsets
instead of conservatively reporting unknown.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D138991
2022-12-18 10:51:20 +05:30
Fangrui Song
53243f2a29 std::optional::value => operator*/operator->
value() has undesired exception checking semantics and calls
__throw_bad_optional_access in libc++. Moreover, the API is unavailable without
_LIBCPP_NO_EXCEPTIONS on older Mach-O platforms (see
_LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS).

This fixes check-clang-tools.
2022-12-17 03:12:04 +00:00
Mitch Phillips
e425a4c456 Revert "[Attributor] Introduce AA[Intra/Inter]Reachability"
This reverts commit fc21f2d7ba.

This patch broke the ASan buildbot. See
https://reviews.llvm.org/rGfc21f2d7bae2e0be630470cc7ca9323ed5859892 for
more information.
2022-12-16 17:56:48 -08:00
Mitch Phillips
3b05255812 Revert "[OpenMP][FIX] Restrict more unsound assmptions about threading"
This reverts commit 07c3753480.

Reason: This change is dependent on a commit that needs to be rolled
back because it broke the ASan buildbot. See
https://reviews.llvm.org/rGfc21f2d7bae2e0be630470cc7ca9323ed5859892 for
more information.
2022-12-16 17:56:38 -08:00
Mitch Phillips
525d6c54b5 Revert "[AAPointerInfo] handle multiple offsets in PHI"
This reverts commit 88db516af6.

Reason: This change is dependent on a commit that needs to be rolled
back because it broke the ASan buildbot. See
https://reviews.llvm.org/rGfc21f2d7bae2e0be630470cc7ca9323ed5859892 for
more information.
2022-12-16 17:55:48 -08:00