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

            Bug ID: 125700
           Summary: `(x == MAX_VALUE) ? y : MIN<x, y>` -> MIN<x,y>
           Product: gcc
           Version: 16.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 fumin(unsigned x, unsigned y)
{
  if (x == -1u) return y;
  return x < y ? x : y;
}

signed fsmin(signed x, signed y)
{
  if (x == __INT_MAX__) return y;
  return x < y ? x : y;
}

unsigned fumax(unsigned x, unsigned y)
{
  if (x == 0) return y;
  return x > y ? x : y;
}

signed fsmax(signed x, signed y)
{
  if (x == -__INT_MAX__-1) return y;
  return x > y ? x : y;
}
```

The comparison against the min/max value should be removed and these just
become min/max of x and y.

This is the generic version of what was mentioned in
https://github.com/llvm/llvm-project/issues/202576 . Mentioning umin/umax and
smin/smax.

Reply via email to