From 1493805f8e9366e7dfc82b1ad772b2e1b2583766 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Mon, 11 Dec 2017 12:52:24 +0300 Subject: [PATCH] Take into account step sign in pre-condition for simple progression So far, all non-end-inclusive progressions had step > 0. With intrinsics for 'reversed' this will change. --- .../forLoop/ForInSimpleProgressionLoopGenerator.kt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInSimpleProgressionLoopGenerator.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInSimpleProgressionLoopGenerator.kt index 9779875a25c..29a706eb214 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInSimpleProgressionLoopGenerator.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInSimpleProgressionLoopGenerator.kt @@ -77,10 +77,20 @@ class ForInSimpleProgressionLoopGenerator( v.load(endVar, asmElementType) if (asmElementType.sort == Type.LONG) { v.lcmp() - v.ifge(loopExit) + if (step > 0) { + v.ifge(loopExit) + } + else { + v.ifle(loopExit) + } } else { - v.ificmpge(loopExit) + if (step > 0) { + v.ificmpge(loopExit) + } + else { + v.ificmple(loopExit) + } } } }