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

            Bug ID: 127844
           Summary: GCC produces less efficient code than LLVM for integer
                    division
           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: ---

Reproducer: https://godbolt.org/z/fWEY6MeP3

$ cat prog.c
#include <stdint.h>

uint8_t src(uint8_t v2_u8) {
  if (!((32 <= v2_u8) && (v2_u8 <= 33))) __builtin_unreachable();
  uint8_t i0_u8 = v2_u8 / 3;
  return i0_u8;
}

GCC at O3:
"src":
        mov     edx, -85
        mov     eax, edi
        mul     dl
        shr     ax, 9
        ret

LLVM at O3:
src:
        imul    eax, edi, 171
        shr     eax, 9
        ret

Reply via email to