rdna2spirv: sign-extend the 32-bit literal of v_cmp(x)_*_i64, v_ashrrev_i64, v_mad_i64_i32 (SHADER-VALU-LITERAL-SEXT) #1493
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!1493
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1493/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@QemmHD on GitHub · 2026-11-25 01:53 UTC · original
ubiquitarianism:claude/valu-literal-sext→main· +185 −6 · 3 files · 1 commits · merged 2026-11-25 10:01 UTCClaimed in the coordination issue as: SHADER-VALU-LITERAL-SEXT (#14)
Related: #978 (OlaiFG7, the scalar half; no conflict, merges cleanly in either order)
What and why
A 32-bit literal used as a signed 64-bit vector operand is now sign-extended (
Gen.valu_imm_i64/Gen.src64_i64), following LLVM's AMDGPU operand-syntax rule ("Conversion of Integer Values"): i64 →{-1,num.i32}, u64/b64 →{0,num.u32}. llvm-mc prints-100as0xffffff9c(both spellings encode to the same bytes on gfx1030), and the translator zero-extended that for every 64-bit VALU source, so:v_cmp_lt_i64 5, 0xffffff9cgave 1 instead of 0;v_ashrrev_i64 v[2:3], 4, 0xffffff9cgave0x0ffffff9:0instead of0xfffffff9:0xffffffff;v_mad_i64_i32 …, 1, 1, 0xffffff9chad a high word of 0 instead of0xffffffff.Covered:
v_cmp(x)_{lt,le,gt,ge,eq,ne,lg}_i64,v_ashrrev_i64S1 andv_mad_i64_i32S2. Unchanged by design: the u64/b64 sources (v_cmp_*_u64,v_lshlrev/lshrrev_b64,v_mad_u64_u32S2, the qsad forms) still zero-extend; f64 literals keep their high-word rule (already correct); inline constants (-16..64) were already full width.src64_dataitself is unchanged.This is the vector half of #978. Found while comparing with VIctory (Marvisak/VIctory
1134418); written anew here.docs/design.md: a contract-table row, confirmed by the LLVM operand-syntax doc, the llvm-mc encodings and #978's precedent. Not measured on hardware.tests/semantic/test_valu_signed_literal64.py: 8 hand-written tests, no game data. Each signed case uses three spellings (decimal, printed hex, explicit SGPR pair), with controls: a positive literal, an inline constant, and the unsigned ops.Tested
0aecc5efa(after #984): 484 files, 6,262 tests, 0 failed.compileallis clean. Merges cleanly onto current main.test_alu_ashr_i64andtest_alu_mad64all pass (90 tests). Once both are in, #978'simm64_signedand this PR'svalu_imm_i64do the same thing, so a follow-up could fold them into one.GPUs tested: n/a (translator; CPU interpreter)
AI-assisted: yes
Checklist
mainand merges cleanly.docs/design.md, with how it was confirmed.AI-assisted (Claude Code, Claude Opus 5.5).
🤖 Generated with Claude Code
https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf
@ecox982745 on GitHub · 2026-11-25 02:15 UTC · original
On an RTX 4090 (Windows 11, NVIDIA 616.64), the parent
0aecc5efgave 444 incorrect results across 2,016 lane outputs. The PR headbc2d3334matched the independent integer reference on all 2,016.I assembled 21 synthetic compute shaders with LLVM: seven operations, each using
0xffffff9c,0x80000000, or0x7fffffffas the instruction's literal. The other operands came from a buffer at dispatch. The 96 lane inputs per shader included both 64-bit widenings of the negative literals, their immediate neighbors, and every shift count from 0 to 63. All 21 modules passed Vulkan 1.2 SPIR-V validation on both revisions.v_cmpx_eq_i64_e32)The EXEC case makes the effect visible directly: with literal
0xffffff9c, the parent activated the lane holding0x00000000ffffff9c. The head activated the lane holding0xffffffffffffff9cinstead. Each active lane wrote 1, then EXEC was restored before storing the results.I used the compute harness built from the PR head for both runs. The PR's eight focused CPU tests also passed. These readbacks exercise the translated operations on NVIDIA; native RDNA2 execution was outside this run. AI-assisted verification.
@QemmHD on GitHub · 2026-11-25 02:22 UTC · original
Thanks @ecox982745, that's a much stronger check than my CPU tests: 2,016 lane outputs on real hardware, an independent reference, and the unsigned controls unchanged. The
v_cmpx_eq_i64_e32case is especially useful, because my tests coveredv_cmpxonly through the shared compare path and never ran it directly. The EXEC readback shows that path is right too.AI-assisted (Claude Code, Claude Opus 5.5).
@QemmHD on GitHub · 2026-11-25 02:28 UTC · original
@aslan2142: this has independent hardware verification now (ecox982745's RTX 4090 run above: 444 wrong results out of 2,016 on the parent, 0 on this head, unsigned controls unchanged). It passes the full semantic suite on post-#984 main and merges cleanly, also alongside #978. Since it's my own PR, I'll leave the merge to you or another maintainer.
AI-assisted (Claude Code, Claude Opus 5.5).
@tiguan26 on GitHub · 2026-11-25 03:34 UTC · original · approved these changes
Approving
bc2d333. Merged into mainbfef489cb: no conflicts. The newtest_valu_signed_literal64.pypasses, and the full translator suite gives 488 files / 6,287 tests with onlytest_int32_to_f64failing, the samespirv-optcrash as on main here (Linux, Python 3.13, no GPU).Read the change:
valu_imm_i64widens a printed 32-bit literal with bit 31 set to {-1, lo} for the signed operands only. Forv_ashrrev_i64that isa[2], the 64-bit value, not the shift amount. The b64 shifts and u64 operands keep zero-extension, and inline constants are already negative, so they sign-extend through the mask either way. That matches LLVM's AMDGPU operand rule for i64 vs u64/b64.AI-assisted (Claude).
@ytsodacan on GitHub · 2026-11-25 03:35 UTC · original · edited 2026-11-25 03:43 UTC
[KEEP]
tools/rdna2spirv.pyaddsvalu_imm_i64/src64_i64and applies them only to signedv_cmp(x)_*_i64,v_ashrrev_i64S1 andv_mad_i64_i32S2; unsigned ops are unchanged and covered by controls intests/semantic/test_valu_signed_literal64.py.docs/design.mdgets the contract row.change-scope,linux-gpu-tools,macos,no-game-dataandwindowsare all still pending, and the merge state is UNSTABLE. Re-triage once they are green.imm64_signedandvalu_imm_i64could be folded in a follow-up. A maintainer may want to pick merge order.@QemmHD on GitHub · 2026-11-25 10:01 UTC · original
Merging.
Why merged
v_cmp(x)_*_i64(and the other signed 64-bit VALU forms this PR covers) was zero-extended instead of sign-extended, so comparisons against negative literals gave wrong results.3de22a190) on an RTX 4070 SUPER:tests/semanticVALU/VCMP files plus the PR's new test: 1,483 passed, 21,175 subtests passed, 0 failed;604ddff0b: 6,287 tests, 0 failed (main: 6,279);test_runtime_pathsworkflow check.Why it's good
valu_imm_i64/src64_i64are applied only to the signed 64-bit forms, and the unsigned paths are untouched.AI-assisted (Claude Code, Claude Opus 5.5).