Fix bytecode tests after new optimizations
- Turn some const conditions into non-const conditions - Make sure inlined const values are used where required (otherwise they are eliminated by POP backward propagation)
This commit is contained in:
+4
-2
@@ -3,6 +3,8 @@ fun acceptingBoxed(x : Int?) : Int ? = x
|
|||||||
|
|
||||||
class A(var x : Int? = null)
|
class A(var x : Int? = null)
|
||||||
|
|
||||||
|
val one = 1
|
||||||
|
|
||||||
fun foo() {
|
fun foo() {
|
||||||
val rb = returningBoxed()
|
val rb = returningBoxed()
|
||||||
acceptingBoxed(2)
|
acceptingBoxed(2)
|
||||||
@@ -20,8 +22,8 @@ fun foo() {
|
|||||||
val z: Int? = 8
|
val z: Int? = 8
|
||||||
val res = y === z
|
val res = y === z
|
||||||
|
|
||||||
val c1: Any = if (1 == 1) 0 else "abc"
|
val c1: Any = if (1 == one) 0 else "abc"
|
||||||
val c2: Any = if (1 != 1) 0 else "abc"
|
val c2: Any = if (1 != one) 0 else "abc"
|
||||||
}
|
}
|
||||||
|
|
||||||
// 9 java/lang/Integer.valueOf
|
// 9 java/lang/Integer.valueOf
|
||||||
|
|||||||
Vendored
+2
-2
@@ -20,11 +20,11 @@ fun box(): String {
|
|||||||
|
|
||||||
|
|
||||||
// Shared variable slots (x1, x2):
|
// Shared variable slots (x1, x2):
|
||||||
// 5 ILOAD 0
|
// 4 ILOAD 0
|
||||||
// 4 ISTORE 0
|
// 4 ISTORE 0
|
||||||
|
|
||||||
// Temporary variable slots for 'x2++':
|
// Temporary variable slots for 'x2++':
|
||||||
// 1 ILOAD 1
|
// 0 ILOAD 1
|
||||||
// 1 ISTORE 1
|
// 1 ISTORE 1
|
||||||
|
|
||||||
// 0 NEW
|
// 0 NEW
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
val a = false
|
||||||
|
val b = false
|
||||||
|
val c = false
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
val a = false
|
|
||||||
val b = false
|
|
||||||
val c = false
|
|
||||||
if (a && b && c) {
|
if (a && b && c) {
|
||||||
"then"
|
"then"
|
||||||
} else {
|
} else {
|
||||||
@@ -9,7 +10,7 @@ fun main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3 ICONST_0
|
// 0 ICONST_0
|
||||||
// 0 ICONST_1
|
// 0 ICONST_1
|
||||||
// 3 IFEQ
|
// 3 IFEQ
|
||||||
// 0 IFNE
|
// 0 IFNE
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
val a = false
|
||||||
|
val b = false
|
||||||
|
val c = false
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
val a = false
|
|
||||||
val b = false
|
|
||||||
val c = false
|
|
||||||
if (a || b || c) {
|
if (a || b || c) {
|
||||||
"then"
|
"then"
|
||||||
} else {
|
} else {
|
||||||
@@ -9,7 +10,7 @@ fun main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3 ICONST_0
|
// 0 ICONST_0
|
||||||
// 0 ICONST_1
|
// 0 ICONST_1
|
||||||
// 1 IFEQ
|
// 1 IFEQ
|
||||||
// 2 IFNE
|
// 2 IFNE
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
val a = false
|
||||||
|
val b = false
|
||||||
|
val c = false
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
val a = false
|
|
||||||
val b = false
|
|
||||||
val c = false
|
|
||||||
if (!(a && b && c)) {
|
if (!(a && b && c)) {
|
||||||
"then"
|
"then"
|
||||||
} else {
|
} else {
|
||||||
@@ -9,7 +10,7 @@ fun main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3 ICONST_0
|
// 0 ICONST_0
|
||||||
// 0 ICONST_1
|
// 0 ICONST_1
|
||||||
// 2 IFEQ
|
// 2 IFEQ
|
||||||
// 1 IFNE
|
// 1 IFNE
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
val a = false
|
||||||
|
val b = false
|
||||||
|
val c = false
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
val a = false
|
|
||||||
val b = false
|
|
||||||
val c = false
|
|
||||||
if (!(a || b || c)) {
|
if (!(a || b || c)) {
|
||||||
"then"
|
"then"
|
||||||
} else {
|
} else {
|
||||||
@@ -9,7 +10,7 @@ fun main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3 ICONST_0
|
// 0 ICONST_0
|
||||||
// 0 ICONST_1
|
// 0 ICONST_1
|
||||||
// 0 IFEQ
|
// 0 IFEQ
|
||||||
// 3 IFNE
|
// 3 IFNE
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
val a = 1
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
val a = 1
|
|
||||||
if (!(a == 0)) {
|
if (!(a == 0)) {
|
||||||
"then"
|
"then"
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
val a = 1
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
val a = 1
|
|
||||||
if (a == 0) {
|
if (a == 0) {
|
||||||
"then"
|
"then"
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+4
-2
@@ -12,11 +12,13 @@ fun builder(c: suspend () -> Unit) {
|
|||||||
c.startCoroutine(EmptyContinuation)
|
c.startCoroutine(EmptyContinuation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val nonConstOne = 1
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
var result = "fail 1"
|
var result = "fail 1"
|
||||||
builder {
|
builder {
|
||||||
// Initialize var with Int value
|
// Initialize var with Int value
|
||||||
for (i in 1..1) {
|
for (i in 1..nonConstOne) {
|
||||||
if ("".length > 0) continue
|
if ("".length > 0) continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,4 +45,4 @@ fun box(): String {
|
|||||||
// 1 LOCALVARIABLE s Ljava/lang/String; L.* 3
|
// 1 LOCALVARIABLE s Ljava/lang/String; L.* 3
|
||||||
// 0 PUTFIELD VarValueConflictsWithTableKt\$box\$1.I\$0 : I
|
// 0 PUTFIELD VarValueConflictsWithTableKt\$box\$1.I\$0 : I
|
||||||
/* 2 loads in cycle */
|
/* 2 loads in cycle */
|
||||||
// 2 ILOAD 3
|
// 2 ILOAD 3
|
||||||
Vendored
+1
-1
@@ -11,4 +11,4 @@ inline fun lookAtMe(f: () -> Int): Int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Less NOPs is better
|
// TODO: Less NOPs is better
|
||||||
// 1 NOP
|
// 2 NOP
|
||||||
@@ -35,29 +35,31 @@ object KoKobject {
|
|||||||
val JvmStaticString: String? = "123"
|
val JvmStaticString: String? = "123"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Any?.use() {}
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
Integer.MIN_VALUE
|
Integer.MIN_VALUE.use()
|
||||||
java.lang.Long.MAX_VALUE
|
java.lang.Long.MAX_VALUE.use()
|
||||||
|
|
||||||
JClass.PrimitiveInt
|
JClass.PrimitiveInt.use()
|
||||||
JClass.BigPrimitiveInt
|
JClass.BigPrimitiveInt.use()
|
||||||
JClass.PrimitiveByte
|
JClass.PrimitiveByte.use()
|
||||||
JClass.PrimitiveChar
|
JClass.PrimitiveChar.use()
|
||||||
JClass.PrimitiveLong
|
JClass.PrimitiveLong.use()
|
||||||
JClass.PrimitiveShort
|
JClass.PrimitiveShort.use()
|
||||||
JClass.PrimitiveBool
|
JClass.PrimitiveBool.use()
|
||||||
JClass.PrimitiveFloat
|
JClass.PrimitiveFloat.use()
|
||||||
JClass.PrimitiveDouble
|
JClass.PrimitiveDouble.use()
|
||||||
JClass.Str
|
JClass.Str.use()
|
||||||
JClass.StrNullable
|
JClass.StrNullable.use()
|
||||||
|
|
||||||
JClass.BoxedInt
|
JClass.BoxedInt.use()
|
||||||
JClass.NonFinal
|
JClass.NonFinal.use()
|
||||||
|
|
||||||
JClass().NonStatic
|
JClass().NonStatic.use()
|
||||||
|
|
||||||
KoKobject.JvmStatic
|
KoKobject.JvmStatic.use()
|
||||||
KoKobject.JvmStaticString
|
KoKobject.JvmStaticString.use()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1 LDC -2147483648
|
// 1 LDC -2147483648
|
||||||
@@ -78,5 +80,4 @@ fun test() {
|
|||||||
// 1 GETFIELD JClass.NonStatic : I
|
// 1 GETFIELD JClass.NonStatic : I
|
||||||
// 1 GETSTATIC KoKobject.JvmStatic : I
|
// 1 GETSTATIC KoKobject.JvmStatic : I
|
||||||
// 1 GETSTATIC KoKobject.JvmStaticString : Ljava/lang/String
|
// 1 GETSTATIC KoKobject.JvmStaticString : Ljava/lang/String
|
||||||
// 3 POP2
|
|
||||||
// 18 POP
|
|
||||||
|
|||||||
@@ -13,4 +13,5 @@ fun less5(a: Any?, b: Any?) = if (a is Byte && b is Byte) a < b else true
|
|||||||
// 3 Intrinsics\.areEqual
|
// 3 Intrinsics\.areEqual
|
||||||
// 3 Intrinsics\.compare
|
// 3 Intrinsics\.compare
|
||||||
// for compare:
|
// for compare:
|
||||||
// 3 IF_ICMPGE
|
// 3 IFGE
|
||||||
|
// 0 IF_ICMPGE
|
||||||
|
|||||||
@@ -13,4 +13,5 @@ fun less5(a: Any?, b: Any?) = if (a is Char && b is Char) a < b else true
|
|||||||
// 3 Intrinsics\.areEqual
|
// 3 Intrinsics\.areEqual
|
||||||
// 3 Intrinsics\.compare
|
// 3 Intrinsics\.compare
|
||||||
// for compare:
|
// for compare:
|
||||||
// 3 IF_ICMPGE
|
// 3 IFGE
|
||||||
|
// 0 IF_ICMPGE
|
||||||
|
|||||||
@@ -13,4 +13,5 @@ fun less5(a: Any?, b: Any?) = if (a is Int && b is Int) a < b else true
|
|||||||
// 3 Intrinsics\.areEqual
|
// 3 Intrinsics\.areEqual
|
||||||
// 3 Intrinsics\.compare
|
// 3 Intrinsics\.compare
|
||||||
// for compare:
|
// for compare:
|
||||||
// 3 IF_ICMPGE
|
// 3 IFGE
|
||||||
|
// 0 IF_ICMPGE
|
||||||
|
|||||||
@@ -13,4 +13,5 @@ fun less5(a: Any?, b: Any?) = if (a is Long && b is Long) a < b else true
|
|||||||
// 3 Intrinsics\.areEqual
|
// 3 Intrinsics\.areEqual
|
||||||
// 3 Intrinsics\.compare
|
// 3 Intrinsics\.compare
|
||||||
// for compare:
|
// for compare:
|
||||||
// 3 IF_ICMPGE
|
// 3 IFGE
|
||||||
|
// 0 IF_ICMPGE
|
||||||
|
|||||||
@@ -13,4 +13,5 @@ fun less5(a: Any?, b: Any?) = if (a is Short && b is Short) a < b else true
|
|||||||
// 3 Intrinsics\.areEqual
|
// 3 Intrinsics\.areEqual
|
||||||
// 3 Intrinsics\.compare
|
// 3 Intrinsics\.compare
|
||||||
// for compare:
|
// for compare:
|
||||||
// 3 IF_ICMPGE
|
// 3 IFGE
|
||||||
|
// 0 IF_ICMPGE
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
val two = 2
|
||||||
|
|
||||||
fun test2() {
|
fun test2() {
|
||||||
val p = 1 < 2;
|
val p = 1 < two
|
||||||
if (!p) {
|
if (!p) {
|
||||||
val p = 1
|
val p = 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
val two = 2
|
||||||
|
|
||||||
fun test2() {
|
fun test2() {
|
||||||
val p = 1 < 2;
|
val p = 1 < two
|
||||||
if (!!!!!!p) {
|
if (!!!!!!p) {
|
||||||
val p = 1
|
val p = 1
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
fun test1() {
|
fun test1() {
|
||||||
val n = null
|
val n = null
|
||||||
n.elvis { "X1" }
|
val u1 = n.elvis { "X1" }
|
||||||
"X2".elvis { "X3" }
|
val u2 = "X2".elvis { "X3" }
|
||||||
}
|
}
|
||||||
|
|
||||||
// @TestKt.class:
|
// @TestKt.class:
|
||||||
|
|||||||
+3
-3
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
// FILE: test.kt
|
// FILE: test.kt
|
||||||
|
|
||||||
fun test1() {
|
fun test1(): String {
|
||||||
val u = Unit
|
val u = Unit
|
||||||
u.mapNullable({ "X1" }, { "X2" })
|
return u.mapNullable({ "X1" }, { "X2" })
|
||||||
}
|
}
|
||||||
|
|
||||||
// @TestKt.class:
|
// @TestKt.class:
|
||||||
@@ -14,5 +14,5 @@ fun test1() {
|
|||||||
// 0 X2
|
// 0 X2
|
||||||
|
|
||||||
// FILE: inline.kt
|
// FILE: inline.kt
|
||||||
inline fun <T : Any, R> T?.mapNullable(ifNotNull: (T) -> R, ifNull: () -> R) =
|
inline fun <T : Any, R> T?.mapNullable(ifNotNull: (T) -> R, ifNull: () -> R): R =
|
||||||
if (this == null) ifNull() else ifNotNull(this)
|
if (this == null) ifNull() else ifNotNull(this)
|
||||||
+4
-2
@@ -38,8 +38,10 @@ object KoKobject {
|
|||||||
val JvmStaticString: String? = "123"
|
val JvmStaticString: String? = "123"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Any?.use() {}
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
"res1: " +
|
("res1: " +
|
||||||
Integer.MIN_VALUE + " " +
|
Integer.MIN_VALUE + " " +
|
||||||
java.lang.Long.MAX_VALUE + " " +
|
java.lang.Long.MAX_VALUE + " " +
|
||||||
JClass.PrimitiveInt + " " +
|
JClass.PrimitiveInt + " " +
|
||||||
@@ -52,7 +54,7 @@ fun test() {
|
|||||||
JClass.PrimitiveFloat + " " +
|
JClass.PrimitiveFloat + " " +
|
||||||
JClass.PrimitiveDouble + " " +
|
JClass.PrimitiveDouble + " " +
|
||||||
JClass.Str + " " +
|
JClass.Str + " " +
|
||||||
JClass.StrNullable
|
JClass.StrNullable).use()
|
||||||
|
|
||||||
"res2: " + JClass.BoxedInt
|
"res2: " + JClass.BoxedInt
|
||||||
"res3: " + JClass.NonFinal
|
"res3: " + JClass.NonFinal
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
|
val nonConstFlag = true
|
||||||
|
|
||||||
inline fun <T, R> calc(value : T, fn: (T) -> R) : R = fn(value)
|
inline fun <T, R> calc(value : T, fn: (T) -> R) : R = fn(value)
|
||||||
|
|
||||||
inline fun <T> identity(value : T) : T = calc(value) {
|
inline fun <T> identity(value : T) : T = calc(value) {
|
||||||
if (1 == 1) return it
|
if (nonConstFlag) return it
|
||||||
it
|
it
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user