Shaders: v_mad_i64_i32 sign-extends a negative literal addend #2380
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2380
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2380/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?
@Melow-code on GitHub · 2026-11-25 12:19 UTC · original
upstream-mad-signext→main· +21 −2 · 1 files · 1 commits · closed without mergingThe addend (src2) of
v_mad_i64_i32isS2.i64(RDNA 2 ISA §12.12), so its 32-bit literal is sign-extended to 64 bits (§6.2.1). The existing guard insrc64matched only names that end in_i64, andv_mad_i64_i32ends in_i32(the multiplied inputs), so the literal fell to the zero-extending arm. Withsrc2 = -100,0 * 0 + src2gave0x00000000_ffffff9cinstead of-100.The guard now also matches
v_mad_i64_i32when the operand is src2 (k == 2).v_mad_u64_u32keeps its zero-extending arm unchanged.Verification
cargo test -p victory-shader --libon Linux: 145 passed, 0 failed, 2 ignored.v_mad_i64_i32_sign_extends_a_negative_literal_addend(VOP3B with literal -100 as the addend).Fixes #2253.
🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 4.6 [email protected]
@steven-seagull27 on GitHub · 2026-11-25 13:30 UTC · original
I ran a one-thread compute shader against the parent
940d32fand PR headd5dd05f. It reads both result VGPRs and compares them with CPU signed and unsigned 64-bit arithmetic. Each revision ran 32 operations per adapter, giving 64 dword readbacks.All eight parent mismatches were in the high dword of the signed instruction, with literal
0xffffff9cor0x80000000. For0 * 0 + literal(-100), both adapters returned0x00000000_ffffff9con the parent and0xffffffff_ffffff9con the PR. The unsigned instruction returned0x00000000_ffffff9con both revisions. Positive literal controls and all low dwords also matched throughout.The test commit also corrects the destination encoding in the translation-only fixture. VOP3B puts the vector destination in bits 7:0 and the scalar destination in bits 14:8, so
v[0:1], vccneeds0xd5776a00. Cherry-pickable test commit@rminzao on GitHub · 2026-11-25 14:53 UTC · original
This is the same
src64change as #2254, which was opened earlier and is triaged as a merge candidate, so one of the two can be closed.The difference is in the test.
v_mad_i64_i32_sign_extends_a_negative_literal_addendonly checks that the program lowers, andmainalready lowers it: with the fix hunk removed, the test still passes. #2254'smad_i64_i32_sign_extends_literal_addendreads the high dword back from the GPU, and it passes with this PR's fix on an Intel UHD (16-lane waves) and on WARP.The
k == 2guard is narrower than #2254's name check, but the result is the same:v_mad_i64_i32reads src0 and src1 as 32-bit sources and only src2 goes throughsrc64(lower.rs, thev_mad_u64_u32 | v_mad_i64_i32arm).Checked on Windows 11 against head
d5dd05f: Intel UHD Graphics (31.0.101.4146) and WARP. AI-assisted.@Marvisak on GitHub · 2026-11-25 14:54 UTC · original
Automated triage for the maintainers.
Needs work (small). The fix itself is right. In
src64(crates/victory-shader/src/emit/lower.rs),v_mad_i64_i32's src2 is a signed 64-bit operand (public RDNA2 ISA:S2.i64), so its literal should sign-extend like the_i64operands already do, andv_mad_u64_u32stays zero-extended. But the new testv_mad_i64_i32_sign_extends_a_negative_literal_addendonly checks that lowering succeeds, not the value, so it passes onmaintoo. Its first word0xD577_006Aalso puts0x6Ain the vector destination field (bits 7:0) and 0 in the scalar destination (bits 14:8);v[0:1], vccis0xD577_6A00.What would change the verdict: fix the encoding and assert the result on the GPU. The cherry-pickable readback test linked in the thread (
63a66f2, signed and unsigned against CPU arithmetic; 8/64 mismatches onmain, 0 with this PR on RTX 5080 and WARP) does both.CI:
checkpassing.Generated by Claude Code
Pull request closed