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

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


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

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

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

div: # @div
    push  ebp                     |
    mov   ebp, esp                |
    push  dword ptr [ebp + 20]    |
    push  dword ptr [ebp + 16]    |
    push  dword ptr [ebp + 12]    |
    push  dword ptr [ebp + 8]     |
    call  __divdi3                |    jmp   __divdi3
    add   esp, 16                 |
    pop   ebp                     |
    ret                           |


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

mod: # @mod
    push  ebp                     |
    mov   ebp, esp                |
    push  dword ptr [ebp + 20]    |
    push  dword ptr [ebp + 16]    |
    push  dword ptr [ebp + 12]    |
    push  dword ptr [ebp + 8]     |
    call  __moddi3                |    jmp   __moddi3
    add   esp, 16                 |
    pop   ebp                     |
    ret                           |


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

mul: # @mul
    push  ebp
    mov   ebp, esp
    push  esi
    mov   ecx, dword ptr [ebp + 16]
    mov   esi, dword ptr [ebp + 8]
    mov   eax, ecx
    imul  ecx, dword ptr [ebp + 12]
    mul   esi
    imul  esi, dword ptr [ebp + 20]
    add   edx, ecx
    add   edx, esi
    pop   esi
    pop   ebp
    ret


More information about the llvm-dev mailing list