RangeContainsLowering: Handle unsigned ranges.

This commit is contained in:
Mark Punzalan
2020-08-08 00:45:27 -07:00
committed by Alexander Udalov
parent ceba9f231d
commit a9359eb530
14 changed files with 112 additions and 74 deletions
@@ -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