https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124560
Bug ID: 124560
Summary: `min(z - y, x - y)` -> `min(z, x) - y`
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: ---
Take:
```
static inline
int smin(int a, int b)
{
return a < b ? a : b;
}
static inline
int smax(int a, int b)
{
return a > b ? a : b;
}
int src(int x, int y, int z)
{
return smin(z - y, x - y);
}
int tgt(int x, int y, int z)
{
return smin(z, x) - y;
}
```
src should be optimized to tgt.
This is true for both min and max and signed and unsigned types.