[JVM_IR] Avoid some boxing when comparing boxed primitives to primitives.

This commit is contained in:
Mads Ager
2020-04-30 14:42:28 +02:00
committed by Dmitry Petrov
parent f3830cb07e
commit db17184cfd
13 changed files with 128 additions and 92 deletions
@@ -1,6 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// TODO KT-36646 Don't box primitive values in equality comparison with nullable primitive values in JVM_IR
fun testBoolean1(a: Boolean?, b: Boolean) = a == b
fun testBoolean2(a: Boolean?, b: Boolean) = a != b
@@ -1,6 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// TODO KT-36646 Don't box primitive values in equality comparison with nullable primitive values in JVM_IR
fun testBoolean1(a: Boolean, b: Boolean?) = a == b
fun testBoolean2(a: Boolean, b: Boolean?) = a != b
@@ -11,17 +11,9 @@ fun less4(a: Byte?, b: Byte?) = if (a is Byte && b is Byte) a < b else true
fun less5(a: Any?, b: Any?) = if (a is Byte && b is Byte) a < b else true
// JVM_TEMPLATES
// 3 Intrinsics\.areEqual
// 0 Intrinsics\.compare
// 4 INVOKEVIRTUAL java/lang/Byte\.byteValue \(\)B
// 2 INVOKEVIRTUAL java/lang/Number\.intValue \(\)I
// 0 IFGE
// 3 IF_ICMPGE
// JVM_IR_TEMPLATES
// 0 Intrinsics\.areEqual
// 0 Intrinsics\.compare
// 8 INVOKEVIRTUAL java/lang/Byte\.byteValue \(\)B
// 4 INVOKEVIRTUAL java/lang/Number\.byteValue \(\)B
// 0 IFGE
// 3 IF_ICMPNE
// 3 IF_ICMPGE
@@ -19,10 +19,10 @@ fun less5(a: Any?, b: Any?) = if (a is Byte && b is Byte) a < b else true
// 0 IF_ICMPGE
// JVM_IR_TEMPLATES
// 0 Intrinsics\.areEqual
// 3 Intrinsics\.areEqual
// 0 Intrinsics\.compare
// 8 INVOKEVIRTUAL java/lang/Byte\.byteValue \(\)B
// 4 INVOKEVIRTUAL java/lang/Number\.byteValue \(\)B
// 4 INVOKEVIRTUAL java/lang/Byte\.byteValue \(\)B
// 2 INVOKEVIRTUAL java/lang/Number\.intValue \(\)I
// 0 IFGE
// 3 IF_ICMPGE
// 3 IF_ICMPNE
// 0 IF_ICMPNE
@@ -11,17 +11,10 @@ fun less4(a: Short?, b: Short?) = if (a is Short && b is Short) a < b else true
fun less5(a: Any?, b: Any?) = if (a is Short && b is Short) a < b else true
// JVM_TEMPLATES
// 3 Intrinsics\.areEqual
// 0 Intrinsics\.compare
// 4 INVOKEVIRTUAL java/lang/Short\.shortValue \(\)S
// 2 INVOKEVIRTUAL java/lang/Number\.intValue \(\)I
// 0 IFGE
// 3 IF_ICMPGE
// JVM_IR_TEMPLATES
// 0 Intrinsics\.areEqual
// 0 Intrinsics\.compare
// 8 INVOKEVIRTUAL java/lang/Short\.shortValue \(\)S
// 4 INVOKEVIRTUAL java/lang/Number\.shortValue \(\)S
// 0 IFGE
// 3 IF_ICMPGE
// 3 IF_ICMPNE
// 0 IF_ICMPNE
@@ -18,10 +18,10 @@ fun less5(a: Any?, b: Any?) = if (a is Short && b is Short) a < b else true
// 0 IF_ICMPGE
// JVM_IR_TEMPLATES
// 0 Intrinsics\.areEqual
// 3 Intrinsics\.areEqual
// 0 Intrinsics\.compare
// 8 INVOKEVIRTUAL java/lang/Short\.shortValue \(\)S
// 4 INVOKEVIRTUAL java/lang/Number\.shortValue \(\)S
// 4 INVOKEVIRTUAL java/lang/Short\.shortValue \(\)S
// 2 INVOKEVIRTUAL java/lang/Number\.intValue \(\)I
// 0 IFGE
// 3 IF_ICMPGE
// 3 IF_ICMPNE
// 0 IF_ICMPNE
@@ -1,6 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// TODO KT-36646 Don't box primitive values in equality comparison with objects in JVM_IR
fun testInt(i: Int?) =
when (i) {
0 -> "zero"