8657 Commits

Author SHA1 Message Date
Pierre van Houtryve
aa9f8596b0
[AMDGPU] Add flag to prevent reruns of LowerModuleLDS (#129520)
FullLTO has to run this early before module splitting occurs otherwise
module splitting won't work as expected. There was a targeted fix for
fortran on another branch that disables the LTO run but that'd break
full LTO module splitting entirely.

Test changes are due to metadata indexes shifting.

See #122891
2025-05-15 09:54:21 +02:00
Shoreshen
a1664e5015
[AMDGPU] Remove verification failing cases due to bundle (#139868)
This is a fix up PR for https://github.com/llvm/llvm-project/pull/136112

There are test cases failing machine instruction verifier due to bundle
(see this
issue:https://github.com/llvm/llvm-project/issues/139102#issuecomment-2863620759)
2025-05-14 19:00:12 +08:00
Pierre van Houtryve
4e63e0457c
[AMDGPU] Canonicalize G_ZEXT of the shift amount in RegBankCombiner (#131792)
Canonicalize it to a G_AND instead so that ISel patterns can pick it
up and ignore it, as the shift instructions only read low bits.
G_ZEXT would be lowered to a v/s_and anyway in most cases.

I'm also looking at making a DAG version of this in a separate patch.
2025-05-14 10:48:51 +02:00
Frederik Harwath
1377535d99
[AMDGPU] si-peephole-sdwa: Fix cndmask vcc use for wave32 (#139541)
Before V_CNDMASK_B32_e64 gets converted to SDWA form, a conversion to
V_CNDMASK_B32_e32 occurs.
The vcc use of this instruction must be fixed into a vcc_lo use for wave32.
This fix only happens after the final conversion to the SDWA form. This led
to a compiler error in situations where the conversion to SDWA aborts.

Make sure that the vcc-fix gets applied even if the SDWA conversion is
not completed.

---------

Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2025-05-14 07:37:01 +02:00
Shoreshen
c5331276cb
AMDGPU: Add sgpr bit convert tests (#136112)
Add inreg test for sgpr purpose

This is the second PR after
https://github.com/llvm/llvm-project/pull/135729.

To test sgpr inputs and outputs, using inreg cases for bit-conversions

---------

Co-authored-by: Matt Arsenault <Matthew.Arsenault@amd.com>
2025-05-14 09:55:37 +08:00
Lucas Ramirez
6456ee056f
Reapply "[AMDGPU][Scheduler] Refactor ArchVGPR rematerialization during scheduling (#125885)" (#139548)
This reapplies 067caaa and 382a085 (reverting b35f6e2) with fixes to
issues detected by the address sanitizer (MIs have to be removed from
live intervals before being removed from their parent MBB).

Original commit description below.

AMDGPU scheduler's `PreRARematStage` attempts to increase function
occupancy w.r.t. ArchVGPR usage by rematerializing trivial
ArchVGPR-defining instruction next to their single use. It first
collects all eligible trivially rematerializable instructions in the
function, then sinks them one-by-one while recomputing occupancy in all
affected regions each time to determine if and when it has managed to
increase overall occupancy. If it does, changes are committed to the
scheduler's state; otherwise modifications to the IR are reverted and
the scheduling stage gives up.

In both cases, this scheduling stage currently involves repeated queries
for up-to-date occupancy estimates and some state copying to enable
reversal of sinking decisions when occupancy is revealed not to
increase. The current implementation also does not accurately track
register pressure changes in all regions affected by sinking decisions.

This commit refactors this scheduling stage, improving RP tracking and
splitting the stage into two distinct steps to avoid repeated occupancy
queries and IR/state rollbacks.

- Analysis and collection (`canIncreaseOccupancyOrReduceSpill`). The
number of ArchVGPRs to save to reduce spilling or increase function
occupancy by 1 (when there is no spilling) is computed. Then,
instructions eligible for rematerialization are collected, stopping as
soon as enough have been identified to be able to achieve our goal
(according to slightly optimistic heuristics). If there aren't enough of
such instructions, the scheduling stage stops here.
- Rematerialization (`rematerialize`). Instructions collected in the
first step are rematerialized one-by-one. Now we are able to directly
update the scheduler's state since we have already done the occupancy
analysis and know we won't have to rollback any state. Register
pressures for impacted regions are recomputed only once, as opposed to
at every sinking decision.

In the case where the stage attempted to increase occupancy, and if both
rematerializations alone and rescheduling after were unable to improve
occupancy, then all rematerializations are rollbacked.
2025-05-13 11:11:00 +02:00
Brox Chen
89f8267340
[AMDGPU][True16][CodeGen] update more GFX11Plus codegen test with true16 mode (#138600)
This is a NFC patch.

This patch duplicate GFX11plus runlines and apply them with
"+mattr=+real-true16" and "+mattr=-real-true16" on more gfx11/gfx12
tests. And then update the test with the update script
2025-05-12 12:19:46 -04:00
Simon Pilgrim
f1043b1643 [AMDGPU] combine_vloads.ll regenerate test checks
Make it easier to detect regressions
2025-05-12 12:33:53 +01:00
Simon Pilgrim
4e535601b0 [AMDGPU] ashr.v2i16.ll - regenerate to match shl/lshr v2i16 test coverage 2025-05-12 10:35:12 +01: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
Vitaly Buka
b35f6e26a5
Revert "[AMDGPU][Scheduler] Refactor ArchVGPR rematerialization during scheduling (#125885)" (#139341)
And related "[AMDGPU] Regenerate mfma-loop.ll test"

Introduce memory error detected by Asan #125885.

This reverts commit 382a085a95b0abeac77b150b7b644b372bd08e78.
This reverts commit 067caaafb58a156d0d77229422607782a639f5b5.
2025-05-09 17:51:46 -07:00
Matt Arsenault
cccb4fc4b8
AMDGPU: Test more types with minimumnum and maximumnum (#139242)
We had custom lowering for the wider vectors of f16, but missing
test coverage for them. Also add more vector tests for bf16, and
split the bf16 cases into separate files so we can add globalisel
run lines.
2025-05-09 20:29:14 +02:00
Emma Pilkington
7babf22461
[StructurizeCFG] Stop setting DebugLocs in flow blocks (#139088)
Flow blocks are generated code that don't really correspond to any
location in the source, so principally they should have empty DebugLocs.
Practically, setting these debug locs leads to redundant is_stmts being
generated after #108251, causing stepping test failures in the ROCm GDB
test suite.

Fixes SWDEV-502134
2025-05-09 14:22:14 -04:00
Matt Arsenault
790ce0ec94
AMDGPU: Add minimumnum/maximumnum to list of canonicalizing opcodes (#139124)
This makes no difference in the test, as these always expand now.
2025-05-09 18:36:12 +02:00
Matt Arsenault
e4751d5cbc
AMDGPU: Add minimumnum/maximumnum tests with amdgpu-ieee=0 (#139145)
With the IEEE bit disabled, the hardware instructions have the
same behavior as these operations.
2025-05-09 08:17:49 +02:00
Matt Arsenault
6cf84e036e
AMDGPU: Test more subtargets in minimumnum/maximumnum tests (#139144) 2025-05-09 08:15:09 +02:00
Matt Arsenault
f13ff77842
AMDGPU: Form min3/max3 from minimumnum/maximumnum (#139137) 2025-05-09 08:12:54 +02:00
Matt Arsenault
458e2416ca
AMDGPU: Add baseline tests for min3/max3 from minimumnum/maximumnum (#139136) 2025-05-09 08:10:06 +02:00
Matt Arsenault
912df60b08
AMDGPU: Handle minimumnum/maximumnum in fneg combines (#139133) 2025-05-09 08:07:01 +02:00
Matt Arsenault
07f36f21e9
AMDGPU: Add baseline tests for fneg with min/max intrinsics (#139132)
Copy the minnum and maxnum tests into versions with minimum/maximum
and minimumnum/maximumnum.
2025-05-09 08:04:09 +02:00
Stanislav Mekhanoshin
d2c5fbe9ea
[AMDGPU] Legalize vector fminimum and fmaximum with VOP3P (#138971)
Co-authored-by: Matt Arsenault <Matthew.Arsenault@amd.com>
2025-05-08 22:31:27 -07:00
Brox Chen
13b2f7c785
[AMDGPU][True16][CodeGen] add fake16 to gisel test (#138588)
This is a NFC patch.

Add '-mattr=-real-true16' to gfx11/gfx12 test. 

GISEL is not fully supported in true16 mode yet. However we might want
to turn on true16 mode for SDAG as default first. This patch is
preparing for this mode shift in the short future so we can have a small
patch to turn it on
2025-05-08 17:37:08 -04:00
Chinmay Deshpande
3a5af231fd
[GlobalISel][AMDGPU] Fix handling of v2i128 type for AND, OR, XOR (#138574)
Current behavior crashes the compiler.

This bug was found using the AMDGPU Fuzzing project.

Fixes SWDEV-508816.
2025-05-08 19:31:28 +02:00
Brox Chen
9d907a2bb1
AMDGPU][True16][CodeGen] FP_Round f64 to f16 in true16 (#128911)
Update the f64 to f16 lowering for targets which support f16 types. 

For unsafe mode, lowered to two FP_ROUND. (This patch
https://reviews.llvm.org/D154528 stops from combining these two FP_ROUND
back). In safe mode, select LowerF64ToF16 (round-to-nearest-even
rounding mode)
2025-05-08 13:30:09 -04:00
pvanhout
e9df48e8a4 Revert "(reland) [GlobalISel] Diagnose inline assembly constraint lowering errors (#139049)"
This reverts commit 534d221b63bb52f64e1f3ad3c40cfb87323d28ec.
2025-05-08 15:03:42 +02:00
pvanhout
382a085a95 [AMDGPU] Regenerate mfma-loop.ll test
#125885 did not update the test.
2025-05-08 14:46:20 +02:00
Pierre van Houtryve
534d221b63
(reland) [GlobalISel] Diagnose inline assembly constraint lowering errors (#139049)
The initial patch (#135782 caused issues because it emits an error, and llc is sensitive to it.
It also caused compiler-rt/lib/scudo/standalone/tests/wrappers_cpp_test.cpp to fail.

Use warnings instead + reject lowering. That way, the fallback path is used without llc/clang returning a failure code.
If fallback isn't enabled then the warnings provide context as to why lowering failed.

Original commit description for #135782:

Instead of printing something to dbgs (which is not visible to all users),
emit a diagnostic like the DAG does. We still crash later because we fail to
select the inline assembly, but at least now users will know why it's crashing.

In a future patch we could also recover from the error like the DAG does, so the
lowering can keep going until it either crashes or gives a different error later.
2025-05-08 13:22:57 +02:00
Lucas Ramirez
067caaafb5
[AMDGPU][Scheduler] Refactor ArchVGPR rematerialization during scheduling (#125885)
AMDGPU scheduler's `PreRARematStage` attempts to increase function
occupancy w.r.t. ArchVGPR usage by rematerializing trivial
ArchVGPR-defining instruction next to their single use. It first
collects all eligible trivially rematerializable instructions in the
function, then sinks them one-by-one while recomputing occupancy in all
affected regions each time to determine if and when it has managed to
increase overall occupancy. If it does, changes are committed to the
scheduler's state; otherwise modifications to the IR are reverted and
the scheduling stage gives up.

In both cases, this scheduling stage currently involves repeated queries
for up-to-date occupancy estimates and some state copying to enable
reversal of sinking decisions when occupancy is revealed not to
increase. The current implementation also does not accurately track
register pressure changes in all regions affected by sinking decisions.

This commit refactors this scheduling stage, improving RP tracking and
splitting the stage into two distinct steps to avoid repeated occupancy
queries and IR/state rollbacks.

- Analysis and collection (`canIncreaseOccupancyOrReduceSpill`). The
number of ArchVGPRs to save to reduce spilling or increase function
occupancy by 1 (when there is no spilling) is computed. Then,
instructions eligible for rematerialization are collected, stopping as
soon as enough have been identified to be able to achieve our goal
(according to slightly optimistic heuristics). If there aren't enough of
such instructions, the scheduling stage stops here.
- Rematerialization (`rematerialize`). Instructions collected in the
first step are rematerialized one-by-one. Now we are able to directly
update the scheduler's state since we have already done the occupancy
analysis and know we won't have to rollback any state. Register
pressures for impacted regions are recomputed only once, as opposed to
at every sinking decision.

In the case where the stage attempted to increase occupancy, and if both
rematerializations alone and rescheduling after were unable to improve
occupancy, then all rematerializations are rollbacked.
2025-05-08 12:51:06 +02:00
Iris Shi
f9783c559f
[InstCombine] Fix frexp(frexp(x)) -> frexp(x) fold (#138837)
Fixes #138819

When frexp is applied twice, the second result should be zero.
2025-05-08 00:37:46 +08:00
Brox Chen
09d01be856
[AMDGPU][True16][CodeGen] replace subreg_to_reg to req_sequence (#138746)
Since subreg_to_reg is considered broken in llvm, replace subreg_to_reg
to reg_sequence
2025-05-07 10:28:10 -04:00
pvanhout
0db040576d Revert "[GlobalISel] Diagnose inline assembly constraint lowering errors (#135782)"
This reverts commit c22081c320340d0e7542b247ee093ca515509b52.
2025-05-07 14:50:45 +02:00
Pierre van Houtryve
c22081c320
[GlobalISel] Diagnose inline assembly constraint lowering errors (#135782)
Instead of printing something to dbgs (which is not visible to all users),
emit a diagnostic like the DAG does. We still crash later because we fail to
select the inline assembly, but at least now users will know why it's crashing.

In a future patch we could also recover from the error like the DAG does, so the
lowering can keep going until it either crashes or gives a different error later.
2025-05-07 14:13:25 +02:00
Pierre van Houtryve
c3a638caab
[GlobalISel] Fix silently dropped MIFlags on selected instructions (#138851)
We used uint16 for flags but flags now go up to 24 bits, so all flags in bits 16-24 were lost.

Fixes #110801
2025-05-07 14:07:16 +02:00
Pierre van Houtryve
0d0eed419f
[AMDGPU][Legalizer] Widen i16 G_SEXT_INREG (#131308)
It's better to widen them to avoid it being lowered into a G_ASHR + G_SHL. With this change we just extend to i32 then trunc the result.
2025-05-07 10:22:15 +02:00
Jeffrey Byrnes
7fa721ac6c
[AMDGPU] Extend test coverage for cross RC register coalescing (#138617)
[[Change-Id:
I36894fc36e6e6214930fae67f2ca35999abf3b88](https://github.com/llvm/llvm-project/pull/132137)
](https://github.com/llvm/llvm-project/pull/132137) landed, but was
breaking bots. In the rebase, I accidentally brought in unintended
changes. I have reverted the commit
8b9ae65d51
and fixed the rebase.

This PR is to land the original patch / extension to the test.

---------

Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2025-05-06 18:07:30 -07:00
Matthias Braun
675cb70641
Register assembly printer passes (#138348)
Register assembly printer passes in the pass registry.

This makes it possible to use `llc -start-before=<target>-asm-printer ...` in tests.

Adds a `char &ID` parameter to the AssemblyPrinter constructor to allow
targets to use the `INITIALIZE_PASS` macros and register the pass in the
pass registry. This currently has a default parameter so it won't break
any targets that have not been updated.
2025-05-06 18:01:17 -07:00
Chinmay Deshpande
c7659d88ac
[NFC][GlobalISel] Pre-commit GISel AMDGPU tests for XOR, OR, AND (#138586) 2025-05-06 12:59:15 -07:00
Manuel Carrasco
6479e9bad3
[AMDGPU] Fix UB in tests due to mismatched calling conventions (#137957)
Fixes UB in tests due to mismatched CC (definition and callsite).
2025-05-06 18:31:27 +02:00
Brox Chen
cd6c4b6103
[AMDGPU][True16][CodeGen] optimize codegen for mad-mix in true16 (#124995)
remove unnecessary COPY for SDAG for mad-mix pattern
2025-05-05 23:08:03 -04:00
Jeffrey Byrnes
8b9ae65d51 Revert "[AMDGPU] Extend test coverage for cross RC register coalescing (#132137)"
This reverts commit 0bd065dc943ff65e0749a9f2a7b7a672acd45193.
2025-05-05 16:33:18 -07:00
Jeffrey Byrnes
0bd065dc94
[AMDGPU] Extend test coverage for cross RC register coalescing (#132137)
Add some test cases for subregister to subregister copies. Also add
cases where the register class is not required by the instruction.
2025-05-05 16:20:41 -07:00
Jeffrey Byrnes
00e7a02295
[ScheduleDAG] Allow disabling the SchedModel / Itineraries during Scheduling (#138057)
This provides the `disable-schedmodel-in-sched-mi` flag. Using this, we
will disable the SchedModel / Itineraries during scheduling. This has
the effect of not using any latency / hardware resource information for
scheduling decisions.

We have the `schedmodel` flag, but this disables the `SchedModel` for
all passes. This allows disabling only for scheduling while preserving
the behavior of other passes (e.g. MachineLICM). This is conceptually
similar to other flags like `enable-aa-sched-mi`
2025-05-05 14:07:23 -07:00
Brox Chen
d4706e17f5
[AMDGPU][True16][CodeGen] readfirstlane for vgpr16 copy to sgpr32 (#118037)
i16 can be selected into sgpr32 or vgpr16 in isel lowering in true16
mode. And thus, it creates cases that we copy from vgpr16 to sgpr32 in
ext selection and this seems inevitable without sgpr16 support.

legalize the src/dst reg when we decide to lower this special copy to a
readfirstlane in fix-sgpr-copy pass and add a lit test
2025-05-05 15:17:34 -04:00
Ryan Buchner
4fb7d1953d
[AMDGPU] Remove implicit definition of register group when restoring the last sub-register after a spill (#133986)
Extension of https://reviews.llvm.org/D141101 to remove the define flag
from the last stack memory access. Fixes case where COPY instructions
are used for some of the stack restoration, but the copies get optimized
away during the machine-cp pass.

Prior to this change, was possible to produce the following code:
$agpr16_agpr17_agpr18_agpr19 = SCRATCH_LOAD_DWORDX4_ST 64, 0, implicit
$exec, implicit $flat_scr, implicit-def
$agpr16_agpr17_agpr18_agpr19_agpr20_agpr21_agpr22_agpr23_agpr24_agpr25_agpr26_agpr27_agpr28_agpr29_agpr30_agpr31
:: (load (s128) from %stack.17, align 4, addrspace 5)
$agpr20_agpr21_agpr22_agpr23 = SCRATCH_LOAD_DWORDX4_ST 80, 0, implicit
$exec, implicit $flat_scr :: (load (s128) from %stack.17 + 16, align 4,
addrspace 5)
$agpr24_agpr25_agpr26_agpr27 = SCRATCH_LOAD_DWORDX4_ST 96, 0, implicit
$exec, implicit $flat_scr :: (load (s128) from %stack.17 + 32, align 4,
addrspace 5)
$agpr31 = COPY $agpr112, implicit
$agpr16_agpr17_agpr18_agpr19_agpr20_agpr21_agpr22_agpr23_agpr24_agpr25_agpr26_agpr27_agpr28_agpr29_agpr30_agpr31
$agpr30 = COPY $agpr208, implicit
$agpr16_agpr17_agpr18_agpr19_agpr20_agpr21_agpr22_agpr23_agpr24_agpr25_agpr26_agpr27_agpr28_agpr29_agpr30_agpr31
$agpr28_agpr29 = SCRATCH_LOAD_DWORDX2_ST 112, 0, implicit $exec,
implicit $flat_scr, implicit-def
$agpr16_agpr17_agpr18_agpr19_agpr20_agpr21_agpr22_agpr23_agpr24_agpr25_agpr26_agpr27_agpr28_agpr29_agpr30_agpr31
:: (load (s64) from %stack.17 + 48, align 4, addrspace 5)

where `$agpr30 = COPY $agpr208` would be optimized away by `machine-cp`
pass. Instead, change to:
$agpr28_agpr29 = SCRATCH_LOAD_DWORDX2_ST 112, 0, implicit $exec,
implicit $flat_scr :: (load (s64) from %stack.17 + 48, align 4,
addrspace 5)

Fixes #131386.

Made the simple fix, but I'm not completely comfortable with this change
since the reason for the previous inclusion of `IsLastSubReg` is unclear
to me.

@krzysz00
2025-05-05 20:17:36 +02:00
Brox Chen
71ee3366fa
[AMDGPU][True16][CodeGen] clean up a few codegen test for true16 mode (#138542)
This is a NFC patch.

Clean up three test for true16 mode:
1. remove strayed test line
2. remove t16 test line from fake16 mir test
3. update check-label to shrink test size
2025-05-05 13:17:31 -04:00
Frederik Harwath
721cba476d
[AMDGPU] SIPeepholeSDWA: Handle V_CNDMASK_B32_e64 (#137930)
The VOP3 form of the V_CNDMASK_B32 instruction takes a carry-in
operand. The conversion to SDWA implies a conversion to VOP2 form
which reads from VCC instead.

Convert V_CNDMASK_B32_e64 instructions that might be converted to SDWA
to V_CNDMASK_B32_e32 first and introduce a copy of the carry-in operand
to VCC.

Closes #133431.

---------

Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2025-05-05 18:14:14 +02:00
Akhilesh Moorthy
9c9013f703
[AMDGPU] Handle MachineOperandType global address in SIFoldOperands. (#135424)
This patch handles the global operand type properly, fixing the
bug : Assertion `(isFI() || isCPI() || isTargetIndex() ||
isJTI()) && "Wrong MachineOperand accessor"` failed.

Fixes SWDEV-504645

---------

Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2025-05-05 18:12:35 +02:00
Diana Picus
45d96df797
[AMDGPU] Support arbitrary types in amdgcn.dead (#134841)
Legalize the amdgcn.dead intrinsic to work with types other than i32. It
still generates IMPLICIT_DEFs.

Remove some of the previous code for selecting/reg bank mapping it for
32-bit types, since everything is done in the legalizer now.
2025-05-05 14:08:00 +02:00
Baoshan
883afa4ef9
[AMDGPU] remove move instruction if there is no user of it (#136735)
Co-authored-by: Baoshan Pang <bpang@fortinet.com>
2025-05-03 08:23:52 +02:00
Jay Foad
9060ca0191
[AMDGPU] Check for nonnull loads feeding addrspacecast (#138184)
Handle nonnull loads just like nonnull arguments when checking for
addrspacecasts that are known never null.
2025-05-02 12:54:22 +01:00