Make all progression headers inclusive, and decrement last for

last-exclusive progressions (i.e., "until" progressions and loop over
array indices).

This change makes it possible to correctly implement the handling of
"step" progressions. Computing the last element of a stepped progression
requires that the last is inclusive.

Also invert the while loop (into if + do-while) that is used when
lowering for-loops over progressions that cannot overflow. This keeps
the performance characteristics closer to the ForLoopsLowering in
kotlin-native, since the goal is to converge to this shared version.

Also used IrType instead of KotlinType, where possible.

 https://github.com/JetBrains/kotlin/pull/2390
 https://github.com/JetBrains/kotlin/pull/2305
This commit is contained in:
Mark Punzalan
2019-06-14 00:59:47 -07:00
committed by Mikhael Bogdanov
parent 39f6416757
commit de1e27c584
75 changed files with 1873 additions and 377 deletions
@@ -1,3 +1,4 @@
// IGNORE_BACKEND: JVM_IR
fun test() {
var sum = 0
for (i in arrayOf("", "", "", "").indices) {
@@ -5,10 +6,20 @@ fun test() {
}
}
// JVM non-IR uses while.
// JVM IR uses if + do-while.
// 0 iterator
// 0 getStart
// 0 getEnd
// 0 getFirst
// 0 getLast
// JVM_TEMPLATES
// 1 IF_ICMPGE
// 1 IF
// 1 IF
// JVM_IR_TEMPLATES
// 1 IF_ICMPGT
// 1 IF_ICMPLE
// 2 IF
@@ -0,0 +1,19 @@
// TARGET_BACKEND: JVM_IR
fun test() {
var sum = 0
for (i in arrayOf("", "", "", "").indices) {
sum += i
}
}
// JVM non-IR uses while.
// JVM IR uses if + do-while.
// 0 iterator
// 0 getStart
// 0 getEnd
// 0 getFirst
// 0 getLast
// 1 IF_ICMPGT
// 1 IF_ICMPLE
// 2 IF
@@ -1,3 +1,4 @@
// IGNORE_BACKEND: JVM_IR
fun test() {
var sum = 0
for (i in intArrayOf(0, 0, 0, 0).indices) {
@@ -5,6 +6,9 @@ fun test() {
}
}
// JVM non-IR uses while.
// JVM IR uses if + do-while.
// 0 iterator
// 0 getStart
// 0 getEnd
@@ -0,0 +1,19 @@
// TARGET_BACKEND: JVM_IR
fun test() {
var sum = 0
for (i in intArrayOf(0, 0, 0, 0).indices) {
sum += i
}
}
// JVM non-IR uses while.
// JVM IR uses if + do-while.
// 0 iterator
// 0 getStart
// 0 getEnd
// 0 getFirst
// 0 getLast
// 1 IF_ICMPGT
// 1 IF_ICMPLE
// 2 IF