Implement constant folding in the IR backend for JVM
The newly added pass folds the set of constant functions of the current backend, plus IrBuiltIns.
This commit is contained in:
committed by
max-kammerer
parent
7e4d33be24
commit
79fcaae991
@@ -0,0 +1,16 @@
|
||||
// WITH_RUNTIME
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
fun foo(): Array<Boolean> {
|
||||
return arrayOf(
|
||||
0.0 / 0 == 0.0 / 0,
|
||||
0.0F > -0.0F,
|
||||
0.0.equals(-0.0),
|
||||
(0.0 / 0.0).equals(1.0 / 0.0)
|
||||
)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (foo().any { it == true })
|
||||
return "fail: ${foo().contentDeepToString()}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// WITH_RUNTIME
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
fun foo(): Array<Boolean> {
|
||||
return arrayOf(
|
||||
19 < 20.0,
|
||||
12 > 11,
|
||||
3.0F <= 4.0,
|
||||
4.0F >= 4,
|
||||
0.0 / 0 != 0.0 / 0,
|
||||
0.0 == -0.0,
|
||||
123 == 123,
|
||||
123L == 123L,
|
||||
0.0F == -0.0F,
|
||||
0.0.compareTo(-0.0) > 0,
|
||||
(0.0 / 0.0).compareTo(1.0 / 0.0) > 0
|
||||
)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (foo().any { it == false })
|
||||
return "fail: ${foo().contentDeepToString()}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// IGNORE_BACKEND: JS
|
||||
// reason - no error from division by zero in JS
|
||||
|
||||
fun expectArithmeticException(f: () -> Unit): Boolean {
|
||||
try {
|
||||
f()
|
||||
} catch (e: ArithmeticException) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (!expectArithmeticException { 1 / 0 })
|
||||
return "fail: 1 / 0 didn't throw exception"
|
||||
|
||||
if (!expectArithmeticException { 1 * 2 / 0 })
|
||||
return "fail: 1 * 2 / 0 didn't throw exception"
|
||||
|
||||
if (!expectArithmeticException { 1 * (2 / 0) })
|
||||
return "fail: 1 * (2 / 0) didn't throw exception"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
fun box() : String {
|
||||
230?.toByte()?.hashCode()
|
||||
9.hashCode()
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
fun identity(x: Int): Int {
|
||||
return when {
|
||||
x < 0 -> identity(x + 1) - 1
|
||||
x > 0 -> identity(x - 1) + 1
|
||||
else -> 0
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
// Just hard enough that the test won't get optimized away at compile time.
|
||||
val twoThirty = identity(230)
|
||||
val nine = identity(9)
|
||||
twoThirty?.toByte()?.hashCode()
|
||||
nine.hashCode()
|
||||
|
||||
if(twoThirty.equals(nine.toByte())) {
|
||||
return "fail"
|
||||
}
|
||||
|
||||
if(twoThirty == nine.toByte().toInt()) {
|
||||
return "fail"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user