Arm64: keep SP in base operand for large-offset adds#130467
Conversation
Fixes dotnet#130437 When generating large stack offsets, the base register can be SP. Therefore ensure that base is not used for reg3.
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
There was a problem hiding this comment.
Pull request overview
This PR adjusts ARM64 add operand ordering in a couple of codegen/emitter paths so that when the base register is SP (possible for large stack offsets), SP is used in the “base” operand position rather than the third operand position, avoiding the assert(isGeneralRegister(reg3)) constraint in emitIns_R_R_R.
Changes:
- In
emitInsLoadStoreOp, swap theaddoperands for the large-offset materialization so the base register isreg2and the temp remainsreg3. - In
CodeGen::instGen_Set_Reg_To_Base_Plus_Imm, swap theaddoperands in the large-immediate fallback for the same reason.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/coreclr/jit/emitarm64.cpp | Reorders add operands in the large-offset address materialization path to keep SP out of reg3. |
| src/coreclr/jit/codegenarm64.cpp | Reorders add operands in the large-immediate fallback helper to keep SP out of reg3. |
JulieLeeMSFT
left a comment
There was a problem hiding this comment.
LGTM.
nit: I wonder if we need to add a test, e.g., a test forcing a large stack frame with an SP-relative access at a ≥4KB offset.
|
Did something change here recently? It seems like jitstressregs should have hit large spill+mask reg spill pretty easily |
The bug itself isn't new, but it was #128037 that exposed it. |
More specifically: #128037 passes |
Added a test. |
| @@ -2161,7 +2161,7 @@ void CodeGen::instGen_Set_Reg_To_Base_Plus_Imm(emitAttr size, | |||
| else | |||
There was a problem hiding this comment.
(github wont let me leave a comment on line 2157)
anyway, I looked at this bug Friday before I realized you were as well - Copilot flagged the "imm < 4096" line thinking it should capture "imm < -4096" as well, I guess for FP-based frames? Is this a real issue we want to fix in the future?
Can make a new bug if so since this has nothing to do with your change.
Change LGTM either way
Fixes #130437
When generating large stack offsets, the base register can be SP. Therefore ensure that base is not used for reg3.