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

            Bug ID: 100857
           Summary: Simple common code sinking is not performed
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nok.raven at gmail dot com
  Target Milestone: ---

void bar(int);

void foo(bool f)
{
    if (f) {
        bar(1);
    }
    else {
        bar(2);
    }
}

; GCC
foo(bool):
        test    dil, dil
        je      .L2
        mov     edi, 1
        jmp     bar(int)
.L2:
        mov     edi, 2
        jmp     bar(int)

; Clang
foo(bool):
        mov     eax, 2
        sub     eax, edi
        mov     edi, eax
        jmp     bar(int)

https://godbolt.org/z/4oEPY4ncb

Reply via email to