[llvm-bugs] [Bug 50138] New: x86 Poor codegen on 7 parameter thunk (missed tail call opportunity)
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Apr 27 03:15:02 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=50138
Bug ID: 50138
Summary: x86 Poor codegen on 7 parameter thunk (missed tail
call opportunity)
Product: clang
Version: 11.0
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: LLVM Codegen
Assignee: unassignedclangbugs at nondot.org
Reporter: positronthief at gmail.com
CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
richard-llvm at metafoo.co.uk
While discussing clang's [[musttail]] attribute on Reddit, we discovered a case
where clang/llvm doesn't produce a tail call and GCC and MSVC both _do_:
https://gcc.godbolt.org/z/doYGdG1dT
```
int bar(int, int, int, int, int, int, int);
int foo(int a, int b, int c, int d, int e, int f, int g) {
return bar(a, b, c, d, e, f, g+7);
}
```
Clang output:
```
foo(int, int, int, int, int, int, int): # @foo(int, int, int, int, int, int,
int)
push rax
mov eax, dword ptr [rsp + 16]
add eax, 7
mov dword ptr [rsp], eax
call bar(int, int, int, int, int, int, int)
pop rcx
ret
```
Additionally, it seems to oddly push rax at the start of the function, but
restore it into _rcx_ at the end. It seems likely that this saved register is
why it's not performing the tail call, but it shouldn't be trying to preserve
rax in the first place!
Using godbolt to try on older iterations of clang suggests that this codegen
issue is very old indeed.
--
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/20210427/43d00c24/attachment.html>
More information about the llvm-bugs
mailing list