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: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected]

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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to