1587 Commits

Author SHA1 Message Date
Changpeng Fang
5035d20dcb
AMDGPU: Implement ds_atomic_async_barrier_arrive_b64/ds_atomic_barrier_arrive_rtn_b64 (#146409)
These two instructions are supported by gfx1250. We define the
instructions and implement the corresponding intrinsic and builtin.

Co-authored-by: Stanislav Mekhanoshin <Stanislav.Mekhanoshin@amd.com>
2025-07-01 11:08:49 -07:00
Changpeng Fang
1f5f381920
AMDGPU: Implement intrinsic/builtins for gfx1250 load transpose instructions (#146289) 2025-06-29 14:33:31 -07:00
Fabian Ritter
215e61c088
[AMDGPU][SDAG] Add ISD::PTRADD DAG combines (#142739)
This patch focuses on generic DAG combines, plus an AMDGPU-target-specific one
that is closely connected.

The generic DAG combine is based on a part of PR #105669 by rgwott, which was
adapted from work by jrtc27, arichardson, davidchisnall in the CHERI/Morello
LLVM tree. I added some parts and removed several disjuncts from the
reassociation condition:
- `isNullConstant(X)`, since there are address spaces where 0 is a perfectly
  normal value that shouldn't be treated specially,
- `(YIsConstant && ZOneUse)` and `(N0OneUse && ZOneUse && !ZIsConstant)`, since
  they cause regressions in AMDGPU.

For SWDEV-516125.
2025-06-26 09:40:04 +02:00
Matt Arsenault
020fefb6af
AMDGPU: Avoid report_fatal_error in image intrinsic lowering (#145201) 2025-06-26 00:00:36 +09:00
Chinmay Deshpande
3413aa83f3
Revert "[AMDGPU] Implement IR variant of isFMAFasterThanFMulAndFAdd (… (#145580)
…#121465)"

This reverts commit 211bcf67aadb1175af382f55403ae759177281c7.
2025-06-24 16:10:27 -04:00
Matt Arsenault
48155f93dd
CodeGen: Emit error if getRegisterByName fails (#145194)
This avoids using report_fatal_error and standardizes the error
message in a subset of the error conditions.
2025-06-23 16:33:35 +09:00
Matt Arsenault
16607f6437
AMDGPU: Fix typo in argument allocation error message (#145265) 2025-06-23 16:26:10 +09:00
Aaditya
6a0593b0a3
[AMDGPU] Extend wave reduce intrinsics for i32 type (#126469)
Currently, wave reduction intrinsics are supported for `umin` and `umax`
operations for `i32` type only.
This patch extends support for the following operations: 
`add`, `sub`, `min`, `max`, `and`, `or`, `xor` for `i32` type.

---------

Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2025-06-23 10:31:22 +05:30
Matt Arsenault
ed155ff9f2
AMDGPU: Avoid report_fatal_error on ds ordered intrinsics (#145202) 2025-06-23 13:09:09 +09:00
Matt Arsenault
584a2c2e7c
AMDGPU: Avoid report_fatal_error for reporting libcalls (#145134) 2025-06-22 23:10:18 +09:00
Matt Arsenault
f280d3b705
AMDGPU: Avoid report_fatal_error for getRegisterByName subtarget case (#145173) 2025-06-22 08:19:19 +09:00
Jay Foad
6e86b7e34b
[AMDGPU] Do not replace SALU floating point multiply with VALU-only ldexp (#145048) 2025-06-20 16:52:43 +01:00
Matt Arsenault
dd4776d429
AMDGPU: Remove AMDGPUInstrInfo class (#144984)
This was never constructed and only provided one static helper
function.
2025-06-20 18:26:56 +09:00
Nicolai Hähnle
3bee9ba015
AMDGPU/GFX12: Fix s_barrier_signal_isfirst for single-wave workgroups (#143634)
Barrier instructions are no-ops in single-wave workgroups. This includes
s_barrier_signal_isfirst, which will leave SCC unmodified.

Model this correctly (via an implicit use of SCC) and ensure SCC==1
before the barrier instruction (if the wave is the only one of the
workgroup, then it is the first).

---------

Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2025-06-19 11:22:49 -07:00
Matt Arsenault
c80282d333
AMDGPU: Directly select minimumnum/maximumnum with ieee_mode=0 (#141903)
The hardware min/max follow the IR rules with IEEE mode disabled,
so we can avoid the canonicalizes of the input. We lose the quieting
of a signaling nan if both inputs are nans, but we only require that
with strictfp.
2025-06-18 00:27:41 +09:00
Matt Arsenault
b91936aeff
AMDGPU: Combine nnan fminimum/fmaximum to fminnum_ieee/fmaxnum_ieee (#142217)
This improves codegen for gfx950, where fminimum/fmaximum are
legal through fminimum3/fmaximum3, so may have an additional
encoding cost.
2025-06-17 21:55:57 +09:00
Fabian Ritter
8b11de7068
[AMDGPU][SDAG] Initial support for ISD::PTRADD (#141725)
Enable generation of PTRADD SelectionDAG nodes for pointer arithmetic for SI,
for now behind an internal CLI option. Also add basic patterns to match these
nodes. Optimizations will come in follow-up PRs. Basic tests for SDAG codegen
with PTRADD are in test/CodeGen/AMDGPU/ptradd-sdag.ll

Only affects 64-bit address spaces for now, since the immediate use case only
affects the flat address space.

For SWDEV-516125.
2025-06-13 15:59:58 +02:00
Changpeng Fang
70e78be7dc
AMDGPU: Custom lower fptrunc vectors for f32 -> f16 (#141883)
The latest asics support v_cvt_pk_f16_f32 instruction. However current
implementation of vector fptrunc lowering fully scalarizes the vectors,
and the scalar conversions may not always be combined to generate the
packed one.
We made v2f32 -> v2f16 legal in
https://github.com/llvm/llvm-project/pull/139956. This work is an
extension to handle wider vectors. Instead of fully scalarization, we
split the vector to packs (v2f32 -> v2f16) to ensure the packed
conversion can always been generated.
2025-06-06 15:15:24 -07:00
Stanislav Mekhanoshin
0c1c60fa63
[AMDGPU] Make <2 x bfloat> fabs legal (#142908) 2025-06-05 02:22:09 -07:00
Diana Picus
40a7dce9ef
[AMDGPU] Remove duplicated/confusing helpers. NFCI (#142598)
Move canGuaranteeTCO and mayTailCallThisCC into AMDGPUBaseInfo instead
of keeping two copies for DAG/Global ISel.

Also remove isKernelCC, which doesn't agree with isKernel and doesn't
seem very useful.

While at it, also move all the CC-related helpers into AMDGPUBaseInfo.h and
mark them constexpr.
2025-06-05 11:19:20 +02:00
Stanislav Mekhanoshin
a56442529c
[AMDGPU] Make <2 x bfloat> fneg legal (#142870) 2025-06-04 22:09:25 -07:00
Shilei Tian
8cd5604f59
[AMDGPU][AtomicExpand] Use full flat emulation if a target supports f64 global atomic add instruction (#142859)
If a target supports f64 global atomic add instruction, we can also use
full flat emulation.
2025-06-05 00:45:42 -04:00
Matt Arsenault
ad0a52202e
AMDGPU: Improve v32f16/v32bf16 copysign handling (#142177) 2025-05-31 08:24:51 +02:00
Matt Arsenault
3aeffcfde1
AMDGPU: Improve v16f16/v16bf16 copysign handling (#142176) 2025-05-31 08:18:52 +02:00
Matt Arsenault
ffee01e748
AMDGPU: Improve v8f16/v8bf16 copysign handling (#142175) 2025-05-31 08:15:45 +02:00
Matt Arsenault
20ad4209dd
AMDGPU: Improve v4f16/v4bf16 copysign handling (#142174) 2025-05-31 08:09:51 +02:00
Matt Arsenault
4aa4005e04
AMDGPU: Make copysign with matching v2f16/v2bf16 inputs legal (#142173)
Fixes #141931
2025-05-31 08:06:49 +02:00
Matt Arsenault
6a6aec6f4e
AMDGPU: Handle vectors in copysign sign type combine (#142157)
This avoids some ugly codegen on pre-16-bit instruction targets now
from annoying f16 legalization effects. This also avoids regressions
on newer targets in a future patch.
2025-05-30 20:02:07 +02:00
Matt Arsenault
e39e99022a
AMDGPU: Handle vectors in copysign magnitude sign case (#142156) 2025-05-30 19:58:55 +02:00
Matt Arsenault
d8235affcf
AMDGPU: Add is.shared/is.private intrinsics to isBoolSGPR (#141804)
No change in the net output since these ultimately expand to setcc,
but saves a step in the DAG.
2025-05-28 21:38:48 +02:00
Matt Arsenault
9ffbc8a4ce
AMDGPU: Add overflow operations to isBoolSGPR (#141803)
The particular use in the test doesn't seem to do anything for
the expanded cases (i.e. the signed add/sub or multiplies).
2025-05-28 21:35:04 +02:00
Matt Arsenault
e6bae02db3
AMDGPU: Add is_fpclass to isBoolSGPR (#141801) 2025-05-28 21:31:31 +02:00
Justin Bogner
b7bb256703
Warn on misuse of DiagnosticInfo classes that hold Twines (#137397)
This annotates the `Twine` passed to the constructors of the various
DiagnosticInfo subclasses with `[[clang::lifetimebound]]`, which causes
us to warn when we would try to print the twine after it had already
been destructed.

We also update `DiagnosticInfoUnsupported` to hold a `const Twine &`
like all of the other DiagnosticInfo classes, since this warning allows
us to clean up all of the places where it was being used incorrectly.
2025-05-28 12:26:39 -07:00
Matt Arsenault
db0bac0ef2
AMDGPU: Form v_med_f32 from minimumnum/maximumnum immediate pattern (#141048)
This makes little difference in the final output, as we manage to form this
after these are lowered to the _ieee operations. This does result in fewer steps
in the DAG, and helps prepare for changing the handling of minnum/maxnum.
2025-05-22 21:04:47 +02:00
Brox Chen
7f62800fb8
[AMDGPU][True16][CodeGen] select vgpr16 for asm inline 16bit vreg (#140946)
select vgpr16 for asm inline 16bit vreg in true16 mode
2025-05-21 17:47:28 -04:00
Krzysztof Drewniak
4bdd116b80
[AMDGPU] Add a new amdgcn.load.to.lds intrinsic (#137425)
This PR adds a amdgns_load_to_lds intrinsic that abstracts over loads to
LDS from global (address space 1) pointers and buffer fat pointers
(address space 7), since they use the same API and "gather from a
pointer to LDS" is something of an abstract operation.

This commit adds the intrinsic and its lowerings for addrspaces 1 and 7,
and updates the MLIR wrappers to use it (loosening up the restrictions
on loads to LDS along the way to match the ground truth from target
features).

It also plumbs the intrinsic through to clang.
2025-05-19 07:15:04 -07:00
Kazu Hirata
ff78648b09
[llvm] Use llvm::find_if (NFC) (#140412) 2025-05-17 17:02:04 -07:00
Changpeng Fang
f01f08292e
AMDGPU: Make v2f32 -> v2f16 legal when target supports v_cvt_pk_f16_f32 (#139956)
If targets support v_cvt_pk_f16_f32 instruction, v2f32 -> v2f16 should
be legal. However, SelectionDAG does not allow us to specify the source
type in the legalization rules. To workaround this, we make FP_ROUND
Custom for v2f16 then set up v2f32 -> v2f16 to be legal during custom
lowering.

Fixes: SWDEV-532608 -- expected v_cvt_pk_f16_f32 was not generated.
2025-05-15 15:09:21 -07: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
f13ff77842
AMDGPU: Form min3/max3 from minimumnum/maximumnum (#139137) 2025-05-09 08:12:54 +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
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
Jay Foad
f9f79d9331
[AMDGPU] Fix VTList for BUFFER_LOAD and DENORM_MODE (#138704)
This fixes bugs that would be caught by verifyTargetNode in #119709.
2025-05-06 19:02:39 +01: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
Kazu Hirata
aa15596b5f
[llvm] Remove unused local variables (NFC) (#138478) 2025-05-04 21:33:54 -07:00
Kazu Hirata
d144c13ae5
[Target] Remove unused local variables (NFC) (#138443) 2025-05-04 07:56:38 -07:00
mssefat
7495f92f08
[AMDGPU] Fix undefined scc register in successor block of SI_KILL terminators (#134718)
Fix issue 131298 where an undefined $scc register causes verifier errors
when using SI_KILL_F32_COND_IMM_TERMINATOR instructions. The problem
occurs because the $scc register defined in a comparison before the kill
terminator is used in successor blocks, but was not properly marked as live-in.

This patch:
- Adds code to check if SCC is used in the successor block
- Adds SCC as a live-in to successor blocks
- Handles both explicit and implicit uses of SCC

With this patch the machine verifier no longer reports undefined $scc
errors in following kill terminator instruction.

Fixes #131298

---------

Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2025-04-30 09:02:45 -05:00
Matt Arsenault
ee2aba7cc6
AMDGPU: Use poison in some lowering contexts (#137325)
This replaces most of the places that use undef. I left alone
the cases that require additional thought.
2025-04-25 16:04:34 +02:00
Jay Foad
886f1199f0
[AMDGPU] Use variadic isa<>. NFC. (#137016) 2025-04-24 08:19:09 +01:00
Pankaj Dwivedi
a25fdd7aca
Reapply "[AMDGPU] Insert readfirstlane in the function returns in sgpr." (#136678)
Reapply  #135326 and fix the target-dependent constant check.

---------

Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2025-04-22 17:48:55 +05:30