[PATCH] D69372: [X86][VARARG] Avoid spilling xmm vararg arguments.

Reid Kleckner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 14 15:34:24 PST 2020


rnk added a comment.

In D69372#1820099 <https://reviews.llvm.org/D69372#1820099>, @avl wrote:

> In D69372#1818166 <https://reviews.llvm.org/D69372#1818166>, @rnk wrote:
>
> > It should be possible to use musttail thunk with a prototype of `void (int, ...)` between the call to foo and bar.
>
>
> if I correctly understood the example - such a situation should not occur.
>  My understanding is that musttail thunk and it`s target _must_ have identical signatures.


The third point under musttail is meant to create an exception for for perfectly forwarding thunks: https://llvm.org/docs/LangRef.html#id325

> If the musttail call appears in a function with the "thunk" attribute and the caller and callee both have varargs, than any unprototyped arguments in register or memory are forwarded to the callee. Similarly, the return value of the callee is returned to the caller’s caller, even if a void return type is in use.

In retrospect, I think it may have been a mistake to repurpose varargs to indicate that all remaining argument registers should be preserved. Maybe we don't need to use a varargs function prototype to implement perfectly forwarding thunks. We ended up needing the `"thunk"` function attribute, so we could base it on that instead.

> This patch does not work on windows . It is only for amd64 ABI:

OK, but the C++ code I provided illustrates the use case of perfect forwarding, which might come up on Linux. It sets up a chain of calls that looks like:

- indirect call to thunk, pass FP in XMM ->
- in thunk, save XMM, use XMM, restore XMM, tail call to callee ->
- receive XMM value in callee

The use case for perfectly forwarding thunks is pretty rare. I don't think there is a way to convince clang to generate one for Linux, just Windows.

---

Anyway, it seems like you could do away with a fair amount of the complexity in this patch for handling guarding musttail forwarding by declaring them to be an "explicit FP use", since it is not, in general, possible for a perfectly forwarding thunk to know if XMM arguments have been used.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69372/new/

https://reviews.llvm.org/D69372





More information about the llvm-commits mailing list