595 Commits

Author SHA1 Message Date
Jay Foad
f8559751fc
[llvm-project] Fix typo "propogate" (#114795) 2024-11-04 15:33:19 +00:00
Kazu Hirata
98ea1a81a2
[IPO] Remove unused includes (NFC) (#114716)
Identified with misc-include-cleaner.
2024-11-03 13:48:55 -08:00
Shilei Tian
5a74a4a667
[Attributor] Take the address space from addrspacecast directly (#108258)
Currently `AAAddressSpace` relies on identifying the address spaces of
all underlying objects. However, it might infer sub-optimal address
space when the underlying object is a function argument. In
`AMDGPUPromoteKernelArgumentsPass`, the promotion of a pointer kernel
argument is by adding a series of `addrspacecast` instructions (as shown
below), and hoping `InferAddressSpacePass` can pick it up and do the
rewriting accordingly.

Before promotion:

```
define amdgpu_kernel void @kernel(ptr %to_be_promoted) {
  %val = load i32, ptr %to_be_promoted
  ...
  ret void
}
```

After promotion:

```
define amdgpu_kernel void @kernel(ptr %to_be_promoted) {
  %ptr.cast.0 = addrspace cast ptr % to_be_promoted to ptr addrspace(1)
  %ptr.cast.1 = addrspace cast ptr addrspace(1) %ptr.cast.0 to ptr
  # all the use of %to_be_promoted will use %ptr.cast.1
  %val = load i32, ptr %ptr.cast.1
  ...
  ret void
}
```

When `AAAddressSpace` analyzes the code after promotion, it will take
`%to_be_promoted` as the underlying object of `%ptr.cast.1`, and use its
address space (which is 0) as its final address space, thus simply do
nothing in `manifest`. The attributor framework will them eliminate the
address space cast from 0 to 1 and back to 0, and replace `%ptr.cast.1`
with `%to_be_promoted`, which basically reverts all changes by
`AMDGPUPromoteKernelArgumentsPass`.

IMHO I'm not sure if `AMDGPUPromoteKernelArgumentsPass` promotes the
argument in a proper way. To improve the handling of this case, this PR
adds an extra handling when iterating over all underlying objects. If an
underlying object is a function argument, it means it reaches a terminal
such that we can't futher deduce its underlying object further. In this
case, we check all uses of the argument. If they are all `addrspacecast`
instructions and their destination address spaces are same, we take the
destination address space.

Fixes: SWDEV-482640.
2024-10-09 22:51:07 -04:00
Johannes Doerfert
335e137267
[Attributor][FIX] Track returned pointer offsets (#110534)
If the pointer returned by a function is not "the base pointer" but has
an offset, we need to track the offset such that users can apply it to
their offset chain when they create accesses.
This was reported by @ye-luo and reduced test cases are included. The
OffsetInfo was moved and the container was replaced with a set to avoid
excessive growth. Otherwise, the patch just replaces the "returns
pointer" flag with the "returned offsets", and deals with the applying
to offsets at the call site.

---------

Co-authored-by: Johannes Doerfert <jdoerfert@llnl.gov>
2024-10-01 12:41:15 -05:00
Jeremy Morse
96f37ae453
[NFC] Use initial-stack-allocations for more data structures (#110544)
This replaces some of the most frequent offenders of using a DenseMap that
cause a malloc, where the typical element-count is small enough to fit in
an initial stack allocation.

Most of these are fairly obvious, one to highlight is the collectOffset
method of GEP instructions: if there's a GEP, of course it's going to have
at least one offset, but every time we've called collectOffset we end up
calling malloc as well for the DenseMap in the MapVector.
2024-09-30 23:15:18 +01:00
Shilei Tian
0b7a18bd4a
[Attributor] Use more appropriate approach to check flat address space (#108713) 2024-09-27 18:26:55 -04:00
macurtis-amd
72fd35b85b
[Attributor] Report change when updating ReachesReturn (#108965) 2024-09-19 11:10:18 -05:00
Shilei Tian
4808842771
[NFC][Attributor] Use unsigned integer for address space tracking (#108447) 2024-09-12 13:56:21 -07:00
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
ce2e38653f
[Attributor] Add support for atomic operations in AAAddressSpace (#106927) 2024-09-06 12:45:16 -04:00
Shilei Tian
109cd11dc4
[Attributor] Skip AS specialization for volatile memory instructions (#107250) 2024-09-06 11:00:30 -04:00
Johannes Doerfert
84bf0da34d
[Attributor][FIX] Ensure to always translate call site arguments (#107323)
When we propagate call site arguments we always need to translate them,
this is important as we ended up picking the function argument for a
recurisve call not the call site argument. `@recBad` and `@recGood` in
`returned.ll` show the problem as they used to transform them the same
way. The restructuring cleans the code up and helps derive more
"returned" arguments and better information in the presence of recursive
calls. The "dropped" attributes are simply dropped because we do not
query them anymore, not because we cannot derive them.
2024-09-05 13:37:21 -07:00
Johannes Doerfert
e6dece9f69
[Attributor][FIX] Mark "may" accesses through call sites as such (#107439)
Before, we kept the call site access kind (may/must) when we translated
the access. However, the pointer we access it through (by passing it to
the callee) might not be the underlying object. We have similar logic
when we add store and load accesses.
2024-09-05 13:33:58 -07:00
Anshil Gandhi
ed2f90902c
[NFC][Attributor] Track the number of promoted indirect calls (#106214) 2024-08-27 13:28:33 -04:00
Kazu Hirata
820396c3a8
[Transforms] Construct SmallVector with iterator ranges (NFC) (#105607) 2024-08-21 23:32:13 -07:00
Johannes Doerfert
8266d47cd1
[Attributor] Improve AAUnderlyingObjects (#104835)
- Allocas and GlobalValues cannot be simplified, so we should not try.
- If we never used any assumed state, the AAUnderlyingObjects doesn't
require an additional update.
- If we have seen an object (or it's underlying object) before, we do
not need to inspect it anymore.

The original logic for "SeenObjects" was flawed and caused us to add
intermediate values to the underlying object list if a PHI or select
instruction referenced the same underlying object twice. The test
changes are all instances of this situation and we now correctly derive
`memory(none)` for the functions that only access stack memory.

---------

Co-authored-by: Shilei Tian <i@tianshilei.me>
2024-08-20 12:05:20 -07:00
Johannes Doerfert
7156bcf286
[Attributor][FIX] Ensure we do not use stale references (#104495)
When copying map entries, we might run into resizing and invalidate the
RHS of the assignment. We dealt with this before and now use the proper
helper to avoid the problem in another place.

Fixes: https://github.com/llvm/llvm-project/issues/104397
2024-08-15 18:45:36 -04:00
Shilei Tian
1ca9fe6db3 Reapply "[Attributor][AMDGPU] Enable AAIndirectCallInfo for AMDAttributor (#100952)"
This reverts commit 36467bfe89f231458eafda3edb916c028f1f0619.
2024-08-14 17:16:47 -04:00
Yingwei Zheng
f364b2ee22
[LLVM] Don't peek through bitcast on pointers and gep with zero indices. NFC. (#102889)
Since we are using opaque pointers now, we don't need to peek through
bitcast on pointers and gep with zero indices.
2024-08-13 22:38:50 +08: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
53d33d3ba5
[Attributor] Fix an issue that an access is skipped by mistake (#101862)
When we check if an access can be skipped, there is a case that an
inter-procedural interference access exists after a dominant write.
Currently we
rely on `AAInterFnReachability` to tell if the access can be reachable.
If it is
not, we can safely skip the access. However, it is based on an
assumption that
the AA exists. It is possible that the AA doesn't exist. In this case,
we can't
safely assume the acess can be skipped because we have to assume the
access can
reach. This can happen when `AAInterFnReachability` is not in the
allowed AA
list when creating the attributor, such as AMDGPUAttributor.

Co-authored-by: Mark de Wever <koraq@xs4all.nl>
2024-08-06 21:29:39 -04:00
Shilei Tian
4b6e3e38c4
[Attributor] Improve debug string of AAUnderlyingObjects (#101861) 2024-08-06 12:31:35 -07: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
Shilei Tian
e7f73c03df [Attributor] Use getPointerAddressSpace to replace a cast followed by a getAddressSpace 2024-08-01 22:57:43 -04:00
Shilei Tian
9373a43218
[Attributor] Indicate optimistic fixed point if an instruction already has non-zero address space (#101589) 2024-08-01 22:55:09 -04:00
Vidush Singhal
c7633ddb28
[Attributor]: Ensure cycle info is not null when handling PHI in AAPointerInfo (#97321)
Ensure cycle info object is not null for simple PHI case

for the test:
`llvm/test/Transforms/Attributor/phi_bug_pointer_info.ll`

Debug info Before the change: 

```
Accesses by bin after update:
[8-12] : 1
     - 9 -   store i32 %0, ptr %field2, align 4
       - c:   %0 = load i32, ptr %val, align 4
[32-36] : 1
     - 9 -   store i32 %1, ptr %field8, align 4
       - c:   %1 = load i32, ptr %val2, align 4
[2147483647-4294967294] : 1
     - 6 -   %ret = load i32, ptr %x, align 4
       - c: <unknown>
```

Debug info After the change: 

```
Accesses by bin after update:
[8-12] : 2
     - 9 -   store i32 %0, ptr %field2, align 4
       - c:   %0 = load i32, ptr %val, align 4
     - 6 -   %ret = load i32, ptr %x, align 4
       - c: <unknown>
[32-36] : 2
     - 9 -   store i32 %1, ptr %field8, align 4
       - c:   %1 = load i32, ptr %val2, align 4
     - 6 -   %ret = load i32, ptr %x, align 4
       - c: <unknown>
```

Co-authored-by: Vidush Singhal <singhal2@ruby964.llnl.gov>
2024-07-01 17:20:34 -07:00
Youngsuk Kim
2051736f7b [llvm][Transforms] Avoid 'raw_string_ostream::str' (NFC)
Since `raw_string_ostream` doesn't own the string buffer, it is
desirable (in terms of memory safety) for users to directly reference
the string buffer rather than use `raw_string_ostream::str()`.

Work towards TODO comment to remove `raw_string_ostream::str()`.
2024-06-30 09:03:29 -05:00
Nikita Popov
9df71d7673
[IR] Add getDataLayout() helpers to Function and GlobalValue (#96919)
Similar to https://github.com/llvm/llvm-project/pull/96902, this adds
`getDataLayout()` helpers to Function and GlobalValue, replacing the
current `getParent()->getDataLayout()` pattern.
2024-06-28 08:36:49 +02:00
Nikita Popov
2d209d964a
[IR] Add getDataLayout() helpers to BasicBlock and Instruction (#96902)
This is a helper to avoid writing `getModule()->getDataLayout()`. I
regularly try to use this method only to remember it doesn't exist...

`getModule()->getDataLayout()` is also a common (the most common?)
reason why code has to include the Module.h header.
2024-06-27 16:38:15 +02:00
Stephen Tozer
d75f9dd1d2 Revert "[IR][NFC] Update IRBuilder to use InsertPosition (#96497)"
Reverts the above commit, as it updates a common header function and
did not update all callsites:

  https://lab.llvm.org/buildbot/#/builders/29/builds/382

This reverts commit 6481dc57612671ebe77fe9c34214fba94e1b3b27.
2024-06-24 18:00:22 +01:00
Stephen Tozer
6481dc5761
[IR][NFC] Update IRBuilder to use InsertPosition (#96497)
Uses the new InsertPosition class (added in #94226) to simplify some of
the IRBuilder interface, and removes the need to pass a BasicBlock
alongside a BasicBlock::iterator, using the fact that we can now get the
parent basic block from the iterator even if it points to the sentinel.
This patch removes the BasicBlock argument from each constructor or call
to setInsertPoint.

This has no functional effect, but later on as we look to remove the
`Instruction *InsertBefore` argument from instruction-creation
(discussed
[here](https://discourse.llvm.org/t/psa-instruction-constructors-changing-to-iterator-only-insertion/77845)),
this will simplify the process by allowing us to deprecate the
InsertPosition constructor directly and catch all the cases where we use
instructions rather than iterators.
2024-06-24 17:27:43 +01:00
Fangrui Song
89e8e63f47 [Attributor] Stabilize llvm.assume output
Don't rely on the iteration order of DenseSet<StringRef>, which is not
guaranteed to be deterministic.
2024-06-19 15:36:46 -07:00
Vidush Singhal
bea329ecb0
[Attributor]: allow more than one offset for a pass through user in AAPointerInfo (#94416)
Co-authored-by: Vidush Singhal <singhal2@ruby964.llnl.gov>
2024-06-17 16:31:39 -07:00
Kazu Hirata
7c6d0d26b1
[llvm] Use llvm::unique (NFC) (#95628) 2024-06-14 22:49:36 -07:00
Johannes Doerfert
f33310e450
[Attributor][FIX] Ensure nonnull IR deduction is not optimistic (#93322)
We cannot use assumed dead information for nonnull IR-implied deduction
as we will never go back and re-check. This was reported in
  https://github.com/llvm/llvm-project/pull/85810
2024-06-13 08:42:36 +03:00
Vidush Singhal
bfc0f856b6
[NFC] : Run clang-format on Attributor.h and AttributorAttributes.cpp (#94484)
This PR just runs Clang format on Attributor.h and AttributorAttributes.cpp

Co-authored-by: Vidush Singhal <singhal2@ruby964.llnl.gov>
2024-06-05 11:32:22 -07:00
Nikita Popov
deab451e7a
[IR] Remove support for icmp and fcmp constant expressions (#93038)
Remove support for the icmp and fcmp constant expressions.

This is part of:
https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179

As usual, many of the updated tests will no longer test what they were
originally intended to -- this is hard to preserve when constant
expressions get removed, and in many cases just impossible as the
existence of a specific kind of constant expression was the cause of the
issue in the first place.
2024-06-04 08:31:03 +02:00
Johannes Doerfert
d48d108bc6
[Attributor][FIX] Replace AANoFPClass MBEC propagation (#91030)
The old use of must-be-executed-context (MBEC) did propagate
through calls even if that was not allowed. We now only propagate from
call site arguments. If there are calls/intrinsics that allows
propagation, we need to add them explicitly.

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

---------

Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2024-06-03 20:41:52 -07:00
Matt Arsenault
2d61692d4b
Attributor: Do not assume function context in AANoCapture (#91462)
If the calling function has the null_pointer_is_valid attribute, somehow
a null constant reaches here. I'm not sure why exactly, it doesn't
happen for other types of constants.

Fixes #87856
2024-05-23 19:31:33 +02:00
Harald van Dijk
60de56c743
[ValueTracking] Restore isKnownNonZero parameter order. (#88873)
Prior to #85863, the required parameters of llvm::isKnownNonZero were
Value and DataLayout. After, they are Value, Depth, and SimplifyQuery,
where SimplifyQuery is implicitly constructible from DataLayout. The
change to move Depth before SimplifyQuery needed callers to be updated
unnecessarily, and as commented in #85863, we actually want Depth to be
after SimplifyQuery anyway so that it can be defaulted and the caller
does not need to specify it.
2024-04-16 15:21:09 +01:00
Yingwei Zheng
e0a628715a
[ValueTracking] Convert isKnownNonZero to use SimplifyQuery (#85863)
This patch converts `isKnownNonZero` to use SimplifyQuery. Then we can
use the context information from `DomCondCache`.

Fixes https://github.com/llvm/llvm-project/issues/85823.
Alive2: https://alive2.llvm.org/ce/z/QUvHVj
2024-04-12 23:47:20 +08:00
Matt Arsenault
733640d29e
Attributor: Handle inferring align from use by atomics (#85762) 2024-03-21 10:54:03 +05:30
lcvon007
676c495195
[Attributor][FIX] Register right new created BB. (#84929)
CBBB will keep same after the first iteration so
registerManifestAddedBasicBlock would always register the same basic
block later.

Co-authored-by: laichunfeng <laichunfeng@tencent.com>
2024-03-13 16:38:48 +08: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
Nikita Popov
6c2fbc3a68
[IRBuilder] Add CreatePtrAdd() method (NFC) (#77582)
This abstracts over the common pattern of creating a gep with i8 element
type.
2024-01-12 14:21:21 +01:00
Bill Wendling
fc6b5666db
[NFC][ObjectSizeOffset] Use classes instead of std::pair (#76882)
The use of std::pair makes the values it holds opaque. Using classes
improves this while keeping the POD aspect of a std::pair. As a nice
addition, the "known" functions held inappropriately in the Visitor
classes can now properly reside in the value classes. :-)
2024-01-05 18:08:53 -08:00
Nikita Popov
658b260dbf [Attributor] Don't construct pretty GEPs
Bring this in line with other transforms like ArgPromotion/SROA/
SCEVExpander and always produce canonical i8 GEPs.
2023-12-22 16:48:13 +01:00
Nikita Popov
696cc20d4e [LVI] Make UndefAllowed argument of getConstantRange() required
For the two remaining uses that did not explicitly specify it,
set UndefAllowed=false. In both cases, I believe that treating
undef as a full range is the correct behavior.
2023-12-12 11:43:52 +01:00