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

            Bug ID: 122617
           Summary: `x >= 0 ?  MIN<x, y> : y` -> `(signed)MIN<(unsigned)x,
                    (unsigned)y>` when y is known to be non-negative
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

```
int f1(int x, int  b)
{
  if(b < 0)
    __builtin_unreachable();
  int t = x;
  if (x < 0)
    t = b;
  else if (x >= b)
    t = b;
  return t;
}
```

This should be optimized to just `umin<x, b>` as we know the `sign bit` of b is
not set.

Note clang only optimizes this for b being a constant but we should be able to
handle for "all values" of b when we know b is non-negative only (not umin<x,0>
is always 0 so zero works here too).

Reply via email to