Skip to content
This repository has been archived by the owner on Jun 24, 2023. It is now read-only.

Papyrinth Optimizations #16

Open
erri120 opened this issue Jun 19, 2022 · 1 comment
Open

Papyrinth Optimizations #16

erri120 opened this issue Jun 19, 2022 · 1 comment
Labels
enhancement New feature or request optimizer Issue related to the optimizer

Comments

@erri120
Copy link
Collaborator

erri120 commented Jun 19, 2022

From @cadpnq

  • When two labels are next to one another all branches pointing at the first can be rewritten to point to the second.
  • When a label is followed by a jump all branches to the label can be rewritten to point to the target of the jump.
  • A label with no branches targeting it can be removed.
  • All code between a jump or return and the next label is dead and can be removed.
  • Branches followed by their target can be removed.
  • A conditional branch pointing at an identical conditional branch can be written to point at the target of the second one.
  • A conditional branch pointing at an opposite conditional branch can be written to point at just after the second branch.
  • Assigning or casting something to itself can be removed.
  • With the exception of function calls, any instruction storing to ::nonevar can be removed.
  • A cast instruction where dest and source are of the same type can be turned into an assign instruction.
  • Any instruction except function calls that store a value that is not used can be removed.
  • Two groups of temporaries can be combined if they are of the same type and none of them interfere with each other.
  • When a value is not'ed and only used in a branch the not can be removed and the branch can be rewritten to use the opposite condition.
  • Anything storing to a temp that is only used in an assign to another variable can be rewritten to store directly to that variable.
  • Any assign to a temporary that is only used in the next instruction can be removed and the next instruction rewritten to use the source of the assign.
@erri120 erri120 added enhancement New feature or request optimizer Issue related to the optimizer labels Jun 19, 2022
@erri120 erri120 changed the title Papyrinth Discussions Papyrinth Optimizations Jun 19, 2022
@cadpnq
Copy link

cadpnq commented Jun 19, 2022

It's worth noting that on some of these referencing labels we're talking about branch destinations. You will likely have something different, but during script loading in papyrith I convert branch offsets into references to uniquely named psuedo-instructions that I inserted into the bytecode.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request optimizer Issue related to the optimizer
Projects
None yet
Development

No branches or pull requests

2 participants