[fpc-devel] CSE and node optimisation question

J. Gareth Moreton gareth at moreton-family.com
Thu Feb 25 04:31:17 CET 2021


Hi everyone,

I've been looking at some node-level optimisations as of late, and I 
came across a couple of potential ones while doing experiments with the 
test on i38527, namely (R is an ordinal tempref, and n is an ordinal 
constant):

add
   |- add
   |   |- R
   |   |- R
   |
   |- R

Becoming:

mul
   |- R
   |- 3

And:

add
   |- mul
   |   |- R
   |   |- n
   |
   |- R

Becoming:

mul
   |- R
   |- n+1

I've been having a couple of issues though that I haven't been able to 
solve, the main thing is that taddnode.simplify doesn't get called to 
transmute the nodes as desired because pass 1 is already complete for 
most of the nodes by the time CSE is executed.

I've tried a few workarounds, but ran into problems:

- Once CSE is complete, calling simplify via foreachnodestatic with the 
pre-process option is unacceptably slow.
- Attempting to selectively reset the pass 1 flags (in an attempt to 
minimise the massive performance loss with manually calling simplify as 
above) causes Internal Error 200405231 because it seems to upset 
implicit finally blocks.
- Moving "add_entry_exit_code" to after "optcse" causes compilation of 
case blocks to malfunction.

Can anyone give me advice on how to implement such a node-level 
CSE-specific optimisation? Such a thing may be useful for pure functions 
(as well as when writing things like "4 * n + 4 * n + 4 * n + 4 * n + 4 
* n"!).  Thanks in advance.

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