[interp] Add constant propagation of integers (mono/mono#17326)
authorVlad Brezae <brezaevlad@gmail.com>
Wed, 16 Oct 2019 10:56:14 +0000 (13:56 +0300)
committerGitHub <noreply@github.com>
Wed, 16 Oct 2019 10:56:14 +0000 (13:56 +0300)
commit46f8111efbd416f9ea59e7f8c7425afd49df38f6
tree9f60413305a8b215937fd764c9dfa70fe55e995b
parent4409151d4fd5e324d169017afd24ee7ad9ff0c36
[interp] Add constant propagation of integers (mono/mono#17326)

* [interp] Make StackValue more intuitive

Replace the opcode field with an enum which will represent what type of value is contained (STACK_VALUE_LOCAL, STACK_VALUE_I4 etc)

* [interp] Add the mint type to the local data

Makes the emitting code easier and we no longer compute the mint type for each local access, which is fairly expensive.

* [interp] Handle indirect locals saner during cprop

Instead of checking for the indirect flag when loading from a local, simply never store a StackValue into such a local since we can't use it. We use the same logic when not pushing on the stack values for such locals.

* [interp] Add constant folding for integers

We decode the values from LDC_I4 and LDC_I8 opcodes and track/propagate the values on the stack and in the locals using the existing infrastructure. When loading a local, we try to load using the known constant value instead, so we might get to kill that local.

* [interp] Similar to stloc.np we can optimize pop/push pairs

If the pushing instruction pushes the same value that was popped by the previous instruction, we can kill them both

* [tests] Remove issue that seems to have been fixed for a while

Commit migrated from https://github.com/mono/mono/commit/0aabccef9bf6f17313fa384349a8089e8d8b0642
src/mono/mono/mini/interp/mintops.h
src/mono/mono/mini/interp/transform.c