Repository navigation
perf(shader): fold integer compares by value sets and known bits - #6176
Conversation
|
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.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Windows NVIDIA run, since the description lists RADV only. Windows 11 Pro 26200, NVIDIA GeForce RTX 4080 (driver 617.42), AMD Ryzen 7 5800X, WinLibs GCC 15.2.0 r7, Ninja, Release, bundled dependencies,
Correctness only; no performance measurement and no title run. AI-assisted: yes (runs done with Claude Code). |
|
Tested on Linux (Arch),
Most likely cause: lavapipe runs subgroups of 8 here (other tests print "subgroup size 8 does not hold exactly one wave32"), so a wave32 Suggested fix: skip with Separately, this PR breaks two existing tests when merged with an older open PR (same
This is the check at
The two PRs share no file (#5353 changes AI-assisted: yes |
IEqual32 and INotEqual32 against a constant fold when the other operand has a value set of at most 64 values (built through shifts, bitfield extracts, and/or/xor/mul/umin with a constant, add and select) that excludes the constant or holds only it, or when a known bit of the operand contradicts the constant. Known bits come from constants, shifts and bitfield extracts by constants, and/or/xor, add (up to the first unknown bit), mul (trailing zeros), umin, select, phi and lane reads. The value set of x & mask leaves out the known bits of x. ULessThan32 against a constant folds from the known-bit and value-set bounds. A fold pass computes the known bits and value set of each compared operand once, so a chain of compares against one operand does not repeat the analysis, and a sum is not enumerated when its two operand sets hold more than 65 values together, since without wraparound it then has more than 64 values. All folds are identities of the operand's possible values; out-of-range M0 handling of the relative indexing lowerings is unchanged. With M0 = 4i + k, three of every four entries of an s_movrels/s_movreld compare chain fold away.
SPIR-V specialization emitted a new OpConstant for every folded result. A folded value now reuses the id of an existing constant of the same type and value for the operands the specialization decodes (VisitInputs); consumers it does not decode, such as subgroup and extended instructions, keep their own constant definitions, and the unused-constant removal keeps those definitions while anything names them. An OpBitcast to its operand's type or back to the type before a previous bitcast becomes a copy. A compute program with one formatted load shrinks from 10730 to 1117 words, so the formatted-load sharing check compares the words two more loads add with the words the first one added instead of with the module size.
…less than a wave32
088f950 to
6d73220
Compare
|
This pull request is labeled |
…R-V constant sharing) at 088f950 # Conflicts: # core/shader/recompiler/SpirvBackend/src/SpirvSpecialization.cpp
…onstant of its value boykopovar#6176 aliases every folded result to the first module constant of the same type and value. A select that boykopovar#5315's dead-constant test folds to a copy of one constant then aliased to the variant's own selector constant whenever the two held the same value, so variants that differ only in that folded constant kept it (and its name) and specialized to different SPIR-V (agc_shader_disk_cache). A folded OpCopyObject now aliases to its source constant (or that constant's alias); other folds keep boykopovar#6176's canonical choice. AI-assisted: yes
boykopovar#5353 reads the buffer stride at run time in compute modules, so the linear and swizzled buffer addresses multiply the stride instead of a specialization constant. With index 0 the swizzled index MSB folds to 0, and boykopovar#6176 shares that folded 0 with the module's own 0, so both address forms emitted the same OpIMul 0, stride in one block (agc_redundant_value_elimination: 2 repeats). The specializer now folds OpIMul with a known 0 operand to 0, which removes the dead address arithmetic of both forms. AI-assisted: yes
…ts referenced constants agc_spirv_optimizer (built with ANYPS5_ENABLE_SPIRV_TOOLS, as upstream's Linux job does; build-local has it off) failed on this branch before today's local fixes as well. boykopovar#6176's test counted five module constants: %one and %three stayed because nothing removed unreferenced module constants on its head. boykopovar#5315 now drops them, so the module keeps %two, 7 and 8, the three the stored lane + 23 reads. The test expects 3. AI-assisted: yes
…R-V constant sharing) at 088f950 # Conflicts: # core/shader/recompiler/SpirvBackend/src/SpirvSpecialization.cpp
…onstant of its value boykopovar#6176 aliases every folded result to the first module constant of the same type and value. A select that boykopovar#5315's dead-constant test folds to a copy of one constant then aliased to the variant's own selector constant whenever the two held the same value, so variants that differ only in that folded constant kept it (and its name) and specialized to different SPIR-V (agc_shader_disk_cache). A folded OpCopyObject now aliases to its source constant (or that constant's alias); other folds keep boykopovar#6176's canonical choice. AI-assisted: yes
boykopovar#5353 reads the buffer stride at run time in compute modules, so the linear and swizzled buffer addresses multiply the stride instead of a specialization constant. With index 0 the swizzled index MSB folds to 0, and boykopovar#6176 shares that folded 0 with the module's own 0, so both address forms emitted the same OpIMul 0, stride in one block (agc_redundant_value_elimination: 2 repeats). The specializer now folds OpIMul with a known 0 operand to 0, which removes the dead address arithmetic of both forms. AI-assisted: yes
…ts referenced constants agc_spirv_optimizer (built with ANYPS5_ENABLE_SPIRV_TOOLS, as upstream's Linux job does; build-local has it off) failed on this branch before today's local fixes as well. boykopovar#6176's test counted five module constants: %one and %three stayed because nothing removed unreferenced module constants on its head. boykopovar#5315 now drops them, so the module keeps %two, 7 and 8, the three the stored lane + 23 reads. The test expects 3. AI-assisted: yes
What
Two commits.
Integer compare folding:
IEqual32andINotEqual32against a constant fold when the other operand has a value set of at most 64 values (through shifts, bitfield extracts, and/or/xor/mul/umin with a constant, add and select) that excludes the constant or holds only it, or when a known bit of the operand contradicts the constant. Known bits come from constants, shifts and bitfield extracts by constants, and/or/xor, add (up to the first unknown bit), mul (trailing zeros), umin, select, phi and lane reads.ULessThan32against a constant folds from the known-bit and value-set bounds. A fold pass computes known bits and value set once per compared operand, and a sum is not enumerated when its two operand sets hold more than 65 values together. All folds are identities of the operand's possible values; out-of-range M0 handling of the relative indexing lowerings is unchanged. With M0 = 4i + k, three of every four entries of ans_movrels/s_movreldcompare chain fold away.SPIR-V constant sharing: specialization emitted a new
OpConstantper folded result. A folded value now reuses an existing constant of the same type and value for the operands the specialization decodes; other consumers (subgroup, extended instructions) keep their own definitions. AnOpBitcastto its operand's type, or back to the type before a previous bitcast, becomes a copy. A compute program with one formatted load shrinks from 10730 to 1117 words, so the formatted-load sharing check now compares the words two more loads add with the words the first added.Tests:
IntegerFolding, additions toSpirvOptimizer, and the execution testRelativeIndexingKnownBits.Tested
Linux, RX 9060 XT (RADV GFX12, local Mesa). Full
ctestpasses exceptagc_driver_tessellation, which segfaults inside RADV while linking pipeline libraries on unmodified upstream 703aa8f as well.Performance, old base (upstream d539606 + #454 + the 1D fix), Astro Bot hub, GPU busy per frame: 166 ms vs 172-179 ms (-4 to -5%); with
APS5_LOOP_GUARD=64, 136 ms vs 141-143 ms. Not re-measured individually on 703aa8f.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code