feat: remove 'single use' intermediate variables #6268
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Problem*
Resolves #6085
Summary*
This PR tries to benefit from Barretenberg's 'big-add gates' support, which was enabled by PR AztecProtocol/aztec-packages#8960
It's a simple optimisation which removes intermediate variables usually created by the CSatTransformer if they are not re-used elsewhere.
The PR assumes that the backend is able to handle infinite width, but still requires the CSatTransformer, which is not really consistent. I plan to make follow-up PRs to get rid of this (but I can't guarantee it will work).
Additional Context
I tested the optimisation on all 'execution_sucess' test cases. In most cases, there were no change at all, while in some cases we would win one or two (10 max) on the circuit size.
However, in a few cases, listed below in the form "test case: circuit size with 'intermediate var' optimisation vs no optimisation", it can be more significant:
7_function: 2955 vs 2992
bit_shifts_runtime: 5451 vs 5761
eddsa: 65805 vs 70406
hashmap: 135023 vs 150661
nested_array_dynamic: 12594 vs 12922
nested_array_in_slice: 5371 vs 5449
poseidon_bn254_hash: 1028 vs 1060
poseidon_bn254_hash_width_3: 1028 vs 1495
poseidonsponge_x5_254: 1244 vs 1307
regression_5252: 76491 vs 83862
sha256_var_size_regression: 74093 vs 74529
sha2_byte: 93998 vs 94006
slice_dynamic_index: 6308 vs 6419
slices: 3835 vs 3874
to_be_bytes: 135 vs 143
to_bytes_consistent: 6 vs 51
to_bytes_integration: 434 vs 484
u128: 4662 vs 4707
u16_support: 3023 vs 3057
Documentation*
Check one:
PR Checklist*
cargo fmt
on default settings.