Shader: ignore guarded or modified v_mov_b32 in Lower::konst #2448
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!2448
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2448/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?
@Texbirds on GitHub · 2026-11-25 13:39 UTC · original
Texbirds:fix/shader-konst-respect-guards-and-modifiers→main· +92 −8 · 1 files · 1 commits · merged 2026-11-25 21:56 UTCProblem
In
crates/victory-shader/src/emit/lower.rs,Lower::konst()(used bydead_on_edge()viacompared()to prove branch conditions constant and discard dead incoming phi edges) treats anyv_mov_b32withsdwa.is_none() && dpp.is_none()as unconditionally producing its raww.src[0]constant bits.That misses two cases already handled elsewhere in
lower.rs:self.x.st.guards[b][i].is_some(), cf.whole()at line 8574): a guardedv_mov_b32 v1, 0only writes0in active lanes; inactive lanes preserve their previous register value, sov1is not unconditionally0.w.abs != 0 || w.neg != 0 || w.clamp || w.omod != 0, cf.v_mov_b32lowering at line 5636):v_mov_b32_e64 v1, -(1.0)writes-1.0f(0xBF80_0000), not the unmodified source1.0f(0x3F80_0000).In either case,
dead_on_edge()can falsely prove a branch condition constant and drop a live incoming phi edge.Change
Lower::def_site(v)returning(block, inst_index, &Inst)(withdef_instdelegating to it).Lower::konst(), returnNonewhenself.x.st.guards[b][i].is_some(), and requirew.abs == 0 && w.neg == 0 && !w.clamp && w.omod == 0in addition tow.sdwa.is_none() && w.dpp.is_none()forv_mov_b32.v_mov_b32,s_mov_b32,s_movk_i32, andcompared()are unchanged.Test
guarded_or_modified_v_mov_b32_is_not_folded_as_constant(synthetic GFX10 compute shader words followinga_value_no_lane_from_its_edge_reads_needs_no_form, cross-platform, no game data):v_mov_b32:v1is initialized to-1, thenv_mov_b32 v1, 0runs underv_cmpx_eq_u32 exec, 0, v0. Inactive lanes keep-1, pass the join comparev_cmp_eq_u32 vcc_lo, -1, v1, and reads6(s_memtime, unsupported in DXIL). Asserts lowering refuses it identically to a direct read (onmain,dead_on_edgefalsely foldsv1to0and accepts it). Replacing the guard withs_nopverifies unguardedv_mov_b32still folds and lowers.v_mov_b32_e64:v_mov_b32_e64 v1, -(1.0)([0xD581_0001, 0x2000_00F2]) writes-1.0f, matchingv_cmp_eq_u32 vcc_lo, -1.0, v1sos6is live. Asserts lowering refuses it identically to a direct read (onmain,konstignoresnegand folds1.0f != -1.0f). Clearing thenegbit (0x0000_00F2) verifies unmodifiedv_mov_b32_e64still folds and lowers.@kotekompotek on GitHub · 2026-11-25 14:26 UTC · original
Both holes are real miscompiles: a guarded
v_mov_b32only writes active lanes (inactive lanes keep the old value — the test'sv_cmpxcase shows the folded constant leaking into lanes that kept-1), and VOP3neg/abs/clamp/omodtransform the source (-(1.0)folds to the wrong sign). Checkingguardsat the def site plus the modifier fields is the right granularity — unguarded plain moves still fold. The test's refusal-equality trick (guarded program must fail the same way as the directs_memtimeread) is a clean way to pin liveness through the fold.@cloph-dsp on GitHub · 2026-11-25 14:49 UTC · original
Independent local validation (Windows, Rust 1.100.0/MSVC, head 8f5cf05, no game data):
cargo test --locked -p victory-shader --lib-> 248 passed, 0 failed, 3 ignored, exit 0;git diff --check HEAD~1 HEADclean. The lib test count matches upstream main, so this is a compile/regression check only; I did not independently replay the synthetic guarded/modified v_mov_b32 scenario in Lower::konst. AI-assisted (Hy4 flash). GPU/driver: N/A for the CPU test run. No game data, assets or extracted content used.@Marvisak on GitHub · 2026-11-25 16:08 UTC · original · edited 2026-11-25 16:45 UTC
Automated triage for the maintainers.
Merge candidate.
Lower::konst(emit/lower.rs) no longer folds av_mov_b32whose definition is EXEC-guarded (st.guards[b][i]), or one with VOP3abs/neg/clamp/omod. Both folds were wrong: a guarded move keeps the old value in inactive lanes, and the modifiers change the result. This matches howmainalready handles both:whole()checks the same guard, and thev_mov_b32lowering goes the float path under the same modifiers. Without the fix,dead_on_edgecould drop a live phi edge. I checked the test's encodings by hand (v_cmpx_eq_u32,v_cmp_eq_u32,v_mov_b32_e64withnegat bit 29 of word 1). Each case has a control showing that the unguarded or unmodified move still folds. The newdef_sitehelper is shared withdef_inst.CI:
checkpassing.Generated by Claude Code
@Texbirds on GitHub · 2026-11-25 16:23 UTC · original
Rebased cleanly onto
main(67e8ae1) ind5f7b7b(resolved the test-insertion conflict incrates/victory-shader/src/emit/lower.rs).