[RegAllocFast] Consume SSA MachineIR, absorbing PHI and two-address lowering - #6
Open
MaskRay wants to merge 1 commit into
Open
[RegAllocFast] Consume SSA MachineIR, absorbing PHI and two-address lowering#6MaskRay wants to merge 1 commit into
MaskRay wants to merge 1 commit into
Conversation
…owering PHIElimination and TwoAddressInstructionPass cost 3.8-4.1% of llc -O0 time in whole-function rewrite walks, and the allocator then cleans up after their output. Teach RegAllocFast to consume SSA MachineIR, skipping both passes: * PHI sources and destinations are cross-block values, so they already live in dedicated stack slots. A source that dies in its incoming predecessor takes the destination's slot, making its spill the edge transfer; every other edge becomes a COPY in the predecessor, where the allocator often coalesces it away. A PHI whose destination could be read on another path out of a predecessor is lowered through a virtual register, as PHIElimination does. * A tied use that dies at the instruction takes over the tied def's register when its class contains it, and is otherwise copied into it, matching TwoAddressInstructionPass. * REG_SEQUENCE and INSERT_SUBREG expand to subregister COPYs. Targets opt in with TargetMachine::setEnableSSAFastRegAlloc(); X86 and AArch64 do. AMDGPU keeps the standard pipeline, anchoring SILowerControlFlow and SIWholeQuadMode on the skipped pass IDs. The SSA path requires the incoming MIR to carry IsSSA, so partial pipelines follow the MIR they are given; -regalloc-fast-ssa overrides the target default in either direction, and =0 restores byte-identical output. clang -O0: codegen for lld/ELF/Driver.cpp takes 276.6ms -> 264.2ms (-4.5%). On -O2 bitcode through llc -O0, where PHIs are plentiful, .text -1.17% (Driver.cpp) and -1.67% (ScalarEvolution.cpp); AArch64 -0.16%. CTMark builds, runs and verifies 10/10 at -O0 and at -O2 -regalloc=fast. RFC: https://discourse.llvm.org/t/make-regallocfast-consume-machineir-in-ssa-form/91607
MaskRay
force-pushed
the
fastra-ssa-preview
branch
from
August 19, 2026 07:52
19b1ad1 to
b1a072d
Compare
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.
PHIElimination and TwoAddressInstructionPass cost 3.8-4.1% of llc -O0 time in whole-function rewrite walks, and the allocator then cleans up after their output. Teach RegAllocFast to consume SSA MachineIR, skipping both passes:
Targets opt in with TargetMachine::setEnableSSAFastRegAlloc(); X86 and AArch64 do. AMDGPU keeps the standard pipeline, anchoring SILowerControlFlow and SIWholeQuadMode on the skipped pass IDs. The SSA path requires the incoming MIR to carry IsSSA, so partial pipelines follow the MIR they are given; -regalloc-fast-ssa overrides the target default in either direction, and =0 restores byte-identical output.
clang -O0: codegen for lld/ELF/Driver.cpp takes 276.6ms -> 264.2ms (-4.5%). On -O2 bitcode through llc -O0, where PHIs are plentiful, .text -1.10% (Driver.cpp) and -1.89% (ScalarEvolution.cpp); AArch64 -0.16%. CTMark at -O0 builds, runs and verifies 10/10.
RFC: https://discourse.llvm.org/t/make-regallocfast-consume-machineir-in-ssa-form/91607