Make redundant null check optimization independent of boxing optimization algorithm.

Run DCE after each single redundant null check optimization pass.
This commit is contained in:
Dmitry Petrov
2017-02-06 20:01:54 +03:00
parent eda43c8b45
commit 3fc106572e
20 changed files with 454 additions and 141 deletions

View File

@@ -0,0 +1,18 @@
// WITH_RUNTIME
fun test1() {
val a = null
if (a != null) {
println("X1")
}
if (a == null) {
println("X2")
}
}
// 0 IFNULL
// 0 IFNONNULL
// 0 X1
// 1 X2

View File

@@ -0,0 +1,19 @@
// WITH_RUNTIME
// FILE: test.kt
fun test1() {
val n = null
n.elvis { "X1" }
"X2".elvis { "X3" }
}
// @TestKt.class:
// 0 IFNULL
// 0 IFNONNULL
// 1 X1
// 1 X2
// 0 X3
// FILE: inline.kt
inline fun <T : Any> T?.elvis(rhs: () -> T): T = this ?: rhs()

View File

@@ -0,0 +1,18 @@
// WITH_RUNTIME
fun test1() {
val a = Unit
if (a != null) {
println("X1")
}
if (a == null) {
println("X2")
}
}
// 0 IFNULL
// 0 IFNONNULL
// 1 X1
// 0 X2

View File

@@ -0,0 +1,18 @@
// WITH_RUNTIME
// FILE: test.kt
fun test1() {
val u = Unit
u.mapNullable({ "X1" }, { "X2" })
}
// @TestKt.class:
// 0 IFNULL
// 0 IFNONNULL
// 1 X1
// 0 X2
// FILE: inline.kt
inline fun <T : Any, R> T?.mapNullable(ifNotNull: (T) -> R, ifNull: () -> R) =
if (this == null) ifNull() else ifNotNull(this)