solidity
solidity copied to clipboard
Yul optimizier: replace add with sub when it would save gas
Trying to fix https://github.com/ethereum/solidity/issues/6765.
This all feels very ad-hoc and hacky, I'm not sure at all if this makes sense and is at the reasonable place.
But so far some small example works for me, and some tests are broken.
Left some comments in https://github.com/ethereum/solidity/issues/6765#issuecomment-1258687946
@gumb0 Are you still working on this ? Or shall we take it over
@gumb0 Are you still working on this ? Or shall we take it over
Not at the moment, feel free to take it over.
Shouldn't this be a peephole optimizer step?
Thanks a lot for your contribution, @gumb0 . Unfortunately, I don't think we can use it like this because the optimization is still done during the main optimizer loop, where the goal is to simplify expressions (and also unify them) instead of optimizing gas usage. We should add that at the very end somehow, maybe in the peephole optimizer.