[llvm-bugs] [Bug 48641] New: [SimplifyCFG] Failure to use select min/max for the saturated operations instead of phi

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Dec 31 07:29:22 PST 2020


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

            Bug ID: 48641
           Summary: [SimplifyCFG] Failure to use select min/max for the
                    saturated operations instead of phi
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: llvm-bugs at lists.llvm.org

#define OP +

int foo_add_ok (const unsigned char *tmp, int i, int val)
{
     int R = (tmp[i] OP val);
  return ((R>0xFF)?0xFF:(((R)<0)?0:(R)));
}

int foo_add2_bad(const unsigned char *tmp, int i, int val)
{
  return (((tmp[i] OP val)>0xFF)?0xFF:(((tmp[i] OP val)<0)?0:(tmp[i] OP val)));
}


Clang:
foo_add_ok(unsigned char const*, int, int): # @foo_add_ok(unsigned char const*,
int, int)
  movsxd rax, esi
  movzx ecx, byte ptr [rdi + rax]
  xor eax, eax
  add ecx, edx
  cmovs ecx, eax
  cmp ecx, 255
  mov eax, 255
  cmovl eax, ecx
  ret
foo_add2_bad(unsigned char const*, int, int): # @foo_add2_bad(unsigned char
const*, int, int)
  movsxd rax, esi
  movzx ecx, byte ptr [rdi + rax]
  add ecx, edx
  cmp ecx, 255
  jle .LBB1_1
  mov eax, 255
  ret
.LBB1_1:
  xor eax, eax
  test ecx, ecx
  cmovns eax, ecx
  ret

GCC:
foo_add_ok(unsigned char const*, int, int):
        movsx   rsi, esi
        movzx   eax, BYTE PTR [rdi+rsi]
        add     eax, edx
        mov     edx, 0
        cmovs   eax, edx
        mov     edx, 255
        cmp     eax, 255
        cmovg   eax, edx
        ret
foo_add2_bad(unsigned char const*, int, int):
        movsx   rsi, esi
        movzx   eax, BYTE PTR [rdi+rsi]
        add     eax, edx
        mov     edx, 0
        cmovs   eax, edx
        mov     edx, 255
        cmp     eax, 255
        cmovg   eax, edx
        ret

https://godbolt.org/z/zdoo8f

-- 
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/20201231/84f0e579/attachment.html>


More information about the llvm-bugs mailing list