Skip to content

TEST-982: Handle LLVM 23 true16 spelling in VALU tests - #4549

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
lahlousaad4:fix/llvm23-valu-true16
Nov 23, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
lahlousaad4:fix/llvm23-valu-true16

Conversation

@lahlousaad4

Copy link
Copy Markdown
Contributor

TEST-982 (claim, report).

Reuse the hardware oracle's fixed-instruction probe in the VALU tests so they choose the spelling the assembler accepts. Extend the existing true16 helper to spell bare low-half VGPRs in the affected binary float and integer forms. Keep explicit halves, operand selectors, packed forms and raw encodings intact. The GFX11 opcode test still compares the exact bytes, and it now reports the assembler's diagnostic when no encoding is available.

Tested

  • Reproduced both reported failures on 03b09a08 with AMDGPU-enabled LLVM/Clang 23.1.5 on Windows x64. Both pass with this change.
  • pytest -q tests/test_valu_fuzz.py tests/test_hw_oracle.py: 123 passed, 7 skipped. This includes the GFX11 opcode comparison and GFX11/GFX10 assembly tests.
  • Four additional binary f16 and i16 forms assembled on gfx1201 with explicit low-half registers.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested e3a855ea81 on Linux, Python 3.10, CPU only, synthetic fixtures, no game files: pass.

  • pytest tests/test_valu_fuzz.py tests/test_hw_oracle.py → 116 passed, 14 skipped (llvm-mc absent on this box), 3 subtests passed.
  • Negative control on main's tools/hw_oracle/asm.py + runner.py: 1 failed / 115 passed, so the true16 spelling cases discriminate even without llvm-mc.
  • The LLVM-23 v0.l spelling path itself needs AMDGPU llvm-mc 23, not available here.
  • git diff --check and check_no_game_data.py clean.

AI-assisted (Devin).

@Kam471 Kam471 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.

Ran this at e3a855ea on Windows 11: tests/test_hw_oracle.py -> 45 tests, OK (2 skipped); tests/test_valu_fuzz.py -> exit 0; git diff --check clean.

LLVM 23's true16 VALU spelling is now handled by the assembler/runner, with the added oracle tests passing. No AMD HIP runtime here, so only the CPU side is exercised. No blocking issue.

@tupacfan04

Copy link
Copy Markdown
Contributor

Tested at the head (e3a855ea) on Windows 11 / Python 3.13.0: pytest tests/test_hw_oracle.py tests/test_valu_fuzz.py 116 passed / 14 skipped, standalone test_hw_oracle.py 45 OK (2 skipped), compileall and git diff --check clean, merge clean. Negative control: main's asm.py/runner.py with the new spelling test fails once.

Three notes:

  • docs/shader_validation.md:182-184 is now stale: it still says the oracle spells only the two conversions and seven unary ops, and that "another f16 op needs adding", while tools/hw_oracle/asm.py:362-366 now spells binary ops too. Please update it in this PR.
  • The actual LLVM 23 fix is not verifiable here (no LEONIDA_AMD_CLANG/llvm-mc, so tests/test_valu_fuzz.py:341,364 skip). Also asm.py:364-366 omits v_fmac_f16, v_fma_f16, v_med3_f16, v_add_nc_u16 and v_sub_nc_u16 (tools/valu_fuzz.py:404-414); the VOP3 ones are skipped via the op_sel guard (:375). The author's LLVM-23 run says the bare forms assemble - a second check would confirm.
  • test_valu_fuzz.py:374-378 reuses the wave32 probe for wave64 kernels, relying on .l being accepted with -mwavefrontsize64, which is unverified here.

Approve with the docs update. AI-assisted review, no game files, no GPU.

@AGInformatique81 AGInformatique81 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.

Tested this head on WSL, CPython 3.14.7, using Debian's AMDGPU-enabled Clang and llvm-mc 21.1.8. With both LEONIDA_AMD_CLANG and LLVM_MC set, the two suites gave 122 passed, 7 hardware skips, and one failure. The opcode-table test fails identically on base 03b09a08, so this is an existing compatibility issue, not a regression introduced here.

