JVM_IR KT-46864 handle "unused" LDC instructions properly
This commit is contained in:
committed by
TeamCityServer
parent
be097244d4
commit
9091ca7b51
+15
-11
@@ -19,14 +19,12 @@ 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.org.objectweb.asm.Opcodes
|
||||
import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode
|
||||
import org.jetbrains.org.objectweb.asm.tree.InsnList
|
||||
import org.jetbrains.org.objectweb.asm.tree.InsnNode
|
||||
import org.jetbrains.org.objectweb.asm.tree.MethodNode
|
||||
import org.jetbrains.org.objectweb.asm.tree.*
|
||||
|
||||
class StackPeepholeOptimizationsTransformer : MethodTransformer() {
|
||||
override fun transform(internalClassName: String, methodNode: MethodNode) {
|
||||
while (transformOnce(methodNode)) {
|
||||
while (true) {
|
||||
if (!transformOnce(methodNode)) break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,20 +113,26 @@ class StackPeepholeOptimizationsTransformer : MethodTransformer() {
|
||||
opcode == Opcodes.DUP
|
||||
|
||||
private fun AbstractInsnNode.isPurePushOfSize1(): Boolean =
|
||||
opcode in Opcodes.ACONST_NULL..Opcodes.FCONST_2 ||
|
||||
opcode in Opcodes.BIPUSH..Opcodes.ILOAD ||
|
||||
opcode == Opcodes.FLOAD ||
|
||||
opcode == Opcodes.ALOAD ||
|
||||
isUnitInstance()
|
||||
!isLdcOfSize2() && (
|
||||
opcode in Opcodes.ACONST_NULL..Opcodes.FCONST_2 ||
|
||||
opcode in Opcodes.BIPUSH..Opcodes.ILOAD ||
|
||||
opcode == Opcodes.FLOAD ||
|
||||
opcode == Opcodes.ALOAD ||
|
||||
isUnitInstance()
|
||||
)
|
||||
|
||||
private fun AbstractInsnNode.isEliminatedByPop2() =
|
||||
isPurePushOfSize2() ||
|
||||
opcode == Opcodes.DUP2
|
||||
|
||||
private fun AbstractInsnNode.isPurePushOfSize2(): Boolean =
|
||||
opcode == Opcodes.LCONST_0 || opcode == Opcodes.LCONST_1 ||
|
||||
isLdcOfSize2() ||
|
||||
opcode == Opcodes.LCONST_0 || opcode == Opcodes.LCONST_1 ||
|
||||
opcode == Opcodes.DCONST_0 || opcode == Opcodes.DCONST_1 ||
|
||||
opcode == Opcodes.LLOAD ||
|
||||
opcode == Opcodes.DLOAD
|
||||
|
||||
private fun AbstractInsnNode.isLdcOfSize2(): Boolean =
|
||||
opcode == Opcodes.LDC && this is LdcInsnNode && (this.cst is Double || this.cst is Long)
|
||||
}
|
||||
|
||||
|
||||
+12
@@ -27998,6 +27998,18 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt446.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt46864_double.kt")
|
||||
public void testKt46864_double() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt46864_double.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt46864_long.kt")
|
||||
public void testKt46864_long() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt46864_long.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt518.kt")
|
||||
public void testKt518() throws Exception {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
fun box(): String {
|
||||
// NB it's important that the following expression is unused
|
||||
(40.523 !== 62.562)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun box(): String {
|
||||
// NB it's important that the following expression is unused
|
||||
(1234L !== 5678L)
|
||||
return "OK"
|
||||
}
|
||||
+12
@@ -27968,6 +27968,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt446.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt46864_double.kt")
|
||||
public void testKt46864_double() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt46864_double.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt46864_long.kt")
|
||||
public void testKt46864_long() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt46864_long.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt518.kt")
|
||||
public void testKt518() throws Exception {
|
||||
|
||||
+12
@@ -27998,6 +27998,18 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt446.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt46864_double.kt")
|
||||
public void testKt46864_double() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt46864_double.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt46864_long.kt")
|
||||
public void testKt46864_long() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt46864_long.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt518.kt")
|
||||
public void testKt518() throws Exception {
|
||||
|
||||
+10
@@ -23744,6 +23744,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt446.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt46864_double.kt")
|
||||
public void testKt46864_double() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt46864_double.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt46864_long.kt")
|
||||
public void testKt46864_long() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt46864_long.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt518.kt")
|
||||
public void testKt518() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt518.kt");
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
Generated
+10
@@ -18668,6 +18668,16 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt446.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt46864_double.kt")
|
||||
public void testKt46864_double() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt46864_double.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt46864_long.kt")
|
||||
public void testKt46864_long() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt46864_long.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt518.kt")
|
||||
public void testKt518() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt518.kt");
|
||||
|
||||
Generated
+10
@@ -18074,6 +18074,16 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt446.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt46864_double.kt")
|
||||
public void testKt46864_double() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt46864_double.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt46864_long.kt")
|
||||
public void testKt46864_long() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt46864_long.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt518.kt")
|
||||
public void testKt518() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt518.kt");
|
||||
|
||||
Generated
+10
@@ -18139,6 +18139,16 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt446.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt46864_double.kt")
|
||||
public void testKt46864_double() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt46864_double.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt46864_long.kt")
|
||||
public void testKt46864_long() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt46864_long.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt518.kt")
|
||||
public void testKt518() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt518.kt");
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java
Generated
+10
@@ -11475,6 +11475,16 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt446.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt46864_double.kt")
|
||||
public void testKt46864_double() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt46864_double.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt46864_long.kt")
|
||||
public void testKt46864_long() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt46864_long.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt518.kt")
|
||||
public void testKt518() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/primitiveTypes/kt518.kt");
|
||||
|
||||
Reference in New Issue
Block a user