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

            Bug ID: 42673
           Summary: Missed optimization: division reminder
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangb...@nondot.org
          Reporter: zamazan...@tut.by
                CC: llvm-bugs@lists.llvm.org, neeil...@live.com,
                    richard-l...@metafoo.co.uk

For the code below clang(trunk) with -O3:

int DivRem(int a, int b, int* result)
{
    int div = a / b;
    *result = a - (div * b);
    return div;
}

produces this:

DivRem(int, int, int*): # @DivRem(int, int, int*)
  mov rcx, rdx
  mov eax, edi
  cdq
  idiv esi
  imul esi, eax
  sub edi, esi
  mov dword ptr [rcx], edi
  ret

but gcc(trunk) with -O3 produces this:

DivRem(int, int, int*):
  mov eax, edi
  mov r8, rdx
  cdq
  idiv esi
  mov DWORD PTR [r8], edx
  ret


I think we can do in LLVM as GCC.

P.S. Compiler explorer example: https://godbolt.org/z/RryrJw

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