[llvm-bugs] [Bug 27921] New: x86: uint8_t % and / doesn't take advantage of the results already being in the same register

via llvm-bugs llvm-bugs at lists.llvm.org
Fri May 27 19:40:01 PDT 2016


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

            Bug ID: 27921
           Summary: x86: uint8_t % and / doesn't take advantage of the
                    results already being in the same register
           Product: new-bugs
           Version: 3.8
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: peter at cordes.ca
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

clang3.8 compiles (https://godbolt.org/g/558Tg6) this with -O3, for amd64:

__attribute__((always_inline)) 
  unsigned cvt_to_2digit(uint8_t i, uint8_t base) {
  return ((i / base) | (uint32_t)(i % base)<<8);
}

        movzbl  %dil, %eax
        divb    %sil
        # should just return here, result is already in ax, with the upper
bytes of eax zeroed
        movzbl  %ah, %ecx  # NOREX
        movzbl  %al, %eax
        shll    $8, %ecx
        orl     %eax, %ecx
        movl    %ecx, %eax

gcc compiles to just movzx/div/movzx/ret. 

See the godbolt link for related functions that compile similarly (including
one with a union where gcc which gets gcc to make bad code like this, too).

-- 
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/20160528/9d47c5cf/attachment.html>


More information about the llvm-bugs mailing list