[vm/compiler] Replace LoadClassId for known cids.
Change-Id: I4c5b31cd83882892657d0cfff1e75aab494fd20b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/101661
Commit-Queue: Teagan Strickland <sstrickl@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
diff --git a/runtime/vm/compiler/backend/constant_propagator.cc b/runtime/vm/compiler/backend/constant_propagator.cc
index acf4f9c..931ffa3 100644
--- a/runtime/vm/compiler/backend/constant_propagator.cc
+++ b/runtime/vm/compiler/backend/constant_propagator.cc
@@ -844,15 +844,9 @@
}
void ConstantPropagator::VisitLoadClassId(LoadClassIdInstr* instr) {
- intptr_t cid = instr->object()->Type()->ToCid();
- if (cid != kDynamicCid) {
- SetValue(instr, Smi::ZoneHandle(Z, Smi::New(cid)));
- return;
- }
-
const Object& object = instr->object()->definition()->constant_value();
if (IsConstant(object)) {
- cid = object.GetClassId();
+ const intptr_t cid = object.GetClassId();
SetValue(instr, Smi::ZoneHandle(Z, Smi::New(cid)));
return;
}
diff --git a/runtime/vm/compiler/backend/il.cc b/runtime/vm/compiler/backend/il.cc
index 635c4be..cbffc1a 100644
--- a/runtime/vm/compiler/backend/il.cc
+++ b/runtime/vm/compiler/backend/il.cc
@@ -3414,6 +3414,15 @@
return cids().HasClassId(value_cid) ? NULL : this;
}
+Definition* LoadClassIdInstr::Canonicalize(FlowGraph* flow_graph) {
+ const intptr_t cid = object()->Type()->ToCid();
+ if (cid != kDynamicCid) {
+ const auto& smi = Smi::ZoneHandle(flow_graph->zone(), Smi::New(cid));
+ return flow_graph->GetConstant(smi);
+ }
+ return this;
+}
+
Instruction* CheckClassIdInstr::Canonicalize(FlowGraph* flow_graph) {
if (value()->BindsToConstant()) {
const Object& constant_value = value()->BoundConstant();
diff --git a/runtime/vm/compiler/backend/il.h b/runtime/vm/compiler/backend/il.h
index 370136a..cf93aaa 100644
--- a/runtime/vm/compiler/backend/il.h
+++ b/runtime/vm/compiler/backend/il.h
@@ -5246,6 +5246,8 @@
DECLARE_INSTRUCTION(LoadClassId)
virtual CompileType ComputeType() const;
+ virtual Definition* Canonicalize(FlowGraph* flow_graph);
+
Value* object() const { return inputs_[0]; }
virtual bool ComputeCanDeoptimize() const { return false; }