12 Commits

Author SHA1 Message Date
Ivan Kosarev
dbd8727088
[AMDGPU][NFC] Refine the representation of MODE register values. (#177574)
- Eliminate the field masks.
- Segregate the encoding logic.
- Simplify and clarify the user code.

This is supposed to help updating downstream branches where we
have a more advanced version of the same facility.
2026-01-26 13:10:24 +00:00
Tim Gymnich
13197d2f23
[AMDGPU] Reduce number of emitted S_SET_VGPR_MSB instructions (#176502)
Given a `S_SET_VGPR_MSB` instruction with `CurrentMode` and
`CurrentMask` where `CurrentMask` is a bit mask with 1 for every bit
position we set to 0 or 1 in `CurrentMode`.

We also have a new mode bitset `Mode` and a `Mask` with the bit position
we want set.

Currently we check if the difference between `Mode` and `CurrentMode`
(`Delta = Mode ^ CurrentMode`) overlaps with the bit positions we
previously set (`Delta & CurrentMask .== 0`). We then update
`CurrentMode` and `CurrentMask` accordingly.

However if bit positions differ in `Mode` and `CurrentMode` but we do
not care about these bit positions for our next instruction `(Delta &
Mask) & CurrentMask .== 0`) we can still update the previous
`S_SET_VGPR_MSB`, since we don't interfere with any of the bit positions
in `CurrentMask`


```mir
     S_SET_VGPR_MSB 0x0002
     $vgpr0 = V_MOV_B32_e32 $vgpr530          ; mode: 0b0000_0010   mask:  0b0000_0011
->   $vgpr1 = V_ADD_U32_e32 0x1234, $vgpr531  ; mode: 0b0000_1000   mask:  0b0000_1100
                                              ; src0 is imm so we don't care about it.
```

|   | dst  |  src2 | src1  | src0  |
|---|---|---|---|---|
|  CurrentMode | 00  | 00  | 00  | 10  |
| CurrentMask  |  00  | 00  | 00  | 11  |
|  Mode | 00  | 00  |  10  |  00  |
|  Mask | 00  |  00  |  11  | 00  |
|  Delta |  00 | 00  | 10   | 10  |
| Delta & CurrentMask  | 00  | 00  | 00  | 10  |
| Delta & Mask & CurrentMask  |  00 | 00  | 00  | 00  |
2026-01-20 10:47:24 +01:00
Jeffrey Byrnes
bbafff1752
[AMDGPU] NFC: Add a comment (#176435) 2026-01-16 15:49:14 -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
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
Aiden Grossman
2a005892a4
[AMDGPU][NewPM] Consistently preserve IR analyses in MF passes
These three passes were not doing so, unlike all the other passes.

Reviewers: vikramRH, cdevadas, paperchalice, arsenm

Pull Request: https://github.com/llvm/llvm-project/pull/173758
2025-12-28 13:12:10 -08:00
Jeffrey Byrnes
e45241a4fe
[AMDGPU] Hoist s_set_vgpr_msb past SALU program state instructions (#172108)
Hoisting past the program state instructions is legal and allows for
better coissue.
2025-12-12 18:04:20 -08:00
Stanislav Mekhanoshin
be2ae264dd
[AMDGPU] Record old VGPR MSBs in the high bits of s_set_vgpr_msb (#165035)
Fixes: SWDEV-562450
2025-10-31 12:21:59 -07:00
Stanislav Mekhanoshin
0d9c75be2d
[AMDGPU] Reset VGPR MSBs at the end of fallthrough basic block (#164901)
By convention a basic block shall start with MSBs zero. We also
need to know a previous mode in all cases as SWDEV-562450 asks
to record the old mode in the high bits of the mode.
2025-10-31 10:58:22 -07:00
Stanislav Mekhanoshin
5901d896f4
[AMDGPU] Register amdgpu-lower-vgpr-encoding pass in npm (#156971) 2025-09-05 00:07:47 -07:00
Stanislav Mekhanoshin
1f0f3473e6
[AMDGPU] High VGPR lowering on gfx1250 (#156965) 2025-09-04 16:20:47 -07:00