https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126728

            Bug ID: 126728
           Summary: smax(a-b,b-a) -> abs(a-b) (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
                CC: unassigned at gcc dot gnu.org
  Target Milestone: ---

Take:
```

int __GIMPLE (ssa,startwith("optimized"))
f (int a, int b)
{
  int t;
  int _3;

  __BB(2):
  t_2 = a_1(D) - b_5(D);
  t_4 = b_5(D) - a_1(D);
  _3 = __MAX (t_2, t_4);
  return _3;
}
```


On aarch64 with -O2 -march=armv9.5-a (enabling CSSC) we get:
```
f:
        sub     w2, w0, w1
        sub     w0, w1, w0
        smax    w0, w2, w0
        ret
```

But this could be:
        sub     w2, w0, w1
        abs     w0, w2
        ret

Same source as PR 126726 .

Reply via email to