[llvm-bugs] [Bug 28153] New: 64-bit divide by constant on 32-bit targets poorly optimised

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jun 15 17:50:24 PDT 2016


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

            Bug ID: 28153
           Summary: 64-bit divide by constant on 32-bit targets poorly
                    optimised
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: simon.hosie at arm.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Given:

    int64_t fn(int x) {
      return x / (int64_t)1000;
    }

We can see that this could trivially be implemented as a 32-bit divide, and in
turn replaced with a reciprocal multiply.  Unfortunately, on 32-bit platforms
(tried ARM and x86) we get a call to a divide function instead:

    asr     r1, r0, #31
    mov     r2, #1000
    mov     r3, #0
    bl      __aeabi_ldivmod

Simply remove the cast from the constant to see preferable code:

    ldr     r1, .LCPI1_0
    smmul   r0, r0, r1
    asr     r1, r0, #6
    add     r0, r1, r0, lsr #31
    asr     r1, r0, #31

The cast to 64-bit comes from `X_PER_Y` constants where it might want to imply
64-bit promotion when used in multiplication.  Changing the code isn't an
option because of the errors it could introduce (and it looks weird next to the
constants that do need to be 64-bit, 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/20160616/f11bf992/attachment-0001.html>


More information about the llvm-bugs mailing list