mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 00:21:26 +00:00
Using basic constant propagation (only integer constants, no arithmetic calculations), rewrite conditional jump instructions with constant arguments. This covers problem description in KT-17007. Note that it also works transparently with inline functions. Partial evaluation is required to cover more "advanced" cases. As a side effect, this also covers KT-3098: rewrite IF_ICMP<cmp_op>(x, 0) to IF<cmp0_op>(x).
25 lines
569 B
Kotlin
Vendored
25 lines
569 B
Kotlin
Vendored
// FILE: util.kt
|
|
|
|
inline fun ieq(x: Int, y: Int) = x == y
|
|
inline fun ine(x: Int, y: Int) = x != y
|
|
inline fun ilt(x: Int, y: Int) = x < y
|
|
inline fun ile(x: Int, y: Int) = x <= y
|
|
inline fun igt(x: Int, y: Int) = x > y
|
|
inline fun ige(x: Int, y: Int) = x >= y
|
|
|
|
// FILE: test.kt
|
|
|
|
fun testeq(x: Int) = ieq(x, 0)
|
|
fun testne(x: Int) = ine(x, 0)
|
|
fun testlt(x: Int) = ilt(x, 0)
|
|
fun testle(x: Int) = ile(x, 0)
|
|
fun testgt(x: Int) = igt(x, 0)
|
|
fun testge(x: Int) = ige(x, 0)
|
|
|
|
// @TestKt.class:
|
|
// 0 IF_ICMPEQ
|
|
// 0 IF_ICMPNE
|
|
// 0 IF_ICMPGE
|
|
// 0 IF_ICMPGT
|
|
// 0 IF_ICMPLE
|
|
// 0 IF_ICMPLT |