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: unassignedb...@nondot.org
          Reporter: david.bolvan...@gmail.com
                CC: craig.top...@gmail.com, llvm-bugs@lists.llvm.org,
                    llvm-...@redking.me.uk, spatel+l...@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to