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

            Bug ID: 127088
           Summary: [Missed optimization] fail to optimize (C << x) >> x
                    => C
           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/bfT61GKaf

cat prog.c
int src(int v1) {
  if (!((0 <= v1) && (v1 <= 11))) __builtin_unreachable();
  int i0 = 4 << v1;
  int i1 = i0 >> v1;
  return i1;
}

GCC at O3:
"src":
        mov     ecx, edi
        mov     eax, 4
        sal     eax, cl
        sar     eax, cl
        ret

LLVM at O3:
src:
        mov     eax, 4
        ret

Reply via email to