[VM] Use strict compare instruction only if receiver is nullable int
Since in Dart 1 == 1.0 is true.
Change-Id: I05faebb31c6c725095a54020a9665cf40cc55a4b
Reviewed-on: https://dart-review.googlesource.com/c/84531
Reviewed-by: Martin Kustermann <kustermann@google.com>
diff --git a/runtime/vm/compiler/aot/aot_call_specializer.cc b/runtime/vm/compiler/aot/aot_call_specializer.cc
index d905077..571be51 100644
--- a/runtime/vm/compiler/aot/aot_call_specializer.cc
+++ b/runtime/vm/compiler/aot/aot_call_specializer.cc
@@ -432,16 +432,18 @@
CompileType* right_type = right_value->Type();
const bool is_equality_op = Token::IsEqualityOperator(op_kind);
- const bool receiver_is_nullable_numeric = left_type->IsNullableNumeric();
- const bool can_use_strict_compare =
- is_equality_op && receiver_is_nullable_numeric &&
- (left_type->IsNullableSmi() || right_type->IsNullableSmi());
const bool has_nullable_int_args =
left_type->IsNullableInt() && right_type->IsNullableInt();
+ // NOTE: We cannot use strict comparisons if the receiver has an overridden
+ // == operator or if either side can be a double, since 1.0 == 1.
+ const bool can_use_strict_compare =
+ is_equality_op && has_nullable_int_args &&
+ (left_type->IsNullableSmi() || right_type->IsNullableSmi());
+
// We only support binary operations if both operands are nullable integers
// or when we can use a cheap strict comparison operation.
- if (!has_nullable_int_args && !can_use_strict_compare) {
+ if (!has_nullable_int_args) {
return false;
}
diff --git a/runtime/vm/compiler/backend/il.h b/runtime/vm/compiler/backend/il.h
index 32415aa..dff225c 100644
--- a/runtime/vm/compiler/backend/il.h
+++ b/runtime/vm/compiler/backend/il.h
@@ -226,18 +226,6 @@
return false;
}
- // Returns true if value of this type is either Smi, Mint, Double or null.
- bool IsNullableNumeric() {
- if (cid_ == kSmiCid || cid_ == kMintCid || cid_ == kDoubleCid) {
- return true;
- }
- if (cid_ == kIllegalCid || cid_ == kDynamicCid) {
- return type_ != NULL && (type_->IsIntType() || type_->IsDoubleType() ||
- type_->IsNumberType());
- }
- return false;
- }
-
void PrintTo(BufferFormatter* f) const;
const char* ToCString() const;