9262 Commits

Author SHA1 Message Date
LU-JOHN
3e10bdd18e
[NFC][AMDGPU] Pre-commit test for setcc removal by using add/sub carryout (#155118)
Pre-commit test for setcc removal by using add/sub carryout.

---------

Signed-off-by: John Lu <John.Lu@amd.com>
2025-09-04 09:27:11 -05:00
Pierre van Houtryve
e2bd10cf16
[AMDGPU][gfx1250] Add 128B cooperative atomics (#156418)
- Add clang built-ins + sema/codegen
- Add IR Intrinsic + verifier
- Add DAG/GlobalISel codegen for the intrinsics
- Add lowering in SIMemoryLegalizer using a MMO flag.
2025-09-04 09:19:25 +00:00
Diana Picus
018dc1b397
[AMDGPU] Tail call support for whole wave functions (#145860)
Support tail calls to whole wave functions (trivial) and from whole wave
functions (slightly more involved because we need a new pseudo for the
tail call return, that patches up the EXEC mask).

Move the expansion of whole wave function return pseudos (regular and
tail call returns) to prolog epilog insertion, since that's where we
patch up the EXEC mask.
2025-09-04 10:34:43 +02:00
Matt Arsenault
76cb5fcfb6
AMDGPU: Define agpr versions of ds permute instructions (#156695)
Correctly model these without AV_* operands. This is another
step towards removing the special casing in
TargetInstrInfo::getRegClass. Also add some tests for this.
2025-09-04 15:13:59 +09:00
Matt Arsenault
c34cdd75fc
AMDGPU: Add tests for every mfma intrinsic v-to-a mapping (#153026)
Make sure the MFMA VGPR to AGPR InstrMapping table is complete.
I think I got everything, except the full cross product of input
types with the mfma scale intrinsics. Also makes sure we have
coverage for smfmac and mfma_scale cases.
2025-09-04 11:24:54 +09:00
Matt Arsenault
dc170c7e31 AMDGPU: Special case align requirement for AV_MOV_B64_IMM_PSEUDO
This should not require aligned registers. Fixes expensive_checks
test failure. I don't see a better way until the new system
to specify the alignment per register is done.
2025-09-04 09:55:39 +09:00
Matt Arsenault
1959e12e7d
AMDGPU: Add agpr variants of multi-data DS instructions (#156420)
The instruction definitions for loads and stores do not
accurately model the operand constraints of loads and stores
with AGPRs. They use AV register classes, plus a hack
a hack in getRegClass/getOpRegClass to avoid using AGPRs or
AV classes with the multiple operand cases, but it did not
consider the 3 operand case.

Model this correctly by using separate all-VGPR and all-AGPR
variants for the cases with multiple data operands.

This does regress the assembler errors on gfx908 for the
multi-operand cases. It now reports a generic operand
invalid error for GPU instead of the specific message
that agpr loads and stores aren't supported.

In the future AMDGPURewriteAGPRCopyMFMA should be taught
to replace the VGPR forms with the AGPR ones.

Most of the diff is fighting the DS pseudo structure. The
mnemonic was being used as the key to SIMCInstr, which is a
collision in the AGPR case. We also need to go out of our way
to make sure we are using the gfx9+ variants of the pseudos
without the m0 use. The DS multiclasses could use a lot of
cleanup.

Fixes #155777
2025-09-04 09:13:36 +09:00
Stanislav Mekhanoshin
6aebbb0a85
[AMDGPU] Define 1024 VGPRs on gfx1250 (#156765)
This is a baseline support, it is not useable yet.
2025-09-03 16:25:18 -07:00
Jay Foad
7b96cd7f59
[AMDGPU] Use "v_bfi_b32 x, y, -1" to implement (y | ~x) (#156653) 2025-09-03 20:04:01 +01:00
Changpeng Fang
7753f61f61
[AMDGPU] Support cluster_load_async_to_lds instructions on gfx1250 (#156595) 2025-09-03 11:22:10 -07:00
Jay Foad
fee17b3a96
[AMDGPU] Remove most uses of /dev/null in tests (#156630)
Using options like -filetype=null instead should allow tools to save
some work by not generating any output.
2025-09-03 16:39:29 +01:00
Frederik Harwath
47793f9a73
[AMDGPU] Implement IR expansion for frem instruction (#130988)
This patch implements a correctly rounded expansion of the frem
instruction in LLVM IR. This is useful for target architectures for
which such an expansion is too involved to be implement in ISel
Lowering. The expansion is based on the code from the AMD device libs
and has been tested successfully against the OpenCL conformance tests on
amdgpu. The expansion is implemented in the preexisting "expand-fp"
pass. It replaces the expansion of "frem" in ISel for the amdgpu target;
it is enabled for targets which do not directly support "frem" and for
which no matching "fmod" LibCall is available.

---------

Co-authored-by: Matt Arsenault <Matthew.Arsenault@amd.com>
2025-09-03 16:27:15 +02:00
Jay Foad
d4de780969
[AMDGPU] Use "v_bfi_b32 x, 0, z" to implement (z & ~x) (#156636) 2025-09-03 11:00:03 +00:00
Vikash Gupta
49ffe31def
[AMDGPU][LIT][NFC] Adding -mtriple for AMDGPUAnnotateUniformValues Pass tests (#156437)
It specifies the target machine as AMDGPU for
AMDGPUAnnotateUniformValues pass-related test (that uses UA). Before in
its absense, the UA would consider everything Uniform resulting in
setting metadata incorrectly for AMDGPU. Now, after specifying the
AMDGPU, the UA would be rightful sets the right metadata as the test
gets commpiled for AMDGPU.
2025-09-03 15:32:28 +05:30
Nikita Popov
cd7f7cf5cc Reapply [IR] Remove options to make scalable TypeSize access a warning (#156336)
Reapplying now that buildbot has picked up the new configuration
that does not use -treat-scalable-fixed-error-as-warning.

-----

This removes the `LLVM_ENABLE_STRICT_FIXED_SIZE_VECTORS` cmake option
and the `-treat-scalable-fixed-error-as-warning` opt flag.

We stopped treating these as warnings by default a long time ago
(62f09d788f9fc540db12f3cfa2f98760071fca96), so I don't think it makes
sense to retain these options at this point. Accessing a scalable
TypeSize as fixed should always result in an error.
2025-09-03 11:12:11 +02:00
Matt Arsenault
da8f692e3e
AMDGPU: Handle V->A MFMA copy from case with immediate src2 (#153023)
Handle a special case for copies from AGPR VGPR on the MFMA inputs.
If the "input" is really a subregister def, we will not see the
usual copy to VGPR for src2, only the read of the subregister def.
Not sure if this pattern appears in practice.
2025-09-03 16:21:46 +09:00
Matt Arsenault
3294cddb98
AMDGPU: Add test for mfma rewrite pass respecting optnone (#153025) 2025-09-03 06:07:44 +00:00
Matt Arsenault
d373ec7f16
AMDGPU: Add baseline test for unspilling VGPRs after MFMA rewrite (#154322)
Test for #154260
2025-09-03 14:13:35 +09:00
Matt Arsenault
085471d777
AMDGPU: Handle rewriting VGPR MFMA fed from AGPR copy (#153022)
Previously we handled the inverse situation only.
2025-09-03 14:12:45 +09:00
Matt Arsenault
c5d766236d
AMDGPU: Add tests for ds_write2 formation with agprs (#155765)
The current handling for write2 formation is overly conservative
and cannot form write2s with AGPR inputs.
2025-09-03 01:27:18 +00:00
Matt Arsenault
4ec890857d
AMDGPU: Try to constrain av registers to VGPR to enable ds_write2 formation (#156400)
In future changes we will have more AV_ virtual registers, which
currently
block the formation of write2. Most of the time these registers can
simply
be constrained to VGPR, so do that.

Also relaxes the constraint in flat merging case. We already have the
necessary
code to insert copies to the original result registers, so there's no
point
in avoiding it.

Addresses the easy half of #155769
2025-09-03 00:48:21 +00:00
Matt Arsenault
dd5eb46690
AMDGPU: Fold 64-bit immediate into copy to AV class (#155615)
This is in preparation for patches which will intoduce more
copies to av registers.
2025-09-03 09:29:59 +09:00
Matt Arsenault
3a7d14acce
AMDGPU: Avoid using exact class check in reg_sequence AGPR fold (#156135)
This does better in cases which mix align2 and non-align2 classes.
2025-09-03 09:05:48 +09:00
Changpeng Fang
d3d1d8ff21
[AMDGPU] Support cluster load instructions for gfx1250 (#156548) 2025-09-02 16:34:20 -07:00
Matt Arsenault
bb54be5853
AMDGPU: Fix DPP combiner using isOperandLegal on incomplete inst (#155595)
It is not safe to use isOperandLegal on an instruction that does
not have a complete set of operands. Unforunately the APIs are
not set up in a convenient way to speculatively check if an instruction
will be legal in a hypothetical instruction. Build all the operands
and then verify they are legal after. This is clumsy, we should have
a more direct check for will these operands give a legal instruction.

This seems to fix a missed optimization in the gfx11 test. The
fold was firing for gfx1150, but not gfx1100. Both should support
vop3 literals so I'm not sure why it wasn't working before.
2025-09-03 01:19:01 +09:00
Matt Arsenault
96e4caadb4
AMDGPU: Stop special casing aligned VGPR targets in operand folding (#155559)
Perform a register class constraint check when performing the fold
2025-09-02 16:15:25 +00:00
Matt Arsenault
1ff6bfe7a5
AMDGPU: Add VS_64_Align2 class (#156132)
We need an aligned version of the VS class to properly
represent operand constraints.

This fixes regressions with #155559
2025-09-02 23:24:07 +09:00
Ana Mihajlovic
c4885849ad
[AMDGPU] Fix hw stage metadata setting for unsigned values (#154502) 2025-09-02 10:42:11 +02:00
Nikita Popov
95e76c14da Revert "[IR] Remove options to make scalable TypeSize access a warning (#156336)"
This reverts commit 8f59a946740bf8dbe2574b33eaa431fde3ce9204.

Failed on clang-aarch64-sve-vls-2stage, which still uses the option.
2025-09-02 09:52:37 +02:00
Pierre van Houtryve
d6edc1a96f
[AMDGPU] Reenable BackOffBarrier on GFX11/12 (#155370)
Re-enable it by adding a wait on vm_vsrc before every barrier "start"
instruction in GFX10/11/12 CU mode.

This is a less strong wait than what we do without BackOffBarrier, thus
this shouldn't introduce
any new guarantees that can be abused, instead it relaxes the guarantees
we have now to the bare
minimum needed to support the behavior users want (fence release +
barrier works).

There is an exact memory model in the works which will be documented
separately.
2025-09-02 09:37:43 +02:00
Nikita Popov
8f59a94674
[IR] Remove options to make scalable TypeSize access a warning (#156336)
This removes the `LLVM_ENABLE_STRICT_FIXED_SIZE_VECTORS` cmake option
and the `-treat-scalable-fixed-error-as-warning` opt flag.

We stopped treating these as warnings by default a long time ago
(62f09d788f9fc540db12f3cfa2f98760071fca96), so I don't think it makes
sense to retain these options at this point. Accessing a scalable
TypeSize as fixed should always result in an error.
2025-09-02 09:10:45 +02:00
Matt Arsenault
0849dc11d9
AMDGPU: Switch merge-load-store-agpr test to generated checks (#156387)
Also had to fix missing --- separators between functions
2025-09-02 03:09:45 +00:00
Pierre van Houtryve
9ad8e12c57
[AMDGPU] Expand scratch atomics to flat atomics if GAS is enabled (#154710) 2025-09-01 10:17:38 +02:00
Nikita Popov
055bfc0271
[InstCombine] Strip leading zero indices from GEP (#155415)
GEPs are often in the form `gep [N x %T], ptr %p, i64 0, i64 %idx`.
Canonicalize these to `gep %T, ptr %p, i64 %idx`.

This enables transforms that only support one GEP index to work and
improves CSE.

Various transforms were recently hardened to make sure they still work
without the leading index.
2025-09-01 09:58:11 +02:00
Krzysztof Drewniak
9470113495
[AMDGPU] Mark workitem IDs uniform in more cases (#152581)
This fixes an old FIXME, where (workitem ID X) / (wavefrront size) would
never be marked uniform if it was possible that there would be Y and Z
dimensions. Now, so long as the required size of the X dimension is a
power of 2, dividing that dimension by the wavefront size creates a
uniform value.

Furthermore, if the required launch size of the X dimension is a power
of 2 that's at least the wavefront size, the Y and Z workitem IDs are
now marked uniform.

---------

Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2025-08-29 01:21:04 -05:00
paperchalice
19464d951a
[NFC] #155740 post cleanup (#155966)
Remove all "approx-func-fp-math" in tests.
2025-08-29 12:45:38 +08:00
Vigneshwar Jayakumar
df96e09c1e
[StructurizeCFG] nested-if zerocost hoist bugfix (#155408)
When zero cost instructions are hoisted, the simplifyHoistedPhi function
was setting incoming phi values which were not dominating the use
causing runtime failure. This was set to poison by rebuildSSA function.
This commit fixes the issue.
2025-08-28 09:04:14 -05:00
Nicolai Hähnle
353b5e43c6
AMDGPU: Refactor lowering of s_barrier to split barriers (#154648)
Let's do the lowering of non-split into split barriers in a new IR pass,
AMDGPULowerIntrinsics. That way, there is no code duplication between
SelectionDAG and GlobalISel. This simplifies some upcoming extensions to
the code.
2025-08-28 07:01:20 -07:00
Matt Arsenault
736c9c6374
AMDGPU: Add tests for atomics with AGPR operands (#155820)
The handling of AGPR vs. VGPR operand restrictions is
broken and results in bugs like #155777 and missed optimizations.
Add some baseline tests for future improvements.
2025-08-28 22:21:07 +09:00
Pierre van Houtryve
75c8985876
[AMDGPU] Precommit memory legalizer tests for private AS (#154709) 2025-08-28 09:58:20 +02:00
paperchalice
595573d1ed
[AMDGPU] Remove ApproxFuncFPMath uses (#155578)
One of options in `resetTargetOptions`, this removes `ApproxFuncFPMath`
in AMDGPU part.
2025-08-28 11:09:01 +08:00
Nicolai Hähnle
a0af7b8fc3
AMDGPU: llvm.amdgcn.inverse.ballot needs to be convergent (#155725)
It is only defined for uniform inputs (instruction selection inserts
v_readfirstlane as necessary).
2025-08-27 19:40:27 -07:00
vigneshwar jayakumar
60c06632bf [StructurizeCFG] Add nested_if tests
Added nested-if tests for hoisitng zero cost instructions in
StructurizeCFG pass. This is a patch with precommited tests for
https://github.com/llvm/llvm-project/pull/155408
2025-08-27 17:22:07 -05:00
Yoonseo Choi
6a8c20549e
[AMDGPU] Avoid bundling a SCHED_BARRIER with memops (#153533)
Avoid bundling a SCHED_BARRIER with memops. Memops are still can be
bundled and a SCHED_BARRIER ends the bundle. (e.g. [load, load, ...
SCHED_BARRIER(exclusive from the bundle) ), This is to honor the
SCHED_BARRIERs maximally without intervention of bundling.

If a SCHED_BARRIER is placed in a bundle between memops, the
SCHED_BARRIER is not used during IGroupLPMutation in postra mi-sched
phase. In addition, bundling memory ops with in-between SCHED_BARRIER
can prevent that SCHED_BARRIER or any neighboring SCHED_BARRIER being
honored. As users already provided SCHED_BARRIER between memory ops,
don't bundle it together with memory ops. Bypassing any bundling in a
MBB with a SCHED_BARRIER removes all those problems occur.
2025-08-27 17:09:27 -05: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
Chris Jackson
7d0203b39f
[AMDGPU] Prevent generation of unused SGPR IMPLICIT_DEF assignments (#155241)
Dead VGPR->SGPR copies were converted to IMPLICIT_DEF assignments that
were unused. Prevent these from being created and update the numerous
affected tests.
2025-08-27 13:18:18 +01:00
Matt Arsenault
9091108c66
AMDGPU: Fold mov imm to copy to av_32 class (#155428)
Previously we had special case folding into copies to AGPR_32,
ignoring AV_32. Try folding into the pseudos.

Not sure why the true16 case regressed.
2025-08-27 02:13:14 +00:00
Shoreshen
7fff93db50
[AMDGPU] Set GRANULATED_WAVEFRONT_SGPR_COUNT of compute_pgm_rsrc1 to 0 for gfx10+ (#154666)
According to `llvm-project/llvm/docs/AMDGPUUsage.rst::L5212` the
`GRANULATED_WAVEFRONT_SGPR_COUNT`, which is `compute_pgm_rsrc1[6:9]` has
to be 0 for gfx10+ arch

---------

Co-authored-by: Matt Arsenault <Matthew.Arsenault@amd.com>
2025-08-27 09:48:42 +08:00
Matt Arsenault
71ce079248
Reapply "[AMDGPU] gfx1250 trans instructions bf16 codegen tests update. NFC (#155310)" (#155515) 2025-08-27 09:13:34 +09:00
Miguel Saldivar
0a8acd2eb2
[DAG] ComputeNumSignBits - ISD::EXTRACT_ELEMENT needs to return at least 1 (#155455)
When going through the ISD::EXTRACT_ELEMENT case, `KnownSign - rIndex *
BitWidth`
could produce a negative. When a negative is produced, the lower bound
of the `std::clamp` is returned. Change that lower bound to one to avoid
potential underflows, because the expectation is that
`ComputeNumSignBits`
should always return at least 1.

Fixes #155452.
2025-08-26 14:28:02 -07:00