Skip to content

Commit

Permalink
[vm/compiler] Fix constant propagation of truncating Unbox instructions
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
alexmarkov authored and Commit Queue committed Oct 31, 2024
1 parent da9b6a7 commit 507d40f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion runtime/vm/compiler/backend/constant_propagator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1499,11 +1499,25 @@ void ConstantPropagator::VisitCaseInsensitiveCompare(
}

void ConstantPropagator::VisitUnbox(UnboxInstr* instr) {
const Object& value = instr->value()->definition()->constant_value();
Object& value = instr->value()->definition()->constant_value();
if (IsUnknown(value)) {
return;
}

if (auto* unbox_int = instr->AsUnboxInteger()) {
if (!value.IsInteger()) {
SetValue(instr, non_constant_);
return;
}
if (unbox_int->is_truncating() &&
((unbox_int->representation() == kUnboxedInt32) ||
(unbox_int->representation() == kUnboxedUint32))) {
const int64_t result_val = Evaluator::TruncateTo(
Integer::Cast(value).Value(), unbox_int->representation());
value = Integer::NewCanonical(result_val);
}
}

SetValue(instr, value);
}

Expand Down

0 comments on commit 507d40f

Please sign in to comment.