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: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected]

#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
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to