https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127444
Bug ID: 127444
Summary: `x sCMP -x` should be simplified into x sCMP 0
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: easyhack, 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:
```
int f(int x)
{
return x < -x;
}
```
This can be convert into `x < 0`.
And this is true for all signed comparisons too.
We already have a pattern for EQ:
```
/* -x == x -> x == 0 */
(for cmp (eq ne)
(simplify
(cmp:c @0 (negate @0))
(if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
&& !TYPE_OVERFLOW_WRAPS (TREE_TYPE(@0)))
(cmp @0 { build_zero_cst (TREE_TYPE(@0)); }))))
```
For `>`, this can be done even for wrapping values but still for signed only.