-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(perf): Remove useless paired RC instructions within a block duri…
…ng DIE (#6160) # Description ## Problem\* Resolves <!-- Link to GitHub Issue --> Part of general effort to reduce Brillig bytecode sizes. ## Summary\* We currently have a pass for removing paired `inc_rc` and `dec_rc` instructions as long as there is no array set to an array of the same type between them. However, this is pass only checks the first block for inc_rc instructions and the return block for dec_rc instructions. This is because during SSA gen we add inc_rc instructions on array function parameters and dec_rc parameters when we exit the function scope, so this pass still allows us to get rid of a lot of instructions. However, function scope entry and exit are not the only places we add inc_rc instructions. And once we inline functions and go through other SSA opts, it is common to have inc_rc and dec_rc instructions through a block. e.g. This is the SSA of the return block of `execution_success/poseidon2`: ``` b4(): v17 = load v10 v19 = call poseidon2_permutation(v17, u32 4) inc_rc v19 dec_rc v19 inc_rc v19 v20 = array_get v19, index u32 0 dec_rc v19 constrain v20 == v1 return ``` All of those inc_rc/dec_rc pairs are useless and we should be able to remove them. This PR removes paired inc_rc/dec_rc instructions per block when there is not an array set to an array of the same type between them. The return block of `execution_success/poseidon2` after this PR is the following: ``` b4(): v17 = load v10 v19 = call poseidon2_permutation(v17, u32 4) v20 = array_get v19, index u32 0 constrain v20 == v1 return ``` ## Additional Context Right now I just focused on removing these inc_rc/dec_rc instructions per block for simplicity. Removing them across blocks is more complex and that work can come in a follow-up. ## Documentation\* Check one: - [X] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [X] I have tested the changes locally. - [X] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
- Loading branch information
Showing
2 changed files
with
161 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters