https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126726
Bug ID: 126726
Summary: smax(a,-a) -> abs for RTL
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: easyhack, missed-optimization
Severity: enhancement
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Similar to PR 55152 but this time for the RTL level; sometimes smax shows up
during RTL.
Take:
```
int __GIMPLE (ssa,startwith("optimized"))
f (int a)
{
int t;
int _3;
__BB(2):
t_2 = -a_1(D);
_3 = __MAX (t_2, a_1(D));
return _3;
}
```
On aarch64 with -O2 -march=armv9.5-a (enabling CSSC) we get:
```
f:
neg w1, w0
smax w0, w1, w0
ret
```
Note I noticed this while looking into Wren6991's code changes to add a
peephole but really this should be done in simplify-rtl.cc.
https://github.com/Wren6991/gcc/commit/2ec0d1a0ba822a539fd26261707941c357be9147