[PATCH] D43566: [ARM] Fix access to stack arguments when re-aligning SP in Armv6m

Momchil Velikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 21 04:19:00 PST 2018


chill created this revision.
chill added reviewers: rengolin, efriedma.
Herald added subscribers: kristof.beyls, javed.absar.

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. For example, compiling:

  void h(int, int *);
  void f(int n, ...) {
    __builtin_va_list ap;
    __builtin_va_start(ap, n);
    __attribute__((aligned(16))) int v[4];
    h(n, v);
  }

with `clang -target arm-eabi -mcpu=cortex-m0 -O2` yields the following assembly:

  f:
          sub     sp, #12
          push    {r4, r6, r7, lr}
          add     r7, sp, #8
          sub     sp, #20
          mov     r4, sp
          lsrs    r4, r4, #4
          lsls    r4, r4, #4
          mov     sp, r4
          str     r3, [sp, #44]
          str     r2, [sp, #40]
          str     r1, [sp, #36]
       ...

where incoming register varargs are stored using the SP after alignment.

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.


Repository:
  rL LLVM

https://reviews.llvm.org/D43566

Files:
  lib/Target/ARM/ThumbRegisterInfo.cpp
  test/CodeGen/Thumb/frame-access.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43566.135228.patch
Type: text/x-patch
Size: 15711 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180221/064b5d88/attachment.bin>


More information about the llvm-commits mailing list