Repository navigation
fix(shader): preserve integer narrowing in constant folding - #4195
Conversation
Remove unsafe U16/U8 round-trip cancellation and cover nonconstant, immediate, bitcast and dead-code cleanup paths with Release-active IR regressions.
|
The bug is real and the fix is minimal and correct. Worked through it with a concrete value: for a nonconstant Two things worth confirming, and both hold: the optimization isn't lost for the case where it's actually safe — a genuinely constant operand still gets caught by the earlier immediate-folding rules in the same pass, before it would ever reach the removed code, so No overlap with #3951, reviewed earlier tonight in this same file: that PR touches Written with AI assistance. |
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
|
|
Windows run, to go with the Linux one in the description. Setup: Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, CI configure flags, an RTX 4070 Laptop GPU and an Intel Raptor Lake-S iGPU. The head 3df53d9 merged into
Written with AI assistance. |
What
Prevent the shader constant folder from cancelling unsigned narrowing followed by widening for nonconstant operands.
ConvertU32U16(ConvertU16U32(x))andConvertU32U8(ConvertU8U32(x))are not identity operations for arbitrary 32-bit values: the conversions must discard the upper 16 or 24 bits respectively.Remove the two unsafe folding rules while preserving the existing immediate-conversion and bitcast optimizations.
Add a Release-active IR regression test covering nonconstant operands, narrowing boundaries, immediates, bitcasts, and dead-code cleanup.
Tested
BUILD_TESTING=ON,ANYPS5_ENABLE_SPIRV_TOOLS=ON).agc_integer_narrowing: 975 cases, 0 failures.agc_vector_windowfailed its function-scope array assertion. The identical failure was reproduced after rebuilding with the originalorigin/mainConstantFolder.cpp, then the proposed fix was restored and rebuilt.python3 tools/check_conventions.py --base origin/main: passed.Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repository