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

            Bug ID: 90087
           Summary: Suboptimal codegen for x < 0 ? x - INT_MIN : x
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nok.raven at gmail dot com
  Target Milestone: ---
            Target: x86_64,AArch64

int foo(int x)
{
    return x < 0 ? x - INT_MIN : x;
}

       | GCC                            | Clang
-------+--------------------------------+-------------------------
x86-64 | movl   %edi, %eax              | movl %edi, %eax       
       | leal   -2147483648(%rdi), %edx | andl $2147483647, %eax
       | testl  %edi, %edi              |
       | cmovs  %edx, %eax              |
-------+--------------------------------+-------------------------
ARM64  | cmp    w0, 0                   | and w0, w0, #0x7fffffff
       | mov    w1, -2147483648         |
       | add    w1, w0, w1              |
       | csel   w0, w1, w0, lt          |

https://godbolt.org/z/VX0Ou2

Reply via email to