Skip to content

Commit 507d40f

Browse files
alexmarkovCommit Queue
authored and
Commit Queue
committed
[vm/compiler] Fix constant propagation of truncating Unbox instructions
TEST=ffi/data_test Fixes #56996 Change-Id: I153a468d784eae16d65722e91a039347930fd801 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392841 Commit-Queue: Slava Egorov <[email protected]> Auto-Submit: Alexander Markov <[email protected]> Reviewed-by: Slava Egorov <[email protected]>
1 parent da9b6a7 commit 507d40f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

runtime/vm/compiler/backend/constant_propagator.cc

+15-1
Original file line numberDiff line numberDiff line change
@@ -1499,11 +1499,25 @@ void ConstantPropagator::VisitCaseInsensitiveCompare(
14991499
}
15001500

15011501
void ConstantPropagator::VisitUnbox(UnboxInstr* instr) {
1502-
const Object& value = instr->value()->definition()->constant_value();
1502+
Object& value = instr->value()->definition()->constant_value();
15031503
if (IsUnknown(value)) {
15041504
return;
15051505
}
15061506

1507+
if (auto* unbox_int = instr->AsUnboxInteger()) {
1508+
if (!value.IsInteger()) {
1509+
SetValue(instr, non_constant_);
1510+
return;
1511+
}
1512+
if (unbox_int->is_truncating() &&
1513+
((unbox_int->representation() == kUnboxedInt32) ||
1514+
(unbox_int->representation() == kUnboxedUint32))) {
1515+
const int64_t result_val = Evaluator::TruncateTo(
1516+
Integer::Cast(value).Value(), unbox_int->representation());
1517+
value = Integer::NewCanonical(result_val);
1518+
}
1519+
}
1520+
15071521
SetValue(instr, value);
15081522
}
15091523

0 commit comments

Comments
 (0)