solidity icon indicating copy to clipboard operation
solidity copied to clipboard

Yul optimizier: replace add with sub when it would save gas

Open gumb0 opened this issue 2 years ago • 1 comments

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.

gumb0 avatar Sep 17 '22 20:09 gumb0

image

gumb0 avatar Sep 17 '22 20:09 gumb0

Left some comments in https://github.com/ethereum/solidity/issues/6765#issuecomment-1258687946

hrkrshnn avatar Sep 26 '22 22:09 hrkrshnn

@gumb0 Are you still working on this ? Or shall we take it over

nishant-sachdeva avatar Nov 10 '22 19:11 nishant-sachdeva

@gumb0 Are you still working on this ? Or shall we take it over

Not at the moment, feel free to take it over.

gumb0 avatar Nov 10 '22 22:11 gumb0

Shouldn't this be a peephole optimizer step?

chriseth avatar Nov 14 '22 11:11 chriseth

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.

chriseth avatar Nov 14 '22 11:11 chriseth