9815 Commits

Author SHA1 Message Date
vangthao95
5b4ed87289
[AMDGPU][GlobalISel] Add RegBankLegalize rules for [us]addsat/[us]subsat (#176255) 2026-01-16 08:01:19 -08:00
vangthao95
c52a878269
[AMDGPU][GlobalISel] Fix G_TRUNC S16 to VCC for pre-GFX8 targets (#176254) 2026-01-16 08:00:42 -08:00
Alexander Weinrauch
2eb709b95d
[AMDGPU] Fix typo in LowerVGPREncoding to allow it to hoist past waitcnt instructions (#176355)
Fixes a typo which prevented `set_vgpr_msb` to be hoisted past `waitcnt`
instructions.
2026-01-16 13:52:47 +00:00
Alexander Weinrauch
c2a28da5fe
[AMDGPU] Fix hoist location for s_set_vgpr_msb past SALU program state instructions (#176206)
If we exit the loop at a non SALU state instruction we have to return
the next instruction because we will insert before the instruction we
return. The check before the loop already did this for cases we start on
a non SALU state instruction by returning `I`. This is now done
afterwards.
2026-01-16 12:00:19 +00:00
Juan Manuel Martinez Caamaño
c30c2f4f3e
[AMDGPU] Rematerialize VGPR candidates when SGPR spills results in VGPR Excess (#168079)
Before, when selecting candidates to rematerialize, we would only
consider SGPR candidates when there was an excess of SGPR registers.

Failing to eliminate the excess would result in spills to VGPRs.
This is normally not an issue, unless spilling to VGPRs results in
excess VGPRs.

This patch does 2 things:
* It relaxes the GCNRPTarget success criteria: now we accept regions
  where we spill SGPRs to VGPRs, as long as this does not end up in
  excess VGPRs.
* It changes isSaveBeneficial to consider the excess VGPRs (which
  includes the SGPRs that would be spilled to VGPR).

With these changes, the compiler rematerializes VGPRs when the excess
SGPRs would result in VGPR excess.

This has some unaddressed flaws: we should attempt to rematerialize
SGPRs
first in order to eliminate the SGPR excess that results in VGPR excess.

Related to SWDEV-549940
2026-01-16 09:08:55 +01:00
Stanislav Mekhanoshin
b501f666c5
[AMDGPU] Fix expensive checks in fmaak/fmamk f16 folding (#176238)
Register classes of sources also has to be restrained to lo128.
There are few regression with register coalescing in true16 mode
though, but otherwise it fails verification.
2026-01-15 14:03:07 -08:00
Tony Linthicum
15b9109bc7
Make MachineBlockFrequencyInfo a required pass for the MachineScheduler pass. (#176172)
This is needed to support functionality in the AMDGPU scheduler. Various
passes have been modified to preserve MBFI to ensure that this change
does not introduce new invocations of MBFI. Some targets have passes
reordered, but there are no new runs of MBFI.
2026-01-15 20:26:51 +00:00
Stanislav Mekhanoshin
5546ce99d8
[AMDGPU] Allow 16-bit imm folding in real true16 (#173318) 2026-01-15 11:15:12 -08:00
Stanislav Mekhanoshin
fa3ef64011
[AMDGPU] Create V_FMAAK_F16/V_FMAMK_F16 in true16 with imm folding (#173317)
This does not cover real true16 with tests, the next patch will.
2026-01-15 11:06:34 -08:00
Akash Dutta
fc10fbb71e
Reapply "AMDGPU: Do not infer implicit inputs for !nocallback intrinsics" (#176081)
This reverts #174224 and re-applies #131759 .

Note: If #117544 is reverted, this should also be reverted.
2026-01-15 09:08:27 -06:00
Stanislav Mekhanoshin
dd947ebcf3
[AMDGPU] Update gfx1250 memory model for global acquire/release (#175865)
Inserts required waits around GLOBAL_INV/GLOBAL_WBINV for
agent scope and above.
2026-01-15 03:25:03 -08:00
sstipano
cc1e10d50b
[AMDGPU] Disable s_add_pc_i64 instruction (#175644)
s_add_pc_i64 instruction is broken on gfx1250. Disable it by default.
2026-01-14 23:01:43 +01:00
Stanislav Mekhanoshin
65ab8fe54b
[AMDGPU] Make VGPR_16_Lo128 allocatable (#173309)
Allows allocation of V_FMAMK_F16/V_FMAAK_F16 registers in
real true16 mode.
2026-01-14 10:40:05 -08:00
Jay Foad
ef0680ba54
[AMDGPU] Encode unused VALU src0/1/2 fields as inline 0 on GFX10+ (#175753)
This has no functional effect since these source fields are unused, but
it can avoid some conservative stalls due to these instructions looking
like they read from an SGPR, since 0 is the encoding for s0. Using 0x80
is more benign since it is the encoding for inline immediate 0.

Fixes: SWDEV-574953
2026-01-14 18:23:27 +00:00
Stanislav Mekhanoshin
4e84513b72
[AMDGPU] Add test for v_fmamk_f16/v_fmaak_f16 in real-true16. NFC (#173307)
This is to display a bug in real true16 mode that we do not have
an allocatable 16-bit VGPR class and these instructions do not
have VOP3 forms for allocatable VGPR_16 to be used. To use these
instructions 'VGPR_16_Lo128' must be allocable.
2026-01-14 09:49:56 -08:00
saxlungs
62a9aadddc
[AMDGPU] Add optimization for llvm.amdgcn.wave.shuffle in uniform cases (#174795)
When the llvm.amdgcn.wave.shuffle intrinsic is called with a uniform
Index operand, it is effectively the same as the llvm.amdgcn.readlane
intrinsic. This change handles this situation and replaces it with the
readlane intrinsic

---------

Signed-off-by: Domenic Nutile <domenic.nutile@gmail.com>
2026-01-14 17:49:42 +00:00
Anshil Gandhi
f41767651b
[AMDGPU] Add regbankselect rules for G_ICMP/G_FCMP (#172048)
- Legalize G_ICMP for S16, S32, S64, Ptr32 and Ptr64 operands.
- Legalize G_FCMP for S16, S32 and S64 operands.
2026-01-14 12:37:16 -05:00
LU-JOHN
cf237465b3
[AMDGPU] Invert scc uses to delete s_cmp_eq* (#167382)
Delete s_cmp_eq* instructions by inverting instructions that use scc.

---------

Signed-off-by: John Lu <John.Lu@amd.com>
2026-01-14 10:24:24 -06:00
Teja Alaghari
7cc013af9c
[CodeGen][NPM] Add support for -print-regusage in New Pass Manager (#169761)
Support `-print-regusage` flag in NPM for printing register usage information
2026-01-14 11:00:02 +05:30
Grigor Nikolov
50703faab8
[AMDGPU][Test][AIX] use tr instead of sed for line split (#175557)
Test case is using sed command `sed 's/,/,\n/g'` to split a line.
On AIX that is not working with the AIX system's `sed`

AIX external BB fails from
https://lab.llvm.org/buildbot/#/builders/64/builds/6911

Here substitute:
`sed 's/,/,\n/g'`
with:
`tr ',' '\n'`
but because `tr` does not keeps the comma, also needed to change looked
for texts i.e. to remove the comma `,` from them since it is not needed
for the correctness.

Co-authored-by: Daniel Chen <cdchen@ca.ibm.com>
2026-01-13 14:47:28 -05:00
Lucas Ramirez
7b699cc5de
Revert "[AMDGPU][Scheduler] Scoring system for rematerializations (#175050)" (#175813)
This reverts 8ab79377740789f6a34fc6f04ee321a39ab73724 and
f21e3593371c049380f056a539a1601a843df558 which are causing a HIP failure
in a Blender test.
2026-01-13 19:29:50 +00:00
Austin Jiang
e6cdfb75ac
Fix typos and spelling errors across codebase (#156270)
Corrected various spelling mistakes such as 'occurred', 'receiver',
'initialized', 'length', and others in comments, variable names,
function names, and documentation throughout the project. These
changes improve code readability and maintain consistency in naming
and documentation.

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2026-01-13 11:52:46 -05:00
Matt Arsenault
2e0e4f6cb3
AMDGPU: Directly use v2bf16 as register type for bf16 vectors. (#175761)
Previously we were casting v2bf16 to i32, unlike the f16 case. Simplify
this by using the natural vector type. This is probably a leftover from
before v2bf16 was treated as legal. This is preparation for fixing a
miscompile in globalisel.
2026-01-13 17:48:38 +01:00
Abhinav Garg
7af6abd6a4
[AMDGPU][GlobalISel] Add RegBankLegalize support for amd_gcn_end_cf (#175118) 2026-01-13 18:18:39 +05:30
Lucas Ramirez
6aaa7fd7fb
[AMDGPU][Scheduler] Scoring system for rematerializations (#175050)
This is a significant refactoring of the scheduler's rematerialization
stage meant to improve rematerialization capabilities and lay strong
foundations for future improvements.

As before, the stage identifies scheduling regions in which RP must be
reduced (so-called "target regions"), then rematerializes registers to
try and achieve the desired reduction. All regions affected by
rematerializations are re-scheduled, and, if the MIR is deemed worse
than before, rematerializations are rolled back to leave the MIR in its
pre-stage state.

The core contribution is a scoring system to estimate the benefit of
each rematerialization candidate. This score favors rematerializing
candidates which, in order, would

1. (if the function is spilling) reduce RP in highest-frequency target
regions,
2. be rematerialized to lowest-frequency target regions, and
3. reduce RP in the highest number of target regions.

All rematerialization opportunities are initially scored and
rematerialized in decreasing score order until RP objectives are met or
pre-computed scores diverge from reality; in the latter case remaining
candidates are re-scored and the process repeats. New tests in
`machine-scheduler-rematerialization-scoring.mir` showcase how the
scoring system dictates which rematerialization are the most beneficial
and therefore performed first

A minor contribution included in this PR following previous feedback is
that rollback now happens in-place i.e., without having to re-create the
rematerialized MI. This leaves original slot indices and registers
untouched. We achieve this by temporarily switching the opcode of
rollback-able instructions to a debug opcode during re-scheduling so
that they are ignored.
2026-01-13 12:24:16 +01:00
hidekisaito
a062249932
[AMDGPU] Add DS loop waitcnt optimization for GFX12+ (#172728)
Add support for flushing DS_CNT in loop preheaders when the loop uses
values that were DS-loaded outside the loop. This is similar to the
existing VMEM loop optimization.

Assisted-by: Cursor / claude-4.5-opus-high
2026-01-12 13:34:02 -08:00
Jay Foad
27074aa31a
[AMDGPU] Fix crash in SIInsertWaitcnts debug output (#175518)
In some cases we were accessing `OldWaitcntInstr.getParent()->end()`
after `OldWaitcntInstr` had already been erased from its parent.
2026-01-12 14:48:53 +00:00
Pankaj Dwivedi
3dfb782333
[AMDGPU][SIInsertWaitcnt] Implement Waitcnt Expansion for Profiling (#169345)
Reference issue: https://github.com/ROCm/llvm-project/issues/67

This patch adds support for expanding s_waitcnt instructions into
sequences with decreasing counter values, enabling PC-sampling profilers
to identify which specific memory operation is causing a stall.

This is controlled via:
Clang flag: -mamdgpu-expand-waitcnt-profiling /
-mno-amdgpu-expand-waitcnt-profiling
Function attribute: "amdgpu-expand-waitcnt-profiling"

When enabled, instead of emitting a single waitcnt, the pass generates a
sequence that waits for each outstanding operation individually. For
example, if there are 5 outstanding memory operations and the target is
to wait until 2 remain:


**Original**: 
s_waitcnt vmcnt(2)

**Expanded**:  
s_waitcnt vmcnt(4)
s_waitcnt vmcnt(3)
s_waitcnt vmcnt(2)

The expansion starts from (Outstanding - 1) down to the target value,
since waitcnt(Outstanding) would be a no-op (the counter is already at
that value).

- Uses ScoreBrackets to determine the actual number of outstanding
operations
- Only expands when operations complete in-order
- Skips expansion for mixed event types (e.g., LDS+SMEM on same counter)
- Skips expansion for scalar memory (always out-of-order)

Releated previous work for Reference
- **PR**: llvm/llvm-project#79236 (related `-amdgpu-waitcnt-forcezero`)

---------

Co-authored-by: Pierre van Houtryve <pierre.vanhoutryve@amd.com>
2026-01-12 17:35:06 +05:30
Shilei Tian
df3629dc0c
[AMDGPU] Handle s_setreg_imm32_b32 targeting MODE register (#174681)
On certain hardware, this instruction clobbers VGPR MSB `bits[12:19]`,
so we need to restore the current mode.

Fixes SWDEV-571581.
2026-01-09 14:43:41 -05:00
vangthao95
b3d25f59d5
[AMDGPU][GlobalISel] Add RegBankLegalize support for G_FLDEXP (#175072) 2026-01-09 08:52:35 -08:00
vangthao95
7df0826c41
[AMDGPU][GlobalISel] Add RegBankLegalize support for G_PTRMASK (#174889)
Add support for G_PTRMASK but we are missing p8 (buffer resource) due to
a legalizer issue in GlobalISel which does not occur on SelectionDAG:
`LLVM ERROR: unable to legalize instruction: %17:_(p8) = G_PTRMASK %0:_,
%22:_(s128) (in function: v_ptrmask_buffer_resource_variable_i48)`

Added a FIXME to indicate this issue.
2026-01-09 08:51:51 -08:00
vangthao95
121a9c414f
[AMDGPU][GlobalISel] Add RegBankLegalize support for G_FCANONICALIZE (#174662)
Added -global-isel flags to fcanonicalize.ll test.
2026-01-09 08:51:16 -08:00
Christudasan Devadasan
e486a26b9c
[AMDGPU] Add liverange split instructions into BB Prolog (#117544)
The COPY inserted for liverange split during sgpr-regalloc
pipeline currently breaks the BB prolog during the subsequent
vgpr-regalloc phase while spilling and/or splitting the vector
liveranges. This patch fixes it by correctly including the
LR split instructions during sgpr-regalloc and wwm-regalloc
pipelines into the BB prolog.
2026-01-09 21:25:14 +05:30
Jay Foad
475f022cb7
[AMDGPU] Add support for GFX12 expert scheduling mode 2 (#170319) 2026-01-09 15:49:10 +00:00
Anshil Gandhi
03ad3d2e8f
[CodeGen] Consider imm offsets when sorting framerefs (#171012)
LocalStackSlotAllocation pass disallows negative offsets with respect to
a base register. The pass ends up introducing a new register for such
frame references. This patch helps LocalStackSlotAlloca to additionally
consider the immediate offset of an instruction, when sorting frame refs
- hence, avoiding negative offsets and maximizing reuse of the existing
registers.
2026-01-08 17:48:30 -05:00
Joseph Huber
5cf92086b7
[AMDGPU] Optimize block count calculations to the new ABI (#174112)
Summary:
We already have a way to get the block count using the old grid size
lookup and dividing it by the number of threads. We did not want to make
a new intrinsic to do the same thing, so this optimization pattern
matches on this usage to automatically optimize it to the new form. This
should improve performance of old kernels by converting branches into a
simple index lookup and removing the division.
2026-01-08 16:03:00 -06:00
vangthao95
f7b20ec57f
[AMDGPU][GlobalISel] Add RegBankLegalize support for G_UMULH, G_SMULH (#174555) 2026-01-08 13:57:57 -08:00
Anshil Gandhi
708663c8e6
Precommit test for PR #171012 (#171013)
This patch precommits a test where base offsets are negative. PR
[171012](https://github.com/llvm/llvm-project/pull/171012 ) will
eliminate negative offsets by sorting the scratch instructions.
2026-01-08 15:46:47 -05:00
Shilei Tian
4e74fba5b2
[AMDGPU] Fix a potential use-after-erase in AMDGPUPromoteAlloca pass (#174529)
In some cases, the placeholder itself can be used as the value for its
corresponding block in `SSAUpdater`, and later used as an incoming value
in another block in `GetValueInMiddleOfBlock`. If we erase it too early,
this can lead to a use-after-erase.
2026-01-08 11:44:16 -05:00
Matt Arsenault
a470e708be
AMDGPU: Teach lowering that sqrt never returns subnormal (#174838) 2026-01-08 12:05:29 +01:00
saxlungs
7bbaf2e16b
[AMDGPU] Improve llvm.amdgcn.wave.shuffle handling for pre-GFX8 (#174845)
Before, GlobalISel would still return true for lowering the intrinsic
for GFX7 and earlier even though the required ds_bpermute_b32
instruction is not supported. After this change, GlobalISel will
properly report failure to select in this case. Testing is updated
appropriately.

Signed-off-by: Domenic Nutile <domenic.nutile@gmail.com>
2026-01-07 21:48:11 +01:00
Jay Foad
e5623b1a9e Revert "SelectionDAG: Do not propagate divergence through glue (#174766)"
This reverts commit 47a0d0e42832558f999b149b22cfd48c46ef2a57.

Reverted due to test failures in LLVM_ENABLE_EXPENSIVE_CHECKS builds.
2026-01-07 14:23:15 +00:00
Jay Foad
47a0d0e428
SelectionDAG: Do not propagate divergence through glue (#174766)
Glue does not carry any value (in the LLVM IR Value sense) that could be
considered uniform or divergent.
2026-01-07 14:04:36 +00:00
Pankaj Dwivedi
1ab7b6655d
Revert "[VectorCombine] Fold scalar selects from bitcast into vector select" (#174758)
Reverts llvm/llvm-project#173990
Reverting to address post-commit review feedback. Will recommit with
fixes.
2026-01-07 18:59:32 +05:30
Pankaj Dwivedi
72f18a05d6
[VectorCombine] Fold scalar selects from bitcast into vector select (#173990) 2026-01-07 15:16:33 +05:30
Shilei Tian
5a63367b15
Reapply "[AMDGPU] Rework the clamp support for WMMA instructions" (#174674) (#174697)
This reverts commit 0b2f3cfb72a76fa90f3ec2a234caabe0d0712590.
2026-01-07 06:12:19 +00:00
dyung
0b2f3cfb72
Revert "[AMDGPU] Rework the clamp support for WMMA instructions" (#174674)
Reverts llvm/llvm-project#174310

This change is causing 2 cross-project-test failures on
https://lab.llvm.org/buildbot/#/builders/174/builds/29695
2026-01-07 01:18:23 +00:00
Shilei Tian
ccca3b8c67
[AMDGPU] Rework the clamp support for WMMA instructions (#174310)
Fixes #166989.
2026-01-06 15:46:40 -05:00
saxlungs
c262893f4b
Reland "[AMDGPU] Add new llvm.amdgcn.wave.shuffle intrinsic (#167372)" (#174614)
This change adds a new intrinsic for AMDGPU that implements a wave
shuffle, allowing arbitrary swizzling between lanes using an index. In
the initial version of this commit, there was an issue in one of the
tests added that returned a signal, causing testing to fail when
combined with another recent change to 'not'.

For context on the initial commit see #167372

---------

Signed-off-by: Domenic Nutile <domenic.nutile@gmail.com>
Co-authored-by: Jay Foad <jay.foad@gmail.com>
2026-01-06 15:02:08 -05:00
theRonShark
dff081c26f
Revert "AMDGPU: Do not infer implicit inputs for !nocallback intrinsics" (#174224)
Reverts llvm/llvm-project#131759

seeing regressions in : Pytorch UT- 8 test cases failed in "test_ops"
test suite
2026-01-06 09:13:28 -05:00