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

            Bug ID: 101044
           Summary: -ABS(A) produces two neg instructions
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---
            Target: x86_64-linux-gnu

Take:
int f4(int A)
{
  return A <= 0? A : -A;
}
int f5(int A)
{
return A < 0?  A : -A;
}
int f2(int A)
{
  A = A < 0 ? -A : A;
  return -A;
}
---- CUT ---
On x86_64 we get two neg for each of these functions now, we used to get none
sometime ago.
Right now we get for each of them:
        movl    %edi, %eax
        negl    %eax
        cmovs   %edi, %eax
        negl    %eax
----- CUT ---
Note aarch64 seems to be fine:
        cmp     w0, 0
        csneg   w0, w0, w0, lt

Reply via email to