From e6e0e9976ca738a3340451813e6153364a6d3a5e Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Wed, 9 Jan 2019 11:23:14 +0300 Subject: [PATCH] Tests for for-in optimization with unsigned ranges --- .../forLoop/forInOptimizableUnsignedRange.kt | 53 +++++++++++++++++++ .../codegen/BytecodeTextTestGenerated.java | 5 ++ .../codegen/IrBytecodeTextTestGenerated.java | 5 ++ 3 files changed, 63 insertions(+) create mode 100644 compiler/testData/codegen/bytecodeText/forLoop/forInOptimizableUnsignedRange.kt diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInOptimizableUnsignedRange.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInOptimizableUnsignedRange.kt new file mode 100644 index 00000000000..456210dab06 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInOptimizableUnsignedRange.kt @@ -0,0 +1,53 @@ +// IGNORE_BACKEND: JVM_IR + +fun testUIntRangeLiteral(a: UInt, b: UInt): Int { + var s = 0 + for (x in a .. b) { + s += x.toInt() + } + return s +} + +fun testULongRangeLiteral(a: ULong, b: ULong): Int { + var s = 0 + for (x in a .. b) { + s += x.toInt() + } + return s +} + +fun testUIntUntil(a: UInt, b: UInt): Int { + var s = 0 + for (x in a until b) { + s += x.toInt() + } + return s +} + +fun testULongUntil(a: ULong, b: ULong): Int { + var s = 0 + for (x in a until b) { + s += x.toInt() + } + return s +} + +fun testUIntDownTo(a: UInt, b: UInt): Int { + var s = 0 + for (x in a downTo b) { + s += x.toInt() + } + return s +} + +fun testULongDownTo(a: ULong, b: ULong): Int { + var s = 0 + for (x in a downTo b) { + s += x.toInt() + } + return s +} + +// 0 iterator +// 0 hasNext +// 0 next diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index ddf37250e3f..7cc45e9a5e2 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -1471,6 +1471,11 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/forLoop/forInCharSequence.kt"); } + @TestMetadata("forInOptimizableUnsignedRange.kt") + public void testForInOptimizableUnsignedRange() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/forLoop/forInOptimizableUnsignedRange.kt"); + } + @TestMetadata("forInRangeSpecializedToUntil.kt") public void testForInRangeSpecializedToUntil() throws Exception { runTest("compiler/testData/codegen/bytecodeText/forLoop/forInRangeSpecializedToUntil.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/IrBytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/IrBytecodeTextTestGenerated.java index f1db9ab9f2d..bdd94ec2b5c 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/IrBytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/IrBytecodeTextTestGenerated.java @@ -1471,6 +1471,11 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/forLoop/forInCharSequence.kt"); } + @TestMetadata("forInOptimizableUnsignedRange.kt") + public void testForInOptimizableUnsignedRange() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/forLoop/forInOptimizableUnsignedRange.kt"); + } + @TestMetadata("forInRangeSpecializedToUntil.kt") public void testForInRangeSpecializedToUntil() throws Exception { runTest("compiler/testData/codegen/bytecodeText/forLoop/forInRangeSpecializedToUntil.kt");