diff --git a/src/coreclr/jit/compiler.cpp b/src/coreclr/jit/compiler.cpp index 998a7d7717d12d..b02c5938a0e122 100644 --- a/src/coreclr/jit/compiler.cpp +++ b/src/coreclr/jit/compiler.cpp @@ -4950,14 +4950,6 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl // call and register argument info, flowgraph and loop info, etc. compJitStats(); -#ifdef TARGET_ARM - if (compLocallocUsed) - { - // We reserve REG_SAVED_LOCALLOC_SP to store SP on entry for stack unwinding - codeGen->regSet.rsMaskResvd |= RBM_SAVED_LOCALLOC_SP; - } -#endif // TARGET_ARM - if (compIsAsync()) { DoPhase(this, PHASE_ASYNC, &Compiler::TransformAsync); diff --git a/src/coreclr/jit/lsra.cpp b/src/coreclr/jit/lsra.cpp index 68bd77e9c70971..0a712d4c82df3e 100644 --- a/src/coreclr/jit/lsra.cpp +++ b/src/coreclr/jit/lsra.cpp @@ -2717,6 +2717,16 @@ void LinearScan::setFrameType() } #endif // TARGET_ARMARCH || TARGET_RISCV64 +#ifdef TARGET_ARM + if (compiler->compLocallocUsed) + { + // We reserve REG_SAVED_LOCALLOC_SP to store SP on entry for stack unwinding + compiler->codeGen->regSet.rsMaskResvd |= RBM_SAVED_LOCALLOC_SP; + JITDUMP(" Reserved REG_SAVED_LOCALLOC_SP (%s) due to localloc\n", getRegName(REG_SAVED_LOCALLOC_SP)); + removeMask |= RBM_SAVED_LOCALLOC_SP.GetIntRegSet(); + } +#endif // TARGET_ARM + if ((removeMask != RBM_NONE) && ((availableIntRegs & removeMask) != 0)) { // We know that we're already in "read mode" for availableIntRegs. However,