[fpc-devel] Question about peephole optimizer

J. Gareth Moreton gareth at moreton-family.com
Thu Sep 16 17:30:29 CEST 2021


Hi everyone,

To get straight to the point, does anyone know if functionality exists 
under x86 to get an unused register in the peephole optimizer? I recall 
seeing something like that somewhere, but that might have been under the 
AArch64 peephole optimizer (it has a larger number of volatile registers).

I'm coming up with a number of potential optimisations that would 
require allocating an unused register - one optimisation in mind is to 
change something like:

je .Lbl1
mov $2,%reg1
.Lbl1:

To:

mov $2,%reg2
cmovne %reg2,%reg1

(Also some possible instruction arrangement so the mov instruction 
appears before the cmp or test instruction so as to better utilise 
parallelisation and to permit mov $0,%reg2 to be optimised to xor 
%reg2,%reg2, since it can't do so if the flags are in use)

I have written a couple of functions for getting an unused register - 
one for general-purpose registers and one for MM registers - but they 
are limited to the registers listed in 
"paramanager.get_volatile_registers_int(current_procinfo.procdef.proccalloption)" 
and 
"paramanager.get_volatile_registers_mm(current_procinfo.procdef.proccalloption);", 
which is okay, but I would like to extend it to registers that have 
actually been saved to the stack by the procedure, but I figure this may 
require some extensions to TProcInfo so it remembers which registers it 
uses (the information is only in the register allocator object that gets 
lost once it's no longer needed). But of course, I don't want to write 
new functions if perfectly usable ones already exist.

Gareth aka. Kit


-- 
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus



More information about the fpc-devel mailing list