ForLoopsLowering: Add additional bytecode text tests for optimization of

unsigned progressions.
This commit is contained in:
Mark Punzalan
2020-04-07 22:52:17 -07:00
committed by Alexander Udalov
parent 0e6af517d7
commit f249e7f5e9
22 changed files with 713 additions and 15 deletions
@@ -0,0 +1,41 @@
// TARGET_BACKEND: JVM_IR
// WITH_RUNTIME
fun box(): String {
for (i in 1u..6u step 0) {
}
return "OK"
}
// 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 variables:
// val newStep = throw IllegalArgumentException("Step must be positive, was: 0.")
//
// // Standard form of loop over progression
// var inductionVar = 1u
// val last = getProgressionLastElement(1u, 6u, newStep)
// val step = newStep
// if (inductionVar <= last) {
// // Loop is not empty
// do {
// val i = inductionVar
// inductionVar += step
// // Loop body
// } while (i != last)
// }
// 0 iterator
// 0 getStart
// 0 getEnd
// 0 getFirst
// 0 getLast
// 0 getStep
// 0 INVOKESTATIC kotlin/internal/ProgressionUtilKt.getProgressionLastElement
// 1 NEW java/lang/IllegalArgumentException
// 1 ATHROW
// 0 IF
// 0 ARETURN