mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-18 15:54:05 +00:00
RangeContainsLowering: Handle unsigned ranges.
This commit is contained in:
committed by
Alexander Udalov
parent
ceba9f231d
commit
a9359eb530
@@ -1,6 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// TODO KT-36829 Optimize 'in' expressions in JVM_IR
|
||||
|
||||
fun ub_ub(x: UByte, a: UByte, b: UByte) = x in a..b
|
||||
fun ub_us(x: UByte, a: UShort, b: UShort) = x in a..b
|
||||
fun ub_ui(x: UByte, a: UInt, b: UInt) = x in a..b
|
||||
@@ -16,9 +13,7 @@ fun ui_us(x: UInt, a: UShort, b: UShort) = x in a..b
|
||||
fun ui_ui(x: UInt, a: UInt, b: UInt) = x in a..b
|
||||
fun ui_ul(x: UInt, a: ULong, b: ULong) = x in a..b
|
||||
|
||||
fun ul_ub(x: ULong, a: UByte, b: UByte) = x in a..b // ULong in range of UInt, uses non-intrinsic 'contains'
|
||||
fun ul_us(x: ULong, a: UShort, b: UShort) = x in a..b // ULong in range of UInt, uses non-intrinsic 'contains'
|
||||
fun ul_ui(x: ULong, a: UInt, b: UInt) = x in a..b // ULong in range of UInt, uses non-intrinsic 'contains'
|
||||
// ul_ub, ul_us, ul_ui combinations are tested in inMixedUnsignedRange_2.kt (different behavior in non-IR vs IR backends)
|
||||
fun ul_ul(x: ULong, a: ULong, b: ULong) = x in a..b
|
||||
|
||||
fun n_ub_ub(x: UByte, a: UByte, b: UByte) = x !in a..b
|
||||
@@ -36,17 +31,16 @@ fun n_ui_us(x: UInt, a: UShort, b: UShort) = x !in a..b
|
||||
fun n_ui_ui(x: UInt, a: UInt, b: UInt) = x !in a..b
|
||||
fun n_ui_ul(x: UInt, a: ULong, b: ULong) = x !in a..b
|
||||
|
||||
fun n_ul_ub(x: ULong, a: UByte, b: UByte) = x !in a..b // ULong in range of UInt, uses non-intrinsic 'contains'
|
||||
fun n_ul_us(x: ULong, a: UShort, b: UShort) = x !in a..b // ULong in range of UInt, uses non-intrinsic 'contains'
|
||||
fun n_ul_ui(x: ULong, a: UInt, b: UInt) = x !in a..b // ULong in range of UInt, uses non-intrinsic 'contains'
|
||||
// n_ul_ub, n_ul_us, n_ul_ui combinations are tested in inMixedUnsignedRange_2.kt (different behavior in non-IR vs IR backends)
|
||||
fun n_ul_ul(x: ULong, a: ULong, b: ULong) = x !in a..b
|
||||
|
||||
// 6 contains
|
||||
// 13 IFLE
|
||||
// 13 IFLT
|
||||
// 13 IFGE
|
||||
// 13 IFGT
|
||||
// 0 contains
|
||||
// 0 L2I
|
||||
// 22 SIPUSH 255
|
||||
// 24 LDC 65535
|
||||
// 18 SIPUSH 255
|
||||
// 2 LDC 255
|
||||
// 20 LDC 65535
|
||||
// 2 LDC 4294967295
|
||||
|
||||
// "SIPUSH/LDC 255" represent conversion from UByte to UInt/ULong
|
||||
// "LDC 65535" is UShort to UInt/ULong
|
||||
// "LDC 4294967295" is UInt to ULong
|
||||
22
compiler/testData/codegen/bytecodeText/ranges/inMixedUnsignedRange_2.kt
vendored
Normal file
22
compiler/testData/codegen/bytecodeText/ranges/inMixedUnsignedRange_2.kt
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
// ULong in range of UInt, uses non-intrinsic 'contains' for non-IR backend
|
||||
|
||||
fun ul_ub(x: ULong, a: UByte, b: UByte) = x in a..b
|
||||
fun ul_us(x: ULong, a: UShort, b: UShort) = x in a..b
|
||||
fun ul_ui(x: ULong, a: UInt, b: UInt) = x in a..b
|
||||
|
||||
fun n_ul_ub(x: ULong, a: UByte, b: UByte) = x !in a..b
|
||||
fun n_ul_us(x: ULong, a: UShort, b: UShort) = x !in a..b
|
||||
fun n_ul_ui(x: ULong, a: UInt, b: UInt) = x !in a..b
|
||||
|
||||
// JVM_TEMPLATES
|
||||
// 6 contains
|
||||
|
||||
// JVM_IR_TEMPLATES
|
||||
// 0 contains
|
||||
// 4 LDC 255
|
||||
// 4 LDC 65535
|
||||
// 4 LDC 4294967295
|
||||
|
||||
// "LDC 255" represent conversion from UByte to ULong
|
||||
// "LDC 65535" is UShort to ULong
|
||||
// "LDC 4294967295" is UInt to ULong
|
||||
@@ -14,7 +14,6 @@ fun inDouble(x: Float): Boolean {
|
||||
return x in 1.0..2.0
|
||||
}
|
||||
|
||||
// 2 I2L
|
||||
// 0 INVOKESPECIAL
|
||||
// 0 NEW
|
||||
// 0 rangeTo
|
||||
@@ -25,7 +24,9 @@ fun inDouble(x: Float): Boolean {
|
||||
// 0 contains
|
||||
|
||||
// JVM_TEMPLATES
|
||||
// 2 I2L
|
||||
// 3 F2D
|
||||
|
||||
// JVM_IR_TEMPLATES
|
||||
// 2 F2D
|
||||
// 1 I2L
|
||||
// 1 F2D
|
||||
@@ -1,6 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// TODO KT-36829 Optimize 'in' expressions in JVM_IR
|
||||
|
||||
fun testUIntRangeLiteral(a: UInt, b: UInt) = 42u in a .. b
|
||||
|
||||
fun testULongRangeLiteral(a: ULong, b: ULong) = 42UL in a .. b
|
||||
|
||||
Reference in New Issue
Block a user