JVM_IR generate range-based loop closer to Java counter loop
KT-48435 KT-48507
This commit is contained in:
+10
-17
@@ -1,4 +1,14 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
|
||||
// IMPORTANT!
|
||||
// Please, when your changes cause failures in bytecodeText tests for 'for' loops,
|
||||
// examine the resulting bytecode shape carefully.
|
||||
// Range and progression-based loops generated with Kotlin compiler should be
|
||||
// as close as possible to Java counter loops ('for (int i = a; i < b; ++i) { ... }').
|
||||
// Otherwise it may result in performance regression due to missing HotSpot optimizations.
|
||||
// Run Kotlin compiler benchmarks (https://github.com/Kotlin/kotlin-benchmarks)
|
||||
// with compiler built from your changes if you are not sure.
|
||||
|
||||
fun box(): String {
|
||||
for (i in 1..6 step 0) {
|
||||
}
|
||||
@@ -8,23 +18,6 @@ fun box(): String {
|
||||
|
||||
// For "step" progressions in JVM IR, if the step is constant and <= 0, the expression for step is replaced with an
|
||||
// IllegalArgumentException. The backend can then eliminate the entire loop and the rest of the function as dead code.
|
||||
//
|
||||
// Expected lowered form of loop (before bytecode optimization):
|
||||
//
|
||||
// // Additional statements:
|
||||
// throw IllegalArgumentException("Step must be positive, was: 0.")
|
||||
//
|
||||
// // Standard form of loop over progression
|
||||
// var inductionVar = 1
|
||||
// val last = getProgressionLastElement(1, 6, 0)
|
||||
// if (inductionVar <= last) {
|
||||
// // Loop is not empty
|
||||
// do {
|
||||
// val i = inductionVar
|
||||
// inductionVar += 0
|
||||
// // Loop body
|
||||
// } while (i != last)
|
||||
// }
|
||||
|
||||
// 0 iterator
|
||||
// 0 getStart
|
||||
|
||||
+18
-18
@@ -1,4 +1,14 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
|
||||
// IMPORTANT!
|
||||
// Please, when your changes cause failures in bytecodeText tests for 'for' loops,
|
||||
// examine the resulting bytecode shape carefully.
|
||||
// Range and progression-based loops generated with Kotlin compiler should be
|
||||
// as close as possible to Java counter loops ('for (int i = a; i < b; ++i) { ... }').
|
||||
// Otherwise it may result in performance regression due to missing HotSpot optimizations.
|
||||
// Run Kotlin compiler benchmarks (https://github.com/Kotlin/kotlin-benchmarks)
|
||||
// with compiler built from your changes if you are not sure.
|
||||
|
||||
fun box(): String {
|
||||
for (i in (1..8).reversed() step 2) {
|
||||
}
|
||||
@@ -9,22 +19,6 @@ fun box(): String {
|
||||
// For "step" progressions in JVM IR, a call to getProgressionLastElement() is made to compute the "last" value.
|
||||
// If the step is non-constant, there is a check that it is > 0, and if not, an IllegalArgumentException is thrown. However, when the
|
||||
// step is constant and > 0, this check does not need to be added.
|
||||
//
|
||||
// Expected lowered form of loop:
|
||||
//
|
||||
// // Standard form of loop over progression
|
||||
// val last = getProgressionLastElement(8, 1, -2)
|
||||
// var inductionVar = 8
|
||||
// if (last <= inductionVar) {
|
||||
// // Loop is not empty
|
||||
// do {
|
||||
// val i = inductionVar
|
||||
// inductionVar += -2
|
||||
// // Loop body
|
||||
// } while (i != last)
|
||||
// }
|
||||
//
|
||||
// We can't use "0 reversed" in the regex below because "reversed" is in the test filename.
|
||||
|
||||
// 0 INVOKE.*reversed
|
||||
// 0 iterator
|
||||
@@ -37,5 +31,11 @@ fun box(): String {
|
||||
// 0 NEW java/lang/IllegalArgumentException
|
||||
// 0 ATHROW
|
||||
// 1 IF_ICMPGT
|
||||
// 1 IF_ICMPNE
|
||||
// 2 IF
|
||||
// 1 IF_ICMPEQ
|
||||
// 2 IF
|
||||
// 4 ILOAD
|
||||
// 2 ISTORE
|
||||
// 0 IADD
|
||||
// 0 ISUB
|
||||
// 1 IINC
|
||||
// 1 IINC
|
||||
@@ -1,4 +1,14 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
|
||||
// IMPORTANT!
|
||||
// Please, when your changes cause failures in bytecodeText tests for 'for' loops,
|
||||
// examine the resulting bytecode shape carefully.
|
||||
// Range and progression-based loops generated with Kotlin compiler should be
|
||||
// as close as possible to Java counter loops ('for (int i = a; i < b; ++i) { ... }').
|
||||
// Otherwise it may result in performance regression due to missing HotSpot optimizations.
|
||||
// Run Kotlin compiler benchmarks (https://github.com/Kotlin/kotlin-benchmarks)
|
||||
// with compiler built from your changes if you are not sure.
|
||||
|
||||
fun box(): String {
|
||||
for (i in 1..7 step 2) {
|
||||
}
|
||||
@@ -9,20 +19,6 @@ fun box(): String {
|
||||
// For "step" progressions in JVM IR, a call to getProgressionLastElement() is made to compute the "last" value.
|
||||
// If the step is non-constant, there is a check that it is > 0, and if not, an IllegalArgumentException is thrown. However, when the
|
||||
// step is constant and > 0, this check does not need to be added.
|
||||
//
|
||||
// Expected lowered form of loop:
|
||||
//
|
||||
// // Standard form of loop over progression
|
||||
// var inductionVar = 1
|
||||
// val last = getProgressionLastElement(1, 7, 2)
|
||||
// if (inductionVar <= last) {
|
||||
// // Loop is not empty
|
||||
// do {
|
||||
// val i = inductionVar
|
||||
// inductionVar += 2
|
||||
// // Loop body
|
||||
// } while (i != last)
|
||||
// }
|
||||
|
||||
// 0 iterator
|
||||
// 0 getStart
|
||||
@@ -34,5 +30,10 @@ fun box(): String {
|
||||
// 0 NEW java/lang/IllegalArgumentException
|
||||
// 0 ATHROW
|
||||
// 1 IF_ICMPGT
|
||||
// 1 IF_ICMPNE
|
||||
// 2 IF
|
||||
// 1 IF_ICMPEQ
|
||||
// 2 IF
|
||||
// 4 ILOAD
|
||||
// 2 ISTORE
|
||||
// 0 IADD
|
||||
// 0 ISUB
|
||||
// 1 IINC
|
||||
+18
-21
@@ -1,4 +1,14 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
|
||||
// IMPORTANT!
|
||||
// Please, when your changes cause failures in bytecodeText tests for 'for' loops,
|
||||
// examine the resulting bytecode shape carefully.
|
||||
// Range and progression-based loops generated with Kotlin compiler should be
|
||||
// as close as possible to Java counter loops ('for (int i = a; i < b; ++i) { ... }').
|
||||
// Otherwise it may result in performance regression due to missing HotSpot optimizations.
|
||||
// Run Kotlin compiler benchmarks (https://github.com/Kotlin/kotlin-benchmarks)
|
||||
// with compiler built from your changes if you are not sure.
|
||||
|
||||
fun box(): String {
|
||||
val intProgression = 1..7 step 3 // `step` ensures type is IntProgression, NOT IntRange
|
||||
for (i in intProgression step 2) {
|
||||
@@ -12,25 +22,7 @@ fun box(): String {
|
||||
// If the step is non-constant, there is a check that it is > 0, and if not, an IllegalArgumentException is thrown. However, when the
|
||||
// step is constant and > 0, this check does not need to be added.
|
||||
//
|
||||
// Expected lowered form of loop:
|
||||
//
|
||||
// // Additional statements:
|
||||
// val nestedFirst = intProgression.first
|
||||
// val nestedLast = intProgression.last
|
||||
// val nestedStep = intProgression.step
|
||||
// val maybeNegatedStep = if (nestedStep <= 0) -2 else 2
|
||||
//
|
||||
// // Standard form of loop over progression
|
||||
// var inductionVar = nestedFirst
|
||||
// val last = getProgressionLastElement(nestedFirst, nestedLast, maybeNegatedStep)
|
||||
// if ((maybeNegatedStep > 0 && inductionVar <= last) || (maybeNegatedStep < 0 && last <= inductionVar)) {
|
||||
// // Loop is not empty
|
||||
// do {
|
||||
// val i = inductionVar
|
||||
// inductionVar += maybeNegatedStep
|
||||
// // Loop body
|
||||
// } while (i != last)
|
||||
// }
|
||||
|
||||
|
||||
// 0 iterator
|
||||
// 0 getStart
|
||||
@@ -43,9 +35,14 @@ fun box(): String {
|
||||
// 0 ATHROW
|
||||
// 1 IF_ICMPGT
|
||||
// 1 IF_ICMPLE
|
||||
// 1 IF_ICMPNE
|
||||
// 1 IF_ICMPEQ
|
||||
// 1 IFLE
|
||||
// 1 IFGT
|
||||
// 1 IFGE
|
||||
// 6 IF
|
||||
// 0 INEG
|
||||
// 0 INEG
|
||||
// 14 ILOAD
|
||||
// 6 ISTORE
|
||||
// 1 IADD
|
||||
// 0 ISUB
|
||||
// 0 IINC
|
||||
@@ -1,4 +1,14 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
|
||||
// IMPORTANT!
|
||||
// Please, when your changes cause failures in bytecodeText tests for 'for' loops,
|
||||
// examine the resulting bytecode shape carefully.
|
||||
// Range and progression-based loops generated with Kotlin compiler should be
|
||||
// as close as possible to Java counter loops ('for (int i = a; i < b; ++i) { ... }').
|
||||
// Otherwise it may result in performance regression due to missing HotSpot optimizations.
|
||||
// Run Kotlin compiler benchmarks (https://github.com/Kotlin/kotlin-benchmarks)
|
||||
// with compiler built from your changes if you are not sure.
|
||||
|
||||
fun one() = 1
|
||||
|
||||
fun box(): String {
|
||||
@@ -11,23 +21,6 @@ fun box(): String {
|
||||
// For "step" progressions in JVM IR, a call to getProgressionLastElement() is made to compute the "last" value.
|
||||
// If the step is non-constant, there is a check that it is > 0, and if not, an IllegalArgumentException is thrown.
|
||||
//
|
||||
// Expected lowered form of loop:
|
||||
//
|
||||
// // Additional statements:
|
||||
// var stepArg = one()
|
||||
// if (stepArg <= 0) throw IllegalArgumentException("Step must be positive, was: $stepArg.")
|
||||
//
|
||||
// // Standard form of loop over progression
|
||||
// var inductionVar = 1
|
||||
// val last = getProgressionLastElement(1, 7, stepArg)
|
||||
// if (inductionVar <= last) {
|
||||
// // Loop is not empty
|
||||
// do {
|
||||
// val i = inductionVar
|
||||
// inductionVar += stepArg
|
||||
// // Loop body
|
||||
// } while (i != last)
|
||||
// }
|
||||
|
||||
// 0 iterator
|
||||
// 0 getStart
|
||||
@@ -39,6 +32,11 @@ fun box(): String {
|
||||
// 1 NEW java/lang/IllegalArgumentException
|
||||
// 1 ATHROW
|
||||
// 1 IF_ICMPGT
|
||||
// 1 IF_ICMPNE
|
||||
// 1 IF_ICMPEQ
|
||||
// 1 IFGT
|
||||
// 3 IF
|
||||
// 3 IF
|
||||
// 9 ILOAD
|
||||
// 4 ISTORE
|
||||
// 1 IADD
|
||||
// 0 ISUB
|
||||
// 0 IINC
|
||||
Vendored
+18
-23
@@ -1,4 +1,14 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
|
||||
// IMPORTANT!
|
||||
// Please, when your changes cause failures in bytecodeText tests for 'for' loops,
|
||||
// examine the resulting bytecode shape carefully.
|
||||
// Range and progression-based loops generated with Kotlin compiler should be
|
||||
// as close as possible to Java counter loops ('for (int i = a; i < b; ++i) { ... }').
|
||||
// Otherwise it may result in performance regression due to missing HotSpot optimizations.
|
||||
// Run Kotlin compiler benchmarks (https://github.com/Kotlin/kotlin-benchmarks)
|
||||
// with compiler built from your changes if you are not sure.
|
||||
|
||||
fun one() = 1
|
||||
|
||||
fun box(): String {
|
||||
@@ -13,27 +23,7 @@ fun box(): String {
|
||||
// If "step" is called on a non-literal progression, there is a check to see if that progression's step value is < 0.
|
||||
// If the step is non-constant, there is a check that it is > 0, and if not, an IllegalArgumentException is thrown.
|
||||
//
|
||||
// Expected lowered form of loop:
|
||||
//
|
||||
// // Additional statements:
|
||||
// val nestedFirst = intProgression.first
|
||||
// val nestedLast = intProgression.last
|
||||
// val nestedStep = intProgression.step
|
||||
// var stepArg = one()
|
||||
// if (stepArg <= 0) throw IllegalArgumentException("Step must be positive, was: $stepArg.")
|
||||
// if (nestedStep <= 0) stepArg = -stepArg
|
||||
//
|
||||
// // Standard form of loop over progression
|
||||
// var inductionVar = nestedFirst
|
||||
// val last = getProgressionLastElement(nestedFirst, nestedLast, stepArg)
|
||||
// if ((stepArg > 0 && inductionVar <= last) || (stepArg < 0 && last <= inductionVar)) {
|
||||
// // Loop is not empty
|
||||
// do {
|
||||
// val i = inductionVar
|
||||
// inductionVar += stepArg
|
||||
// // Loop body
|
||||
// } while (i != last)
|
||||
// }
|
||||
|
||||
|
||||
// 0 iterator
|
||||
// 0 getStart
|
||||
@@ -46,9 +36,14 @@ fun box(): String {
|
||||
// 1 ATHROW
|
||||
// 1 IF_ICMPGT
|
||||
// 1 IF_ICMPLE
|
||||
// 1 IF_ICMPNE
|
||||
// 1 IF_ICMPEQ
|
||||
// 1 IFLE
|
||||
// 2 IFGT
|
||||
// 1 IFGE
|
||||
// 7 IF
|
||||
// 1 INEG
|
||||
// 1 INEG
|
||||
// 18 ILOAD
|
||||
// 8 ISTORE
|
||||
// 1 IADD
|
||||
// 0 ISUB
|
||||
// 0 IINC
|
||||
+17
-19
@@ -1,4 +1,14 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
|
||||
// IMPORTANT!
|
||||
// Please, when your changes cause failures in bytecodeText tests for 'for' loops,
|
||||
// examine the resulting bytecode shape carefully.
|
||||
// Range and progression-based loops generated with Kotlin compiler should be
|
||||
// as close as possible to Java counter loops ('for (int i = a; i < b; ++i) { ... }').
|
||||
// Otherwise it may result in performance regression due to missing HotSpot optimizations.
|
||||
// Run Kotlin compiler benchmarks (https://github.com/Kotlin/kotlin-benchmarks)
|
||||
// with compiler built from your changes if you are not sure.
|
||||
|
||||
fun box(): String {
|
||||
val intRange = 1..7
|
||||
for (i in intRange step 2) {
|
||||
@@ -12,23 +22,6 @@ fun box(): String {
|
||||
// However, if the progression is of type *Range (e.g., IntRange) instead of *Progression (e.g., IntProgression), this
|
||||
// check is not needed since *Range always has step == 1.
|
||||
//
|
||||
// Expected lowered form of loop:
|
||||
//
|
||||
// // Additional statements:
|
||||
// val nestedFirst = intRange.first
|
||||
// val nestedLast = intRange.last
|
||||
//
|
||||
// // Standard form of loop over progression
|
||||
// var inductionVar = nestedFirst
|
||||
// val last = getProgressionLastElement(nestedFirst, nestedLast, 2)
|
||||
// if (inductionVar <= last) {
|
||||
// // Loop is not empty
|
||||
// do {
|
||||
// val i = inductionVar
|
||||
// inductionVar += 2
|
||||
// // Loop body
|
||||
// } while (i != last)
|
||||
// }
|
||||
|
||||
// 0 iterator
|
||||
// 0 getStart
|
||||
@@ -40,6 +33,11 @@ fun box(): String {
|
||||
// 0 NEW java/lang/IllegalArgumentException
|
||||
// 0 ATHROW
|
||||
// 1 IF_ICMPGT
|
||||
// 1 IF_ICMPNE
|
||||
// 1 IF_ICMPEQ
|
||||
// 2 IF
|
||||
// 0 INEG
|
||||
// 0 INEG
|
||||
// 7 ILOAD
|
||||
// 4 ISTORE
|
||||
// 0 IADD
|
||||
// 0 ISUB
|
||||
// 1 IINC
|
||||
@@ -1,4 +1,14 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
|
||||
// IMPORTANT!
|
||||
// Please, when your changes cause failures in bytecodeText tests for 'for' loops,
|
||||
// examine the resulting bytecode shape carefully.
|
||||
// Range and progression-based loops generated with Kotlin compiler should be
|
||||
// as close as possible to Java counter loops ('for (int i = a; i < b; ++i) { ... }').
|
||||
// Otherwise it may result in performance regression due to missing HotSpot optimizations.
|
||||
// Run Kotlin compiler benchmarks (https://github.com/Kotlin/kotlin-benchmarks)
|
||||
// with compiler built from your changes if you are not sure.
|
||||
|
||||
fun box(): String {
|
||||
for (i in 1..4 step 1) {
|
||||
}
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
|
||||
// IMPORTANT!
|
||||
// Please, when your changes cause failures in bytecodeText tests for 'for' loops,
|
||||
// examine the resulting bytecode shape carefully.
|
||||
// Range and progression-based loops generated with Kotlin compiler should be
|
||||
// as close as possible to Java counter loops ('for (int i = a; i < b; ++i) { ... }').
|
||||
// Otherwise it may result in performance regression due to missing HotSpot optimizations.
|
||||
// Run Kotlin compiler benchmarks (https://github.com/Kotlin/kotlin-benchmarks)
|
||||
// with compiler built from your changes if you are not sure.
|
||||
|
||||
fun box(): String {
|
||||
for (i in 1..4 step 1 step 1) {
|
||||
}
|
||||
|
||||
+17
-18
@@ -1,4 +1,14 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
|
||||
// IMPORTANT!
|
||||
// Please, when your changes cause failures in bytecodeText tests for 'for' loops,
|
||||
// examine the resulting bytecode shape carefully.
|
||||
// Range and progression-based loops generated with Kotlin compiler should be
|
||||
// as close as possible to Java counter loops ('for (int i = a; i < b; ++i) { ... }').
|
||||
// Otherwise it may result in performance regression due to missing HotSpot optimizations.
|
||||
// Run Kotlin compiler benchmarks (https://github.com/Kotlin/kotlin-benchmarks)
|
||||
// with compiler built from your changes if you are not sure.
|
||||
|
||||
fun box(): String {
|
||||
for (i in 1..7 step 3 step 2) {
|
||||
}
|
||||
@@ -11,22 +21,6 @@ fun box(): String {
|
||||
// If the step is non-constant, there is a check that it is > 0, and if not, an IllegalArgumentException is thrown. However, when the
|
||||
// step is constant and > 0, this check does not need to be added.
|
||||
//
|
||||
// Expected lowered form of loop:
|
||||
//
|
||||
// // Additional variables:
|
||||
// val outerNestedLast = getProgressionLastElement(1, 7, 3)
|
||||
//
|
||||
// // Standard form of loop over progression
|
||||
// var inductionVar = 1
|
||||
// val last = getProgressionLastElement(1, outerNestedLast, 2)
|
||||
// if (inductionVar <= last) {
|
||||
// // Loop is not empty
|
||||
// do {
|
||||
// val i = inductionVar
|
||||
// inductionVar += 2
|
||||
// // Loop body
|
||||
// } while (i != last)
|
||||
// }
|
||||
|
||||
// 0 iterator
|
||||
// 0 getStart
|
||||
@@ -38,5 +32,10 @@ fun box(): String {
|
||||
// 0 NEW java/lang/IllegalArgumentException
|
||||
// 0 ATHROW
|
||||
// 1 IF_ICMPGT
|
||||
// 1 IF_ICMPNE
|
||||
// 2 IF
|
||||
// 1 IF_ICMPEQ
|
||||
// 2 IF
|
||||
// 5 ILOAD
|
||||
// 3 ISTORE
|
||||
// 0 IADD
|
||||
// 0 ISUB
|
||||
// 1 IINC
|
||||
@@ -1,4 +1,14 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
|
||||
// IMPORTANT!
|
||||
// Please, when your changes cause failures in bytecodeText tests for 'for' loops,
|
||||
// examine the resulting bytecode shape carefully.
|
||||
// Range and progression-based loops generated with Kotlin compiler should be
|
||||
// as close as possible to Java counter loops ('for (int i = a; i < b; ++i) { ... }').
|
||||
// Otherwise it may result in performance regression due to missing HotSpot optimizations.
|
||||
// Run Kotlin compiler benchmarks (https://github.com/Kotlin/kotlin-benchmarks)
|
||||
// with compiler built from your changes if you are not sure.
|
||||
|
||||
fun box(): String {
|
||||
for (i in (1..8 step 2).reversed()) {
|
||||
}
|
||||
|
||||
+17
-15
@@ -1,4 +1,14 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
|
||||
// IMPORTANT!
|
||||
// Please, when your changes cause failures in bytecodeText tests for 'for' loops,
|
||||
// examine the resulting bytecode shape carefully.
|
||||
// Range and progression-based loops generated with Kotlin compiler should be
|
||||
// as close as possible to Java counter loops ('for (int i = a; i < b; ++i) { ... }').
|
||||
// Otherwise it may result in performance regression due to missing HotSpot optimizations.
|
||||
// Run Kotlin compiler benchmarks (https://github.com/Kotlin/kotlin-benchmarks)
|
||||
// with compiler built from your changes if you are not sure.
|
||||
|
||||
fun box(): String {
|
||||
for (i in 1..8 step 2 step 2) {
|
||||
}
|
||||
@@ -11,19 +21,6 @@ fun box(): String {
|
||||
// If the step is non-constant, there is a check that it is > 0, and if not, an IllegalArgumentException is thrown. However, when the
|
||||
// step is constant and > 0, this check does not need to be added.
|
||||
//
|
||||
// Expected lowered form of loop:
|
||||
//
|
||||
// // Standard form of loop over progression
|
||||
// var inductionVar = 1
|
||||
// val last = getProgressionLastElement(1, 8, 2)
|
||||
// if (inductionVar <= last) {
|
||||
// // Loop is not empty
|
||||
// do {
|
||||
// val i = inductionVar
|
||||
// inductionVar += 2
|
||||
// // Loop body
|
||||
// } while (i != last)
|
||||
// }
|
||||
|
||||
// 0 iterator
|
||||
// 0 getStart
|
||||
@@ -35,5 +32,10 @@ fun box(): String {
|
||||
// 0 NEW java/lang/IllegalArgumentException
|
||||
// 0 ATHROW
|
||||
// 1 IF_ICMPGT
|
||||
// 1 IF_ICMPNE
|
||||
// 2 IF
|
||||
// 1 IF_ICMPEQ
|
||||
// 2 IF
|
||||
// 4 ILOAD
|
||||
// 2 ISTORE
|
||||
// 0 IADD
|
||||
// 0 ISUB
|
||||
// 1 IINC
|
||||
+17
-22
@@ -1,4 +1,14 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
|
||||
// IMPORTANT!
|
||||
// Please, when your changes cause failures in bytecodeText tests for 'for' loops,
|
||||
// examine the resulting bytecode shape carefully.
|
||||
// Range and progression-based loops generated with Kotlin compiler should be
|
||||
// as close as possible to Java counter loops ('for (int i = a; i < b; ++i) { ... }').
|
||||
// Otherwise it may result in performance regression due to missing HotSpot optimizations.
|
||||
// Run Kotlin compiler benchmarks (https://github.com/Kotlin/kotlin-benchmarks)
|
||||
// with compiler built from your changes if you are not sure.
|
||||
|
||||
fun one() = 1
|
||||
|
||||
fun box(): String {
|
||||
@@ -11,26 +21,6 @@ fun box(): String {
|
||||
// For "step" progressions in JVM IR, if the step is non-constant, there is a check that it is > 0, and if not, an IllegalArgumentException
|
||||
// is thrown.
|
||||
//
|
||||
// Expected lowered form of loop:
|
||||
//
|
||||
// // Additional statments:
|
||||
// var innerStepArg = one()
|
||||
// if (innerStepArg <= 0) throw IllegalArgumentException("Step must be positive, was: $innerStepArg.")
|
||||
// val outerNestedLast = getProgressionLastElement(1, 6, innerStepArg)
|
||||
// var outerStepArg = one()
|
||||
// if (outerStepArg <= 0) throw IllegalArgumentException("Step must be positive, was: $outerStepArg.")
|
||||
//
|
||||
// // Standard form of loop over progression
|
||||
// var inductionVar = 1
|
||||
// val last = getProgressionLastElement(1, outerNestedLast, outerStepArg)
|
||||
// if (inductionVar <= last) {
|
||||
// // Loop is not empty
|
||||
// do {
|
||||
// val i = inductionVar
|
||||
// inductionVar += outerStepArg
|
||||
// // Loop body
|
||||
// } while (i != last)
|
||||
// }
|
||||
|
||||
// 0 iterator
|
||||
// 0 getStart
|
||||
@@ -42,6 +32,11 @@ fun box(): String {
|
||||
// 2 NEW java/lang/IllegalArgumentException
|
||||
// 2 ATHROW
|
||||
// 1 IF_ICMPGT
|
||||
// 1 IF_ICMPNE
|
||||
// 1 IF_ICMPEQ
|
||||
// 2 IFGT
|
||||
// 4 IF
|
||||
// 4 IF
|
||||
// 13 ILOAD
|
||||
// 6 ISTORE
|
||||
// 1 IADD
|
||||
// 0 ISUB
|
||||
// 0 IINC
|
||||
|
||||
+17
-18
@@ -1,4 +1,14 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
|
||||
// IMPORTANT!
|
||||
// Please, when your changes cause failures in bytecodeText tests for 'for' loops,
|
||||
// examine the resulting bytecode shape carefully.
|
||||
// Range and progression-based loops generated with Kotlin compiler should be
|
||||
// as close as possible to Java counter loops ('for (int i = a; i < b; ++i) { ... }').
|
||||
// Otherwise it may result in performance regression due to missing HotSpot optimizations.
|
||||
// Run Kotlin compiler benchmarks (https://github.com/Kotlin/kotlin-benchmarks)
|
||||
// with compiler built from your changes if you are not sure.
|
||||
|
||||
fun box(): String {
|
||||
for (i in 1..5 step 2 step 1) {
|
||||
}
|
||||
@@ -11,22 +21,6 @@ fun box(): String {
|
||||
// If the step is non-constant, there is a check that it is > 0, and if not, an IllegalArgumentException is thrown. However, when the
|
||||
// step is constant and > 0, this check does not need to be added.
|
||||
//
|
||||
// Expected lowered form of loop:
|
||||
//
|
||||
// // Additional variables:
|
||||
// val innerNestedLast = getProgressionLastElement(1, 5, 2)
|
||||
//
|
||||
// // Standard form of loop over progression
|
||||
// var inductionVar = 1
|
||||
// val last = innerNestedLast
|
||||
// if (inductionVar <= last) {
|
||||
// // Loop is not empty
|
||||
// do {
|
||||
// val i = inductionVar
|
||||
// inductionVar += 1
|
||||
// // Loop body
|
||||
// } while (i != last)
|
||||
// }
|
||||
|
||||
// 0 iterator
|
||||
// 0 getStart
|
||||
@@ -38,5 +32,10 @@ fun box(): String {
|
||||
// 0 NEW java/lang/IllegalArgumentException
|
||||
// 0 ATHROW
|
||||
// 1 IF_ICMPGT
|
||||
// 1 IF_ICMPNE
|
||||
// 2 IF
|
||||
// 1 IF_ICMPEQ
|
||||
// 2 IF
|
||||
// 4 ILOAD
|
||||
// 2 ISTORE
|
||||
// 0 IADD
|
||||
// 0 ISUB
|
||||
// 1 IINC
|
||||
|
||||
Reference in New Issue
Block a user