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

            Bug ID: 127082
           Summary: [Missed optimization] 96 % [-96, -65] yields [0, 95]
                    instead of [0, 31]
           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_i8) {
  if (!((-96 <= v0_i8) && (v0_i8 <= -65))) __builtin_unreachable();
  int i0_i8 = (int)96 % v0_i8;
  int i1_i8 = i0_i8 | -96;
  return i1_i8;
}

```
  # RANGE [irange] int [-96, -65] MASK 0x1f VALUE 0xffffffa0
  int v0_i8_3(D) = v0_i8;
  # RANGE [irange] int [0, 95] MASK 0x7f VALUE 0x0
  i0_i8_4 = 96 % v0_i8_3(D);
```

GCC at O3:
"src":
        xor     edx, edx
        mov     eax, 96
        idiv    edi
        mov     eax, edx
        or      eax, -96
        ret

LLVM at O3:
src:
        mov     eax, edi
        ret

Reply via email to