[llvm-dev] Where's the optimiser gone? (part 5.c): missed tail calls, and more...
Stefan Kanthak via llvm-dev
llvm-dev at lists.llvm.org
Sat Dec 1 09:29:09 PST 2018
Compile the following functions with "-O3 -target i386-win32"
(see <https://godbolt.org/z/exmjWY>):
__int64 __fastcall div(__int64 foo, __int64 bar)
{
return foo / bar;
}
On the left the generated code; on the right the expected,
properly optimised code:
push dword ptr [esp + 16] |
push dword ptr [esp + 16] |
push dword ptr [esp + 16] |
push dword ptr [esp + 16] |
call __alldiv | jmp __alldiv
ret 16 |
__int64 __fastcall mod(__int64 foo, __int64 bar)
{
return foo % bar;
}
push dword ptr [esp + 16] |
push dword ptr [esp + 16] |
push dword ptr [esp + 16] |
push dword ptr [esp + 16] |
call __allrem | jmp __allrem
ret 16 |
__int64 __fastcall mul(__int64 foo, __int64 bar)
{
return foo * bar;
}
push esi | mov ecx, dword ptr [esp + 16]
mov ecx, dword ptr [esp + 16] | mov edx, dword ptr [esp + 12]
mov esi, dword ptr [esp + 8] | imul edx, dword ptr [esp + 8]
mov eax, ecx | mov eax, dword ptr [esp + 4]
imul ecx, dword ptr [esp + 12] | imul ecx, eax
mul esi | add ecx, edx
imul esi, dword ptr [esp + 20] | mul dword ptr [esp + 12]
add edx, ecx | add edx, ecx
add edx, esi | ret 16
pop esi |
ret 16 |
More information about the llvm-dev
mailing list