JVM IR: Optimize type checks to null checks if possible
This commit is contained in:
committed by
Georgy Bronnikov
parent
07737f8fc6
commit
951b2fa770
+2
@@ -69,6 +69,8 @@ private class TypeOperatorLowering(private val context: JvmBackendContext) : Fil
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
argument.type.isNullable() && !type.isNullable() && argument.type.erasedUpperBound == type.erasedUpperBound ->
|
||||||
|
irNotEquals(argument, irNull())
|
||||||
else -> irIs(argument, type.makeNotNull())
|
else -> irIs(argument, type.makeNotNull())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+5
-2
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND: JVM_IR
|
|
||||||
abstract class A8 : MutableCollection<Any> {
|
abstract class A8 : MutableCollection<Any> {
|
||||||
override fun contains(o: Any): Boolean {
|
override fun contains(o: Any): Boolean {
|
||||||
throw UnsupportedOperationException()
|
throw UnsupportedOperationException()
|
||||||
@@ -8,5 +7,9 @@ abstract class A8 : MutableCollection<Any> {
|
|||||||
// 1 bridge
|
// 1 bridge
|
||||||
// 1 public final bridge size
|
// 1 public final bridge size
|
||||||
// 0 INSTANCEOF
|
// 0 INSTANCEOF
|
||||||
/* Only 1 IFNULL should be within contains method */
|
|
||||||
|
/* Only 1 null check should be within the contains method */
|
||||||
|
// JVM_TEMPLATES:
|
||||||
// 1 IFNULL
|
// 1 IFNULL
|
||||||
|
// JVM_IR_TEMPLATES:
|
||||||
|
// 1 IFNONNULL
|
||||||
|
|||||||
Vendored
+5
-2
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND: JVM_IR
|
|
||||||
abstract class A<T : Any> : MutableCollection<T> {
|
abstract class A<T : Any> : MutableCollection<T> {
|
||||||
override fun contains(o: T): Boolean {
|
override fun contains(o: T): Boolean {
|
||||||
throw UnsupportedOperationException()
|
throw UnsupportedOperationException()
|
||||||
@@ -8,5 +7,9 @@ abstract class A<T : Any> : MutableCollection<T> {
|
|||||||
// 1 bridge
|
// 1 bridge
|
||||||
// 1 public final bridge size
|
// 1 public final bridge size
|
||||||
// 0 INSTANCEOF
|
// 0 INSTANCEOF
|
||||||
/* Only 1 IFNULL should be within contains method (because T is not nullable) */
|
|
||||||
|
/* Only 1 null check should be within the contains method (because T is not nullable) */
|
||||||
|
// JVM_TEMPLATES:
|
||||||
// 1 IFNULL
|
// 1 IFNULL
|
||||||
|
// JVM_IR_TEMPLATES:
|
||||||
|
// 1 IFNONNULL
|
||||||
|
|||||||
Reference in New Issue
Block a user