diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index 0a8bed88202..85cce01551e 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -5931,6 +5931,7 @@ Task fileCheckTest(String name, Closure configureClosure) { if (!isCrossCompiling) { extraOpts project.globalTestArgs } + extraOpts task.extraOpts extraOpts "-Xtemporary-files-dir=$testOutputFileCheck/$name/$target" extraOpts "-Xsave-llvm-ir-after=${task.phaseToCheck}" if (lib != null) { @@ -5975,6 +5976,14 @@ if (HostManager.@Companion.hostIsMac) { // LLVM might infer attributes. phaseToCheck = "BitcodeOptimization" } + + fileCheckTest("filecheck_redundant_safepoints_removal") { + enabled = isExperimentalMM && project.globalTestArgs.contains("-opt") + annotatedSource = project.file('filecheck/redundant_safepoints.kt') + targetName = "watchos_arm32" + extraOpts = ["-Xbinary=memoryModel=experimental", "-opt"] + phaseToCheck = "RemoveRedundantSafepoints" + } } fileCheckTest("filecheck_replace_invoke_with_call") { diff --git a/kotlin-native/backend.native/tests/filecheck/redundant_safepoints.kt b/kotlin-native/backend.native/tests/filecheck/redundant_safepoints.kt new file mode 100644 index 00000000000..9445c8b0cc6 --- /dev/null +++ b/kotlin-native/backend.native/tests/filecheck/redundant_safepoints.kt @@ -0,0 +1,42 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ +import kotlin.native.Retain + +class C + +fun f(): Any { + return C() +} + +fun g() = f() + +// CHECK-LABEL: define %struct.ObjHeader* @"kfun:#h(kotlin.Boolean){}kotlin.Any" +@Retain +fun h(cond: Boolean): Any { + // CHECK: Kotlin_mm_safePointFunctionPrologue + // CHECK-NOT: Kotlin_mm_safePointFunctionPrologue + // CHECK: br + if (cond) { + // CHECK: Kotlin_mm_safePointFunctionPrologue + // CHECK-NOT: Kotlin_mm_safePointFunctionPrologue + // CHECK: br + return listOf(C(), C()) + } else { + // CHECK: Kotlin_mm_safePointFunctionPrologue + // CHECK-NOT: Kotlin_mm_safePointFunctionPrologue + return listOf(C(), C(), C()) + } +// CHECK: } +} + +// CHECK-LABEL: define void @"kfun:#main(){}"() +@Retain +fun main() { + // CHECK: Kotlin_mm_safePointFunctionPrologue + // CHECK-NOT: Kotlin_mm_safePointFunctionPrologue + println(g()) + println(h(true)) +// CHECK: } +} \ No newline at end of file diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/FileCheckTest.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/FileCheckTest.kt index c93969850a6..9149c32178d 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/FileCheckTest.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/FileCheckTest.kt @@ -69,6 +69,9 @@ open class FileCheckTest : DefaultTask() { @get:Optional var additionalFileCheckFlags: List? = null + @get:Input + var extraOpts: List = emptyList() + @get:Optional @get:Input var targetName: String = project.testTarget.name