[PATCH] D97815: [AVR] Remove redundant dynalloca SP save/restore pass

Ayke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 2 16:00:57 PST 2021


aykevl created this revision.
aykevl added a reviewer: dylanmckay.
Herald added subscribers: Jim, hiraditya.
aykevl requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

I think this pass was previously used under the assumption that most
functions would not need a frame pointer and it would be more efficient
to store the old stack pointer in a regular register pair.

Unfortunately, right now we're forced to always reserve the Y register
as a frame pointer: whether or not this is needed is only known after
regsiter allocation at which point it doesn't make sense anymore to mark
it as non-reserved. Therefore, it makes sense to use the Y register to
store the old stack pointer in functions with dynamic allocas (with a
variable size or not in the entry block). Knowing this can make the code
around dynamic allocas a lot simpler: simply save/restore the frame
pointer.

This is especially relevant in functions that have a frame pointer
anyway (for example, because they have stack spills). The stack restore
in the epilogue will implicitly restore the old stack pointer, so there
is no need to store the old stack pointer separately. It even reduces
register pressure as a side effect.

---

Warning: I haven't really tested this outside of the unit tests (and studying the output assembly). I'm not exactly sure how to test this, maybe by linking some test code with an existing program to check that it works as expected? However, the assembly looks good to me.
I checked compiler-rt and picolibc and both don't have any dynamic stack allocation (as I should have expected).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97815

Files:
  llvm/lib/Target/AVR/AVR.h
  llvm/lib/Target/AVR/AVRFrameLowering.cpp
  llvm/lib/Target/AVR/AVRTargetMachine.cpp
  llvm/test/CodeGen/AVR/dynalloca.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97815.327611.patch
Type: text/x-patch
Size: 7638 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210303/9252d6b2/attachment.bin>


More information about the llvm-commits mailing list