[all-commits] [llvm/llvm-project] 3ab1c9: [AVR] Fix stack size in functions with a frame poi...

Ayke via All-commits all-commits at lists.llvm.org
Tue Jun 16 04:54:28 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 3ab1c97e35164f51f97b5d727d1c684ed1c1e213
      https://github.com/llvm/llvm-project/commit/3ab1c97e35164f51f97b5d727d1c684ed1c1e213
  Author: Ayke van Laethem <aykevanlaethem at gmail.com>
  Date:   2020-06-16 (Tue, 16 Jun 2020)

  Changed paths:
    M llvm/lib/Target/AVR/AVRFrameLowering.cpp
    M llvm/test/CodeGen/AVR/calling-conv/c/stack.ll
    M llvm/test/CodeGen/AVR/return.ll
    M llvm/test/CodeGen/AVR/varargs.ll

  Log Message:
  -----------
  [AVR] Fix stack size in functions with a frame pointer

This patch fixes a bug in stack save/restore code. Because the frame
pointer was saved/restored manually (not by marking it as clobbered) the
StackSize variable was not updated accordingly. Most code still worked,
but code that tried to load a parameter passed on the stack did not.

This commit fixes this by marking the frame pointer as a
callee-clobbered register. This will let it be saved without any effort
in prolog/epilog code and will make sure the correct address is
calculated for loading parameters that are passed on the stack.

This approach is used by most other targets (such as X86, AArch64 and
RISC-V).

Differential Revision: https://reviews.llvm.org/D78579


  Commit: 5aa8014ca811c8132ff99921c1eb39940f98c7e9
      https://github.com/llvm/llvm-project/commit/5aa8014ca811c8132ff99921c1eb39940f98c7e9
  Author: Ayke van Laethem <aykevanlaethem at gmail.com>
  Date:   2020-06-16 (Tue, 16 Jun 2020)

  Changed paths:
    M llvm/lib/Target/AVR/AVRFrameLowering.cpp
    M llvm/test/CodeGen/AVR/call.ll
    M llvm/test/CodeGen/AVR/dynalloca.ll
    M llvm/test/CodeGen/AVR/varargs.ll

  Log Message:
  -----------
  [AVR] Remove faulty stack pushing behavior

An instruction like this will need to allocate some stack space for the
last parameter:

  %x = call addrspace(1) i16 @bar(i64 undef, i64 undef, i16 undef, i16 0)

This worked fine when passing an actual value (in this case 0). However,
when passing undef, no value was pushed to the stack and therefore no
push instructions were created. This caused an unbalanced stack leading
to interesting results.

This commit fixes that by replacing the push logic with a regular stack
adjustment and stack-relative load/stores. This is less efficient but at
least it correctly compiles the code.

I can think of a few improvements in the future:

  * The stack should have been adjusted in the function prologue when
    there are no allocas in the function.
  * Many (if not most) stack adjustments can be replaced by
    pushing/popping the values directly. Exactly like the previous code
    attempted but didn't do correctly.
  * Small stack adjustments can be done more efficiently with a few
    push/pop instructions (pushing/popping bogus values), both for code
    size and for speed.

All in all, as long as there are no allocas in the function I think that
it is almost always more efficient to emit regular push/pop
instructions. This is however left for future optimizations.

Differential Revision: https://reviews.llvm.org/D78581


Compare: https://github.com/llvm/llvm-project/compare/71c1080328c7...5aa8014ca811


More information about the All-commits mailing list