[AIE] Handle large stack frames in adjustSPReg#1148
Open
atassis wants to merge 1 commit into
Open
Conversation
atassis
requested review from
F-Stuckmann,
SagarMaheshwari99,
abhinay-anubola,
abnikant,
andcarminati,
katerynamuts,
khallouh,
konstantinschwarz,
martien-de-jong,
mludevid,
niwinanto and
stephenneuendorffer
as code owners
July 19, 2026 23:01
atassis
force-pushed
the
adjustspreg-large-stack-frame
branch
from
July 22, 2026 14:49
e730384 to
ba15f63
Compare
adjustSPReg reported a fatal error ("adjustSPReg cannot yet handle adjustments
> +-2^N bytes") when a function's stack frame exceeded the range encodable by the
sp_imm pointer-add form (2^18 on AIE2P/AIE2PS, 2^17 on AIE2), so the backend
crashed instead of generating code. This is reachable whenever a function needs a
frame that large, for example at -O0 where large vector temporaries are not
coalesced and spill to the stack.
Materialize the offset in a modifier register with MOVXM and apply it with a
register-form pointer add. AIE2P and AIE2PS have a dedicated SP register-modifier
instruction, PADDXM_pstm_sp, the sibling of the sp_imm form (it defs and uses SP
implicitly). AIE2 has no register-form SP add and SP is reserved, so it copies SP
into a scratch pointer register, adds the offset there, and copies back, the same
sequence the backend already uses to update SP for a dynamic stack allocation.
The virtual scratch registers are resolved by the register scavenger
(requiresRegisterScavenging is true).
atassis
force-pushed
the
adjustspreg-large-stack-frame
branch
from
July 24, 2026 22:40
ba15f63 to
fb88982
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.
Problem
adjustSPRegemits the SP adjustment via thesp_immpointer-add form, which encodes a limited immediate (+-2^18 bytes on AIE2P/AIE2PS, +-2^17 on AIE2). For a larger frame it took areport_fatal_error(...)path, crashing the backend instead of generating code. This is reachable whenever a function needs a frame that large, e.g. at-O0where large vector temporaries spill to the stack. Minimal repro (aie2p):llc -O0 -mtriple=aie2pon that hits the fatal error.Fix
Materialize the offset in an
eMmodifier register withMOVXM, then apply it with a register-form pointer add:PADDXM_pstm_sp(paddxm [sp], $mod), the register-operand sibling of thePADDXM_pstm_sp_immused for small frames. It defs/uses SP implicitly, so the reserved SP register is not an explicit operand.MOV_mv_scl), add the offset there (PADDA_lda_ptr_inc_idx), and copy back to SP. This is the same sequence the backend already emits to update SP for a dynamic stack allocation.The virtual scratch registers are resolved by the register scavenger (
requiresRegisterScavengingis true on all three targets);adjustRegand the dynamic-alloca lowering already rely on the identical patterns.Testing
New tests
llvm/test/CodeGen/AIE/{aie2p,aie2ps,aie2}/large-stack-frame.ll(run with-verify-machineinstrs). Each checks that a larger-than-range frame emits the register-form SP adjust and that an in-range frame still uses the compactsp_immform (no regression). Verified for all three: the minimal repro that crashed now compiles, passes-verify-machineinstrs, and assembles to a valid object; the existing prolog/epilog and dyn-stackalloc tests still pass.Notes
adjustRegalsoreport_fatal_errors on large offsets (no register-materialization pattern to mirror), and it is the legacy target.MOVXMencodes a 32-bit signed immediate, which covers any representable stack frame.