Bug 125700 - `(x == MAX_VALUE) ? y : MIN<x, y>` -> MIN<x,y>
Summary: `(x == MAX_VALUE) ? y : MIN<x, y>` -> MIN<x,y>
Status: ASSIGNED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 16.0
: P3 enhancement
Target Milestone: ---
Assignee: Samarth Tandale
URL:
Keywords: easyhack, missed-optimization
Depends on:
Blocks:
 
Reported: 2026-06-09 20:42 UTC by Drea Pinski
Modified: 2026-08-05 05:03 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2026-07-09 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Drea Pinski 2026-06-09 20:42:26 UTC
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.
Comment 1 Samarth Tandale 2026-07-09 17:36:16 UTC
mine