On gfx1150, LLVM 21 accepts the bare-register spelling and encodes SRC2 as 0 for all eight two-source operations in the table. For example, v_mul_lo_u16 v20, v21, v22 gives 14 00 05 d7 15 2d 02 00, while vop3_words ends in 02 (SRC2 = 128). LLVM 21's own disassembler accepts its output and rejects the encoding ending in 02.

I tried clearing SRC2 in the expected test value when this PR's true16 probe is false, keeping the exact-byte comparison and leaving vop3_words untouched. That gave 123 passed, 7 skipped on this toolchain. This checks a toolchain encoding difference only. No hardware oracle, game data, or LLVM 23 run in this review. AI-assisted with Codex.

@lunarminus

Copy link
Copy Markdown

Tested e3a855ea on CachyOS Linux with Arch's LLVM/Clang 23.1.5 (LEONIDA_AMD_CLANG=/usr/bin/clang): pass. I had a fix for TEST-982 of my own in progress; I'm releasing the claim in favour of this PR, and here are the checks from it.

  • pytest tests/test_valu_fuzz.py: 78 passed with LLVM 23, where 03b09a08 has 2 failures. tests/test_hw_oracle.py: OK.

  • Encoding equivalence. I took every line F16Family.hw_body("gfx11") writes for 400 programs per wave size (seed 7), plus a few hand-written forms with SGPR, constant and modifier operands. Each line went through llvm-mc twice:

    • the old spelling, under -mattr=-real-true16, which puts LLVM 23 back in fake16 mode;
    • this PR's true16_spelling, under LLVM 23's default.

    For gfx1100, gfx1103, gfx1150 and gfx1200: 19,252 lines encode byte-identically, 0 differ. So the respelling is exact for everything the fuzzer emits.

  • The only lines it misses are v_subrev_f16 (_e32/_e64, 7 lines). It isn't in _TRUE16_BINARY, so it stays bare, and LLVM 23 rejects it. The f16 family never generates it today (F16_BIN has no subrev), so this isn't a bug now. Adding subrev to the alternation makes all 19,259 identical, which I checked with the same harness.

Two optional suggestions, from my version:

  1. v_subrev_f16 in _TRUE16_BINARY, as above.
  2. Check op_sel too. With a true16 assembler, test_gfx11_opcode_table_matches_llvm_mc can check the op_sel bit layout that hw_body writes as .long words. Before, no assembler could spell it; now v20.h does. With LLVM 23.1.5 this passes for all 8 ops in GFX11_VOP3_OPCODE:
    for bits in ((1, 0, 0), (0, 1, 0), (0, 0, 1), (1, 1, 1)):      # src0, src1, dst
        h = lambda r, b: f"v{r}.{'h' if b else 'l'}"
        text = f"{name}_e64 {h(20, bits[2])}, {h(21, bits[0])}, {h(22, bits[1])}\n"
        sel = bits[0] | bits[1] << 1 | bits[2] << 3
        w0, w1 = vf.vop3_words(opcode, 20, [21, 22], sel)
        # assemble text and compare its bytes with (w0, w1), as the test already does for sel = 0
    Then the hand-written opcode table and the op_sel field positions are both checked against LLVM.

AI-assisted (Claude Code).

@abnalstlll-byte abnalstlll-byte 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.

Independently tested head \e3a855ea\ on Windows 11 with native AMD Clang 23 (�.0.0git, ocm-sdk-core 10.0.0) and RDNA2 \gfx1036\ (\ ools/hw_oracle): 127 passed, 3 skipped, 0 failed. Confirmed true16 bare assembly and fuzzers run cleanly on the live AMD LLVM 23 toolchain. No game files. AI-assisted review (Gemini).

@memorypressure

Copy link
Copy Markdown

Verified on Linux: merges cleanly into current main; test_hw_oracle 46 OK (3 tool-gated skips) and test_valu_fuzz 73 passed / 5 skipped in the venv (re-run). The extended TRUE16_BINARY rewriter provably skips op_sel lines, comments, .long encodings and v_pk*, and the idempotence tests confirm re-runs are unchanged. Heads-up: hw_oracle/asm.py, runner.py and test_hw_oracle.py are also touched by open #3954 and #4152 (verified in their diffs) — whoever lands second rebases. Checks pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@ItsNotRexed
ItsNotRexed merged commit d7f08f4 into ItsNotRexed:main Nov 23, 2026
2 of 4 checks 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.

9 participants