https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113912
Bug ID: 113912 Summary: push2/pop2 generated when stack isn't aligned to 16 bytes Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: hjl.tools at gmail dot com CC: crazylht at gmail dot com Target Milestone: --- Target: x86-64 [hjl@gnu-cfl-3 apx-1]$ cat x.c extern int bar (int); void foo () { int a,b,c,d,e,f,i; a = bar (5); b = bar (a); c = bar (b); d = bar (c); e = bar (d); f = bar (e); for (i = 1; i < 10; i++) { a += bar (a + i) + bar (b + i) + bar (c + i) + bar (d + i) + bar (e + i) + bar (f + i); } } [hjl@gnu-cfl-3 apx-1]$ make /export/build/gnu/tools-build/gcc-gitlab-debug/build-x86_64-linux/gcc/xgcc -B/export/build/gnu/tools-build/gcc-gitlab-debug/build-x86_64-linux/gcc/ -mapxf -O2 -mpreferred-stack-boundary=3 -fomit-frame-pointer -S x.c [hjl@gnu-cfl-3 apx-1]$ cat x.s .file "x.c" .text .p2align 4 .globl foo .type foo, @function foo: .LFB0: .cfi_startproc pushp %r15 .cfi_def_cfa_offset 16 .cfi_offset 15, -16 movl $5, %edi push2p %r13, %r14 .cfi_def_cfa_offset 32 .cfi_offset 14, -24 .cfi_offset 13, -32 push2p %rbp, %r12 .cfi_def_cfa_offset 48 .cfi_offset 12, -40 .cfi_offset 6, -48 pushp %rbx .cfi_def_cfa_offset 56 .cfi_offset 3, -56 movl $1, %ebx subq $8, %rsp .cfi_def_cfa_offset 64 call bar movl %eax, %edi movl %eax, %r12d call bar movl %eax, %edi movl %eax, %r15d call bar movl %eax, %edi movl %eax, %r14d call bar movl %eax, %edi movl %eax, %r13d call bar movl %eax, %edi movl %eax, (%rsp) call bar movl %eax, 4(%rsp) .p2align 4,,10 .p2align 3 .L2: leal (%r12,%rbx), %edi call bar leal (%r15,%rbx), %edi movl %eax, %ebp call bar leal (%r14,%rbx), %edi addl %eax, %ebp call bar leal 0(%r13,%rbx), %edi addl %eax, %ebp call bar addl %ebx, (%rsp), %edi addl %eax, %ebp call bar addl %ebx, 4(%rsp), %edi addl $1, %ebx addl %eax, %ebp call bar addl %eax, %ebp addl %ebp, %r12d cmpl $10, %ebx jne .L2 addq $8, %rsp .cfi_def_cfa_offset 56 popp %rbx .cfi_def_cfa_offset 48 pop2p %r12, %rbp .cfi_restore 12 .cfi_restore 6 .cfi_def_cfa_offset 32 pop2p %r14, %r13 .cfi_restore 14 .cfi_restore 13 .cfi_def_cfa_offset 16 popp %r15 .cfi_def_cfa_offset 8 ret .cfi_endproc .LFE0: .size foo, .-foo .ident "GCC: (GNU) 14.0.1 20240213 (experimental)" .section .note.GNU-stack,"",@progbits [hjl@gnu-cfl-3 apx-1]$ With -mpreferred-stack-boundary=3, the coming stack is 8-byte aligned. push2/pop2 shouldn't be generated in this case.