shader_ir: preserve sign inside lit(-V) instead of turning it into VOP3 neg(V) (SHADER-IR-LIT-NEGATIVE-SIGN) #2013
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!2013
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/shader-ir-lit-neg"
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?
Pull request successfully merged and closed
Claimed in #1608 as
SHADER-IR-LIT-NEGATIVE-SIGN.What and why
tools/shader_ir.py::operand, thelit(...)unwrap checkedif t.startswith("-"):after substitutinglit(V)->V:lit(...)such aslit(-1)orlit(-0x10)became"-1"/"-0x10"and was immediately rewritten to"neg(1)"/"neg(0x10)"— i.e.,{"k": "imm", "v": 1, "neg": True}instead of{"k": "imm", "v": -1}!tools/rdna2spirv.py,"neg": Trueapplies a VOP3 sign-bit XOR (^ 0x80000000), sos_mov_b32 s4, lit(-1)andv_add_nc_u32_e32 v2, lit(-0x10), v0silently produced0x80000001andv0 + 0x80000010instead of0xFFFFFFFFandv0 - 16.outer_neg = t.startswith("-")before_LIT.sub(r"\1", t)keeps a leading-onlit(...)itself as the VOP3neg(...)modifier (e.g.,-lit(0x3f800000),-lit(-1.5),-|lit(-1.5)|) while preserving the negative value insidelit(-V)(matchingoperand("-1"),operand("-0x10"),operand("-1.5")).Testing
tests/test_shader_ir.py::OperandTests::test_llvm23_lit_is_the_constantwithlit(-1),lit(-0x10),lit(-1.5),-lit(-1),-lit(-1.5),|lit(-1.5)|,-|lit(-1.5)|,neg(lit(-1)).tests/semantic/test_shader_ir_lit_neg.pyend-to-end throughtools/rdna2spirv.py+spirv_mini_interp.py.origin/main:tests/semantic/test_shader_ir_lit_neg.pyfails onorigin/mainwith2147483649 (0x80000001) != 4294967295 (0xFFFFFFFF).python -I tests/test_shader_ir.py -v(39/39 OK)python -I tests/test_shader_ir_parse.py -v(3/3 OK)python -I tests/semantic/test_shader_ir_lit_neg.py -v(1/1 OK)python -I tests/test_text_write_line_endings.py(3/3 OK)python -m compileall -q tools/shader_ir.py tests/test_shader_ir.py tests/semantic/test_shader_ir_lit_neg.pypython -I scripts/check_no_game_data.py tools/shader_ir.py tests/test_shader_ir.py tests/semantic/test_shader_ir_lit_neg.pygit diff --checkApproving
9b7af801. I verified it onmain747809e7 (merged cleanly).-in front oflit(...)is the VOP3 neg modifier now. A-insidelit(-V)stays part of the constant, solit(-1)is no longer read asneg(1). The fix is a small, local change inoperand().tests/semantic/test_shader_ir_lit_neg.pyis OK, andpytest tests/test_shader_ir.pygives 39 passed.main'stools/shader_ir.pythe new semantic test fails, and 3test_shader_ir.pycases fail.Ubuntu 26.04, Python 3.14, LLVM 21.1.8, SPIRV-Tools 2026.1.
AI-assisted review, CPU only.
#2013 | head 9b7af801d9f0df7c2e1f035414cd88656a838d63 (merged cleanly with main 039870ea2) |
python -I tests/test_shader_ir.py && python -I tests/semantic/test_shader_ir_lit_neg.py| red on main:FAILED (failures=3)intest_shader_ir.py(lit(-1)rewritten toneg(1)0x80000001instead of0xFFFFFFFF) andFAILED (failures=1)intest_shader_ir_lit_neg.py| green on PR+main:39 tests OKand1 test OK| Windows 11, Python 3.12.10 | AI-assisted: yesAudited
outer_neghandling inshader_ir.operand(tools/shader_ir.py) solit(-V)preserves negative integer/float constants while leading-lit(...)still emits VOP3neg(...). Also passedtests/test_ci_registration.py(18 OK),tests/test_text_write_line_endings.py(3 OK),tests/test_runner_calls_all_tests.py(3 OK), andscripts/check_no_game_data.py.Red/green: tests/test_shader_ir.py fails 3 assertions and tests/semantic/test_shader_ir_lit_neg.py fails 1 on main because lit(-1) is read as neg(1), and both pass with the PR.
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main cb7a239cc in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)