https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117081

--- Comment #20 from Hongtao Liu <liuhongt at gcc dot gnu.org> ---

> 
> W/o more usage of callee-saved registers, callee needs to restore them
> before exit which is not needed if more caller-saved register are used.

W/ https://gcc.gnu.org/pipermail/gcc-patches/2025-February/675714.html

the codegen is like

foo:
.LFB0:
        .cfi_startproc
        pushq   %r12
        .cfi_def_cfa_offset 16
        .cfi_offset 12, -16
        movq    %rsi, %r12
        pushq   %rbp
        .cfi_def_cfa_offset 24
        .cfi_offset 6, -24
        movq    %rdi, %rbp
        pushq   %rbx
        .cfi_def_cfa_offset 32
        .cfi_offset 3, -32
        movq    %rdx, %rbx
        subq    $32, %rsp
        .cfi_def_cfa_offset 64
        leaq    16(%rsp), %rcx
        leaq    24(%rsp), %r8
        call    bar
        movl    %eax, %edx
        testl   %eax, %eax
        je      .L1
        vmovsd  16(%rsp), %xmm0
        vxorpd  %xmm1, %xmm1, %xmm1
        vcomisd %xmm1, %xmm0
        jbe     .L18
        vmovsd  .LC1(%rip), %xmm1
        vcomisd %xmm0, %xmm1
        ja      .L21
.L18:
        xorl    %edx, %edx
.L3:
        vmovsd  24(%rsp), %xmm0
        vxorpd  %xmm1, %xmm1, %xmm1
        vcomisd %xmm1, %xmm0
        jbe     .L1
        vmovsd  .LC1(%rip), %xmm1
        vcomisd %xmm0, %xmm1
        ja      .L22
.L1:
        addq    $32, %rsp
        .cfi_remember_state
        .cfi_def_cfa_offset 32
        movl    %edx, %eax
        popq    %rbx
        .cfi_def_cfa_offset 24
        popq    %rbp
        .cfi_def_cfa_offset 16
        popq    %r12
        .cfi_def_cfa_offset 8
        ret
        .p2align 4,,10
        .p2align 3

There're 3 pops, more than best one(2 pops), less than worst one(4 pops), but
it looks more reasonable since we do want to keep rsi in callee-saved register
to preserve it across call.

Reply via email to