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

            Bug ID: 87268
           Summary: Missed optimization for a tailcall
           Product: gcc
           Version: 8.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: no...@turm-lahnstein.de
  Target Milestone: ---

For a simple code like this:

  extern int shared;
  void doit(int *);
  int call_doit(){
    doit(&shared);
  }

when compiled with -O3 the resulting assembler is without tailcall
optimization:

   call_doit:
        subq    $8, %rsp
        movl    $shared, %edi
        call    doit
        addq    $8, %rsp
        ret

There are two thing that are probably not needed:

   1. The whole "subq    $8, %rsp / addq    $8, %rsp"  is not really necessary,
isn't it?
   2. call instead of simple jmp, which would be possible due to tailcall
optimization. Possibly it was not performed, because subq/addq are still
hanging around.

If I'm not mistaken, something like:

   call_doit:                            
        movl    $global, %edi
        jmp     doit    

should be possible as output.

Reply via email to