JVM remove dead code during constant condition elimination

This avoids an extra call to 'analyze', which is rather costly.

Update debugger testData: Constant condition
elimination now performs DCE more consistently.
This commit is contained in:
Dmitry Petrov
2021-06-01 17:16:27 +03:00
committed by TeamCityServer
parent 1fd94d1bc2
commit 7a43c2de79
18 changed files with 357 additions and 13 deletions
@@ -0,0 +1,68 @@
// IGNORE_BACKEND: WASM
var log = ""
fun foo() {
try {
log += "1"
mightThrow()
log += "2"
} catch (e: Throwable) {
log += "3"
return
}
val t = try {
log += "4"
mightThrow2()
log += "5"
} catch (e: Throwable) {
log += "6"
return
}
val x = try {
log += "7"
mightThrow3()
log += "8"
} catch (e: Throwable) {
log += "9"
return
}
}
var throw1 = false
var throw2 = false
var throw3 = false
fun mightThrow() {
if (throw1) throw Exception()
}
fun mightThrow2() {
if (throw2) throw Exception()
}
fun mightThrow3(): Int {
if (throw3) throw Exception()
return 42
}
fun box(): String {
log += "a"
foo()
throw3 = true
log += " b"
foo()
throw2 = true
log += " c"
foo()
throw1 = true
log += " d"
foo()
if (log != "a124578 b124579 c1246 d13")
return "Failed: $log"
return "OK"
}
@@ -0,0 +1,54 @@
// IGNORE_BACKEND: WASM
var log = ""
fun foo() {
try {
log += "1"
mightThrow()
log += "2"
} catch (e: Throwable) {
log += "3"
"OK"
} finally {
log += "4"
"FINALLY"
}
val t = try {
log += "5"
mightThrow2()
log += "6"
} catch (e: Throwable) {
log += "7"
"OK2"
} finally {
log += "8"
"FINALLY2"
}
}
var throw1 = false
var throw2 = false
fun mightThrow() {
if (throw1) throw Exception()
}
fun mightThrow2() {
if (throw2) throw Exception()
}
fun box(): String {
log += "a"
foo()
throw2 = true
log += " b"
foo()
throw1 = true
log += " c"
foo()
if (log != "a124568 b124578 c134578")
return "Failed: $log"
return "OK"
}
@@ -0,0 +1,56 @@
// IGNORE_BACKEND: WASM
var log = ""
fun foo() {
try {
log += "1"
mightThrow()
log += "2"
} finally {
log += "3"
"FINALLY"
}
val t = try {
log += "4"
mightThrow2()
log += "5"
} finally {
log += "6"
"FINALLY2"
}
}
var throw1 = false
var throw2 = false
fun mightThrow() {
if (throw1) throw Exception()
}
fun mightThrow2() {
if (throw2) throw Exception()
}
fun test() {
log += "a"
foo()
throw2 = true
log += " b"
foo()
// Never gets here.
throw1 = true
log += " c"
foo()
}
fun box(): String {
try {
test()
} catch (e: Exception) {}
if (log != "a123456 b12346")
return "Failed: $log"
return "OK"
}
+1 -2
View File
@@ -16,7 +16,7 @@ fun box(): String {
}
} finally {
return "OK"
} // TODO: why do we go to this line before going to the line above for the finally block.
}
return "FAIL"
}
@@ -33,5 +33,4 @@ fun box(): String {
// test.kt:10 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException
// test.kt:11 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException, y:java.lang.String="y":java.lang.String
// test.kt:14 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException
// test.kt:19 box:
// test.kt:18 box:
+1 -2
View File
@@ -16,7 +16,7 @@ fun box(): String {
}
} finally {
return "OK"
} // TODO: why stop here before the line above for the finally block?
}
return "FAIL"
}
@@ -33,6 +33,5 @@ fun box(): String {
// test.kt:10 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException
// test.kt:11 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException, y:java.lang.String="y":java.lang.String
// test.kt:14 box: i:int=0:int, e:java.lang.Exception=java.lang.RuntimeException
// test.kt:19 box:
// test.kt:18 box:
+12
View File
@@ -59,13 +59,21 @@ fun box() {
// test.kt:32 mightThrow2
// test.kt:33 mightThrow2
// test.kt:11 foo
// LINENUMBERS JVM_IR
// test.kt:10 foo
// LINENUMBERS JVM
// test.kt:13 foo
// LINENUMBERS
// test.kt:16 foo
// test.kt:17 foo
// test.kt:36 mightThrow3
// test.kt:37 mightThrow3
// test.kt:17 foo
// LINENUMBERS JVM_IR
// test.kt:16 foo
// LINENUMBERS JVM
// test.kt:19 foo
// LINENUMBERS
// test.kt:21 foo
// test.kt:42 box
// test.kt:43 box
@@ -79,7 +87,11 @@ fun box() {
// test.kt:32 mightThrow2
// test.kt:33 mightThrow2
// test.kt:11 foo
// LINENUMBERS JVM
// test.kt:13 foo
// LINENUMBERS JVM_IR
// test.kt:10 foo
// LINENUMBERS
// test.kt:16 foo
// test.kt:17 foo
// test.kt:36 mightThrow3
+13 -1
View File
@@ -52,7 +52,11 @@ fun box() {
// test.kt:13 foo
// test.kt:17 foo
// test.kt:18 foo
// LINENUMBERS JVM
// test.kt:17 foo
// LINENUMBERS JVM_IR
// test.kt:12 foo
// LINENUMBERS
// test.kt:19 foo
// test.kt:34 box
// test.kt:35 box
@@ -69,7 +73,11 @@ fun box() {
// test.kt:15 foo
// test.kt:17 foo
// test.kt:18 foo
// LINENUMBERS JVM
// test.kt:17 foo
// LINENUMBERS JVM_IR
// test.kt:12 foo
// LINENUMBERS
// test.kt:19 foo
// test.kt:36 box
// test.kt:37 box
@@ -87,6 +95,10 @@ fun box() {
// test.kt:15 foo
// test.kt:17 foo
// test.kt:18 foo
// LINENUMBERS JVM
// test.kt:17 foo
// LINENUMBERS JVM_IR
// test.kt:12 foo
// LINENUMBERS
// test.kt:19 foo
// test.kt:38 box
// test.kt:38 box
+4
View File
@@ -56,7 +56,11 @@ fun box() {
// LINENUMBERS
// test.kt:13 foo
// test.kt:14 foo
// LINENUMBERS JVM
// test.kt:13 foo
// LINENUMBERS JVM_IR
// test.kt:10 foo
// LINENUMBERS
// test.kt:15 foo
// test.kt:30 box
// test.kt:31 box