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

            Bug ID: 47049
           Summary: min/max with 1/-1 could use TEST instead of CMP
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: unassignedb...@nondot.org
          Reporter: david.bolvan...@gmail.com
                CC: craig.top...@gmail.com, llvm-bugs@lists.llvm.org,
                    llvm-...@redking.me.uk, spatel+l...@rotateright.com

#define max(a,b) (((a) > (b))? (a) : (b))
#define min(a,b) (((a) < (b))? (a) : (b))


int smin(int x)
{
  return min(x,1);
}

int smax(int x)
{
  return max(x,-1);
}


Clang:
smin(int):                               # @smin(int)
        cmp     edi, 2
        mov     eax, 1
        cmovl   eax, edi
        ret
smax(int):                               # @smax(int)
        cmp     edi, -2
        mov     eax, -1
        cmovg   eax, edi
        ret

GCC:
smin(int):
        test    edi, edi
        mov     eax, 1
        cmovle  eax, edi
        ret
smax(int):
        test    edi, edi
        mov     eax, -1
        cmovns  eax, edi
        ret


https://godbolt.org/z/E3EEcn

-- 
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