[clang] [llvm] Try to use non-volatile registers for `preserve_none` parameters (PR #88333)

Joshua Haberman via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 7 19:02:50 PST 2025


haberman wrote:

Consider the case that `boring()` uses `preserve_most`:

```c
__attribute__((preserve_most)) void boring(void *);

__attribute__((preserve_none)) void (continuation)(void *, void *, void *, void *, void*);

__attribute__((preserve_none)) void entry(void *a, void *b, void *c, void *d, void* e)
{
    boring(a);
    __attribute__((musttail)) return continuation(a, b, c, d, e);
}
```

It seems we could get even better results for this case (without compromising the regular case) if we rearranged the arguments a bit further.

Original order (before this PR):

- RDI, RSI, RDX, RCX, R8, R9, R11, R12, R13, R14, R15, RAX

Current order (after this PR):

- R12, R13, R14, R15, RDI, RSI, RDX, RCX, R8, R9, R11, RAX

Possible improvements:

1. It appears that we're leaving R11 for second-last. But this is never used as an argument in normal functions, so we could consider using it before any of the normal argument registers.
2. Once we get to the normal argument registers, we could reverse their order to reduce the chance of overlap with `preserve_none` arguments.

A `preserve_none` order that seems ideal when calling `preserve_most`:

- R12, R13, R14, R15, R11, R9, R8, RCX, RDX, RSI, RDI, RAX

https://github.com/llvm/llvm-project/pull/88333


More information about the cfe-commits mailing list