[PATCH] D78581: [AVR] Remove faulty stack pushing behavior

Ayke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 21 12:59:40 PDT 2020


aykevl created this revision.
aykevl added a reviewer: dylanmckay.
Herald added subscribers: Jim, hiraditya.
Herald added a project: LLVM.
aykevl edited the summary of this revision.

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 is almost always more efficient to emit regular push/pop instructions. This is however left for future optimizations.

---

Together with D78579 <https://reviews.llvm.org/D78579> this fixes two additional tests in compiler-rt: powidf2_test.c and powixf2_test.c.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78581

Files:
  llvm/lib/Target/AVR/AVRFrameLowering.cpp
  llvm/test/CodeGen/AVR/call.ll
  llvm/test/CodeGen/AVR/dynalloca.ll
  llvm/test/CodeGen/AVR/varargs.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78581.259079.patch
Type: text/x-patch
Size: 9111 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200421/c3caa226/attachment.bin>


More information about the llvm-commits mailing list