Revert "VM: Constant fold more loads from constants in the optimizer."

This reverts commit 746ab58f46.

Reason: precompiler tests broke

    python tools/test.py -mrelease -cprecompiler -rdart_precompiled -aarm -sandroid --use-blobs -t480 corelib/string_test
    python tools/test.py -mrelease -cprecompiler -rdart_precompiled -aarm -sandroid --use-blobs -t480 corelib/list_test/none
    python tools/test.py -mrelease -cprecompiler -rdart_precompiled -aarm -sandroid --use-blobs -t480 corelib/list_test/01

TBR=kustermann@google.com
BUG=

Review-Url: https://codereview.chromium.org/2894913002 .
This commit is contained in:
Vyacheslav Egorov 2017-05-19 17:17:49 +02:00
parent bd6f0800fc
commit 1040fefdea
3 changed files with 40 additions and 82 deletions

View file

@ -831,33 +831,30 @@ void ConstantPropagator::VisitLoadField(LoadFieldInstr* instr) {
}
}
const Object& constant = instance->definition()->constant_value();
if (IsConstant(constant)) {
if (instr->IsImmutableLengthLoad()) {
if (constant.IsString()) {
if (instr->IsImmutableLengthLoad()) {
ConstantInstr* constant =
instance->definition()->OriginalDefinition()->AsConstant();
if (constant != NULL) {
if (constant->value().IsString()) {
SetValue(instr,
Smi::ZoneHandle(Z, Smi::New(String::Cast(constant).Length())));
Smi::ZoneHandle(
Z, Smi::New(String::Cast(constant->value()).Length())));
return;
}
if (constant.IsArray()) {
if (constant->value().IsArray()) {
SetValue(instr,
Smi::ZoneHandle(Z, Smi::New(Array::Cast(constant).Length())));
Smi::ZoneHandle(
Z, Smi::New(Array::Cast(constant->value()).Length())));
return;
}
if (constant.IsTypedData()) {
SetValue(instr, Smi::ZoneHandle(
Z, Smi::New(TypedData::Cast(constant).Length())));
return;
}
} else {
Object& value = Object::Handle();
if (instr->Evaluate(constant, &value)) {
SetValue(instr, Object::ZoneHandle(Z, value.raw()));
if (constant->value().IsTypedData()) {
SetValue(instr,
Smi::ZoneHandle(
Z, Smi::New(TypedData::Cast(constant->value()).Length())));
return;
}
}
}
SetValue(instr, non_constant_);
}

View file

@ -2121,72 +2121,40 @@ Definition* MathUnaryInstr::Canonicalize(FlowGraph* flow_graph) {
}
bool LoadFieldInstr::Evaluate(const Object& instance, Object* result) {
if (field() == NULL || !field()->is_final() || !instance.IsInstance()) {
return false;
}
// Check that instance really has the field which we
// are trying to load from.
Class& cls = Class::Handle(instance.clazz());
while (cls.raw() != Class::null() && cls.raw() != field()->Owner()) {
cls = cls.SuperClass();
}
if (cls.raw() != field()->Owner()) {
// Failed to find the field in class or its superclasses.
return false;
}
// Object has the field: execute the load.
*result = Instance::Cast(instance).GetField(*field());
return true;
}
Definition* LoadFieldInstr::Canonicalize(FlowGraph* flow_graph) {
if (!HasUses()) return NULL;
if (!IsImmutableLengthLoad()) return this;
if (IsImmutableLengthLoad()) {
// For fixed length arrays if the array is the result of a known constructor
// call we can replace the length load with the length argument passed to
// the constructor.
StaticCallInstr* call =
instance()->definition()->OriginalDefinition()->AsStaticCall();
if (call != NULL) {
if (call->is_known_list_constructor() &&
IsFixedLengthArrayCid(call->Type()->ToCid())) {
return call->ArgumentAt(1);
}
}
CreateArrayInstr* create_array =
instance()->definition()->OriginalDefinition()->AsCreateArray();
if ((create_array != NULL) &&
(recognized_kind() == MethodRecognizer::kObjectArrayLength)) {
return create_array->num_elements()->definition();
}
// For arrays with guarded lengths, replace the length load
// with a constant.
LoadFieldInstr* load_array =
instance()->definition()->OriginalDefinition()->AsLoadField();
if (load_array != NULL) {
const Field* field = load_array->field();
if ((field != NULL) && (field->guarded_list_length() >= 0)) {
return flow_graph->GetConstant(
Smi::Handle(Smi::New(field->guarded_list_length())));
}
// For fixed length arrays if the array is the result of a known constructor
// call we can replace the length load with the length argument passed to
// the constructor.
StaticCallInstr* call =
instance()->definition()->OriginalDefinition()->AsStaticCall();
if (call != NULL) {
if (call->is_known_list_constructor() &&
IsFixedLengthArrayCid(call->Type()->ToCid())) {
return call->ArgumentAt(1);
}
}
// Try folding away loads from constant objects.
if (instance()->BindsToConstant()) {
Object& result = Object::Handle();
if (Evaluate(instance()->BoundConstant(), &result)) {
return flow_graph->GetConstant(result);
}
CreateArrayInstr* create_array =
instance()->definition()->OriginalDefinition()->AsCreateArray();
if ((create_array != NULL) &&
(recognized_kind() == MethodRecognizer::kObjectArrayLength)) {
return create_array->num_elements()->definition();
}
// For arrays with guarded lengths, replace the length load
// with a constant.
LoadFieldInstr* load_array =
instance()->definition()->OriginalDefinition()->AsLoadField();
if (load_array != NULL) {
const Field* field = load_array->field();
if ((field != NULL) && (field->guarded_list_length() >= 0)) {
return flow_graph->GetConstant(
Smi::Handle(Smi::New(field->guarded_list_length())));
}
}
return this;
}

View file

@ -4555,13 +4555,6 @@ class LoadFieldInstr : public TemplateDefinition<1, NoThrow> {
bool IsImmutableLengthLoad() const;
// Try evaluating this load against the given constant value of
// the instance. Returns true if evaluation succeeded and
// puts result into result.
// Note: we only evaluate loads when we can ensure that
// instance has the field.
bool Evaluate(const Object& instance_value, Object* result);
virtual Definition* Canonicalize(FlowGraph* flow_graph);
static MethodRecognizer::Kind RecognizedKindFromArrayCid(intptr_t cid);