[llvm-bugs] [Bug 42673] New: Missed optimization: division reminder

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jul 18 09:30:16 PDT 2019


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: unassignedclangbugs at nondot.org
          Reporter: zamazan4ik at tut.by
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190718/053b9a78/attachment.html>


More information about the llvm-bugs mailing list