Miksilo icon indicating copy to clipboard operation
Miksilo copied to clipboard

Remove unnecessary pop instructions

Open keyboardDrummer opened this issue 6 years ago • 0 comments

Add an optimization that removes pop instructions when possible.

For example the following two instructions can be removed entirely, since all they do is load a value into the stack and then remove it from the stack:

iconst_0
pop

It's important to have an optimization that removes unnecessary pops, because they are generated by Java expressions used as statements, such as method calls with a side-effect where the return value is not used.

Doing this optimization completely and correctly is not trivial! It probably requires constructing a data-dependency graph and finding pairs of pop-pushy instructions in there to eleminate.

Slightly more complicated example than the first:

iconst_0
iconst_1
call method with side-effect that consumes 1 argument from the stack
pop

Desired result:

iconst_1
call method with side-effect that consumes 1 argument from the stack

If this optimization is implemented succesfully make sure to add a demonstration program.

keyboardDrummer avatar Sep 02 '17 12:09 keyboardDrummer