Don't generate jump for last when condition
This commit is contained in:
+5
-1
@@ -603,6 +603,7 @@ class ExpressionCodegen(
|
|||||||
assert(exhaustive || expression.type.isUnit()) {
|
assert(exhaustive || expression.type.isUnit()) {
|
||||||
"non-exhaustive conditional should return Unit: ${expression.dump()}"
|
"non-exhaustive conditional should return Unit: ${expression.dump()}"
|
||||||
}
|
}
|
||||||
|
val lastBranch = expression.branches.lastOrNull()
|
||||||
for (branch in expression.branches) {
|
for (branch in expression.branches) {
|
||||||
val elseLabel = Label()
|
val elseLabel = Label()
|
||||||
if (branch.condition.isFalseConst() || branch.condition.isTrueConst()) {
|
if (branch.condition.isFalseConst() || branch.condition.isTrueConst()) {
|
||||||
@@ -628,7 +629,10 @@ class ExpressionCodegen(
|
|||||||
return materializedResult
|
return materializedResult
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mv.goTo(endLabel)
|
|
||||||
|
if (branch != lastBranch) {
|
||||||
|
mv.goTo(endLabel)
|
||||||
|
}
|
||||||
mv.mark(elseLabel)
|
mv.mark(elseLabel)
|
||||||
}
|
}
|
||||||
mv.mark(endLabel)
|
mv.mark(endLabel)
|
||||||
|
|||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
// KOTLIN_CONFIGURATION_FLAGS: +JVM.DISABLE_OPTIMIZATION
|
||||||
|
|
||||||
|
fun consume(i: Int) {}
|
||||||
|
|
||||||
|
fun foo(a: String) {
|
||||||
|
var b = 1
|
||||||
|
if (a[1] == 'b') {
|
||||||
|
b = 2
|
||||||
|
} else if (a[0] == 'a') {
|
||||||
|
b = 3
|
||||||
|
}
|
||||||
|
|
||||||
|
consume(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1 GOTO
|
||||||
|
// 2 IF
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
// KOTLIN_CONFIGURATION_FLAGS: +JVM.DISABLE_OPTIMIZATION
|
||||||
|
|
||||||
|
fun consume(i: Int) {}
|
||||||
|
|
||||||
|
fun foo(a: Boolean) {
|
||||||
|
var b = 1
|
||||||
|
if (a) {
|
||||||
|
b = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
consume(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 0 GOTO
|
||||||
|
// 1 IF
|
||||||
@@ -1614,6 +1614,29 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/testData/codegen/bytecodeText/disabledOptimizations")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class DisabledOptimizations extends AbstractBytecodeTextTest {
|
||||||
|
private void runTest(String testDataFilePath) throws Exception {
|
||||||
|
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllFilesPresentInDisabledOptimizations() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/bytecodeText/disabledOptimizations"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noJumpInLastBranch.kt")
|
||||||
|
public void testNoJumpInLastBranch() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/bytecodeText/disabledOptimizations/noJumpInLastBranch.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noJumpInSingleBranch.kt")
|
||||||
|
public void testNoJumpInSingleBranch() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/bytecodeText/disabledOptimizations/noJumpInSingleBranch.kt");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/bytecodeText/enum")
|
@TestMetadata("compiler/testData/codegen/bytecodeText/enum")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
+23
@@ -1569,6 +1569,29 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/testData/codegen/bytecodeText/disabledOptimizations")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class DisabledOptimizations extends AbstractIrBytecodeTextTest {
|
||||||
|
private void runTest(String testDataFilePath) throws Exception {
|
||||||
|
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllFilesPresentInDisabledOptimizations() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/bytecodeText/disabledOptimizations"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noJumpInLastBranch.kt")
|
||||||
|
public void testNoJumpInLastBranch() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/bytecodeText/disabledOptimizations/noJumpInLastBranch.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noJumpInSingleBranch.kt")
|
||||||
|
public void testNoJumpInSingleBranch() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/bytecodeText/disabledOptimizations/noJumpInSingleBranch.kt");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/bytecodeText/enum")
|
@TestMetadata("compiler/testData/codegen/bytecodeText/enum")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Reference in New Issue
Block a user