[fpc-devel] AArch64 Register efficiency
Florian Klämpfl
florian at freepascal.org
Thu Aug 20 15:54:54 CEST 2020
Am 20.08.20 um 14:18 schrieb J. Gareth Moreton via fpc-devel:
> Hi everyone.
>
> During my evaluation of the assembly language produced by the AArch64 implementation of the Free Pascal Compiler, I've noticed that it uses the stack an awful lot and, generally, not many of the 28 or so general-
> purpose registers available for it.
So it uses memory instead? Can you give an example?
>
> The main problem is that even though x9 to x15 are designed to be used for local variables (caller-saved), the compiler doesn't make use of them because it has to write them to the stack anyway whenever it calls
> another subroutine, while x0-x7 and x19-x28 are not used because they're considered volatile and may not retain their values after a subroutine call. Nevertheless, leaf functions tend to perform a little better when
> it comes to register use.
>
> It's gotten me to thinking... for leaf functions (maybe even all functions if research shows it's plausible), after it has been assigned registers (and maybe gone through peephole optimisation), would it be feasible
> to store a list of used registers with the associated object that the compiler has for said function? That way, when it is called by another routine, the peephole optimizer and the register allocator can see which
> registers are not used, so it is more likely to use a volatile register rather than the stack to save temporary values. It is also potentially cross-platform.
No, we tried this decades ago and it broke horrible havoc.
More information about the fpc-devel
mailing list