[fpc-devel] Register allocation question

Daniël Mantione daniel.mantione at freepascal.org
Sat Apr 9 21:34:34 CEST 2011

Op Sat, 9 Apr 2011, schreef Florian Klämpfl:

> Am 09.04.2011 21:04, schrieb Sergei Gorelkin:
>> 09.04.2011 22:26, Sergei Gorelkin ?????:
>>> 09.04.2011 22:13, Jonas Maebe ?????:
>>>> Simply changing the register order in the array to trgcpu.create in
>>>> Tcgx86_64.init_register_allocators should do it.
>>> Hmm, that was the first thing I tried, but it doesnt't seem to make
>>> any difference :(
>> No, it works, I simply looked at the wrong place. As usual :-/
>> The right place to look is the function not calling other functions, not
>> just any function simple enough.
>> Attached are assembler listings of system.indexqword() compiled for
>> win64 with -O2, with and without the change. Note the prolog and epilog
>> (almost) gone.
>> This is of course a very quick test, and I'll run the testsuite to check
>> more thoroughly.
>> If no issues pop up, it is ok to commit?
> Problem is, this might hurt non leaf functions. Maybe the register
> allocators can be initialized differently for leave and non-leave functions?

This is a form of "biasing", the register allocator is biased to put 
certain values in certain registers. It's a very old trick to get better 
register allocations, and the iterated coalescing we do gets much better 
results than old biased algorithms.

However, I had noted that in many cases the iterated coalescing still 
leaves a lot of freedom during the actual allocations and adding some 
biasing at this point may be helpfull.

I think the challenge is do design some generic infrastructure to tell the 
register allocator about biasing it should do, and then to add some 
heuristics somewhere else (like leaf/non-leaf) to give the register 
allocator the proper instructions.


More information about the fpc-devel mailing list