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: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]

-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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to