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

            Bug ID: 71923
           Summary: Two consecutive "rep ret" instruction in assembly
                    output of recursive function
           Product: gcc
           Version: 6.1.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: SztfG at yandex dot ru
  Target Milestone: ---
              Host: x86_64-linux-gnu
            Target: x86_64-linux-gnu

function

unsigned int fact( unsigned int n) { return n < 1 ? 1 : n*fact(n-1); }

produces

fact:
.LFB0:
        .cfi_startproc
        testl   %edi, %edi
        movl    $1, %eax
        je      .L4
        .p2align 4,,10
        .p2align 3
.L3:
        imull   %edi, %eax
        subl    $1, %edi
        jne     .L3
        rep ret # <-- this instruction can be removed
.L4:
        rep ret
        .cfi_endproc
.LFE0:
        .size   fact, .-fact
        .section        .text.unlikely

can be easily reproduced at http://gcc.godbolt.org/

Reply via email to