If at least one of the range bounds is "pure", order doesn't matter

This commit is contained in:
Dmitry Petrov
2017-07-07 13:07:29 +03:00
parent 22e12dc139
commit ad80c3cd7f
3 changed files with 22 additions and 3 deletions
@@ -52,8 +52,14 @@ class SimpleBoundedValue(
) : this(codegen, rangeCall, lowBound, true, highBound, true)
override fun putHighLow(v: InstructionAdapter, type: Type) {
lowBound.put(type, v)
highBound.put(type, v)
AsmUtil.swap(v, type, type)
if (!lowBound.canHaveSideEffects() || !highBound.canHaveSideEffects()) {
highBound.put(type, v)
lowBound.put(type, v)
}
else {
lowBound.put(type, v)
highBound.put(type, v)
AsmUtil.swap(v, type, type)
}
}
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
fun test(a: Long) = a in 1L .. 10L
// One DUP2_X2 generated for 'in' operator,
// no DUP2_X2 generated for range on stack.
// 1 DUP2_X2
@@ -1912,6 +1912,12 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/ranges/inUntil.kt");
doTest(fileName);
}
@TestMetadata("noSwap2ForConstLongRangeTo.kt")
public void testNoSwap2ForConstLongRangeTo() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/ranges/noSwap2ForConstLongRangeTo.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/bytecodeText/statements")