Fold I2L with ICONST_n when beneficial

ICONST_0; I2L -> LCONST_0
ICONST_1; I2L -> LCONST_1
This commit is contained in:
Dmitry Petrov
2017-07-07 13:45:55 +03:00
parent ad80c3cd7f
commit aa7db727ba
5 changed files with 19 additions and 4 deletions
@@ -65,6 +65,19 @@ class StackPeepholeOptimizationsTransformer : MethodTransformer() {
}
}
Opcodes.I2L -> {
when (prevNonNop.opcode) {
Opcodes.ICONST_0 -> actions.add {
it.remove(insn)
it.set(prevNonNop, InsnNode(Opcodes.LCONST_0))
}
Opcodes.ICONST_1 -> actions.add {
it.remove(insn)
it.set(prevNonNop, InsnNode(Opcodes.LCONST_1))
}
}
}
Opcodes.POP2 -> {
if (prevNonNop.isEliminatedByPop2()) {
actions.add {
@@ -10,5 +10,7 @@ fun testLongWithObjectArray(i: Long, xs: Array<Any>) = i in xs.indices
// 0 getIndices
// 0 contains
// 4 I2L
// 2 I2L
// 4 ARRAYLENGTH
// 2 LCONST_0
// 6 ICONST_0
@@ -7,5 +7,5 @@ fun testLongWithCharSequence(i: Long, cs: CharSequence) = i in cs.indices
// 0 getIndices
// 0 contains
// 2 length
// 2 I2L
// 1 I2L
@@ -7,4 +7,4 @@ fun testLongWithCollection(i: Long, xs: List<Any>) = i in xs.indices
// 0 getIndices
// 0 contains
// 2 size
// 2 I2L
// 1 I2L
@@ -16,7 +16,7 @@ fun inDouble(x: Float): Boolean {
return x in 1.0..2.0
}
// 3 I2L
// 2 I2L
// 3 F2D
// 0 INVOKESPECIAL
// 0 NEW