8847 Commits

Author SHA1 Message Date
Shilei Tian
a99c964d7f
[AMDGPU] Add support for v_cvt_f16_fp8 on gfx1250 (#146302)
Co-authored-by: Mekhanoshin, Stanislav <Stanislav.Mekhanoshin@amd.com>
2025-06-30 07:51:00 -04:00
Changpeng Fang
bb982e733c
AMDGPU: support s_monitor_sleep on gfx1250 (#146293)
Co-Authored-by: Stanislav Mekhanoshin <Stanislav.Mekhanoshin@amd.com>
2025-06-29 21:01:47 -07:00
paperchalice
613222ec33
[DAGCombiner] Remove UnsafeFPMath usage in visitFSUBForFMACombine etc. (#145637)
Remove `UnsafeFPMath` in `visitFMULForFMADistributiveCombine`,
`visitFSUBForFMACombine` and `visitFDIV`.
All affected tests are fixed by add fast math flags manually.
Propagate fast math flags when lowering fdiv in NVPTX backend, so it can
produce optimized dag when `unsafe-fp-math` is absent.
2025-06-30 08:41:23 +08:00
Changpeng Fang
1f5f381920
AMDGPU: Implement intrinsic/builtins for gfx1250 load transpose instructions (#146289) 2025-06-29 14:33:31 -07:00
Guy David
f5c62ee0fa
[PHIElimination] Reuse existing COPY in predecessor basic block (#131837)
The insertion point of COPY isn't always optimal and could eventually
lead to a worse block layout, see the regression test in the first
commit.

This change affects many architectures but the amount of total
instructions in the test cases seems too be slightly lower.
2025-06-29 21:28:42 +03:00
Ana Mihajlovic
08d747c1ef
[AMDGPU] Fix bad removal of s_delay_alu (#145728)
instructionWaitsForSGPRWrites function covers ALL SALU instructions,
including those like s_waitcnt that don't read from sgpr. This results
in removing delay_alu instructions in cases like VALU->SGPR->VALU, which
results in performance regression. Change modifies the function so that
it checks if instruction also reads a sgpr.
2025-06-27 16:15:10 +02:00
Simon Pilgrim
f329689ec0 [AMDGPU] add_i128.ll - regenerate test checks 2025-06-27 14:28:33 +01:00
Matt Arsenault
7e2e030121
GlobalISel: Replace use of report_fatal_error (#145866) 2025-06-27 21:16:23 +09:00
Matt Arsenault
c8ea114741
AMDGPU: Introduce a pass to replace VGPR MFMAs with AGPR (#145024)
In gfx90a-gfx950, it's possible to emit MFMAs which use AGPRs or VGPRs
for vdst and src2. We do not want to do use the AGPR form, unless
required by register pressure as it requires cross bank register
copies from most other instructions. Currently we select the AGPR
or VGPR version depending on a crude heuristic for whether it's possible
AGPRs will be required. We really need the register allocation to
be complete to make a good decision, which is what this pass is for.
    
This adds the pass, but does not yet remove the selection patterns
for AGPRs. This is a WIP, and NFC-ish. It should be a no-op on any
currently selected code. It also does not yet trigger on the real
examples of interest, which require handling batches of MFMAs at
once.
2025-06-27 21:05:03 +09:00
Matt Arsenault
bc1a6a2a93
AMDGPU: Add baseline tests for VGPR MFMA rewriting pass (#145023)
AMDGPU: Add baseline tests for VGPR MFMA rewriting pass

Add baseline tests for a new pass that will rewrite VGPR MFMAs
with copies to AV_* classes into the AGPR form.

Add start of IR test that probably needs to be redone
2025-06-27 21:02:49 +09:00
Simon Pilgrim
7dde6027a0
[DAG] canCreateUndefOrPoison - add handling for ISD::SELECT (#146046)
Followup to #143760 which handled ISD::VSELECT

I've moved ISD::SELECT/VSELECT under the "No poison except from flags
(which is handled above)" subgroup to try to remind people that these
can have poison generating FMFs (NINF/NNAN), even though this hasn't
been well explained anywhere I can find :(

Helps with regressions from #145939
2025-06-27 11:49:08 +01:00
Matt Arsenault
7255c3aee3
DAG: Check libcall function is supported before emission (#144314) 2025-06-27 18:09:04 +09:00
Jun Wang
063cee7bde
[AMDGPU][MC] Allow opsel for v_max_i16 etc in GFX10 (#143982)
In GFX10, a number of VOP3 instructions should allow opsel, including
V_MAX_I16, V_MAX_U16, V_MIN_I16, V_MIN_U16, V_MUL_LO_U16, V_LSHLREV_B16,
V_LSHRREV_B16, and V_ASHRREV_I16.
2025-06-26 14:08:13 -07:00
LU-JOHN
f2991bf791
[AMDGPU] Convert 64-bit sra to 32-bit if shift amt >= 32 (#144421)
Use KnownBits to convert 64-bit sra to 32-bit sra.

Scaled-down alive2 verification with 16/8-bit types:
https://alive2.llvm.org/ce/z/LamASk

---------

Signed-off-by: John Lu <John.Lu@amd.com>
2025-06-26 14:22:59 -04:00
Lucas Ramirez
6307b496f8
[AMDGPU] Add GCNRPTarget to track register pressure against a target (#145765)
This adds the `GCNRPTarget` class which models a register pressure
target (i.e., maximum number of SGPRs/VGPRS) that one can track register
savings against. The only current use of this class is in the
scheduler's rematerialization stage. It replaces the more ad-hoc (and
now deleted) `ExcessRP` class which used to serve the same purpose.

This is only NFC~ish because `GCNRPTarget` tracks VGPR usage more
accurately than `ExcessRP` used to. To estimate required combined VGPR
savings we now additionally take into account the number of available
VGPRs in both banks (ArchVGPR and AGPR) at the time where the RP target
is created, whereas we used to only consider explicit savings made from
the starting RP. This makes VGPR savings estimations more accurate in
cases where we allow for savings in one VGPR bank to help towards
reducing pressure in another VGPR bank (see
`GCNRPTarget::CombineVGPRSavings`). This is the cause for unit test
changes.
2025-06-26 13:11:20 +02:00
Sameer Sahasrabuddhe
741e1ca3b3
[AMDGPU] upgrade test to use auto-generated llc checks (#145832)
This makes it easier to fix the failure in #145720
2025-06-26 14:30:53 +05:30
Fabian Ritter
f070c74e35
[AMDGPU][SDAG] Tests for target-specific ISD::PTRADD combines (#143672)
Pre-committing tests to show improvements in a follow-up PR.
2025-06-26 09:54:45 +02:00
Fabian Ritter
c225d6dee0
[AMDGPU][SDAG] Handle ISD::PTRADD in SelectionDAGAddressAnalysis (#142778)
This is used in a bunch of memory-related transforms.

For SWDEV-516125.
2025-06-26 09:47:46 +02:00
Fabian Ritter
616816468b
[AMDGPU][SDAG] Add test for ISD::PTRADD handling in SelectionDAGAddressAnalysis (#142777)
Pre-committing test to show improvements in a follow-up PR.
2025-06-26 09:43:49 +02: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
Jay Foad
402480325b
[AMDGPU] More tests for S_WAIT_XCNT insertion (#145681) 2025-06-26 08:18:39 +01:00
Matt Arsenault
4cb8308ee9
AMDGPU: Avoid report_fatal_error for unsupported ds_ordered_count (#145172) 2025-06-26 14:06:05 +09:00
Shilei Tian
ae05dbbb04
[NFC][AMDGPU] Add a test that can cause backend crash (#145777)
The crash was reported downstream, but it has been fixed in upstream by
2bada417c1f06361f4b7a992224bfb8e32d55ca6.
This PR is to add the test case upstream. Note that there are some UBs
in the
IRs, such as load/store from/to a nullptr. The crash would not be
reproducible
if any of them is changed to something else.
2025-06-25 23:29:04 -04:00
Matt Arsenault
e1f224b99a
AMDGPU: Handle folding vector splats of inline split f64 inline immediates (#140878)
Recognize a reg_sequence with 32-bit elements that produce a 64-bit
splat value. This enables folding f64 constants into mfma operands
2025-06-26 07:45:49 +09:00
Matt Arsenault
472c9141f9
AMDGPU: Fix tracking subreg defs when folding through reg_sequence (#140608)
We weren't fully respecting the type of a def of an immediate vs.
the type at the use point. Refactor the folding logic to track the
value to fold, as well as a subregister to apply to the underlying
value. This is similar to how PeepholeOpt tracks subregisters (though
only for pure copy-like instructions, no constants).

Fixes #139317
2025-06-26 07:42:55 +09:00
Shilei Tian
ce1c1a0e6d
[AMDGPU] Add support for v_cvt_pk_f16_bf8 on gfx1250 (#145753)
Co-authored-by: Shilei Tian <i@tianshilei.me>
2025-06-25 17:03:52 -04:00
Shilei Tian
ff23ee40d6
[AMDGPU] Add support for v_cvt_pk_f16_fp8 on gfx1250 (#145747)
Co-authored-by: Shilei Tian <i@tianshilei.me>
2025-06-25 17:00:10 -04:00
Matt Arsenault
020fefb6af
AMDGPU: Avoid report_fatal_error in image intrinsic lowering (#145201) 2025-06-26 00:00:36 +09:00
Björn Pettersson
fd3cc204de
[SelectionDAG] Fold undemanded operand to UNDEF for VECTOR_SHUFFLE (#145524)
Always let SimplifyDemandedVectorElts fold either side of a
VECTOR_SHUFFLE to UNDEF if no elements are demanded from that side.

For a single use this could be done by SimplifyDemandedVectorElts
already, but in case the operand had multiple uses we did not eliminate
the use.
2025-06-25 16:05:54 +02:00
Akshat Oke
88297cca8f
[AMDGPU] Correct -mcpu processor name in test (#145493) 2025-06-25 14:34:38 +05:30
Christudasan Devadasan
08b8d467d4
[AMDGPU][GFX1250] Insert S_WAIT_XCNT for SMEM and VMEM load-stores (#145566)
This patch tracks the register operands of both VMEM (FLAT, MUBUF,
MTBUF) and SMEM load-store operations and inserts a S_WAIT_XCNT
instruction with sufficient wait-count before potentially redefining
them. For VMEM instructions, XNACK is returned in the same order as
they were issued and hence non-zero counter values can be inserted.
However, SMEM execution is out-of-order and so is their XNACK reception.
Thus, only zero counter value can be inserted to capture SMEM dependencies.
2025-06-25 10:40:36 +05:30
paperchalice
901e1390c9
[SelectionDAG] Remove UnsafeFPMath check in visitFADDForFMACombine (#127770)
As requested in #127488, remove reference to `Options.UnsafeFPMath`,
which should be obsolete and `AllowFPOpFusion` also handles it.
2025-06-25 12:31:23 +08:00
Brox Chen
505906bff6
[AMDGPU][True16][CodeGen] do not legalize t16 operand during user scan (#145450)
The legalize t16 operand function could insert a reg_sequence which
modify the user list of the targetted register, and we should not call
it in the middle of an user list iteration
2025-06-24 23:49:22 -04: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
Stanislav Mekhanoshin
fe0568389d
[AMDGPU] Require aligned VGPRs for gfx1250 (#145561) 2025-06-24 12:16:01 -07:00
Lucas Ramirez
c74ed8a0d3
[AMDGPU][Scheduler] Support for rematerializing SGPRs and AGPRs (#140036)
This adds the ability to rematerialize SGPRs and AGPRs to the
scheduler's `PreRARematStage`, which can currently only rematerialize
ArchVGPRs. This also fixes a small potential issue in the stage where,
in case of spilling, the target occupancy could be set to a lower than
expected value when the function had either one of the "amdgpu-num-sgpr"
or "amdgpu-num-vgpr" attributes set.
2025-06-24 19:30:27 +02:00
Chris Jackson
bfde147761
[NFC][AMDGPU] Update and.ll test and automate check line generation (#145371)
- Convert the test to use update_llc_test_checks.py.
- Use different check prefixes for the different -mcpu options.
- Remove unused xnack 'off' flag.
2025-06-24 11:42:49 +01:00
Diana Picus
54b522f6fd
[AMDGPU] Fixup a201f8872a63 (#145486)
Fix test lines based on old revision for main.
2025-06-24 11:43:28 +02:00
Diana Picus
a201f8872a
[AMDGPU] Replace dynamic VGPR feature with attribute (#133444)
Use a function attribute (amdgpu-dynamic-vgpr) instead of a subtarget
feature, as requested in #130030.
2025-06-24 11:09:36 +02:00
Fabian Ritter
3e1e368824
[AMDGPU][SDAG] Add tests for ISD::PTRADD DAG combines (#142738)
Pre-committing tests to show improvements in a follow-up PR with the
combines.
2025-06-24 08:43:54 +02:00
Brox Chen
a50cb6ca3e
[AMDGPU][True16][CodeGen] fix a predicate bug in VGPRImm with f16/bf16 (#144942)
Fixed a typo issue that f16/bf16 VGPRImm patterrn is not guarded by the
True16Predicate scope. The curly bracket is misplaced
2025-06-23 10:46:59 -04:00
Matt Arsenault
2dcf436340
AMDGPU: Remove legacy pass manager version of AMDGPUAttributor (#145262) 2025-06-23 16:49:46 +09: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
6b129d6bbf
AsmPrinter: Do not use report_fatal_error for unhandled ConstantExpr (#145275) 2025-06-23 16:29:58 +09:00
Matt Arsenault
4be4b82e74
AMDGPU: Use reportFatalUsageError for unhandled calling conventions (#145261)
Should switch this to DiagnosticInfo and use the default calling
convention, but that would require passing in the context.
2025-06-23 15:30:13 +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
Stanislav Mekhanoshin
40eee8ec7f
[AMDGPU] Add s_setprio_inc_wg gfx1250 instruction (#145152) 2025-06-22 12:52:05 -07:00
Iris Shi
f2eb5d416e
[SelectionDAG] Handle fneg/fabs/fcopysign in SimplifyDemandedBits (#139239) 2025-06-22 22:48:59 +08:00
Matt Arsenault
96493c514e
AMDGPU: Use reportFatalUsageError for regalloc flag error (#145198) 2025-06-22 22:41:05 +09:00