Repository navigation
shader_ir: read LLVM 23's lit(V) operand as the constant V - #6808
Conversation
llvm-mc 23.1.5 prints a literal it could also show as an inline constant as
lit(V). In the pipeline library (docs/shader_library.md) that is 5,733 v_fma_mix*
sources, e.g. `v_fma_mix_f32 v139, lit(0x42200000), s104, neg(0)`. operand()
returned {"k": "raw"} for it, so translate() refused 1,520 programs with
"operand lit(...)". LLVM 21 is worse on the same bytes: it prints the inline
constant of the low half and drops the literal word.
lit(V) now parses as V; a '-' in front is the VOP3 neg modifier, as neg(V).
LLVM 23 still re-encodes only the literal's low half, which is the case
mix_literal() already repairs from the blob, so nothing else changes.
tests/semantic/test_fma_mix_literal.py: llvm-mc 23.1.5's own text and encoding
for an f32 source (clean and re-anchored listings) and for the case the file had
avoided (lit next to an inline constant), plus a refused mismatch. The first two
fail without the change. tests/test_shader_ir.py: lit forms parse as the plain
constant.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The new parser accepts a register inside a literal wrapper. A synthetic listing with Run this script from the repository root with import runpy
t = runpy.run_path("tests/semantic/test_fma_mix_literal.py")
program = t["program"](0, words="01 00 20 cc ff 04 02 02",
text="v_fma_mix_f32 v1, lit(v2), v2, 0")
words = t["FmaMixLiteralTest"]().run_ps(t["listing"](program), None)
print([hex(word) for word in words])Expected: reject On Windows, all 38 shader IR tests and all 10 FMA mix literal tests passed with CPython 3.14.7. AI-assisted. |
Review on ItsNotRexed#6808 (@shdann): lit(v2) parsed as v2, so a synthetic listing with a register in the wrapper ran as if the register were there. Only a number is unwrapped now (hex, decimal or float, optionally negative); lit(v2) keeps its text, which translate() refuses, as on main. The pipeline library's 5,733 lit operands are all hex constants. Tests: test_fma_mix_literal.py runs the review's listing and expects Unsupported; test_shader_ir.py checks lit(v2), lit(s4), -lit(v2) and lit(vcc_lo) are not unwrapped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@shdann right, thanks. Fixed in the new head commit:
The library's 5,733 |
shayderrr
left a comment
There was a problem hiding this comment.
Summary
tools/shader_ir.py operand() now unwraps LLVM 23's lit(V) to the numeric constant (with -lit(V) read as neg(V)) while leaving lit(v2) raw so the translator still refuses it. docs/design.md notes the form in the printed-encodings row. tests/semantic/test_fma_mix_literal.py and tests/test_shader_ir.py add lit-form, register-in-lit, and blob-mismatch cases.
Why merge
LLVM 23 prints 5,733 pipeline-library v_fma_mix* literals as lit(...), which were previously refused as "operand lit(...)", blocking 1,520 programs. With the fix 1,496 translate and pass spirv-val. This is essential for recompiling the shader library with current LLVM.
Verdict: Approve
Summary
Why mergeLLVM 23 prints 5,733 pipeline-library Verdict: Approve |
…s none of ItsNotRexed#6808 reads LLVM's lit(V) as the constant V. llvm-mc's assembler encodes lit(V) as the literal dword V even when V is an inline constant, but the 64-bit float readers tell a literal from an inline constant by value (v_cmp_*_f64, v_ldexp_f64) or by a 0x spelling (parse_line's f64_literal), so a decimal lit(1) on v_add_f64, or lit(0x1) on v_cmp_*_f64 / v_ldexp_f64, read as the inline integer 1 in bits 31:0 instead of the literal in bits 63:32. operand() now marks the imm "literal", parse_line and v_ldexp_f64 honour the mark (read_f64_words and cmp_class_f64 already did), and lit(-1), lit(1.0), a value past one dword and lit64() stay "special" (Unsupported) instead of reading as an imm/fimm whose meaning depends on the operand type. LLVM's disassembler prints lit() only in hex and only where the literal and the inline constant give the same value, so no translation of its listings changes. tests/semantic/test_lit_literal.py (new fixture lit_f64_inline_range.asm) fails on main and passes here; ItsNotRexed#6808's operand test now expects the mark. AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claimed in #5781 (comment).
What
llvm-mc 23.1.5 prints some literals as
lit(V), for examplev_fma_mix_f32 v139, lit(0x42200000), s104, neg(0) op_sel_hi:[0,1,0]. It does this when the literal could also be shown as an inline constant: an f32v_fma_mix*source, or a literal whose low half is an inline f16 constant.shader_ir.operand()returned{"k": "raw"}for that form, sotranslate()refused the program with "operand lit(...)".lit(V)now parses as V. A-in front of it is the VOP3 neg modifier, so-lit(V)reads asneg(V), not integer negation. Nothing else changes: LLVM 23 still re-encodes only the literal's low half, andmix_literal()already restores the full literal from the blob in that case.LLVM 21.1.8 is worse on the same bytes. It prints the inline constant of the low half and consumes 8 bytes instead of 12, dropping the literal word:
With LLVM 21 the printed-encoding check refuses such programs; with LLVM 23 they now translate.
Where it matters
The pipeline library in
shaders.rpf(docs/shader_library.md) has 5,733 such operands in 2,809 programs. None appear in the carved FSSM corpus, whose LLVM 23 runs are already at 26,503/26,503.On the 2,809 programs, disassembled with llvm-mc 23.1.5 for
gfx1013(counts only):main561b65a8spirv-valThe rest stop at other refusals, mostly the FSPX wave32 check (#6809,
s_bfm_b64in wave32 code) and undecodable words.Tests (CPU, no game data)
tests/semantic/test_fma_mix_literal.py:lit(0x3c000001)next to an inline constant;The first two fail without the change.
tests/test_shader_ir.py: thelitforms parse as the plain constant.With the three PRs merged locally (rdna2spirv: write the compute thread-group SGPR (TG_SIZE_EN) #6446, this one, and rdna2spirv: s_bfm_b64 in wave32 code is 64-bit data, not a lane mask #6809):
tests/semantic,tests/test_lane_masks.pyandtests/test_shader_ir.pygive 6,210 passed, 1 skipped, 1 xfailed, no failures.tests/test_rdna2_decode.py::test_parity_with_llvm_mc_on_shader_fixturesfails the same way onmainwith llvm-mc 21.1.8:v_permlane16_b32printsop_sel:[0,1]. That is unrelated to this change.docs/design.md: one sentence in the "Printed encodings" row.AI-assisted (Claude Code). Windows 11, Python 3.12, llvm-mc 21.1.8 and 23.1.5 (built with
scripts/build_llvm_mc.ps1), no GPU used.🤖 Generated with Claude Code