From fff22d9372e27e1e2f2a818ce91ea91cca992afe Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 19 Mar 2019 18:32:50 +0100 Subject: [PATCH] Remove hack from JvmBuiltinOptimizationLowering related to booleanNotSymbol --- .../backend/jvm/codegen/ExpressionCodegen.kt | 3 +-- .../lower/JvmBuiltinOptimizationLowering.kt | 23 ++++--------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt index a3ad7bab9eb..3c2a1aeae76 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt @@ -11,7 +11,6 @@ import org.jetbrains.kotlin.backend.jvm.intrinsics.IrIntrinsicFunction import org.jetbrains.kotlin.backend.jvm.intrinsics.IrIntrinsicMethods import org.jetbrains.kotlin.backend.jvm.lower.CrIrType import org.jetbrains.kotlin.backend.jvm.lower.JvmBuiltinOptimizationLowering.Companion.isNegation -import org.jetbrains.kotlin.backend.jvm.lower.JvmBuiltinOptimizationLowering.Companion.negationArgument import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.codegen.* import org.jetbrains.kotlin.codegen.AsmUtil.* @@ -748,7 +747,7 @@ class ExpressionCodegen( // targets instead. This significantly cuts down the amount of branches and loads of // const_0 and const_1 in the generated java bytecode. if (isNegation(condition, classCodegen.context)) { - condition = negationArgument(condition as IrCall) + condition = (condition as IrCall).dispatchReceiver!! jumpIfFalse = !jumpIfFalse } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmBuiltinOptimizationLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmBuiltinOptimizationLowering.kt index 0fba706faf6..2c5f44c99cd 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmBuiltinOptimizationLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmBuiltinOptimizationLowering.kt @@ -34,19 +34,9 @@ internal val jvmBuiltinOptimizationLoweringPhase = makeIrFilePhase( class JvmBuiltinOptimizationLowering(val context: JvmBackendContext) : FileLoweringPass { companion object { - fun isNegation(expression: IrExpression, context: JvmBackendContext): Boolean { - // TODO: there should be only one representation of the 'not' operator. - return expression is IrCall && - (expression.symbol == context.irBuiltIns.booleanNotSymbol || - context.state.intrinsics.getIntrinsic(expression.symbol.descriptor) is Not) - } - - fun negationArgument(call: IrCall): IrExpression { - // TODO: there should be only one representation of the 'not' operator. - // Once there is only the IR definition the negation argument will - // always be a value argument and this method can be removed. - return call.dispatchReceiver ?: call.getValueArgument(0)!! - } + fun isNegation(expression: IrExpression, context: JvmBackendContext): Boolean = + expression is IrCall && + context.state.intrinsics.getIntrinsic(expression.symbol.descriptor) is Not } private fun hasNoSideEffectsForNullCompare(expression: IrExpression): Boolean { @@ -80,11 +70,8 @@ class JvmBuiltinOptimizationLowering(val context: JvmBackendContext) : FileLower irFile.transformChildrenVoid(object : IrElementTransformerVoid() { override fun visitCall(expression: IrCall): IrExpression { expression.transformChildrenVoid(this) - return if (isNegation(expression, context) && isNegation(negationArgument(expression), context)) { - // TODO: This lowering is currently JvmBackend specific because there are multiple - // definitions of the boolean 'not' operator. Once there is only the irBuiltins - // definition this lowering could be shared with other backends. - negationArgument(negationArgument(expression) as IrCall) + return if (isNegation(expression, context) && isNegation(expression.dispatchReceiver!!, context)) { + (expression.dispatchReceiver as IrCall).dispatchReceiver!! } else if (isNullCheckOfPrimitiveTypeValue(expression, context)) { val left = expression.getValueArgument(0)!! val nonNullArgument = if (left.isNullConst()) expression.getValueArgument(1)!! else left