[llvm-bugs] [Bug 41318] New: Stack realignment produces inefficient code

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Mar 30 11:35:16 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=41318

            Bug ID: 41318
           Summary: Stack realignment produces inefficient code
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: henrik at gramner.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org

-mstackrealign or __attribute__((force_align_arg_pointer)) in combination with
-mstack-alignment=32 (or larger) emits an unnecessary instruction.


Minimal test case:

void foo(void);

__attribute__((force_align_arg_pointer))
void bar(void) {
    foo();
}


-O3 -mstack-alignment=16
  <bar>:
  55                push   rbp
  48 89 e5          mov    rbp,rsp
  48 83 e4 f0       and    rsp,0xfffffffffffffff0
  e8 00 00 00 00    call   <foo>
  48 89 ec          mov    rsp,rbp
  5d                pop    rbp
  c3                ret


-O3 -mstack-alignment=32
  <bar>:
  55                push   rbp
  48 89 e5          mov    rbp,rsp
  48 83 e4 e0       and    rsp,0xffffffffffffffe0
  48 83 ec 20       sub    rsp,0x20 <- This is completely redundant
  e8 00 00 00 00    call   <foo>
  48 89 ec          mov    rsp,rbp
  5d                pop    rbp
  c3                ret


Any stack alignment value larger than 16 results in the unnecessary subtraction
seen above. GCC does not have the same issue.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190330/71c28c3a/attachment.html>


More information about the llvm-bugs mailing list