Generate intrinsic-based numeric comparison only for FP types

This commit is contained in:
Dmitry Petrov
2018-08-01 17:43:42 +03:00
parent cce9505e31
commit 1bfb75a51b
11 changed files with 156 additions and 33 deletions
@@ -3373,31 +3373,33 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
TypeAndNullability left754Type = calcTypeForIeee754ArithmeticIfNeeded(left, getLeftOperandType(primitiveNumericComparisonInfo));
TypeAndNullability right754Type = calcTypeForIeee754ArithmeticIfNeeded(right, getRightOperandType(primitiveNumericComparisonInfo));
if (left754Type != null && right754Type != null) {
if (left754Type.type.equals(right754Type.type)) {
//check nullability cause there is some optimizations in codegen for non-nullable case
if (left754Type.isNullable || right754Type.isNullable) {
if (state.getLanguageVersionSettings().getApiVersion().compareTo(ApiVersion.KOTLIN_1_1) >= 0) {
return StackValue.operation(Type.BOOLEAN_TYPE, v -> {
generate754EqualsForNullableTypesViaIntrinsic(v, opToken, pregeneratedLeft, left, left754Type, right, right754Type);
return Unit.INSTANCE;
});
Type comparisonType = comparisonOperandType(left754Type.type, right754Type.type);
if (comparisonType == Type.FLOAT_TYPE || comparisonType == Type.DOUBLE_TYPE) {
if (left754Type.type.equals(right754Type.type)) {
//check nullability cause there is some optimizations in codegen for non-nullable case
if (left754Type.isNullable || right754Type.isNullable) {
if (state.getLanguageVersionSettings().getApiVersion().compareTo(ApiVersion.KOTLIN_1_1) >= 0) {
return StackValue.operation(Type.BOOLEAN_TYPE, v -> {
generate754EqualsForNullableTypesViaIntrinsic(v, opToken, pregeneratedLeft, left, left754Type, right,
right754Type);
return Unit.INSTANCE;
});
}
else {
return StackValue.operation(Type.BOOLEAN_TYPE, v -> {
generate754EqualsForNullableTypes(v, opToken, pregeneratedLeft, left, left754Type, right, right754Type);
return Unit.INSTANCE;
});
}
}
else {
return StackValue.operation(Type.BOOLEAN_TYPE, v -> {
generate754EqualsForNullableTypes(v, opToken, pregeneratedLeft, left, left754Type, right, right754Type);
return Unit.INSTANCE;
});
leftType = left754Type.type;
rightType = right754Type.type;
}
}
else {
leftType = left754Type.type;
rightType = right754Type.type;
}
}
else if (shouldUseProperIeee754Comparisons()) {
Type comparisonType = comparisonOperandType(left754Type.type, right754Type.type);
if (comparisonType == Type.FLOAT_TYPE || comparisonType == Type.DOUBLE_TYPE) {
else if (shouldUseProperIeee754Comparisons()) {
return Ieee754Equality.create(
myFrameMap,
genLazy(left, boxIfNullable(left754Type)),
@@ -35,6 +35,9 @@ fun calcProperTypeForIeee754ArithmeticIfNeeded(
return TypeAndNullability(asmType, isNullable)
}
private fun KotlinType.isFloatingPointOrNullable() =
KotlinBuiltIns.isDoubleOrNullableDouble(this) || KotlinBuiltIns.isFloatOrNullableFloat(this)
private fun KtExpression.getKotlinTypeForComparison(bindingContext: BindingContext): KotlinType? =
when {
this is KtProperty -> bindingContext[BindingContext.VARIABLE, this]?.type