<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - x86 Poor codegen on 7 parameter thunk (missed tail call opportunity)"
   href="https://bugs.llvm.org/show_bug.cgi?id=50138">50138</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>x86 Poor codegen on 7 parameter thunk (missed tail call opportunity)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>11.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>positronthief@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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_:

<a href="https://gcc.godbolt.org/z/doYGdG1dT">https://gcc.godbolt.org/z/doYGdG1dT</a>

```
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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>