122 Commits

Author SHA1 Message Date
Domenic Nutile
5b33f85a08
[AMDGPU] Change isSingleLaneExecution to account for WWM enabling lanes even if there's only one workitem (#188316)
This issue was discovered during some downstream work around Vulkan CTS
tests, specifically
`dEQP-VK.subgroups.arithmetic.compute.subgroupadd_float`

---------

Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2026-04-06 12:51:46 -04:00
Yoonseo Choi
0ab9053327
[AMDGPU] Cgscc amdgpu attributor boilerplate NFC (#179719)
This PR is adding a boilerplate of CGSCC AMDGPUAttributor pass
(amdgpu-attributor-cgscc) by doing refactoring from the existing Module
AMDGPUAttributor pass (amdgpu-attributor).

CGSCC AMDGPUAttributor pass sets `AttributorConfig.IsModulePass =
false`, and make Attributor's `Functions` set contain only functions in
a SCC.
The main implementations of abstract attributes have not changed - NFC. 

Subsequently, in future work some of the AMDGPU abstract attributors
might move to be handled by CGSCC pass.

---------

Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2026-03-09 15:14:03 -04:00
Shilei Tian
f05d2e8a39
[AMDGPU] Make uniform-work-group-size a valueless attribute (#183925)
The "uniform-work-group-size" function attribute previously took a
string value of "true" or "false". Since presence alone can convey the
"true" semantics and absence can convey "false", the value is
unnecessary.

This patch converts it to a valueless string attribute: presence
indicates true, absence indicates false. For backward compatibility,
auto-upgrade logic is added in both UpgradeAttributes (bitcode) and
UpgradeFunctionAttributes: if the old value is "true", the attribute is
kept without a value; if "false", the attribute is removed.
2026-03-01 21:29:55 +00:00
Matt Arsenault
8b41ad4430
AMDGPU: Stop adding uniform-work-group-size=false (#183502)
This is one of the string attributes that takes a boolean
value for no reason. There is no point in ever writing this
with an explicit false. Stop adding the noise and reporting
an unnecessary change.
2026-02-26 14:53:20 +00:00
Juan Manuel Martinez Caamaño
4fef5e4b4c
[NFC][AMDGPU] Remove unused getLDSSize (#181133)
`getLDSSize` becomes unused after removing `getWavesPerEU` from the
attributor in https://github.com/llvm/llvm-project/pull/181131
2026-02-12 13:13:50 +00:00
Juan Manuel Martinez Caamaño
0c70489533
[NFC][AMDGPU] Remove unused/unimplemented getWavesPerEU variants (#181131) 2026-02-12 14:07:35 +01:00
Akash Dutta
7803b4a6dd
AMDGPU: Add support for llvm.trap to handling of intrinsics with !nocallback (#175230)
This adds support to whitelist trap intrinsics while handling of
intrinsics with !nocallback. This fixes the reasons behind the previous
revert of #131759.

The attributor was exiting early whenever it saw intrinsics without the nocallback bit, so trap-only kernels lost all the inferred “no implicit arg” metadata and their amdgpu-agpr-alloc=0 guarantees. That conservative fallback broke certain workloads by forcing unnecessary implicit arguments and AGPR reservations. This patch allows the pass to recognize leaf-like trap intrinsics, so they no longer poison the analysis.

---------

Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2026-01-30 08:26:40 -06:00
Akash Dutta
fc10fbb71e
Reapply "AMDGPU: Do not infer implicit inputs for !nocallback intrinsics" (#176081)
This reverts #174224 and re-applies #131759 .

Note: If #117544 is reverted, this should also be reverted.
2026-01-15 09:08:27 -06:00
theRonShark
dff081c26f
Revert "AMDGPU: Do not infer implicit inputs for !nocallback intrinsics" (#174224)
Reverts llvm/llvm-project#131759

seeing regressions in : Pytorch UT- 8 test cases failed in "test_ops"
test suite
2026-01-06 09:13:28 -05:00
Shilei Tian
6cfc8bfd0b [NFC][AMDGPU][Attributor] Remove unused code 2025-12-28 23:16:04 -05:00
Shoreshen
e442904e70
[AMDGPU] Apply alignment attr for make.buffer.rsrc (#166914)
Calculating alignment for `make.buffer.rsrc` intrinsic. The logic is the
alignment on use of return value of `make.buffer.rsrc` should be capped
by the base operand's alignment of `make.buffer.rsrc`.

For example:
```ll
define float @foo(ptr addrspace(1) align X %ptr) {
  %fat.ptr = call ptr addrspace(7) @llvm.amdgcn.make.buffer.rsrc.p7.p1(ptr addrspace(1) %ptr, i16 0, i32 C, i32 0)
  %y = load float, ptr addrspace(7) %fat.ptr, align Y
  ret float %y
}
```

We hopes that `Y = min(X, Y)`

---

After discussion, it seems improper for letting `Y = min(X, Y)` since it
contradict with the semantic of align on load.

So we would apply the origin behavior of align, which is letting `X` and
`Y` both equal to `max(X, Y)`

---------

Co-authored-by: Shilei Tian <i@tianshilei.me>
2025-12-08 12:48:54 +08:00
Matt Arsenault
849038cad1
AMDGPU: Do not infer implicit inputs for !nocallback intrinsics
(#131759)

This isn't really the right check, we want to know that the intrinsic
does not perform a true function call to any code (in the module or
not). nocallback
appears to be the closest thing to this property we have now though.
Fixes theoretically
miscompiles with intrinsics like statepoint, which hide a call to a real
function.

Also do the same for inferring no-agpr usage.
2025-11-05 04:53:42 +00:00
Kazu Hirata
902b0bd04a
[llvm] Remove "const" in the presence of "constexpr" (NFC) (#166109)
"const" is extraneous in the presence of "constexpr" for simple
variables and arrays.
2025-11-02 15:52:44 -08:00
Matt Arsenault
01ac00b6d7
AMDGPU: Render non-0 values for amdgpu-agpr-alloc
(#162300)

This now tries to compute a lower bound on the number of registers
for individual inline asm uses. Also starts using AACallEdges
to handling indirect calls.
2025-10-08 16:27:37 +00:00
Matt Arsenault
96e0bbc1df
AMDGPU: Fix parsing wrong operand format for read_register/write_register (#162414)
Apparently the IR verifier doesn't enforce the correct structure.
Also I do not know why we have this extra level of wrapper in the
intrinsic,
it just makes it harder to get at the string. I also do not know why
kokkos is using these intrinsics, but it shouldn't.
2025-10-08 03:13:41 +00:00
Matt Arsenault
cb53a2de37
AMDGPU: Account for read/write register intrinsics for AGPR usage (#161988)
Fix the special case intrinsics that can directly reference a physical
register. There's no reason to use this.
2025-10-08 02:09:22 +00:00
Matt Arsenault
3af95f016e
AMDGPU: Figure out required AGPR count for inline asm (#150910)
For now just try to compute the minimum number of AGPRs required
to allocate the asm. Leave the attributor changes to turn this
into an integer value for later.
2025-10-08 10:31:10 +09:00
Matt Arsenault
051fa18cb4
AMDGPU: Stop inferring amdgpu-agpr-alloc on irrelevant targets (#161957)
This only matters for subtargets with configurable AGPR allocation.
2025-10-08 01:25:50 +09:00
Matt Arsenault
679d2b2ab6
AMDGPU: Fix using IRAttribute with nounwind for AMDGPUNoAGPR (#161954)
Don't think this did anything harmful, but it doesn't make sense
to report this as implementing nounwind handling.
2025-10-04 23:45:16 +09:00
Chaitanya
2d67cb1a1f
[AMDGPU][Attributor] Stop inferring amdgpu-no-flat-scratch-init in sanitized functions. (#161319)
This PR stops the attributor pass to infer `amdgpu-no-flat-scratch-init`
for functions marked with `sanitize_*` attribute.
2025-10-03 21:16:57 +05:30
Shilei Tian
27b242fbff
[AMDGPU][Attributor] Add AAAMDGPUClusterDims (#158076) 2025-09-15 15:04:33 -04:00
Shilei Tian
ca03045d7f
[AMDGPU][Attributor] Remove final update of waves-per-eu after the attributor run (#155246)
We do not need this in the attributor, because `ST.getWavesPerEU`
accounts for both the waves-per-eu and flat-workgroup-size attributes.
If the waves-per-eu values are not valid, it drops them. In the
attributor, we only need to propagate the values without using
intermediate flat workgroup size values.

Fixes SWDEV-550257.
2025-08-27 14:11:03 -04:00
Shilei Tian
1f6e13a161 Revert "[AMDGPU][Attributor] Infer inreg attribute in AMDGPUAttributor (#146720)"
This reverts commit 84ab301554f8b8b16b94263a57b091b07e9204f2 because it breaks
several AMDGPU test bots.
2025-08-18 22:59:52 -04:00
Shilei Tian
84ab301554
[AMDGPU][Attributor] Infer inreg attribute in AMDGPUAttributor (#146720)
This patch introduces `AAAMDGPUUniformArgument` that can infer `inreg` function
argument attribute. The idea is, for a function argument, if the corresponding
call site arguments are always uniform, we can mark it as `inreg` thus pass it
via SGPR.

In addition, this AA is also able to propagate the inreg attribute if feasible.
2025-08-18 22:01:47 -04:00
Matt Arsenault
e19743bd6c
AMDGPU: Remove unused TargetPassConfig include from attributor (#150892) 2025-07-28 20:58:25 +09:00
Juan Manuel Martinez Caamaño
862b9ea805
[AMDGPU] Remove AAInstanceInfo from the AMDGPUAttributor (#150232)
Related to compile-time issue SWDEV-543240 and functional issue
SWDEV-544256
2025-07-24 17:12:04 +02:00
Kazu Hirata
7c83d66719
[llvm] Remove unused includes (NFC) (#148768)
These are identified by misc-include-cleaner.  I've filtered out those
that break builds.  Also, I'm staying away from llvm-config.h,
config.h, and Compiler.h, which likely cause platform- or
compiler-specific build failures.
2025-07-14 22:19:14 -07:00
Shoreshen
181b014c06
Attributor: Infer noalias.addrspace metadata for memory instructions (#136553)
Add noalias.addrspace metadata for store, load and atomic instruction in
AMDGPU backend.
2025-07-08 09:50:31 +08:00
Matt Arsenault
2dcf436340
AMDGPU: Remove legacy pass manager version of AMDGPUAttributor (#145262) 2025-06-23 16:49:46 +09:00
Kazu Hirata
92cebab210
[IPO] Teach AbstractAttribute::getName to return StringRef (NFC) (#141313)
This patch addresses clang-tidy's readability-const-return-type by
dropping const from the return type while switching to StringRef at
the same time because these functions just return string constants.
2025-05-23 23:58:49 -07:00
Kazu Hirata
d9a1f8a3a8 [AMDGPU] Fix a warning
This patch fixes:

  llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp:1139:17: error: unused
  variable 'Func' [-Werror,-Wunused-variable]
2025-05-17 00:27:11 -07:00
Shilei Tian
578741b5e8
[AMDGPU][Attributor] Rework update of AAAMDWavesPerEU (#123995)
Currently, we use `AAAMDWavesPerEU` to iteratively update values based
on attributes from the associated function, potentially propagating
user-annotated values, along with `AAAMDFlatWorkGroupSize`. Similarly,
we have `AAAMDFlatWorkGroupSize`. However, since the value calculated
through the flat workgroup size always dominates the user annotation
(i.e., the attribute), running `AAAMDWavesPerEU` iteratively is
unnecessary if no user-annotated value exists.

This PR completely rewrites how the `amdgpu-waves-per-eu` attribute is
handled in `AMDGPUAttributor`. The key changes are as follows:

- `AAAMDFlatWorkGroupSize` remains unchanged.
- `AAAMDWavesPerEU` now only propagates user-annotated values.
- A new function is added to check and update `amdgpu-waves-per-eu`
based on the following rules:
- No waves per eu, no flat workgroup size: Assume a flat workgroup size
of `1,1024` and compute waves per eu based on this.
- No waves per eu, flat workgroup size exists: Use the provided flat
workgroup size to compute waves-per-eu.
- Waves per eu exists, no flat workgroup size: This is a tricky case. In
this PR, we assume a flat workgroup size of `1,1024`, but this can be
adjusted if a different approach is preferred. Alternatively, we could
directly use the user-annotated value.
- Both waves per eu and flat workgroup size exist: If there’s a
conflict, the value derived from the flat workgroup size takes
precedence over waves per eu.

This PR also updates the logic for merging two waves per eu pairs. The
current implementation, which uses `clampStateAndIndicateChange` to
compute a union, might not be ideal. If we think from ensure proper
resource allocation perspective, for instance, if one pair specifies a
minimum of 2 waves per eu, and another specifies a minimum of 4, we
should guarantee that 4 waves per eu can be supported, as failing to do
so could result in excessive resource allocation per wave. A similar
principle applies to the upper bound. Thus, the PR uses the following
approach for merging two pairs, `lo_a,up_a` and `lo_b,up_b`: `max(lo_a,
lo_b), max(up_a, up_b)`. This ensures that resource allocation adheres
to the stricter constraints from both inputs.

Fix #123092.
2025-05-17 01:01:09 -04:00
Austin Kerbow
2c9a46cce3
[AMDGPU] Move kernarg preload logic to separate pass (#130434)
Moves kernarg preload logic to its own module pass. Cloned function
declarations are removed when preloading hidden arguments. The inreg
attribute is now added in this pass instead of AMDGPUAttributor. The
rest of the logic is copied from AMDGPULowerKernelArguments which now
only check whether an arguments is marked inreg to avoid replacing
direct uses of preloaded arguments. This change requires test updates to
remove inreg from lit tests with kernels that don't actually want
preloading.
2025-05-11 21:18:11 -07:00
Shilei Tian
d6dbe7799e
[AMDGPU][Attributor] Add ThinOrFullLTOPhase as an argument (#123994) 2025-05-02 11:33:56 -04:00
Lucas Ramirez
e377dc4d38
[AMDGPU] Max. WG size-induced occupancy limits max. waves/EU (#137807)
The default maximum waves/EU returned by the family of
`AMDGPUSubtarget::getWavesPerEU` is currently the maximum number of
waves/EU supported by the subtarget (only a valid occupancy range in
"amdgpu-waves-per-eu" may lower that maximum). This ignores maximum
achievable occupancy imposed by flat workgroup size and LDS usage,
resulting in situations where `AMDGPUSubtarget::getWavesPerEU` produces
a maximum higher than the one from
`AMDGPUSubtarget::getOccupancyWithWorkGroupSizes`.

This limits the waves/EU range's maximum to the maximum achievable
occupancy derived from flat workgroup sizes and LDS usage. This only has
an impact on functions which restrict flat workgroup size with
"amdgpu-flat-work-group-size", since the default range of flat workgroup
sizes achieves the maximum number of waves/EU supported by the
subtarget.

Improvements to the handling of "amdgpu-waves-per-eu" are left for a
follow up PR (e.g., I think the attribute should be able to lower the
full range of waves/EU produced by these methods).
2025-05-01 13:22:23 +02:00
Rahul Joshi
a3754ade63
[NFC][LLVM][AMDGPU] Cleanup pass initialization for AMDGPU (#134410)
- Remove calls to pass initialization from pass constructors.
- https://github.com/llvm/llvm-project/issues/111767
2025-04-07 17:27:50 -07:00
Matt Arsenault
428e3a27c3
AMDGPU: Fix attributor not handling all trap intrinsics (#131758) 2025-03-19 10:17:28 +07:00
Matt Arsenault
a216358ce7
AMDGPU: Replace amdgpu-no-agpr with amdgpu-agpr-alloc (#129893)
This performs the minimal replacment of amdgpu-no-agpr to
amdgpu-agpr-alloc=0. Most of the test diffs are due to the new
attribute sorting later alphabetically.

We could do better by trying to perform range merging in the attributor,
and trying to pick non-0 values.
2025-03-06 09:17:51 +07:00
Matt Arsenault
44201679c6
AMDGPU: Fix mishandling of search for constantexpr addrspacecasts (#120346) 2024-12-20 07:37:19 +07:00
Shilei Tian
f4037277bb
[AMDGPU][Attributor] Make AAAMDWavesPerEU honor existing attribute (#114438) 2024-12-11 16:50:06 -05:00
Shilei Tian
7dbd6cd294
[AMDGPU][Attributor] Make AAAMDFlatWorkGroupSize honor existing attribute (#114357)
If a function has `amdgpu-flat-work-group-size`, honor it in `initialize` by
taking its value directly; otherwise, it uses the default range as a starting
point. We will no longer manipulate the known range, which can cause issues
because the known range is a "throttle" to the assumed range such that the
assumed range can't get widened properly in `updateImpl` if the known range is
not set properly for whatever reasons. Another benefit of not touching the known
range is, if we indicate pessimistic state, it also invalidates the AA such that
`manifest` will not be called. Since we honor the attribute, we don't want and
will not add any half-baked attribute added to a function.
2024-12-11 16:47:51 -05:00
Shilei Tian
04269ea0e4
[AMDGPU] Re-enable closed-world assumption as an opt-in feature (#115371)
Although the ABI (if one exists) doesn’t explicitly prohibit
cross-code-object function calls—particularly since our loader can
handle them—such calls are not actually allowed in any of the officially
supported programming models. However, this limitation has some nuances.
For instance, the loader can handle cross-code-object global variables,
which complicates the situation further.

Given this complexity, assuming a closed-world model at link time isn’t
always safe. To address this, this PR introduces an option that enables
this assumption, providing end users the flexibility to enable it for
improved compiler optimizations. However, it is the user’s
responsibility to ensure they do not violate this assumption.
2024-12-10 15:57:41 -05:00
Jun Wang
41ed16c3b3
Reapply "[AMDGPU] Infer amdgpu-no-flat-scratch-init attribute in AMDGPUAttributor (#94647)" (#118907)
This reverts commit 1ef9410a96c1d9669a6feaf03fcab8d0a4a13bd5.

This fixes the test file attributor-flatscratchinit-globalisel.ll.
2024-12-09 16:44:48 -08:00
Matt Arsenault
664a226bf6
AMDGPU: Propagate amdgpu-max-num-workgroups attribute (#113018)
I'm not sure what the interpretation of 0 is supposed to be,
AMDGPUUsage doesn't say.
2024-12-09 09:57:27 -06:00
Philip Reames
1ef9410a96 Revert "[AMDGPU] Infer amdgpu-no-flat-scratch-init attribute in AMDGPUAttributor (#94647)"
This reverts commit e6aec2c12095cc7debd1a8004c8535eef41f4c36.  Commit breaks "ninja check-llvm" on x86 host.
2024-12-04 15:37:25 -08:00
Jun Wang
e6aec2c120
[AMDGPU] Infer amdgpu-no-flat-scratch-init attribute in AMDGPUAttributor (#94647)
The AMDGPUAnnotateKernelFeatures pass infers the "amdgpu-calls" and
"amdgpu-stack-objects" attributes, which are used to infer whether we
need to initialize flat scratch. This is, however, not precise. Instead,
we should use AMDGPUAttributor and infer amdgpu-no-flat-scratch-init on
kernels. Refer to https://github.com/llvm/llvm-project/issues/63586 .
2024-12-04 14:10:15 -08:00
Shilei Tian
9234ae1bbe [NFC] clang-format -i llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp 2024-10-31 11:44:15 -04:00
Shilei Tian
9a7519fdb3 Revert "[NFC][AMDGPU][Attributor] Exit earlier if entry CC (#114177)"
This reverts commit 922a0d3dfe2db7a2ef50e8cef4537fa94a7b95bb.
2024-10-30 00:53:43 -04:00
Shilei Tian
922a0d3dfe
[NFC][AMDGPU][Attributor] Exit earlier if entry CC (#114177)
Avoid calling TTI or other stuff unnecessarily
2024-10-30 00:42:44 -04:00
Shilei Tian
3de5dbb111
[AMDGPU][Attributor] Check the validity of a dependent AA before using its value (#114165)
Even though the Attributor framework will invalidate all its dependent
AAs after the current iteration, a dependent AA can still use the worst
state of a depending AA if it doesn't check the state of the depending
AA in current iteration.
2024-10-29 23:43:45 -04:00