https://bugs.llvm.org/show_bug.cgi?id=52167

            Bug ID: 52167
           Summary: Failure to optimize negative abs properly
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]

long long abs_1(long long i)
{
  return (i > 0) ? -i : i;
}

This is "optimized" by LLVM to `return -llabs(i);`. Instead, it should be
possible to optimize it to avoid the negation by just changing the preceding
compare to the opposite one (as is already done in this example, and that LLVM
currently "optimizes" to have the current output). This is done by GCC, but not
by LLVM.

For comparison, LLVM outputs this on AMD64:

abs_1(long long):
  mov rax, rdi
  neg rax
  cmovl rax, rdi
  neg rax
  ret

GCC outputs this:

abs_1(long long):
  mov rax, rdi
  neg rax
  cmovns rax, rdi
  ret

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to