diff options
author | Momchil Velikov <momchil.velikov@arm.com> | 2018-03-02 15:47:14 +0000 |
---|---|---|
committer | Momchil Velikov <momchil.velikov@arm.com> | 2018-03-02 15:47:14 +0000 |
commit | 505614bb4f695cb2d028726c8f37951f4ed831cf (patch) | |
tree | 5dd6f7f6266a2dd1d621e4f37bf07cb13430cd5b /llvm/lib/Target/ARM/ARMFrameLowering.cpp | |
parent | 36f14f41e6b8f1795cd041a2c9b2f98593cbea8c (diff) | |
download | bcm5719-llvm-505614bb4f695cb2d028726c8f37951f4ed831cf.tar.gz bcm5719-llvm-505614bb4f695cb2d028726c8f37951f4ed831cf.zip |
[ARM] Fix access to stack arguments when re-aligning SP in Armv6m
When an Armv6m function dynamically re-aligns the stack, access to incoming
stack arguments (and to stack area, allocated for register varargs) is done via
SP, which is incorrect, as the SP is offset by an unknown amount relative to the
value of SP upon function entry.
This patch fixes it, by making access to "fixed" frame objects be done via FP
when the function needs stack re-alignment. It also changes the access to
"fixed" frame objects be done via FP (instead of using R6/BP) also for the case
when the stack frame contains variable sized objects. This should allow more
objects to fit within the immediate offset of the load instruction.
All of the above via a small refactoring to reuse the existing
`ARMFrameLowering::ResolveFrameIndexReference.`
Differential Revision: https://reviews.llvm.org/D43566
llvm-svn: 326584
Diffstat (limited to 'llvm/lib/Target/ARM/ARMFrameLowering.cpp')
-rw-r--r-- | llvm/lib/Target/ARM/ARMFrameLowering.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/llvm/lib/Target/ARM/ARMFrameLowering.cpp b/llvm/lib/Target/ARM/ARMFrameLowering.cpp index f438469acb2..9ad1608eda2 100644 --- a/llvm/lib/Target/ARM/ARMFrameLowering.cpp +++ b/llvm/lib/Target/ARM/ARMFrameLowering.cpp @@ -919,15 +919,17 @@ ARMFrameLowering::ResolveFrameIndexReference(const MachineFunction &MF, return FPOffset; } } - } else if (AFI->isThumb2Function()) { + } else if (AFI->isThumbFunction()) { + // Prefer SP to base pointer, if the offset is suitably aligned and in + // range as the effective range of the immediate offset is bigger when + // basing off SP. // Use add <rd>, sp, #<imm8> // ldr <rd>, [sp, #<imm8>] - // if at all possible to save space. if (Offset >= 0 && (Offset & 3) == 0 && Offset <= 1020) return Offset; // In Thumb2 mode, the negative offset is very limited. Try to avoid // out of range references. ldr <rt>,[<rn>, #-<imm8>] - if (FPOffset >= -255 && FPOffset < 0) { + if (AFI->isThumb2Function() && FPOffset >= -255 && FPOffset < 0) { FrameReg = RegInfo->getFrameRegister(MF); return FPOffset; } |