Repository navigation
Keep a pipelined loop's scratch registers off values live across it. - #8
Merged
Merged
Conversation
The software pipeliner takes scratch registers for the values it rotates from VF31 down, skipping only the registers the loop body names. A register holding a value the body does not name, but that is read after the loop or on the next trip of an enclosing loop, counted as free, and a rotation overwrote it. In ps2gl's general program the directional light loop took the registers of material_spec and vert_to_eye, so the next light and the point lights read garbage. Work out which VF lanes are live where each loop is entered and left, over the whole program's control flow, and keep those registers out of the scratch pool along with the ones the body names. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The generic software pipeliner picks scratch registers for the values it rotates from VF31 down, skipping only the registers the loop body names. A register that holds a value the body never names, but that is read after the loop or on the next trip of an enclosing loop, counts as free, and a rotation overwrites it.
ps2gl's
generalprogram hits this with the default pipelining. The directional-light vertex loop's rotations take the registers holdingmaterial_specandvert_to_eye. Both were loaded before the loop and are read again for the next light and by the point-light loop. Those later passes then compute with garbage.general_pv_diffhas the same problem.Fix
findVuLoopCandidatesnow works out which VF lanes are live where each loop is entered and where it is left. It uses lane-level liveness over the whole program's control flow: labels, branches,bal/jrreturns,--endexit, andout_vfread at the exit. The result is stored inVuLoopCandidate::liveVfRegisters.collectLoopVfBaseKeysadds those registers to the ones the body names, so all three scratch pools keep clear of them.Effect
generalandgeneral_pv_diffchange. Every vu-checker register-allocation finding they had is gone, and nothing new appears. The other 10 compile byte-identical.Tests
test/integration/test_pipeline_live_registers.cppadds two cases. Both fail on master without this fix:Not covered
The env-gated generic kernel rewrite has its own rename pool, which this change doesn't touch. That path is not enabled by default.