Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2021-02

CSE and node optimisation question

2 messages · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

J. Gareth Moreton

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

Reply by email

J. Gareth Moreton
to J. Gareth Moreton

Regarding the "intolerably slow" option, I had the build script running for about 45 minutes as it tried to get through ppc2, and then it crashed with runtime error -1073741819.  Converting this to hexadecimal yields C0000005, which I know from experience is an access violation (usually in the kernel somewhere).

So, long story short, I'm still stuck for now!

Gareth aka. Kit

J. Gareth Moreton wrote 59 lines
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

Reply by email