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

            Bug ID: 45759
           Summary: Failure to elide useless mov in sign function
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: unassignedb...@nondot.org
          Reporter: gabrav...@gmail.com
                CC: craig.top...@gmail.com, llvm-bugs@lists.llvm.org,
                    llvm-...@redking.me.uk, spatel+l...@rotateright.com

int sign(int x)
{
    return -((unsigned)x >> 31) | ((unsigned)-x >> 31);
}

With -O3, GCC outputs this :

sign(int):
  mov eax, edi
  sar edi, 31
  neg eax
  shr eax, 31
  or eax, edi
  ret

LLVM outputs this :

sign(int):
  mov eax, edi
  mov ecx, edi
  sar ecx, 31
  neg eax
  shr eax, 31
  or eax, ecx
  ret

Most likely this is specific to the X86 backend and its register allocator, so
I marked it as such

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

Reply via email to