Skip NOP instructions in fast pop backward propagation
This commit is contained in:
+4
-3
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.codegen.optimization.boxing
|
package org.jetbrains.kotlin.codegen.optimization.boxing
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.codegen.optimization.common.findPreviousOrNull
|
||||||
import org.jetbrains.kotlin.codegen.optimization.transformer.MethodTransformer
|
import org.jetbrains.kotlin.codegen.optimization.transformer.MethodTransformer
|
||||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||||
import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode
|
import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode
|
||||||
@@ -34,9 +35,9 @@ class FastPopBackwardPropagationTransformer : MethodTransformer() {
|
|||||||
|
|
||||||
val insns = methodNode.instructions.toArray()
|
val insns = methodNode.instructions.toArray()
|
||||||
|
|
||||||
for (i in 1 until insns.size) {
|
forInsn@ for (i in 1 until insns.size) {
|
||||||
val insn = insns[i]
|
val insn = insns[i]
|
||||||
val prev = insns[i - 1]
|
val prev = insn.findPreviousOrNull { it.opcode != Opcodes.NOP } ?: continue@forInsn
|
||||||
|
|
||||||
when (insn.opcode) {
|
when (insn.opcode) {
|
||||||
Opcodes.POP -> {
|
Opcodes.POP -> {
|
||||||
@@ -52,7 +53,7 @@ class FastPopBackwardPropagationTransformer : MethodTransformer() {
|
|||||||
toRemove.add(prev)
|
toRemove.add(prev)
|
||||||
}
|
}
|
||||||
else if (i > 1) {
|
else if (i > 1) {
|
||||||
val prev2 = insns[i - 2]
|
val prev2 = prev.findPreviousOrNull { it.opcode != Opcodes.NOP } ?: continue@forInsn
|
||||||
if (prev.isEliminatedByPop() && prev2.isEliminatedByPop()) {
|
if (prev.isEliminatedByPop() && prev2.isEliminatedByPop()) {
|
||||||
toReplaceWithNop.add(insn)
|
toReplaceWithNop.add(insn)
|
||||||
toRemove.add(prev)
|
toRemove.add(prev)
|
||||||
|
|||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun testPrimitiveArray(ints: IntArray) =
|
||||||
|
10 in ints.indices
|
||||||
|
|
||||||
|
// 0 DUP
|
||||||
|
// 0 POP
|
||||||
@@ -770,6 +770,12 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/bytecodeText/coercionToUnitOptimization"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/bytecodeText/coercionToUnitOptimization"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inRangeCheckWithConst.kt")
|
||||||
|
public void testInRangeCheckWithConst() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/coercionToUnitOptimization/inRangeCheckWithConst.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt14360.kt")
|
@TestMetadata("kt14360.kt")
|
||||||
public void testKt14360() throws Exception {
|
public void testKt14360() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/coercionToUnitOptimization/kt14360.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/coercionToUnitOptimization/kt14360.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user