[llvm-bugs] [Bug 34662] New: Performance bug: Clang or LLVM failure to eliminate tail recursion in Linux
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Sep 18 14:53:09 PDT 2017
https://bugs.llvm.org/show_bug.cgi?id=34662
Bug ID: 34662
Summary: Performance bug: Clang or LLVM failure to eliminate
tail recursion in Linux
Product: clang
Version: 5.0
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: thecppzoo at gmail.com
CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
Hello. For this code:
__int128 factorial(unsigned arg, __int128 soFar) {
if(arg <= 1) { return soFar; }
return factorial(arg - 1, arg * soFar);
}
Clang 5.0.0 and others fails to eliminate the tail recursion, as can be seen at
the compiler explorer:
https://godbolt.org/g/iqLwgJ
(optimization level -O3)
factorial(unsigned int, __int128): #
@factorial(unsigned int, __int128)
mov rcx, rdx
mov rax, rsi
cmp edi, 2
jb .LBB0_2
push rax
mov edx, edi
dec edi
imul rcx, rdx
mul rdx
add rdx, rcx
mov rsi, rax
call factorial(unsigned int, __int128)
mov rcx, rdx
add rsp, 8
.LBB0_2:
mov rdx, rcx
ret
Curiously, -target aarch64-linux-gnu also with optimization -O3 produces
non-tail-recursive code.
GCC eliminates the tail recursion
--
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/20170918/89e5d2e4/attachment.html>
More information about the llvm-bugs
mailing list