mirror of
https://github.com/dart-lang/sdk
synced 2024-10-02 23:39:19 +00:00
[vm/compiler] Optimize 'double == int' in AOT
TEST=vm/cc/IRTest_DoubleEqualsSmi Fixes https://github.com/dart-lang/sdk/issues/47031 Change-Id: I6395ae50806b238971872b375c495962cb868cb1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212484 Reviewed-by: Slava Egorov <vegorov@google.com> Commit-Queue: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
parent
74d2704382
commit
74dc879d25
|
@ -602,7 +602,7 @@ bool AotCallSpecializer::TryOptimizeDoubleOperation(TemplateDartCall<0>* instr,
|
|||
case Token::kNE: {
|
||||
// TODO(dartbug.com/32166): Support EQ, NE for nullable doubles.
|
||||
// (requires null-aware comparison instruction).
|
||||
if (left_type->IsDouble() && right_type->IsDouble()) {
|
||||
if (!left_type->is_nullable() && !right_type->is_nullable()) {
|
||||
left_value = PrepareStaticOpInput(left_value, kDoubleCid, instr);
|
||||
right_value = PrepareStaticOpInput(right_value, kDoubleCid, instr);
|
||||
replacement = new (Z) EqualityCompareInstr(
|
||||
|
|
|
@ -604,4 +604,33 @@ ISOLATE_UNIT_TEST_CASE(HierarchyInfo_String_Subtype) {
|
|||
RANGES_CONTAIN_EXPECTED_CIDS(abstract_range, expected_cids);
|
||||
}
|
||||
|
||||
// This test verifies that double == Smi is recognized and
|
||||
// implemented using EqualityCompare.
|
||||
// Regression test for https://github.com/dart-lang/sdk/issues/47031.
|
||||
ISOLATE_UNIT_TEST_CASE(IRTest_DoubleEqualsSmi) {
|
||||
const char* kScript = R"(
|
||||
bool foo(double x) => (x + 0.5) == 0;
|
||||
main() {
|
||||
foo(-0.5);
|
||||
}
|
||||
)";
|
||||
|
||||
const auto& root_library = Library::Handle(LoadTestScript(kScript));
|
||||
const auto& function = Function::Handle(GetFunction(root_library, "foo"));
|
||||
|
||||
TestPipeline pipeline(function, CompilerPass::kAOT);
|
||||
FlowGraph* flow_graph = pipeline.RunPasses({});
|
||||
|
||||
auto entry = flow_graph->graph_entry()->normal_entry();
|
||||
ILMatcher cursor(flow_graph, entry, /*trace=*/true,
|
||||
ParallelMovesHandling::kSkip);
|
||||
|
||||
RELEASE_ASSERT(cursor.TryMatch({
|
||||
kMoveGlob,
|
||||
kMatchAndMoveBinaryDoubleOp,
|
||||
kMatchAndMoveEqualityCompare,
|
||||
kMatchReturn,
|
||||
}));
|
||||
}
|
||||
|
||||
} // namespace dart
|
||||
|
|
Loading…
Reference in a new issue