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

            Bug ID: 125709
           Summary: Possible missed optimization at O3
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: apowenq at gmail dot com
  Target Milestone: ---

cat prog.c
int src(int v0_u8) {
  if (!((0 <= v0_u8) && (v0_u8 <= 2))) __builtin_unreachable();
  int i0_u8 = 1 << v0_u8;
  int i1_u8 = v0_u8 / i0_u8;
  return i1_u8;
}


Clang truck at O3 can optimize the C code, but GCC truck at O3 cannot.
Reproducer: https://godbolt.org/z/bzTfPq4Yh

GCC truck at O3:
src:
        mov     ecx, edi
        mov     edx, 1
        mov     eax, edi
        sal     edx, cl
        mov     ecx, edx
        cdq
        idiv    ecx
        ret

Clang truck at O3:
src:
        xor     eax, eax
        ret

Reply via email to