Files
kotlin/compiler/testData/codegen/bytecodeText/intrinsicsCompare/byteSmartCast_before.kt
Mads Ager 1f4a3b0d1c [JVM_IR] Avoid safe-call conversions from Byte? and Short? to Int? for
comparisons.

Having those conversions leads to unnecesary boxing and null checks.

This change does it only for JVM in the optimization lowering. It
is unclear to me if the other backends can get away with something
similar.
2020-05-08 11:39:30 +03:00

28 lines
797 B
Kotlin
Vendored

// !LANGUAGE: -ProperIeee754Comparisons
fun equals3(a: Byte?, b: Byte?) = a != null && b != null && a == b
fun equals4(a: Byte?, b: Byte?) = if (a is Byte && b is Byte) a == b else null!!
fun equals5(a: Any?, b: Any?) = if (a is Byte && b is Byte) a == b else null!!
fun less3(a: Byte?, b: Byte?) = a != null && b != null && a < b
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
// 3 Intrinsics\.compare
// for compare:
// 3 IFGE
// 0 IF_ICMPGE
// JVM_IR_TEMPLATES
// 2 Intrinsics\.areEqual
// 0 Intrinsics\.compare
// 4 INVOKEVIRTUAL java/lang/Byte\.byteValue \(\)B
// 4 INVOKEVIRTUAL java/lang/Number\.byteValue \(\)B
// 0 IFGE
// 3 IF_ICMPGE