[PATCH] D158404: [ARM] Save and restore CPSR around tMOVimm32
Oliver Stannard via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 21 03:43:06 PDT 2023
olista01 created this revision.
Herald added subscribers: hiraditya, kristof.beyls.
Herald added a project: All.
olista01 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
When resolving a frame index with a large offset for v6M execute-only,
we emit a tMOVimm32 pseudo-instruction, which later gets lowered to a
sequence of instructions, all of which are flag-setting. However, a
frame index may be generated for a register spill or reload instruction,
which can be inserted at a point where CPSR is live. This patch inserts
MRS and MSR instructions around the tMOVimm32 to save and restore the
value of CPSR, if CPSR is live at that point.
This may need up to two virtual registers (one to build the immediate
value, one to save CPSR) during frame index lowering, which happens
after register allocation, so we need to ensure two spill slots are
avilable to the register scavenger to ensure it can free up enough
registers for this.
There is no test for the emission (or not) of the MRS/MSR pair, because
it requires a spill or reload to be inserted at a point where CPSR is
live, which requires a large, complex function and is fragile enough
that any optimisation changes will break the test. This bug was easily
found by csmith with -verify-machineinstrs, which I now run regularly on
v6M execute-only (and many other combinations).
Patch by John Brawn and myself.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D158404
Files:
llvm/lib/Target/ARM/ARMFrameLowering.cpp
llvm/lib/Target/ARM/ThumbRegisterInfo.cpp
llvm/test/CodeGen/ARM/execute-only-save-cpsr.mir
llvm/test/CodeGen/ARM/large-stack.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158404.551963.patch
Type: text/x-patch
Size: 23091 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230821/73b52a9b/attachment.bin>
More information about the llvm-commits
mailing list