ForLoopsLowering: Add additional bytecode text tests for optimization of
unsigned progressions.
This commit is contained in:
committed by
Alexander Udalov
parent
0e6af517d7
commit
f249e7f5e9
@@ -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
|
||||
Reference in New Issue
Block a user