Initial version of RangeContainsLowering, which optimizes calls to

contains() on ClosedRanges.
This commit is contained in:
Mark Punzalan
2020-08-04 23:44:04 -07:00
committed by Alexander Udalov
parent ca541337d1
commit 1c1b1b4b0f
36 changed files with 1194 additions and 57 deletions
@@ -1,3 +1,6 @@
fun testChar(x: Char, a: Char, b: Char) =
if (x !in a .. b) "no" else "yes"
fun testInt(x: Int, a: Int, b: Int) =
if (x !in a .. b) "no" else "yes"
@@ -1,5 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// TODO KT-36829 Optimize 'in' expressions in JVM_IR
fun testPrimitiveArray(i: Int, ints: IntArray) = i in ints.indices
fun testObjectArray(i: Int, xs: Array<Any>) = i in xs.indices
@@ -13,4 +11,9 @@ fun testLongWithObjectArray(i: Long, xs: Array<Any>) = i in xs.indices
// 2 I2L
// 4 ARRAYLENGTH
// 2 LCONST_0
// JVM_TEMPLATES
// 6 ICONST_0
// JVM_IR_TEMPLATES
// 10 ICONST_0
@@ -1,5 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// TODO KT-36829 Optimize 'in' expressions in JVM_IR
fun testCharSequence(i: Int, cs: CharSequence) = i in cs.indices
fun testLongWithCharSequence(i: Long, cs: CharSequence) = i in cs.indices
@@ -7,5 +5,4 @@ fun testLongWithCharSequence(i: Long, cs: CharSequence) = i in cs.indices
// 0 getIndices
// 0 contains
// 2 length
// 1 I2L
// 1 I2L
@@ -1,5 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// TODO KT-36829 Optimize 'in' expressions in JVM_IR
fun testCollection(i: Int, xs: List<Any>) = i in xs.indices
fun testLongWithCollection(i: Long, xs: List<Any>) = i in xs.indices
@@ -1,5 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// TODO KT-36829 Optimize 'in' expressions in JVM_IR
fun inInt(x: Long): Boolean {
return x in 1..2
}
@@ -17,7 +15,6 @@ fun inDouble(x: Float): Boolean {
}
// 2 I2L
// 3 F2D
// 0 INVOKESPECIAL
// 0 NEW
// 0 rangeTo
@@ -25,3 +22,10 @@ fun inDouble(x: Float): Boolean {
// 0 intRangeContains
// 0 doubleRangeContains
// 0 floatRangeContains
// 0 contains
// JVM_TEMPLATES
// 3 F2D
// JVM_IR_TEMPLATES
// 2 F2D
@@ -1,11 +1,11 @@
// IGNORE_BACKEND: JVM_IR
// TODO KT-36829 Optimize 'in' expressions in JVM_IR
fun Byte.inByte(left: Byte, right: Byte) = this in left..right
fun Short.inInt(left: Int, right: Int) = this in left .. right
fun Short.inByte(left: Byte, right: Byte) = this in left..right
fun inChar(x: Char, left: Char, right: Char) = x in left..right
fun inInt(x: Int, left: Int, right: Int) = x in left..right
fun inDouble(x: Double, left: Double, right: Double) = x in left..right
@@ -23,3 +23,4 @@ fun inCharWithNullableParameter(x: Char?, left: Char, right: Char) = x!! in left
// 0 CHECKCAST
// 0 INVOKEINTERFACE
// 0 <init>
// 0 contains
+3 -2
View File
@@ -1,5 +1,5 @@
// IGNORE_BACKEND: JVM_IR
// TODO KT-36829 Optimize 'in' expressions in JVM_IR
fun testChar(a: Char, x: Char, y: Char) = a in x until y
fun testByte(a: Byte, x: Byte, y: Byte) = a in x until y
fun testShort(a: Short, x: Short, y: Short) = a in x until y
@@ -10,3 +10,4 @@ fun testLong(a: Long, x: Long, y: Long) = a in x until y
// 0 until
// 0 INVOKEVIRTUAL
// 0 contains