444 Commits

Author SHA1 Message Date
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 e425a4c45618fcfa8ffb13be4ddfaa5d28aa38f1 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 0dc0a441323d41b4860668f38d290579e0de130c.

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 3b052558125cbedf18c2ddb65780b50d6f437d54.

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 8b446ea2ba39e406bcf940ea35d6efb4bb9afe95

Reapplying because this commit is NOT DEPENDENT on the reverted commit
fc21f2d7bae2e0be630470cc7ca9323ed5859892, 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 fc21f2d7bae2e0be630470cc7ca9323ed5859892.

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 07c375348083170e39c9498a42a9679c7e08f07f.

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 88db516af69619d4326edea37e52fc7321c33bb5.

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
Mitch Phillips
7928a6387f Revert "Revert "[AAPointerInfo] handle multiple offsets in PHI""
This reverts commit 12696d302d146ffe616eecab3feceba9d29be2db.

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:38 -08:00
Mitch Phillips
8b446ea2ba Revert "[AAPointerInfo] handle multiple offsets in PHI"
This reverts commit 179ed8871101cd197e0a719a3629cd5077b1a999.

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:54:44 -08:00
Fangrui Song
21c4dc7997 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 clang.
2022-12-17 00:42:05 +00:00
Sameer Sahasrabuddhe
179ed88711 [AAPointerInfo] handle multiple offsets in PHI
Previously reverted in 12696d302d146ffe616eecab3feceba9d29be2db

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-15 12:23:50 +05:30
Sameer Sahasrabuddhe
12696d302d Revert "[AAPointerInfo] handle multiple offsets in PHI"
This reverts commit 88db516af69619d4326edea37e52fc7321c33bb5.
2022-12-15 10:14:39 +05:30
Sameer Sahasrabuddhe
88db516af6 [AAPointerInfo] handle multiple offsets in PHI
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-15 08:48:38 +05:30
Johannes Doerfert
07c3753480 [OpenMP][FIX] Restrict more unsound assmptions about threading
Even if all loads and stores are in `nosync` functions we cannot
guarantee there is no synchronization going on between them. As such, we
cannot use CFG reasoning. We could check the entire module, or, what
happens now to minimize test churn, is to check if all accesses are in
the same function that is `nosync`. A follow up will undo some of the
regressions where possible.

Similarly, reachability cannot be used to exclude an access if the
access is not known to be executed by the same thread as the given
instruction.

The OpenMP-opt test was added for the latter problem.
2022-12-13 22:58:33 -08:00
Johannes Doerfert
fc21f2d7ba [Attributor] Introduce AA[Intra/Inter]Reachability
We had two AAs for reachability but it was very cumbersome to extend
them. We also had some fallback to use LLVM-core mechanisms and cache
the result. The new design shares the query code and interface nicely
between AAIntraFnReachability and AAInterFnReachability.

As part of the rewrite we also added the ExclusionSet to the queries.
2022-12-13 19:38:15 -08:00
Johannes Doerfert
8be3133ecd [OpenMP][FIX] Remove unsound reasoning about written to values
Even if a value is for sure written we need to visit the call sites as
they might end up inside the function that reads and writes the value.
In a follow up we can introduce correct reasoning to avoid the backwards
traversal in this case and instead check if any call site between the
write and the read might reach a potential write we want to exclude.
2022-12-13 18:44:20 -08:00
Kazu Hirata
59686bb3fc [IPO] Fix a warning
This patch fixes:

  llvm/lib/Transforms/IPO/AttributorAttributes.cpp:1028:21: error:
  unused function 'operator<<' [-Werror,-Wunused-function]
2022-12-13 17:25:01 -08:00
Sameer Sahasrabuddhe
6a2305484e [AAPointerInfo] track multiple constant offsets for each use
An expression of the form `gep(base, select(pred, const1, const2))` can result
in a set of offsets instead of just one. PointerInfo can now track these sets
instead of conservatively modeling them as Unknown. In general, AAPointerInfo
now uses AAPotentialConstantValues to examine the operands of the GEP.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D138646
2022-12-13 22:27:25 +05:30
Johannes Doerfert
12e14bc42b [Attributor] Make non-side-effect inline asm be "no-call"
If we have inline asm with side effects we assume any function might be
called. For non-side-effect asm we now assume no function is called.
2022-12-12 20:55:35 -08:00
Sameer Sahasrabuddhe
2fdeb27790 Revert "[AAPointerInfo] track multiple constant offsets for each use"
Assertion fired in openmp-offload-amdgpu-runtime:
https://lab.llvm.org/buildbot/#/builders/193/builds/23177

This reverts commit c2a0baad1fbb21fe111fef83ec93c2d7923b9b0c.
2022-12-12 15:39:18 +05:30
Sameer Sahasrabuddhe
c2a0baad1f [AAPointerInfo] track multiple constant offsets for each use
An expression of the form `gep(base, select(pred, const1, const2))` can result
in a set of offsets instead of just one. PointerInfo can now track these sets
instead of conservatively modeling them as Unknown. In general, AAPointerInfo
now uses AAPotentialConstantValues to examine the operands of the GEP.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D138646
2022-12-12 13:36:45 +05:30
Kazu Hirata
e5ef6aced2 [Analysis] Use std::optional in MemoryBuiltins.cpp (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
2022-12-11 01:32:26 -08:00
Johannes Doerfert
142e38007d [OpenMP][FIX] Do not use reachability reasoning in parallel contexts
Similar to dominance reasoning, we cannot use CFG reachability if the
instructions might be executed by different threads. A follow up will
improve our sensitivity for situations when it is OK to use graph
reasoning.
2022-12-09 14:27:55 -08:00