fix: resolve phi swap cycles in parallel copy lowering #140#145
Open
BibhabenduMukherjee wants to merge 2 commits into
Open
fix: resolve phi swap cycles in parallel copy lowering #140#145BibhabenduMukherjee wants to merge 2 commits into
BibhabenduMukherjee wants to merge 2 commits into
Conversation
Introduce a topological sort and cycle-breaking algorithm for phi move lowerings in both the textual assembly (Asm) and binary machine code (Rcu) generators. This resolves silent value corruption when two or more phi nodes form a circular swap dependency. Cycle-breaking is achieved by pushing the cycle-start value onto the machine stack and restoring it after walking the copy cycle. Added a new regression test package (Tests/PhiSwap) verifying correctness.
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.
Introduce a topological sort and cycle-breaking algorithm for phi move lowerings in both the textual assembly (Asm) and binary machine code (Rcu) generators. This resolves silent value corruption when two or more phi nodes form a circular swap dependency. Cycle-breaking is achieved by pushing the cycle-start value onto the machine stack and restoring it after walking the copy cycle.
Example of Failure
Consider a block transition that requires a register/stack slot swap between two variables a (
located at [rbp - 8]) and b (located at [rbp - 16]):Because the previous implementation of EmitPhiMoves iterated sequentially, it generated the following instructions:
Tests & Verification
We registered a new regression test package, Tests/PhiSwap, containing a loop-based Fibonacci accumulator swap which naturally generates parallel-copy cycles during lowering.
Test Source (
Tests/PhiSwap/Src/Main.rux):Verification Results:
CTest Suite: The new test was successfully registered under CMake and ran as part of CTest:
Executable Exit Code: Running the compiled debug binary directly exits with status code 0, confirming that the Fibonacci numbers computed correctly without any variable corruption: