Skip to content

tests/semantic: the folded SMEM loads read the word at the folded offset - #4047

Open
slint6614-dev wants to merge 1 commit into
ItsNotRexed:mainfrom
slint6614-dev:test/const-prop-load-values
Open

slint6614-dev wants to merge 1 commit into
ItsNotRexed:mainfrom
slint6614-dev:test/const-prop-load-values

Conversation

@slint6614-dev

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: new TEST item, #3918 (comment)

What and why

Nine tests in tests/semantic/test_salu_chained_const_prop.py fold a SALU chain into an s_buffer_load_dword offset and assert only that no branch diamond is emitted. A wrong fold that stays inside the buffer still gives a straight-line load, just from the wrong address, so these tests could not catch a broken sgpr_imm value.

This adds assert_loads_offset(): it runs the translated shader through spirv_mini_interp (via support.mrt0_words) with a buffer whose words encode their own byte offset (0xA000 + offset), and checks the loaded word. SMEM ignores the low two offset bits, so s_lshl2_add_u32's offset 69 reads the word at 68. The existing no-branch checks stay. Test-only change; the translator is untouched.

Tested

Linux (WSL2), CPython 3.14.4, CPU only, no GPU, no game files, at aa2988cc:

  • python -m unittest discover -s tests/semantic -p test_salu_chained_const_prop.py: 11/11 pass.
  • python -I tests/test_text_write_line_endings.py: pass. git diff --check: clean.

Mutation check: I changed one sgpr_imm fold at a time in tools/rdna2spirv.py, then reran this file. Before this change, I also ran the 26 other test files that use these ops, run as CI runs them and all green on main first.

Mutation of the fold main: this file + 26 others this PR: this file
s_add_u32 (+4) not caught caught
s_sub_u32 (+4) not caught caught
s_lshl2_add_u32 (+4) not caught caught
s_andn2_b32 (NOT dropped) not caught caught
s_min_u32 (returns max) not caught caught
s_bfm_b32 (- 1 dropped) not caught caught
s_absdiff_i32 (+4) caught by 3 other files caught

(s_add_u32 was checked against this file only on main. tests/test_cf_diff.py needs pytest and was not run. tests/semantic/test_loop_ballot_barrier.py was left out because it is already red on main; #3995 fixes it.)

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No new rule: test-only.)

AI-assisted (Claude Code).

🤖 Generated with Claude Code

https://claude.ai/code/session_013nWg6BssUf8MjNaKuMSkfc

Nine tests in test_salu_chained_const_prop.py fold a SALU chain into an
s_buffer_load_dword offset and asserted only that no branch diamond is
emitted. A wrong fold that stays inside the buffer still gives a
straight-line load, just from the wrong address, so a broken sgpr_imm
fold for s_add_u32, s_sub_u32, s_lshl2_add_u32, s_andn2_b32, s_min_u32
or s_bfm_b32 passed this file and every other test that uses those ops.

Run each translated shader through spirv_mini_interp with a buffer whose
words encode their own byte offset, and assert the loaded word. The
existing no-branch checks stay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013nWg6BssUf8MjNaKuMSkfc
@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Independent Windows CPU check of 9f9681f against aa2988c. All 11 tests in test_salu_chained_const_prop.py passed. For a separate control I kept translation and interpretation unchanged and shifted the synthetic memory markers by four. The real interpreter then returned 41032 for the folded 69-byte offset and the new assertion rejected it, expecting 41028 for aligned offset 68. The existing structural checks still ran before that assertion. This verifies the output assertion can distinguish adjacent word markers. No GPU or native build ran.

AI-assisted.

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 9f9681f. The added interpreter-backed assertions exercise the loaded word, including aligned SMEM addressing, rather than only checking the translated control flow. I independently ran the focused unittest file on Windows: 11/11 passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants