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

            Bug ID: 90360
           Summary: Missed optimization: unnecessary use of callee-saved
                    registers
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: coypu at sdf dot org
  Target Milestone: ---

if I compile this code with -O3


typedef struct once_t {
        int val;
        int pto_done;
} once_t;

int
once_stub(once_t *o, void (*r)(void))
{

        if (o->pto_done == 0) {
                (*r)();
                o->pto_done = 1;
        }

        return (0);
}


The output is:

once_stub(once_t*, void (*)()):
        movl    4(%rdi), %eax
        testl   %eax, %eax
        jne     .L4
        pushq   %rbx
        movq    %rdi, %rbx
        call    *%rsi
        movl    $1, 4(%rbx)
        xorl    %eax, %eax
        popq    %rbx
        ret
.L4:
        xorl    %eax, %eax
        ret



I think push/pop instructions won't be necessary if
another register besides rbx is picked.

Reply via email to