ForLoopsLowering: Eliminate construction/boxing/unboxing of UInt/ULong.

This needs further cleanup to encapsulate more logic into ProgressionType.
This commit is contained in:
Mark Punzalan
2020-05-02 00:17:26 -07:00
committed by Alexander Udalov
parent e1120f49d8
commit 177967258b
22 changed files with 192 additions and 94 deletions
@@ -35,4 +35,6 @@ fun box(): String {
// 1 INVOKESTATIC kotlin/internal/UProgressionUtilKt.getProgressionLastElement
// 0 NEW java/lang/IllegalArgumentException
// 0 ATHROW
// 0 IF
// 0 IF
// 0 INVOKESTATIC kotlin/UInt.constructor-impl
// 0 INVOKE\w+ kotlin/UInt.(un)?box-impl
@@ -16,4 +16,6 @@ fun f(a: UInt): Int {
// 0 getLast
// 0 getStep
// 1 INVOKESTATIC kotlin/UnsignedKt.uintCompare
// 2 IF
// 2 IF
// 0 INVOKESTATIC kotlin/UInt.constructor-impl
// 0 INVOKE\w+ kotlin/UInt.(un)?box-impl
@@ -16,4 +16,6 @@ fun f(a: ULong): Int {
// 0 getLast
// 0 getStep
// 1 INVOKESTATIC kotlin/UnsignedKt.ulongCompare
// 2 IF
// 2 IF
// 0 INVOKESTATIC kotlin/ULong.constructor-impl
// 0 INVOKE\w+ kotlin/ULong.(un)?box-impl
@@ -56,3 +56,5 @@ fun testULongDownTo(a: ULong, b: ULong): Int {
// 0 getFirst
// 0 getLast
// 0 getStep
// 0 INVOKESTATIC kotlin/U(Int|Long).constructor-impl
// 0 INVOKE\w+ kotlin/U(Int|Long).(un)?box-impl
@@ -1,3 +1,4 @@
// WITH_RUNTIME
const val M = UInt.MAX_VALUE
fun f(a: UInt): Int {
@@ -15,4 +16,6 @@ fun f(a: UInt): Int {
// 0 getLast
// 0 getStep
// 1 INVOKESTATIC kotlin/UnsignedKt.uintCompare
// 2 IF
// 2 IF
// 0 INVOKESTATIC kotlin/UInt.constructor-impl
// 0 INVOKE\w+ kotlin/UInt.(un)?box-impl
@@ -16,4 +16,6 @@ fun f(a: ULong): Int {
// 0 getLast
// 0 getStep
// 1 INVOKESTATIC kotlin/UnsignedKt.ulongCompare
// 2 IF
// 2 IF
// 0 INVOKESTATIC kotlin/ULong.constructor-impl
// 0 INVOKE\w+ kotlin/ULong.(un)?box-impl
@@ -18,6 +18,8 @@ fun f(a: UInt): Int {
// 0 getFirst
// 0 getLast
// 0 getStep
// 0 INVOKESTATIC kotlin/UInt.constructor-impl
// 0 INVOKE\w+ kotlin/UInt.(un)?box-impl
// JVM_TEMPLATES
// 1 INVOKESTATIC kotlin/UnsignedKt.uintCompare
@@ -18,6 +18,8 @@ fun f(a: UInt): Int {
// 0 getFirst
// 0 getLast
// 0 getStep
// 0 INVOKESTATIC kotlin/UInt.constructor-impl
// 0 INVOKE\w+ kotlin/UInt.(un)?box-impl
// JVM_TEMPLATES
// 1 IF
@@ -18,6 +18,8 @@ fun f(a: ULong): Int {
// 0 getFirst
// 0 getLast
// 0 getStep
// 0 INVOKESTATIC kotlin/ULong.constructor-impl
// 0 INVOKE\w+ kotlin/ULong.(un)?box-impl
// JVM_TEMPLATES
// 1 INVOKESTATIC kotlin/UnsignedKt.ulongCompare
@@ -18,6 +18,8 @@ fun f(a: ULong): Int {
// 0 getFirst
// 0 getLast
// 0 getStep
// 0 INVOKESTATIC kotlin/ULong.constructor-impl
// 0 INVOKE\w+ kotlin/ULong.(un)?box-impl
// JVM_TEMPLATES
// 1 IF
@@ -1,17 +1,17 @@
// TARGET_BACKEND: JVM_IR
// WITH_RUNTIME
fun testUByteUntilUByte(a: UByte, b: UByte): UInt {
var sum = 0u
fun testUByteUntilUByte(a: UByte, b: UByte): Int {
var sum = 0
for (i in a until b) {
sum = sum * 10u + i
sum += i.toInt()
}
return sum
}
fun testUShortUntilUShort(a: UShort, b: UShort): UInt {
var sum = 0u
fun testUShortUntilUShort(a: UShort, b: UShort): Int {
var sum = 0
for (i in a until b) {
sum = sum * 10u + i
sum += i.toInt()
}
return sum
}
@@ -31,4 +31,6 @@ fun testUShortUntilUShort(a: UShort, b: UShort): UInt {
// 0 getStep
// 2 IFGT
// 2 IFLE
// 4 IF
// 4 IF
// 0 INVOKESTATIC kotlin/UInt.constructor-impl
// 0 INVOKE\w+ kotlin/UInt.(un)?box-impl
@@ -38,4 +38,6 @@ fun box(): String {
// 1 NEW java/lang/IllegalArgumentException
// 1 ATHROW
// 0 IF
// 0 ARETURN
// 0 ARETURN
// 0 INVOKESTATIC kotlin/UInt.constructor-impl
// 0 INVOKE\w+ kotlin/UInt.(un)?box-impl
@@ -40,4 +40,6 @@ fun box(): String {
// 0 ATHROW
// 1 IFGT
// 1 IF_ICMPNE
// 2 IF
// 2 IF
// 0 INVOKESTATIC kotlin/UInt.constructor-impl
// 0 INVOKE\w+ kotlin/UInt.(un)?box-impl
@@ -50,4 +50,6 @@ fun box(): String {
// 3 IFLE
// 1 IFGE
// 6 IF
// 0 INEG
// 0 INEG
// 0 INVOKESTATIC kotlin/UInt.constructor-impl
// 0 INVOKE\w+ kotlin/UInt.(un)?box-impl
@@ -54,4 +54,6 @@ fun box(): String {
// 4 IFLE
// 1 IFGE
// 7 IF
// 1 INEG
// 1 INEG
// 0 INVOKESTATIC kotlin/UInt.constructor-impl
// 0 INVOKE\w+ kotlin/UInt.(un)?box-impl
@@ -42,4 +42,6 @@ fun box(): String {
// 1 INVOKESTATIC kotlin/UnsignedKt.uintCompare
// 1 IFGT
// 1 IF_ICMPNE
// 2 IF
// 2 IF
// 0 INVOKESTATIC kotlin/UInt.constructor-impl
// 0 INVOKE\w+ kotlin/UInt.(un)?box-impl
@@ -42,4 +42,6 @@ fun box(): String {
// 1 IFEQ
// 1 IFGT
// 1 IF_ICMPNE
// 3 IF
// 3 IF
// 0 INVOKESTATIC kotlin/UInt.constructor-impl
// 0 INVOKE\w+ kotlin/UInt.(un)?box-impl