[llvm-bugs] [Bug 47049] New: min/max with 1/-1 could use TEST instead of CMP

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Aug 7 18:53:02 PDT 2020


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: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
                    llvm-dev at redking.me.uk, spatel+llvm at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200808/8b877a58/attachment.html>


More information about the llvm-bugs mailing list