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

            Bug ID: 127998
           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: ---

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

Possible some missed case in demanded bits analysis (note that `i1 >> 4`).

$cat prog.c
int src(int v2, int v3) {
  if (!(31 <= v2 && v2 <= 32)) __builtin_unreachable();
  if (!(192 <= v3 && v3 <= 193)) __builtin_unreachable();
  int i0 = v3 ^ 141;
  int i1 = v2 ^ i0;
  int i2 = i1 >> 4;
  return i2;
}

GCC at O3:
"src":
        mov     eax, edi
        xor     eax, esi
        sar     eax, 4
        xor     eax, 8
        ret

LLVM at O3:
src:
        shr     edi, 4
        lea     eax, [rdi + 4]
        ret

Reply via email to