Skip to content

Commit 9c3e294

Browse files
alexmarkovCommit Queue
authored and
Commit Queue
committed
[vm/compiler] Improve logic for combining types when both types have the same cid
Previously, a type with known cid was immediately selected, even if another type also has a known cid. Now, if cids match, the static types are also compared. This is useful for record types, because static record type is more accurate than known kRecordCid. TEST=vm/dart/records_field_operations_il_test Issue: #51637 Cq-Include-Trybots: luci.dart.try:vm-aot-linux-release-x64-try,vm-aot-linux-debug-x64-try Change-Id: I4e528d80a355a79d428bf3f03212c5a65af0b661 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292983 Auto-Submit: Alexander Markov <[email protected]> Reviewed-by: Martin Kustermann <[email protected]> Commit-Queue: Martin Kustermann <[email protected]>
1 parent 227e218 commit 9c3e294

File tree

2 files changed

+57
-20
lines changed

2 files changed

+57
-20
lines changed

runtime/tests/vm/dart/records_field_operations_il_test.dart

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ class A2 extends A {
3131
@pragma('vm:never-inline')
3232
(double, double) staticCallD() => (d(1), d(2));
3333

34+
@pragma('vm:prefer-inline')
35+
void inlinedCallD((double, double) xy) {
36+
var (x, y) = xy;
37+
print(x - y);
38+
}
39+
3440
@pragma('vm:never-inline')
3541
@pragma('vm:testing:print-flow-graph')
3642
void testDouble(A obj, double a, double b, (double, double) param) {
@@ -64,6 +70,11 @@ void testDouble(A obj, double a, double b, (double, double) param) {
6470
var (x, y) = obj.instanceCallD();
6571
print(x + y);
6672
}
73+
74+
{
75+
final local = (a, b);
76+
inlinedCallD(local);
77+
}
6778
}
6879

6980
void matchIL$testDouble(FlowGraph graph) {
@@ -124,6 +135,11 @@ void matchIL$testDouble(FlowGraph graph) {
124135
'v6' << match.BinaryDoubleOp('x6_unboxed', 'y6_unboxed'),
125136
'v6_boxed' << match.Box('v6'),
126137
match.MoveArgument('v6_boxed'),
138+
match.StaticCall(),
139+
'v7' << match.BinaryDoubleOp('a', 'b'),
140+
'v7_boxed' << match.Box('v7'),
141+
match.MoveArgument('v7_boxed'),
142+
match.StaticCall(),
127143
match.Return(),
128144
]),
129145
]);
@@ -151,6 +167,12 @@ class B2 extends B {
151167
@pragma('vm:never-inline')
152168
(int, int) staticCallI() => (i(1), i(2));
153169

170+
@pragma('vm:prefer-inline')
171+
void inlinedCallI((int, int) xy) {
172+
var (x, y) = xy;
173+
print(x - y);
174+
}
175+
154176
@pragma('vm:never-inline')
155177
@pragma('vm:testing:print-flow-graph')
156178
void testInt(B obj, int a, int b, (int, int) param) {
@@ -184,6 +206,11 @@ void testInt(B obj, int a, int b, (int, int) param) {
184206
var (x, y) = obj.instanceCallI();
185207
print(x + y);
186208
}
209+
210+
{
211+
final local = (a, b);
212+
inlinedCallI(local);
213+
}
187214
}
188215

189216
void matchIL$testInt(FlowGraph graph) {
@@ -245,6 +272,10 @@ void matchIL$testInt(FlowGraph graph) {
245272
'v6_boxed' << match.BoxInt64('v6'),
246273
match.MoveArgument('v6_boxed'),
247274
match.StaticCall(),
275+
'v7' << match.BinaryInt64Op('a', 'b'),
276+
'v7_boxed' << match.BoxInt64('v7'),
277+
match.MoveArgument('v7_boxed'),
278+
match.StaticCall(),
248279
match.Return(),
249280
]),
250281
]);

runtime/vm/compiler/backend/type_propagator.cc

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -627,30 +627,36 @@ CompileType* CompileType::ComputeRefinedType(CompileType* old_type,
627627
return old_type;
628628
}
629629

630+
CompileType* preferred_type = nullptr;
631+
630632
// Prefer exact Cid if known.
631-
if (new_type->ToCid() != kDynamicCid) {
632-
return new_type;
633-
}
634-
if (old_type->ToCid() != kDynamicCid) {
635-
return old_type;
633+
const intptr_t new_type_cid = new_type->ToCid();
634+
const intptr_t old_type_cid = old_type->ToCid();
635+
if (new_type_cid != old_type_cid) {
636+
if (new_type_cid != kDynamicCid) {
637+
preferred_type = new_type;
638+
} else if (old_type_cid != kDynamicCid) {
639+
preferred_type = old_type;
640+
}
636641
}
637642

638-
const AbstractType* old_abstract_type = old_type->ToAbstractType();
639-
const AbstractType* new_abstract_type = new_type->ToAbstractType();
640-
CompileType* preferred_type = nullptr;
643+
if (preferred_type == nullptr) {
644+
const AbstractType* old_abstract_type = old_type->ToAbstractType();
645+
const AbstractType* new_abstract_type = new_type->ToAbstractType();
641646

642-
// Prefer 'int' if known.
643-
if (old_type->IsNullableInt()) {
644-
preferred_type = old_type;
645-
} else if (new_type->IsNullableInt()) {
646-
preferred_type = new_type;
647-
} else if (old_abstract_type->IsSubtypeOf(*new_abstract_type, Heap::kOld)) {
648-
// Prefer old type, as it is clearly more specific.
649-
preferred_type = old_type;
650-
} else {
651-
// Prefer new type as it is more recent, even though it might be
652-
// no better than the old type.
653-
preferred_type = new_type;
647+
// Prefer 'int' if known.
648+
if (old_type->IsNullableInt()) {
649+
preferred_type = old_type;
650+
} else if (new_type->IsNullableInt()) {
651+
preferred_type = new_type;
652+
} else if (old_abstract_type->IsSubtypeOf(*new_abstract_type, Heap::kOld)) {
653+
// Prefer old type, as it is clearly more specific.
654+
preferred_type = old_type;
655+
} else {
656+
// Prefer new type as it is more recent, even though it might be
657+
// no better than the old type.
658+
preferred_type = new_type;
659+
}
654660
}
655661

656662
// Refine non-nullability and whether it can be sentinel.

0 commit comments

Comments
 (0)