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

            Bug ID: 122366
           Summary: Suboptimal max + negate combination
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ktkachov at gcc dot gnu.org
  Target Milestone: ---
            Target: aarch64

Small testcase for aarch64:
#include <algorithm>

int
foo (int a, int b)
{
  return std::max (-a, b);
}

Generates with -O2:
foo(int, int):
        neg     w0, w0
        cmp     w0, w1
        csel    w0, w0, w1, ge
        ret

But Clang manages to generate the shorter:

foo(int, int):
        cmn     w1, w0
        csneg   w0, w1, w0, gt
        ret

Reply via email to