Skip to content

Commit 375b32d

Browse files
mralephcommit-bot@chromium.org
authored andcommitted
[vm/compiler] Canonicalize more intermediate constants in IL.
* when building IL from Kernel use canonical double representation instead of allocating new double objects; * in constant propagation canonicalize immutable primitive constants (strings, mints and doubles) before replacing instruction with its constant value; This relands 5909932 with the part that was causing timeouts on flutter_test reverted. See #32904 for more details. [email protected] Change-Id: I0c128e44dd6c9689c4b7e9dd91832408214847f3 Reviewed-on: https://dart-review.googlesource.com/51460 Reviewed-by: Vyacheslav Egorov <[email protected]> Reviewed-by: Alexander Aprelev <[email protected]> Commit-Queue: Vyacheslav Egorov <[email protected]>
1 parent 9d7e35b commit 375b32d

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

runtime/vm/compiler/backend/constant_propagator.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ DEFINE_FLAG(bool,
2626
// Quick access to the current zone and isolate.
2727
#define I (isolate())
2828
#define Z (graph_->zone())
29+
#define T (graph_->thread())
2930

3031
ConstantPropagator::ConstantPropagator(
3132
FlowGraph* graph,
@@ -1321,6 +1322,7 @@ void ConstantPropagator::Transform() {
13211322
// instructions, previous pointers, predecessors, etc. after eliminating
13221323
// unreachable code. We do not maintain those properties during the
13231324
// transformation.
1325+
auto& value = Object::Handle(Z);
13241326
for (BlockIterator b = graph_->reverse_postorder_iterator(); !b.Done();
13251327
b.Advance()) {
13261328
BlockEntryInstr* block = b.Current();
@@ -1398,7 +1400,14 @@ void ConstantPropagator::Transform() {
13981400
THR_Print("Constant v%" Pd " = %s\n", defn->ssa_temp_index(),
13991401
defn->constant_value().ToCString());
14001402
}
1401-
ConstantInstr* constant = graph_->GetConstant(defn->constant_value());
1403+
value = defn->constant_value().raw();
1404+
if ((value.IsString() || value.IsMint() || value.IsDouble()) &&
1405+
!value.IsCanonical()) {
1406+
const char* error_str = nullptr;
1407+
value = Instance::Cast(value).CheckAndCanonicalize(T, &error_str);
1408+
ASSERT(!value.IsNull() && (error_str == nullptr));
1409+
}
1410+
ConstantInstr* constant = graph_->GetConstant(value);
14021411
defn->ReplaceUsesWith(constant);
14031412
i.RemoveCurrentFromGraph();
14041413
}

runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8985,9 +8985,9 @@ Fragment StreamingFlowGraphBuilder::BuildDoubleLiteral(
89858985
TokenPosition* position) {
89868986
if (position != NULL) *position = TokenPosition::kNoSource;
89878987

8988-
Double& constant =
8989-
Double::ZoneHandle(Z, Double::New(H.DartString(ReadStringReference()),
8990-
Heap::kOld)); // read string reference.
8988+
Double& constant = Double::ZoneHandle(
8989+
Z, Double::NewCanonical(
8990+
H.DartString(ReadStringReference()))); // read string reference.
89918991
return Constant(constant);
89928992
}
89938993

0 commit comments

Comments
 (0)