[IR] Avoid duplicate IR elements in for loops lowering.
This commit is contained in:
+3
-3
@@ -102,12 +102,12 @@ internal sealed class ForLoopHeader(
|
||||
// // (use `<` if last is exclusive)
|
||||
// (step > 0 && inductionVar <= last) || (step < 0 || last <= inductionVar)
|
||||
val stepKotlinType = progressionType.stepType(builtIns).toKotlinType()
|
||||
val zero = if (progressionType == ProgressionType.LONG_PROGRESSION) irLong(0) else irInt(0)
|
||||
val isLong = progressionType == ProgressionType.LONG_PROGRESSION
|
||||
context.oror(
|
||||
context.andand(
|
||||
irCall(builtIns.greaterFunByOperandType[stepKotlinType]!!).apply {
|
||||
putValueArgument(0, irGet(step))
|
||||
putValueArgument(1, zero)
|
||||
putValueArgument(1, if (isLong) irLong(0) else irInt(0))
|
||||
},
|
||||
irCall(compFun).apply {
|
||||
putValueArgument(0, irGet(inductionVariable))
|
||||
@@ -116,7 +116,7 @@ internal sealed class ForLoopHeader(
|
||||
context.andand(
|
||||
irCall(builtIns.lessFunByOperandType[stepKotlinType]!!).apply {
|
||||
putValueArgument(0, irGet(step))
|
||||
putValueArgument(1, zero)
|
||||
putValueArgument(1, if (isLong) irLong(0) else irInt(0))
|
||||
},
|
||||
irCall(compFun).apply {
|
||||
putValueArgument(0, irGet(last))
|
||||
|
||||
+2
-1
@@ -153,7 +153,8 @@ internal class UntilHandler(private val context: CommonBackendContext, private v
|
||||
it == null && isAdditionalNotEmptyConditionNeeded(receiverValue.type, untilArg.type) ->
|
||||
// Condition is needed and untilArg is non-const.
|
||||
// Build the additional "not empty" condition: `untilArg != MIN_VALUE`.
|
||||
irNotEquals(untilArgExpression, minValueIrConst)
|
||||
// Make sure to copy untilArgExpression as it is also used in `last`.
|
||||
irNotEquals(untilArgExpression.deepCopyWithSymbols(), minValueIrConst)
|
||||
it == minValueAsLong ->
|
||||
// Hardcode "false" as additional condition so that the progression is considered empty.
|
||||
// The entire lowered loop becomes a candidate for dead code elimination, depending on backend.
|
||||
|
||||
Reference in New Issue
Block a user