[llvm-dev] Where's the optimiser gone? (part 5.a): missed tail calls, and more...

Stefan Kanthak via llvm-dev llvm-dev at lists.llvm.org
Sat Dec 1 09:28:43 PST 2018


Compile the following functions with "-O3 -target amd64"
(see <https://godbolt.org/z/5xqYhH>):

__int128 div(__int128 foo, __int128 bar)
{
    return foo / bar;
}

On the left the generated code; on the right the expected,
properly optimised code:

div: # @div
    push  rbp         |
    mov   rbp, rsp    |
    call  __divti3    |    jmp   __divti3
    pop   rbp         |
    ret               |


__int128 mod(__int128 foo, __int128 bar)
{
    return foo % bar;
}

mod: # @mod
    push  rbp         |
    mov   rbp, rsp    |
    call  __modti3    |    jmp   __modti3
    pop   rbp         |
    ret               |


__int128 mul(__int128 foo, __int128 bar)
{
    return foo * bar;
}

mul: # @mul
    push  rbp
    mov   rbp, rsp
    mov   r8, rdx
    mov   rax, rdx
    mul   rdi
    imul  rsi, r8
    add   rdx, rsi
    imul  rcx, rdi
    add   rdx, rcx
    pop   rbp
    ret



More information about the llvm-dev mailing list