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: unassignedb...@nondot.org
          Reporter: simon.ho...@arm.com
                CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to