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

            Bug ID: 126748
           Summary: a/b -> 0 if it is known that a < b (for non-negative)
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: easyhack, missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
unsigned f(unsigned a, unsigned b)
{
    if (b >= a) __builtin_unreachable();
    return b / a;
}

int fs(int a, int b)
{
  a = __builtin_abs(a);
  b = __builtin_abs(b);
  if (b >= a) __builtin_unreachable();
  return b / a;
}
```

Both should optimize to just return 0.

Reply via email to