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)
|
||||
|
||||
val one = 1
|
||||
|
||||
fun foo() {
|
||||
val rb = returningBoxed()
|
||||
acceptingBoxed(2)
|
||||
@@ -20,8 +22,8 @@ fun foo() {
|
||||
val z: Int? = 8
|
||||
val res = y === z
|
||||
|
||||
val c1: Any = if (1 == 1) 0 else "abc"
|
||||
val c2: Any = if (1 != 1) 0 else "abc"
|
||||
val c1: Any = if (1 == one) 0 else "abc"
|
||||
val c2: Any = if (1 != one) 0 else "abc"
|
||||
}
|
||||
|
||||
// 9 java/lang/Integer.valueOf
|
||||
|
||||
Vendored
+2
-2
@@ -20,11 +20,11 @@ fun box(): String {
|
||||
|
||||
|
||||
// Shared variable slots (x1, x2):
|
||||
// 5 ILOAD 0
|
||||
// 4 ILOAD 0
|
||||
// 4 ISTORE 0
|
||||
|
||||
// Temporary variable slots for 'x2++':
|
||||
// 1 ILOAD 1
|
||||
// 0 ILOAD 1
|
||||
// 1 ISTORE 1
|
||||
|
||||
// 0 NEW
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
val a = false
|
||||
val b = false
|
||||
val c = false
|
||||
|
||||
fun main() {
|
||||
val a = false
|
||||
val b = false
|
||||
val c = false
|
||||
if (a && b && c) {
|
||||
"then"
|
||||
} else {
|
||||
@@ -9,7 +10,7 @@ fun main() {
|
||||
}
|
||||
}
|
||||
|
||||
// 3 ICONST_0
|
||||
// 0 ICONST_0
|
||||
// 0 ICONST_1
|
||||
// 3 IFEQ
|
||||
// 0 IFNE
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
val a = false
|
||||
val b = false
|
||||
val c = false
|
||||
|
||||
fun main() {
|
||||
val a = false
|
||||
val b = false
|
||||
val c = false
|
||||
if (a || b || c) {
|
||||
"then"
|
||||
} else {
|
||||
@@ -9,7 +10,7 @@ fun main() {
|
||||
}
|
||||
}
|
||||
|
||||
// 3 ICONST_0
|
||||
// 0 ICONST_0
|
||||
// 0 ICONST_1
|
||||
// 1 IFEQ
|
||||
// 2 IFNE
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
val a = false
|
||||
val b = false
|
||||
val c = false
|
||||
|
||||
fun main() {
|
||||
val a = false
|
||||
val b = false
|
||||
val c = false
|
||||
if (!(a && b && c)) {
|
||||
"then"
|
||||
} else {
|
||||
@@ -9,7 +10,7 @@ fun main() {
|
||||
}
|
||||
}
|
||||
|
||||
// 3 ICONST_0
|
||||
// 0 ICONST_0
|
||||
// 0 ICONST_1
|
||||
// 2 IFEQ
|
||||
// 1 IFNE
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
val a = false
|
||||
val b = false
|
||||
val c = false
|
||||
|
||||
fun main() {
|
||||
val a = false
|
||||
val b = false
|
||||
val c = false
|
||||
if (!(a || b || c)) {
|
||||
"then"
|
||||
} else {
|
||||
@@ -9,7 +10,7 @@ fun main() {
|
||||
}
|
||||
}
|
||||
|
||||
// 3 ICONST_0
|
||||
// 0 ICONST_0
|
||||
// 0 ICONST_1
|
||||
// 0 IFEQ
|
||||
// 3 IFNE
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
val a = 1
|
||||
|
||||
fun main() {
|
||||
val a = 1
|
||||
if (!(a == 0)) {
|
||||
"then"
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
val a = 1
|
||||
|
||||
fun main() {
|
||||
val a = 1
|
||||
if (a == 0) {
|
||||
"then"
|
||||
} else {
|
||||
|
||||
+4
-2
@@ -12,11 +12,13 @@ fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
val nonConstOne = 1
|
||||
|
||||
fun box(): String {
|
||||
var result = "fail 1"
|
||||
builder {
|
||||
// Initialize var with Int value
|
||||
for (i in 1..1) {
|
||||
for (i in 1..nonConstOne) {
|
||||
if ("".length > 0) continue
|
||||
}
|
||||
|
||||
@@ -43,4 +45,4 @@ fun box(): String {
|
||||
// 1 LOCALVARIABLE s Ljava/lang/String; L.* 3
|
||||
// 0 PUTFIELD VarValueConflictsWithTableKt\$box\$1.I\$0 : I
|
||||
/* 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
|
||||
// 1 NOP
|
||||
// 2 NOP
|
||||
@@ -35,29 +35,31 @@ object KoKobject {
|
||||
val JvmStaticString: String? = "123"
|
||||
}
|
||||
|
||||
fun Any?.use() {}
|
||||
|
||||
fun test() {
|
||||
Integer.MIN_VALUE
|
||||
java.lang.Long.MAX_VALUE
|
||||
Integer.MIN_VALUE.use()
|
||||
java.lang.Long.MAX_VALUE.use()
|
||||
|
||||
JClass.PrimitiveInt
|
||||
JClass.BigPrimitiveInt
|
||||
JClass.PrimitiveByte
|
||||
JClass.PrimitiveChar
|
||||
JClass.PrimitiveLong
|
||||
JClass.PrimitiveShort
|
||||
JClass.PrimitiveBool
|
||||
JClass.PrimitiveFloat
|
||||
JClass.PrimitiveDouble
|
||||
JClass.Str
|
||||
JClass.StrNullable
|
||||
JClass.PrimitiveInt.use()
|
||||
JClass.BigPrimitiveInt.use()
|
||||
JClass.PrimitiveByte.use()
|
||||
JClass.PrimitiveChar.use()
|
||||
JClass.PrimitiveLong.use()
|
||||
JClass.PrimitiveShort.use()
|
||||
JClass.PrimitiveBool.use()
|
||||
JClass.PrimitiveFloat.use()
|
||||
JClass.PrimitiveDouble.use()
|
||||
JClass.Str.use()
|
||||
JClass.StrNullable.use()
|
||||
|
||||
JClass.BoxedInt
|
||||
JClass.NonFinal
|
||||
JClass.BoxedInt.use()
|
||||
JClass.NonFinal.use()
|
||||
|
||||
JClass().NonStatic
|
||||
JClass().NonStatic.use()
|
||||
|
||||
KoKobject.JvmStatic
|
||||
KoKobject.JvmStaticString
|
||||
KoKobject.JvmStatic.use()
|
||||
KoKobject.JvmStaticString.use()
|
||||
}
|
||||
|
||||
// 1 LDC -2147483648
|
||||
@@ -78,5 +80,4 @@ fun test() {
|
||||
// 1 GETFIELD JClass.NonStatic : I
|
||||
// 1 GETSTATIC KoKobject.JvmStatic : I
|
||||
// 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\.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\.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\.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\.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\.compare
|
||||
// for compare:
|
||||
// 3 IF_ICMPGE
|
||||
// 3 IFGE
|
||||
// 0 IF_ICMPGE
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
val two = 2
|
||||
|
||||
fun test2() {
|
||||
val p = 1 < 2;
|
||||
val p = 1 < two
|
||||
if (!p) {
|
||||
val p = 1
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
val two = 2
|
||||
|
||||
fun test2() {
|
||||
val p = 1 < 2;
|
||||
val p = 1 < two
|
||||
if (!!!!!!p) {
|
||||
val p = 1
|
||||
}
|
||||
|
||||
+2
-2
@@ -4,8 +4,8 @@
|
||||
|
||||
fun test1() {
|
||||
val n = null
|
||||
n.elvis { "X1" }
|
||||
"X2".elvis { "X3" }
|
||||
val u1 = n.elvis { "X1" }
|
||||
val u2 = "X2".elvis { "X3" }
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
|
||||
+3
-3
@@ -2,9 +2,9 @@
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test1() {
|
||||
fun test1(): String {
|
||||
val u = Unit
|
||||
u.mapNullable({ "X1" }, { "X2" })
|
||||
return u.mapNullable({ "X1" }, { "X2" })
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
@@ -14,5 +14,5 @@ fun test1() {
|
||||
// 0 X2
|
||||
|
||||
// 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)
|
||||
+4
-2
@@ -38,8 +38,10 @@ object KoKobject {
|
||||
val JvmStaticString: String? = "123"
|
||||
}
|
||||
|
||||
fun Any?.use() {}
|
||||
|
||||
fun test() {
|
||||
"res1: " +
|
||||
("res1: " +
|
||||
Integer.MIN_VALUE + " " +
|
||||
java.lang.Long.MAX_VALUE + " " +
|
||||
JClass.PrimitiveInt + " " +
|
||||
@@ -52,7 +54,7 @@ fun test() {
|
||||
JClass.PrimitiveFloat + " " +
|
||||
JClass.PrimitiveDouble + " " +
|
||||
JClass.Str + " " +
|
||||
JClass.StrNullable
|
||||
JClass.StrNullable).use()
|
||||
|
||||
"res2: " + JClass.BoxedInt
|
||||
"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> identity(value : T) : T = calc(value) {
|
||||
if (1 == 1) return it
|
||||
if (nonConstFlag) return it
|
||||
it
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user