[Bug tree-optimization/126748] New: a/b -> 0 if it is known that a < b (for non-negative)

"pinskia at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.