[llvm-bugs] [Bug 43197] New: Signed division with power of two can be faster

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Sep 2 11:25:14 PDT 2019


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

            Bug ID: 43197
           Summary: Signed division with power of two can be faster
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
                    llvm-dev at redking.me.uk, spatel+llvm at rotateright.com

int foo(int i) {
    return i/(1 << 4);
}

foo(int):                                # @foo(int)
        mov     eax, edi
        sar     eax, 31
        shr     eax, 28
        add     eax, edi
        sar     eax, 4
        ret

Dispatch Width:    6
uOps Per Cycle:    3.81
IPC:               2.86
Block RThroughput: 1.5

GCC:
foo(int):
        test    edi, edi
        lea     eax, [rdi+15]
        cmovns  eax, edi
        sar     eax, 4
        ret


Dispatch Width:    6
uOps Per Cycle:    4.38
IPC:               3.13
Block RThroughput: 1.2


GCC's perf is better, microbenchmark confirms it:
int main(void) {
    int s = 0;
    for (int i = -60000000; i < 1000000000; ++i)
        s+= i/(1 << 4);
    return s;
}

Compiled with -O1:

clang -O1 -march=native lop.c 
time ./a.out 

real    0m0,658s
user    0m0,655s
sys     0m0,004s

gcc-9 -O1 -march=native lop.c 
time ./a.out 

real    0m0,605s
user    0m0,605s
sys     0m0,000s

-- 
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/20190902/b0ea2197/attachment.html>


More information about the llvm-bugs mailing list