Minor, refactor bytecode text tests on when-over-string optimization
- Merge `duplicatingItemsSameHashCode.kt` and
`duplicatingItemsSameHashCode2.kt` into one test enabled on both
backends, and rename it to
`duplicatingItemsSameHashCodeFewBranches.kt`.
- Rename `duplicatingItemsSameHashCode3.kt` to
`duplicatingItemsSameHashCodeMoreBranches.kt`, and also enable it for
both backends.
- Use JVM_TEMPLATES/JVM_IR_TEMPLATES to check backend-specific behavior:
1) JVM IR does not optimize less than 2 branches by design
2) JVM IR does not generate duplicate branches, also by design
Related to KT-36846.
This commit is contained in:
Vendored
-17
@@ -1,17 +0,0 @@
|
|||||||
// IGNORE_BACKEND: JVM_IR
|
|
||||||
// TODO KT-36846 Generate TABLESWITCH/LOOKUPSWITCH in case of matching hashCodes in JVM_IR
|
|
||||||
|
|
||||||
fun foo(x : String) : String {
|
|
||||||
assert("abz]".hashCode() == "aby|".hashCode())
|
|
||||||
|
|
||||||
when (x) {
|
|
||||||
"abz]" -> return "abz"
|
|
||||||
"ghi" -> return "ghi"
|
|
||||||
"aby|" -> return "aby"
|
|
||||||
"abz]" -> return "fail"
|
|
||||||
}
|
|
||||||
|
|
||||||
return "other"
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1 LOOKUPSWITCH
|
|
||||||
+5
-5
@@ -1,6 +1,3 @@
|
|||||||
// IGNORE_BACKEND: JVM
|
|
||||||
import kotlin.test.assertEquals
|
|
||||||
|
|
||||||
fun foo(x : String) : String {
|
fun foo(x : String) : String {
|
||||||
assert("abz]".hashCode() == "aby|".hashCode())
|
assert("abz]".hashCode() == "aby|".hashCode())
|
||||||
|
|
||||||
@@ -14,6 +11,9 @@ fun foo(x : String) : String {
|
|||||||
return "other"
|
return "other"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expecting 0 LOOKUPSWITCH as there is only 2 different hash codes.
|
// JVM_TEMPLATES:
|
||||||
// An IF casecade is more efficient.
|
// 1 LOOKUPSWITCH
|
||||||
|
|
||||||
|
// JVM_IR_TEMPLATES:
|
||||||
|
// Expecting 0 LOOKUPSWITCH as there is only 2 different hash codes. An IF cascade is more efficient.
|
||||||
// 0 LOOKUPSWITCH
|
// 0 LOOKUPSWITCH
|
||||||
+2
-1
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND: JVM
|
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
fun foo(x : String) : String {
|
fun foo(x : String) : String {
|
||||||
@@ -16,4 +15,6 @@ fun foo(x : String) : String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 1 LOOKUPSWITCH
|
// 1 LOOKUPSWITCH
|
||||||
|
|
||||||
|
// JVM_IR_TEMPLATES:
|
||||||
// 0 LDC "fail"
|
// 0 LDC "fail"
|
||||||
+6
-11
@@ -4931,19 +4931,14 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
|
|||||||
runTest("compiler/testData/codegen/bytecodeText/whenStringOptimization/duplicatingItems.kt");
|
runTest("compiler/testData/codegen/bytecodeText/whenStringOptimization/duplicatingItems.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("duplicatingItemsSameHashCode.kt")
|
@TestMetadata("duplicatingItemsSameHashCodeFewBranches.kt")
|
||||||
public void testDuplicatingItemsSameHashCode() throws Exception {
|
public void testDuplicatingItemsSameHashCodeFewBranches() throws Exception {
|
||||||
runTest("compiler/testData/codegen/bytecodeText/whenStringOptimization/duplicatingItemsSameHashCode.kt");
|
runTest("compiler/testData/codegen/bytecodeText/whenStringOptimization/duplicatingItemsSameHashCodeFewBranches.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("duplicatingItemsSameHashCode2.kt")
|
@TestMetadata("duplicatingItemsSameHashCodeMoreBranches.kt")
|
||||||
public void testDuplicatingItemsSameHashCode2() throws Exception {
|
public void testDuplicatingItemsSameHashCodeMoreBranches() throws Exception {
|
||||||
runTest("compiler/testData/codegen/bytecodeText/whenStringOptimization/duplicatingItemsSameHashCode2.kt");
|
runTest("compiler/testData/codegen/bytecodeText/whenStringOptimization/duplicatingItemsSameHashCodeMoreBranches.kt");
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("duplicatingItemsSameHashCode3.kt")
|
|
||||||
public void testDuplicatingItemsSameHashCode3() throws Exception {
|
|
||||||
runTest("compiler/testData/codegen/bytecodeText/whenStringOptimization/duplicatingItemsSameHashCode3.kt");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("expression.kt")
|
@TestMetadata("expression.kt")
|
||||||
|
|||||||
+6
-11
@@ -4899,19 +4899,14 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest {
|
|||||||
runTest("compiler/testData/codegen/bytecodeText/whenStringOptimization/duplicatingItems.kt");
|
runTest("compiler/testData/codegen/bytecodeText/whenStringOptimization/duplicatingItems.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("duplicatingItemsSameHashCode.kt")
|
@TestMetadata("duplicatingItemsSameHashCodeFewBranches.kt")
|
||||||
public void testDuplicatingItemsSameHashCode() throws Exception {
|
public void testDuplicatingItemsSameHashCodeFewBranches() throws Exception {
|
||||||
runTest("compiler/testData/codegen/bytecodeText/whenStringOptimization/duplicatingItemsSameHashCode.kt");
|
runTest("compiler/testData/codegen/bytecodeText/whenStringOptimization/duplicatingItemsSameHashCodeFewBranches.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("duplicatingItemsSameHashCode2.kt")
|
@TestMetadata("duplicatingItemsSameHashCodeMoreBranches.kt")
|
||||||
public void testDuplicatingItemsSameHashCode2() throws Exception {
|
public void testDuplicatingItemsSameHashCodeMoreBranches() throws Exception {
|
||||||
runTest("compiler/testData/codegen/bytecodeText/whenStringOptimization/duplicatingItemsSameHashCode2.kt");
|
runTest("compiler/testData/codegen/bytecodeText/whenStringOptimization/duplicatingItemsSameHashCodeMoreBranches.kt");
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("duplicatingItemsSameHashCode3.kt")
|
|
||||||
public void testDuplicatingItemsSameHashCode3() throws Exception {
|
|
||||||
runTest("compiler/testData/codegen/bytecodeText/whenStringOptimization/duplicatingItemsSameHashCode3.kt");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("expression.kt")
|
@TestMetadata("expression.kt")
|
||||||
|
|||||||
Reference in New Issue
Block a user