anoma / juvix

A language for intent-centric and declarative decentralised applications
https://docs.juvix.org
GNU General Public License v3.0
442 stars 54 forks source link

Add an `if` instruction to JuvixReg #2829

Closed lukaszcz closed 4 days ago

lukaszcz commented 2 weeks ago

The if should combine br with boolean comparisons. Branching on comparisons can often be compiled more efficiently without first storing the boolean comparison result. In particular, this is true in Cairo Assembly for comparisons against 0.

We then add an optimization phase which converts br to if when possible. For example,

tmp[0] = eq tmp[1] tmp[2];
br tmp[0] {
  true: ...
  false: ...
};

would be transformed to

if eq tmp[1] tmp[2] {
  true: ...
  false: ...
};

when tmp[0] is not live in the branches.