[fpc-devel] A node-level optimisation that was briefly touched upon

J. Gareth Moreton gareth at moreton-family.com
Thu Oct 20 04:28:20 CEST 2022

Hi everyone,

I just made a new cross-platform node-level optimisation - 
https://gitlab.com/freepascal.org/fpc/source/-/merge_requests/304 - the 
subject of which was briefly touched upon in 
https://gitlab.com/freepascal.org/fpc/source/-/merge_requests/282. This 
seeks to remove unnecessary AND instructions at the node-level when 
reading from fields of record types, thereby taking strain off the 
peephole optimizer.

To answer Florian's question in 282, converting the instructions from, 
say, "movl 28(ref),%eax; shrl $24,%eax" to "movzbl 31(ref),%eax" is 
unfortunately not always possible because, a lot of the time, the code 
generator forces variables to be in (imaginary) registers, which are at 
the mercy of the register allocator... they may become real registers, 
or be stored on the stack.

Still, this is the first step.  Because this is cross-platform, this 
might need a lot of testing on other platforms.  I also admit that I'm 
not sure how this optimisation will perform on bitpacked records and/or 
with sizes that aren't a multiple of 8 bits (or the register word size).


More information about the fpc-devel mailing list