10011 Commits

Author SHA1 Message Date
Nikita Popov
5933294bb1
[AMDGPULowerLDS] Avoid unnecessary ptrtoint/inttoptr roundtrip (#181671)
Store pointers instead of integers in the table, and load them as
pointers.
2026-02-17 09:28:01 +01:00
Mariusz Sikora
2b4a462e95
[AMDGPU] Add missing comma between export target and first export data (#181641)
The new format matches the official ISA spec and ensures the
disassembler prints 'export mrt0, v0, off, off, off' instead of 'export
mrt0 v0, off, off, off'.

No functional encoding changes; printing/AsmString only.
2026-02-17 09:24:34 +01:00
Matt Arsenault
86f167b9df
AMDGPU: Use promotion to f32 path for log/log10 for f16 by default (#180240) 2026-02-16 20:25:45 +01:00
Nikita Popov
3765b09d20 [AMDGPU] Regenerate test checks (NFC) 2026-02-16 15:02:59 +01:00
Aayush Sabharwal
6ce9e363e0
[GISel] handle CTTZ in computeKnownBits (#181474)
Addresses part of #150515. Adapted from the CTLZ code below this
2026-02-15 15:43:05 -08:00
Nikita Popov
c4721872af Revert "[Clang][inlineasm] Add special support for "rm" output constraints (#92040)"
This change landed without approval.

This reverts commit 45e666a8531c1148bdb170b9a120f99e1500c427.
This reverts commit a636dd4c37f12594275de2fe180ca35bc04d76ea.
2026-02-14 15:59:04 +01:00
Bill Wendling
45e666a853
[Clang][inlineasm] Add special support for "rm" output constraints (#92040)
Clang isn't able to support multiple constraints on inputs and outputs,
like "rm". Instead, it picks the "safest" one to use, i.e. the memory
constraint for "rm". This leads to obviously horrible code:

  asm __volatile__ ("pushf\n\t"
                    "popq %0"
                    : "=rm" (x));

is compiled to:

        pushf
	popq -8(%rsp)
	movq	-8(%rsp), %rax

It gets worse when inlined into other functions, because it may
introduce
a stack where none is needed.

With this change, Clang now generates IR for the more optimistic choice
("r"). All but the fast register allocator are able to fold registers if
it turns out that register pressure is too high.

This leaves the fast register allocator. The fast register allocator, as
the name suggests, is built for execution speed, not code quality. Thus,
we add special processing to convert the "optimistic" IR into the
"conservative" choice (again at the IR level), which we know it can
handle.

We focus on "rm" for the initial commit, but that can be expanded in the
future for other constraints where Clang generates ++ungood code (like
"g").

Fixes: https://github.com/llvm/llvm-project/issues/20571
2026-02-14 05:02:24 -08:00
Felipe Quezada
9deb4fda30
[CodeGen][AMDGPU] TwoAddress: Only skip undef COPY at REG_SEQUENCE lowering when there is Live info or no uses for subreg (#175598)
Currently, the compiler doesn't create a COPY for undef operands while
lowering REG_SEQUENCE, and only if LIS information is available, it
propagates the undef flag to the subreg uses. So, if LIS isn't
available, we can end up with some uses without def of those lanes.
Now, we check which lanes are used in a single scan of
use_nodbg_operands() per REG_SEQ, and perform the skip of the COPY only
if LIS is avaible (as undef will be propagated later) or if there are no
uses for that lane.
There is still a scan of the use list, but now it's only one per REG_SEQ
and I think it's necessary, as there is no guarantee to have LIS or
other analysis pass information at this stage.

This is a proposal fix for issue:
https://github.com/llvm/llvm-project/issues/175596

---------

Co-authored-by: Carl Ritson <critson@perlfu.co.uk>
2026-02-13 08:46:30 -08:00
Stanislav Mekhanoshin
7487c7581e
[AMDGPU] Change 9 SWMMAC builtins to use 64-bit index (#181246)
There 9 gfx1250 instructions have 64-bit packed index:

- v_swmmac_f16_16x16x128_bf8_bf8
- v_swmmac_f16_16x16x128_bf8_fp8
- v_swmmac_f16_16x16x128_fp8_bf8
- v_swmmac_f16_16x16x128_fp8_fp8
- v_swmmac_f32_16x16x128_bf8_bf8
- v_swmmac_f32_16x16x128_bf8_fp8
- v_swmmac_f32_16x16x128_fp8_bf8
- v_swmmac_f32_16x16x128_fp8_fp8
- v_swmmac_i32_16x16x128_iu8

Intrinsics accept anyint, but builtins are defined with i32 argument.

Fixes: SWDEV-579843
2026-02-12 15:31:50 -08:00
vangthao95
a00278632d
AMDGPU/GlobalISel: Regbanklegalize rules for buffer load lds intrinsics (#180998) 2026-02-12 14:04:58 -08:00
Lucas Ramirez
efab96c6e9
[AMDGPU] Add missing assert requirement to unit test (#181102)
`-debug-only` is only available when asserts are enabled. The test
currently fails on builds without asserts.
2026-02-12 08:53:26 +00:00
Lucas Ramirez
7cc7a94128
[AMDGPU][Scheduler] Fix inconsistent MI slots after rematerialization revert (#180646)
This fixes an issue in the scheduler's rematerialization stage wherein
slot indices could end up being inconsistent with respect to MI order
following a scheduling revert coupled with rematerialization rollbacks.

When a region's schedule is reverted, instructions are re-ordered into
the region's original instruction order. Furthermore, non-debug
instructions have their slot moved if necessary to maintain consistency
between MI and slot order. Importantly, the rematerialization stage
marks rematerialized MIs as debug during re-scheduling. When reverting
the schedule of regions that have had some of their MIs rematerialized,
the latter are still marked debug, and therefore maintain their
pre-re-scheduling slot even if it no longer is consistent with MI order.

This fixes the issue by restoring the original state of rematerialized
MIs before reverting region schedules, ensuring they are moved if
necessary. An EXPENSIVE_CHECK is added to check that slot order
makes sense with respect to MI order in re-scheduled regions.

Fixes SWDEV-579187.
2026-02-12 01:42:04 +01:00
Syadus Sefat
0a966ff4e2
[AMDGPU][NFC] Fix test by removing debug flag in llvm.amdgcn.raw.buffer.atomic.integer-minmax.ll (#181044)
This patch is a NFC that removes debug flag from the test
llvm.amdgcn.raw.buffer.atomic.integer-minmax.ll
2026-02-11 18:04:31 -06:00
zGoldthorpe
26add8a272
[AMDGPU][ISel] setcc peephole for comparisons with upper 32 bits of a 64-bit register pair (#177662)
This optimisation is motivated by [this minimal
example](https://godbolt.org/z/9o83GvGsM).

Particularly, if `mask` is a 64-bit integer, a select
```cpp
auto out = ((mask >> 32) != 0) ? a : b;
```
converts the null-check on the higher 32-bits of `mask` into a
`v_cmp_lt_u64` with the integer `1 << 32` stored in a pair of VGPRs
(effectively wasting two VGPRs).

More generally, if a 64-bit integer (whose lower 32 bits are known to be
irrelevant) is compared with a 64-bit constant, two VGPRs are wasted to
construct this constant.

This patch modifies ISel to take advantage of how 64-bit values are
stored in pairs of VGPRs (or SGPRs), and truncates the 64-bit constant
to its upper 32-bit constant where possible.

Alive2 proof for analogous middle-end transformation:
https://alive2.llvm.org/ce/z/zizKms
2026-02-11 13:41:03 -07:00
Syadus Sefat
65f3329a55
[AMDGPU][GlobalIsel] Add register bank legalization rules for buffer atomic int min max (#180975)
This patch adds register bank legalization rules for buffer atomic int
min max operations in the AMDGPU GlobalISel pipeline.
2026-02-11 13:24:08 -06:00
Jay Foad
1d18539a7b
[AMDGPU] Treat F64 TRANS instructions as VALU for S_DELAY_ALU insertion (#180940)
This matches the hardware behavior.
2026-02-11 19:14:54 +00:00
vangthao95
90a56a18ee
AMDGPU/GlobalISel: RegBankLegalize for global atomic ordered add (#180829) 2026-02-11 09:30:11 -08:00
vangthao95
0286641f5c
[AMDGPU] Add known bits for G_AMDGPU_COPY_SCC_VCC (#180560) 2026-02-11 09:06:28 -08:00
Nikita Popov
a8f211904a
[ExpandIRInsts] Support saturating fptoi (#179710)
Add support for expanding fptosi.sat and fptoui.sat via IR expansions.
Similar to fptosi/fptoui we would get legalization errors otherwise.

The previous expansion for fptosi/fptoui was already saturating -- but
those instructions do not actually require saturation, and the
implementation of the saturation was incorrect in lots of ways. What
this PR does is:

* For fptosi, remove the unnecessary saturation handling.
* For fptoui, remove the unnecessary saturation handling and sign
multiplication.
* For fptosi, use the previous saturation handling with fixes: We need
to map NaNs to 0 and the saturation condition on the exponent was
incorrect. (I'm performing the NaN check via fcmp -- there's no
requirement to do everything bitwise here.)
* For fptoui use a variation of the signed saturation handling: Negative
values need to go to zero and we saturate to unsigned max.

Proofs: https://alive2.llvm.org/ce/z/Xv9FNd
2026-02-11 14:51:30 +01:00
Sameer Sahasrabuddhe
128437fb6a
[AMDGPU] Introduce asyncmark/wait intrinsics (#180467)
Asynchronous operations are memory transfers (usually between the global
memory and LDS) that are completed independently at an unspecified
scope. A thread that requests one or more asynchronous transfers can use
async marks to track their completion. The thread waits for each mark to
be completed, which indicates that requests initiated in program order
before this mark have also completed.

For now, we implement asyncmark/wait operations on pre-GFX12
architectures that support "LDS DMA" operations. Future work will extend
support to GFX12Plus architectures that support "true" async operations.

This is part of a stack split out from #173259
- #180467
- #180466

Co-authored-by: Ryan Mitchell ryan.mitchell@amd.com

Fixes: SWDEV-521121
2026-02-11 07:15:51 +00:00
Sameer Sahasrabuddhe
b02b395a1e
[AMDGPU] Asynchronous loads from global/buffer to LDS on pre-GFX12 (#180466)
The existing "LDS DMA" builtins/intrinsics copy data from global/buffer
pointer to LDS. These are now augmented with their ".async" version,
where the compiler does not automatically track completion. The
completion is now tracked using explicit mark/wait intrinsics, which
must be inserted by the user. This makes it possible to write programs
with efficient waits in software pipeline loops. The program can now
wait for only the oldest outstanding operations to finish, while
launching more operations for later use.

This change only contains the new names of the builtins/intrinsics,
which continue to behave exactly like their non-async counterparts. A
later change will implement the actual mark/wait semantics in
SIInsertWaitcnts.

This is part of a stack split out from #173259:
- #180467
- #180466

Fixes: SWDEV-521121
2026-02-11 05:26:58 +00:00
Abhinav Garg
16bfc02f4a
[AMDGPU] [GlobalIsel] Enabling lit tests for new regbank select (#180680)
This patch will enable few more lit tests that depends on G_FRAME_INDEX
opcode.
2026-02-11 07:52:47 +05:30
Alexander Weinrauch
979132a02d
[AMDGPU] Fix LDS address correction in promoteConstantOffsetToImm for async stores (#180220)
`updateAsyncLDSAddress`, introduces by
https://github.com/llvm/llvm-project/pull/176816, previously only
handled async loads , where the LDS address is in the `vdst` operand.
Therefore Async stores produced a nullptr dereference since the LDS
address is in `vdata` for those instructions.

---------

Co-authored-by: Jay Foad <jay.foad@gmail.com>
2026-02-10 13:53:51 -08:00
Alexander Weinrauch
1e086d06e9
[DAGCombiner] Fix crash in reassociationCanBreakAddressingModePattern for multi-memop nodes (#180268)
Two code paths in `reassociationCanBreakAddressingModePattern` were
missing a `hasUniqueMemOperand()` guard before calling
`getAddressSpace()`. Note that on `L1214` we already have the same guard
in place.

`getAddressSpace()` chains through `getPointerInfo()` to
`getMemOperand()`, which asserts that the node has exactly one memory
operand.
2026-02-10 13:53:36 -08:00
vangthao95
d354ea6add
AMDGPU/GlobalISel: RegBankLegalize rules for buffer atomic cmpswap (#180666) 2026-02-10 11:11:38 -08:00
Mirko Brkušanin
4280f0d241
[AMDGPU] Add dot4 fp8/bf8 instructions for gfx1170 (#180516) 2026-02-10 12:14:49 +01:00
Anshil Gandhi
bd6dd94584
[AMDGPU] Add legalization rules for atomicrmw max/min ops (#180502)
Adds rules for G_ATOMICRMW_{MAX, MIN, UMAX, UMIN, UINC_WRAP, UDEC_WRAP}.
Each of these generic opcode are supported for S32 and S64 types
on flat, global and local address spaces.
2026-02-10 16:04:05 +05:30
Matt Arsenault
302ff8fd00
InstCombine: Use SimplifyDemandedFPClass on fmul (#177490)
Start trying to use SimplifyDemandedFPClass on instructions, starting
with fmul. This subsumes the old transform on multiply of 0. The
main change is the introduction of nnan/ninf. I do not think anywhere
was systematically trying to introduce fast math flags before, though
a few odd transforms would set them.

Previously we only called SimplifyDemandedFPClass on function returns
with nofpclass annotations. Start following the pattern of
SimplifyDemandedBits, where this will be called from relevant root
instructions.

I was wondering if this should go into InstCombineAggressive, but that
apparently does not make use of InstCombineInternal's worklist.
2026-02-10 09:49:31 +00:00
Diana Picus
24405f070f
[AMDGPU] Add intrinsic exposing s_alloc_vgpr (#163951)
Make it possible to use `s_alloc_vgpr` at the IR level. This is a huge
footgun and use for anything other than compiler internal purposes is
heavily discouraged. The calling code must make sure that it does not
allocate fewer VGPRs than necessary - the intrinsic is NOT a request to
the backend to limit the number of VGPRs it uses (in essence it's not so
different from what we do with the dynamic VGPR flags of the
`amdgcn.cs.chain` intrinsic, it just makes it possible to use this
functionality in other scenarios).
2026-02-10 09:28:31 +01:00
vangthao95
8d8864237b
AMDGPU/GlobalISel: Regbanklegalize rules for G_FSQRT (#179817)
Add S16 rules for G_FSQRT. S32 and S64 are expanded by the legalizer.
2026-02-09 18:24:28 -08:00
Gheorghe-Teodor Bercea
d1dc843c18
[AMDGPU] Enable sinking of free vector ops that will be folded into their uses (#162580)
Sinking ShuffleVectors / ExtractElement / InsertElement into user blocks
can help enable SDAG combines by providing visibility to the values
instead of emitting CopyTo/FromRegs. The sink IR pass disables sinking
into loops, so this PR extends the CodeGenPrepare target hook
shouldSinkOperands.

Co-authored-by: Jeffrey Byrnes <Jeffrey.Byrnes@amd.com>

---------

Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2026-02-09 14:14:31 -05:00
vangthao95
404f9e6c99
AMDGPU/GlobalISel: RegBankLegalize rules for amdgcn_sffbh (#180099)
Change test to use update_llc_test_checks.py and make `v_flbit` test
actually divergent.
2026-02-09 09:18:03 -08:00
vangthao95
0040bdf532
AMDGPU/GlobalISel: Regbanklegalize rules for buffer atomic swap (#180265) 2026-02-09 09:04:17 -08:00
Anshil Gandhi
ab2e10d80f
[AMDGPU] Add legalization rules for G_ATOMICRMW_FADD (#175257)
G_ATOMICRMW_FADD is supported on flat, global and local address spaces
for S32, S64 and V2S16 values.
2026-02-09 15:37:27 +00:00
Shilei Tian
65b4099219
[AMDGPU] Fix instruction size for 64-bit literal constant operands (#180387)
`getLit64Encoding` uses a different approach to determine whether 64-bit
literal encoding is used, which caused a size mismatch between the
`MachineInstr` and the `MCInst`.

For `!isValid32BitLiteral`, it is effectively `!(isInt<32>(Val) ||
isUInt<32>(Val))`, which is `!isInt<32>(Val) && !isUInt<32>(Val)`, but
in `getLit64Encoding`, it is `!isInt<32>(Val) || !isUInt<32>(Val)`.
2026-02-09 14:31:52 +00:00
Shilei Tian
392f0c9767
[NFC][AMDGPU] Add a test to show the impact of wrong s_mov_b64 instruction size (#180386) 2026-02-09 08:56:28 -05:00
Mirko Brkušanin
45b037cf7a
[AMDGPU] Add fp8/bf8 conversion instructions for gfx1170 (#180191) 2026-02-09 13:56:43 +01:00
Petr Kurapov
27a8ab09fa
[AMDGPU] Fix V_INDIRECT_REG_READ_GPR_IDX expansion with immediate index (#179699)
The definition for V_INDIRECT_REG_READ_GPR_IDX_B32_V*'s SSrc_b32 operand
allows immediates, but the expansion logic handles only register cases
now. This can result in expansion failures when e.g.
llvm.amdgcn.wave.reduce.umin.i32 is folded into a constant and then used
as an insertelement idx.
2026-02-09 11:33:30 +01:00
Matt Arsenault
2ffb54364f
AMDGPU: Add a test for libcall simplify pow handling (#180491)
This case could be turned into powr or pown, so track which
case ends up preferred.
2026-02-09 10:01:26 +00:00
Pierre van Houtryve
b79ba02479
[AMDGPU][GFX12.5] Reimplement monitor load as an atomic operation (#177343)
Load monitor operations make more sense as atomic operations, as
non-atomic operations cannot be used for inter-thread communication w/o
additional synchronization.
The previous built-in made it work because one could just override the
CPol bits, but that bypasses the memory model and forces the user to learn
about ISA bits encoding.

Making load monitor an atomic operation has a couple of advantages.
First, the memory model foundation for it is stronger. We just lean on the
existing rules for atomic operations. Second, the CPol bits are abstracted away
from the user, which avoids leaking ISA details into the API.

This patch also adds supporting memory model and intrinsics
documentation to AMDGPUUsage.

Solves SWDEV-516398.
2026-02-09 09:57:27 +01:00
Matt Arsenault
8554ed738f
AMDGPU: Add syntax for s_wait_event values (#180272)
Previously this would just print hex values. Print names for the
recognized values, matching the sp3 syntax.
2026-02-09 08:29:55 +00:00
Matt Arsenault
0c583e784e
AMDGPU: Add llvm.amdgcn.s.wait.event intrinsic (#180170)
Exactly match the s_wait_event instruction. For some reason we already
had this instruction used through llvm.amdgcn.s.wait.event.export.ready,
but that hardcodes a specific value. This should really be a bitmask
that
can combine multiple wait types.

gfx11 -> gfx12 broke compatabilty in a weird way, by inverting the
interpretation of the bit but also shifting the used bit by 1. Simplify
the selection of the old intrinsic by just using the magic number 2,
which should satisfy both cases.
2026-02-09 08:45:13 +01:00
paperchalice
c53acf0443
[SelectionDAGBuilder] Remove NoNaNsFPMath uses (#169904)
Replaced by checking fast-math flags or value tracking results.
2026-02-09 09:48:07 +08:00
paperchalice
5c5677d7b8
[llvm] Remove "no-infs-fp-math" attribute support (#180083)
One of global options in `TargetMachine::resetTargetOptions`, now all
backends no longer support it, remove it.
2026-02-09 08:43:33 +08:00
Alex Wang
a947599991
[AMDGPU][GlobalISel] Add lowering for G_FMODF (#180152)
Add generic expansion for G_FMODF matching the SelectionDAG
implementation.

Enable G_FMODF lowering for AMDGPU with tests.

Related: #179434
2026-02-07 18:43:55 +00:00
Jay Foad
269fda118a
[AMDGPU] Fix pattern selecting fmul to v_fma_mix_f32 (#180210)
This needs to use an addend of -0.0 to get the correct result when the
result should be -0.0.
2026-02-07 09:31:07 +00:00
Iasonaskrpr
6c6fb00c94
[AMDGPU] Optimize S_OR_B32 to S_ADDK_I32 where possible (#177949)
This PR fixes #177753, converting disjoint S_OR_B32 to S_ADDK_I32
whenever possible, it avoids this transformation in case S_OR_B32 can be
converted to bitset.

Note on Test Failures (Draft Status) This change causes significant
register reshuffling across the test suite due to the new allocation
hints and the swaps performed in case src0 is not a register and src1,
along with the change from or to addk. To avoid a massive, noisy diff
during the initial logic review:

This Draft PR only includes a representative sample of updated tests.
CodeGen/AMDGPU/combine-reg-or-const.ll -> Showcases change from S_OR to
S_ADDK
CodeGen/AMDGPU/s-barrier.ll -> Showcases swap between Src0 and Src1 if
src0 is not a register

The rest of the tests show the result of the register allocation hint we
give, I have checked every test I updated and they seem ok to me.

Once the core logic is approved, I will run the update script across the
remaining ~70 failing tests and mark the PR as "Ready for Review."
2026-02-07 09:10:12 +00:00
vangthao95
e67bfe85d9
[AMDGPU][GlobalISel] Fix D16 buffer load RegBankLegalize rules (#179982)
Use fast StandardB rule and add uniform rules and uniform tests.
2026-02-06 08:01:30 -08:00
Frederik Harwath
272d6dd445
[AMDGPU] Support v_lshl_add_u64 with non-constant shift amount (#179904)
This commit also adds GlobalISel testing to llvm/test/CodeGen/AMDGPU/lshl-add-u64.ll.
2026-02-06 16:03:58 +01:00
Jay Foad
4a6697f393
[AMDGPU] Fix and simplify patterns selecting fsub to v_fma_mix_f32 (#180169)
Select (fsub x, y) -> (fma y, -1.0, x). Using -1.0 as the constant
avoids the need for ComplexPatterns to negate x or y.

This also fixes the bad pattern (fsub x, y) -> (fma -x, 1.0, y).
2026-02-06 14:39:13 +00:00