https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124571
Bug ID: 124571
Summary: `ABS<(float)(us1 - us2)> < 1.0f` can be optimized to
us1 == us2
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Blocks: 26163
Target Milestone: ---
```
int f(unsigned short a, unsigned short b)
{
float af = a;
float bf = b;
float s = __builtin_fabsf(a - b);
return s < 1.0f;
}
```
Can be turned into just:
```
int f(unsigned short a, unsigned short b)
{
return a == b;
}
```
Note there is 2 missed optimizations here (for GCC).
One is pushing the abs back over the conversion from float to int.
The second is converting `(float)us1 < 1` into `us1 < 1`.
This shows up in spec 2017 in imagick_r.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=26163
[Bug 26163] [meta-bug] missed optimization in SPEC (2k17, 2k and 2k6 and 95)