[fpc-devel] Peephole optimiser insight

J. Gareth Moreton gareth at moreton-family.com
Thu Jan 2 23:44:03 CET 2020


Hi everyone,

So one of my patch suggestions sought to give a small efficiency boost 
to the post-peephole optimiser stage, since it is only designed to 
convert instructions into abbreviated forms but which would likely 
damage the peephole optimizer if done sooner. 
https://bugs.freepascal.org/view.php?id=36437  Florian rejected it 
because it made the stage act differently to the others and might be 
considered hard to follow.

One thing that I've noted though is that the peephole optimizer only 
investigates instructions, not other entries like labels or register 
allocations (except to update UsedRegs), and it makes me wonder if it's 
possible to convert the peephole optimiser stages so it doesn't enter 
the platform-specific methods if the current list entry is not an 
instruction.  At the moment, it enters a platform-specific method, which 
then checks to see if the current entry is an instruction, and 
immediately exits out if it's not. Instead, I propose that the 
platform-independent method does this check.  It might not sound like 
much, but it means that it cuts down on a number of procedure calls, 
which might number several dozen when analysing a complex function.  It 
also means one can remove the specific checks for the entry type in the 
platform-specific methods.

One thing Florian noted in the above issue is how the parameters were 
still of type tai (class for a list entry) instead of taicpu (which is 
specific for instructions).  Thinking ahead, I don't think this can be 
changed to taicpu without failing some optional sanity checks, because 
if the current instruction gets deleted, most optimisation methods set 
the parameter to the next entry in the list, which may not be an 
instruction.  One could get around this by demanding the methods call 
GetNextInstruction and calling UpdateUsedRegs, but it's asking for 
subtle bugs to be introduced if this gets forgotten sonewhere.

Gareth aka. Kit



More information about the fpc-devel mailing list