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

            Bug ID: 38264
           Summary: Missed optimizations for comparison with
                    multiplications
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedb...@nondot.org
          Reporter: david.bolvan...@gmail.com
                CC: llvm-bugs@lists.llvm.org

Hello,

int f2(int x, int y, int z) {
    int tmp = y--;
    if (tmp * x > x * y)
        return 1;
    return 0;
}

Current codegen:
f2(int, int, int): # @f2(int, int, int)
  lea ecx, [rsi - 1]
  imul esi, edi
  imul ecx, edi
  xor eax, eax
  cmp esi, ecx
  setg al
  ret

GCC:
f2(int, int, int):
  xor eax, eax
  test edi, edi
  setg al
  ret



/////////////////////
int f2(int x, int y, int z) {
    if ((y-1) * x > x * y)
        return 1;
    return 0;
}

f2(int, int, int): # @f2(int, int, int)
  lea ecx, [rsi - 1]
  imul ecx, edi
  imul esi, edi
  xor eax, eax
  cmp ecx, esi
  setg al
  ret

GCC:
f2(int, int, int):
  mov eax, edi
  shr eax, 31
  ret


For unsigned case - Clang:
f2(unsigned int, unsigned int, unsigned int): # @f2(unsigned int, unsigned int,
unsigned int)
  lea ecx, [rsi - 1]
  imul ecx, edi
  imul esi, edi
  xor eax, eax
  cmp ecx, esi
  seta al
  ret

GCC (one multiplication is eliminated):
f2(unsigned int, unsigned int, unsigned int):
  sub esi, 1
  xor eax, eax
  imul esi, edi
  add esi, edi
  setc al
  ret

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

Reply via email to