Don't coerce intrisic value, it's already coerced

This commit is contained in:
Mikhael Bogdanov
2019-11-15 12:04:14 +01:00
parent e409387078
commit f264942bf9
5 changed files with 40 additions and 2 deletions
@@ -329,7 +329,7 @@ class ExpressionCodegen(
override fun visitFunctionAccess(expression: IrFunctionAccessExpression, data: BlockInfo): PromisedValue {
classCodegen.context.irIntrinsics.getIntrinsic(expression.symbol)
?.invoke(expression, this, data)?.let { return it.coerce(expression.type) }
?.invoke(expression, this, data)?.let { return it }
val callable = methodSignatureMapper.mapToCallableMethod(expression)
val callee = expression.symbol.owner
@@ -409,7 +409,8 @@ class ExpressionCodegen(
}
expression is IrConstructorCall ->
MaterialValue(this, asmType, expression.type)
expression is IrDelegatingConstructorCall ->
expression.type.isUnit() && callable.asmMethod.returnType == Type.VOID_TYPE ->
//don't generate redundant UNIT/pop instructions
immaterialUnitValue
expression.type.isUnit() ->
// NewInference allows casting `() -> T` to `() -> Unit`. A CHECKCAST here will fail.
@@ -0,0 +1,7 @@
// KOTLIN_CONFIGURATION_FLAGS: +JVM.DISABLE_OPTIMIZATION
fun foo(s: String = "123") {}
// 1 IF
// 0 Unit\.INSTANCE
// 0 POP
@@ -0,0 +1,10 @@
// KOTLIN_CONFIGURATION_FLAGS: +JVM.DISABLE_OPTIMIZATION
fun bar() {}
fun foo() {
bar()
}
// 0 Unit\.INSTANCE
// 0 POP
@@ -1635,6 +1635,16 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
public void testNoJumpInSingleBranch() throws Exception {
runTest("compiler/testData/codegen/bytecodeText/disabledOptimizations/noJumpInSingleBranch.kt");
}
@TestMetadata("noUnitInstanceInDefaultParameterInitialization.kt")
public void testNoUnitInstanceInDefaultParameterInitialization() throws Exception {
runTest("compiler/testData/codegen/bytecodeText/disabledOptimizations/noUnitInstanceInDefaultParameterInitialization.kt");
}
@TestMetadata("noUnitInstanceOnVoidFunctionCall.kt")
public void testNoUnitInstanceOnVoidFunctionCall() throws Exception {
runTest("compiler/testData/codegen/bytecodeText/disabledOptimizations/noUnitInstanceOnVoidFunctionCall.kt");
}
}
@TestMetadata("compiler/testData/codegen/bytecodeText/enum")
@@ -1590,6 +1590,16 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest {
public void testNoJumpInSingleBranch() throws Exception {
runTest("compiler/testData/codegen/bytecodeText/disabledOptimizations/noJumpInSingleBranch.kt");
}
@TestMetadata("noUnitInstanceInDefaultParameterInitialization.kt")
public void testNoUnitInstanceInDefaultParameterInitialization() throws Exception {
runTest("compiler/testData/codegen/bytecodeText/disabledOptimizations/noUnitInstanceInDefaultParameterInitialization.kt");
}
@TestMetadata("noUnitInstanceOnVoidFunctionCall.kt")
public void testNoUnitInstanceOnVoidFunctionCall() throws Exception {
runTest("compiler/testData/codegen/bytecodeText/disabledOptimizations/noUnitInstanceOnVoidFunctionCall.kt");
}
}
@TestMetadata("compiler/testData/codegen/bytecodeText/enum")