-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[vm/aot] Prefer EqualityCompare to avoid redundant boxing
When specializing x == y comparisons where one of the operands is known to be a Smi but the other one is *not* only emit StrictCompare if either x or y are nullable. For non-nullable equality comparisons prefer EqualityCompare which allows to avoid redundant boxing as non-nullable integer values are highly likely to be unboxed. TEST=vm/dart{,_2}/aot_prefer_equality_comparison_il_test Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-nnbd-linux-release-simarm64-try,vm-kernel-precomp-nnbd-linux-release-simarm_x64-try Change-Id: I1153f111dcbb518d25d753dc4357c72522389951 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214962 Commit-Queue: Slava Egorov <vegorov@google.com> Reviewed-by: Alexander Markov <alexmarkov@google.com>
- Loading branch information
Showing
3 changed files
with
54 additions
and
6 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
runtime/tests/vm/dart/aot_prefer_equality_comparison_il_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
// Test that we emit EqualityCompare rather than StrictCompare+BoxInt64 | ||
// when comparing non-nullable integer to a Smi. | ||
|
||
// MatchIL[AOT]=factorial | ||
// __ GraphEntry | ||
// __ FunctionEntry | ||
// __ CheckStackOverflow | ||
// __ Branch(EqualityCompare) | ||
@pragma('vm:never-inline') | ||
int factorial(int value) => value == 1 ? value : value * factorial(value - 1); | ||
|
||
void main() { | ||
print(factorial(4)); | ||
} |
18 changes: 18 additions & 0 deletions
18
runtime/tests/vm/dart_2/aot_prefer_equality_comparison_il_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
// Test that we emit EqualityCompare rather than StrictCompare+BoxInt64 | ||
// when comparing non-nullable integer to a Smi. | ||
|
||
// MatchIL[AOT]=factorial | ||
// __ GraphEntry | ||
// __ FunctionEntry | ||
// __ CheckStackOverflow | ||
// __ Branch(EqualityCompare) | ||
@pragma('vm:never-inline') | ||
int factorial(int value) => value == 1 ? value : value * factorial(value - 1); | ||
|
||
void main() { | ||
print(factorial(4)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters