Hi all, my question is maybe not directly related with LLVM but general with compilers. The common approach is that compilers often don't align stack pointer for leaf functions if the function utilizes stack just for keeping variables of small sizes. I’m wondering what is the benefit of such behavior. Is saving a few bytes of the stack just once worth of such approach? Or maybe something else stands behind it? Is there any other potential benefit of unaligned Stack Pointer in Leaf Functions? Thanks, Przemek -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200917/3624954a/attachment.html>
Is this really "common"? I would expect many architectures to require stack pointer alignment at all times, as a signal/interrupt/fault can happen at any time. SPARC is a good example. If an interrupt occurs, the OS must flush all register windows out to the user stack. This requires that the stack pointer be aligned. Since you have no control over when an interrupt can occur. you must maintain alignment at all times. On Thu, Sep 17, 2020 at 10:42 AM Przemyslaw Ossowski via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Hi all, > > my question is maybe not directly related with LLVM but general with > compilers. > > > > The common approach is that compilers often don't align stack pointer for > leaf functions if the function utilizes stack just for keeping variables of > small sizes. > > I’m wondering what is the benefit of such behavior. > > > > Is saving a few bytes of the stack just once worth of such approach? > > Or maybe something else stands behind it? Is there any other potential > benefit of unaligned Stack Pointer in Leaf Functions? > > > > Thanks, > > Przemek > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200917/549812db/attachment.html>
Exactly, but for some architectures SP is not aligned for such case. My questions is what for, apart of saving few bytes on stack just during execution od leaf function? Przemek czw., 17 wrz 2020, 17:17 użytkownik David Jones <david.jones at metrics.ca> napisał:> Is this really "common"? > > I would expect many architectures to require stack pointer alignment at > all times, as a signal/interrupt/fault can happen at any time. > > SPARC is a good example. If an interrupt occurs, the OS must flush all > register windows out to the user stack. This requires that the stack > pointer be aligned. Since you have no control over when an interrupt can > occur. you must maintain alignment at all times. > > > On Thu, Sep 17, 2020 at 10:42 AM Przemyslaw Ossowski via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> Hi all, >> >> my question is maybe not directly related with LLVM but general with >> compilers. >> >> >> >> The common approach is that compilers often don't align stack pointer for >> leaf functions if the function utilizes stack just for keeping variables of >> small sizes. >> >> I’m wondering what is the benefit of such behavior. >> >> >> >> Is saving a few bytes of the stack just once worth of such approach? >> >> Or maybe something else stands behind it? Is there any other potential >> benefit of unaligned Stack Pointer in Leaf Functions? >> >> >> >> Thanks, >> >> Przemek >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200917/e790350a/attachment.html>
On Thu, Sep 17, 2020 at 11:17:03AM -0400, David Jones via llvm-dev wrote:> SPARC is a good example. If an interrupt occurs, the OS must flush all > register windows out to the user stack. This requires that the stack > pointer be aligned. Since you have no control over when an interrupt can > occur. you must maintain alignment at all times.The kernel will realign the stack pointer as appropiate for signal handlers, so that argument doesn't really work. Interrupt and exception handlers normally have their own stacks, so the problem doesn't apply to them. Joerg
Reasonably Related Threads
- Glue two instructions together
- Glue two instructions together
- Assigning custom information to IR instruction and passing it to its correspondent in Selection DAG
- Assigning custom information to IR instruction and passing it to its correspondent in Selection DAG
- Handling node through TargetLowering::LowerOperation vs TargetLowering::ReplaceNodeResults