Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: runtime/vm/intermediate_language.cc

Issue 2912903002: Reapply "Fix misoptimization of 'is' test"" (Closed)
Patch Set: Reinstate missing optimization Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/intermediate_language.h ('k') | runtime/vm/intermediate_language_arm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/intermediate_language.h" 5 #include "vm/intermediate_language.h"
6 6
7 #include "vm/bit_vector.h" 7 #include "vm/bit_vector.h"
8 #include "vm/bootstrap.h" 8 #include "vm/bootstrap.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/constant_propagator.h" 10 #include "vm/constant_propagator.h"
(...skipping 2718 matching lines...) Expand 10 before | Expand all | Expand 10 after
2729 const Object& constant_value = value()->BoundConstant(); 2729 const Object& constant_value = value()->BoundConstant();
2730 if (constant_value.IsSmi() && 2730 if (constant_value.IsSmi() &&
2731 cids_.Contains(Smi::Cast(constant_value).Value())) { 2731 cids_.Contains(Smi::Cast(constant_value).Value())) {
2732 return NULL; 2732 return NULL;
2733 } 2733 }
2734 } 2734 }
2735 return this; 2735 return this;
2736 } 2736 }
2737 2737
2738 2738
2739 TestCidsInstr::TestCidsInstr(TokenPosition token_pos,
2740 Token::Kind kind,
2741 Value* value,
2742 const ZoneGrowableArray<intptr_t>& cid_results,
2743 intptr_t deopt_id)
2744 : TemplateComparison(token_pos, kind, deopt_id),
2745 cid_results_(cid_results),
2746 licm_hoisted_(false) {
2747 ASSERT((kind == Token::kIS) || (kind == Token::kISNOT));
2748 SetInputAt(0, value);
2749 set_operation_cid(kObjectCid);
2750 #ifdef DEBUG
2751 ASSERT(cid_results[0] == kSmiCid);
2752 if (deopt_id == Thread::kNoDeoptId) {
2753 // The entry for Smi can be special, but all other entries have
2754 // to match in the no-deopt case.
2755 for (intptr_t i = 4; i < cid_results.length(); i += 2) {
2756 ASSERT(cid_results[i + 1] == cid_results[3]);
2757 }
2758 }
2759 #endif
2760 }
2761
2762
2739 Definition* TestCidsInstr::Canonicalize(FlowGraph* flow_graph) { 2763 Definition* TestCidsInstr::Canonicalize(FlowGraph* flow_graph) {
2740 CompileType* in_type = left()->Type(); 2764 CompileType* in_type = left()->Type();
2741 intptr_t cid = in_type->ToCid(); 2765 intptr_t cid = in_type->ToCid();
2742 if (cid == kDynamicCid) return this; 2766 if (cid == kDynamicCid) return this;
2743 2767
2744 const ZoneGrowableArray<intptr_t>& data = cid_results(); 2768 const ZoneGrowableArray<intptr_t>& data = cid_results();
2745 const intptr_t true_result = (kind() == Token::kIS) ? 1 : 0; 2769 const intptr_t true_result = (kind() == Token::kIS) ? 1 : 0;
2746 for (intptr_t i = 0; i < data.length(); i += 2) { 2770 for (intptr_t i = 0; i < data.length(); i += 2) {
2747 if (data[i] == cid) { 2771 if (data[i] == cid) {
2748 return (data[i + 1] == true_result) 2772 return (data[i + 1] == true_result)
2749 ? flow_graph->GetConstant(Bool::True()) 2773 ? flow_graph->GetConstant(Bool::True())
2750 : flow_graph->GetConstant(Bool::False()); 2774 : flow_graph->GetConstant(Bool::False());
2751 } 2775 }
2752 } 2776 }
2753 2777
2754 // TODO(sra): Handle misses if the instruction is not deoptimizing. 2778 if (!CanDeoptimize()) {
2779 return (data[data.length() - 1] == true_result)
2780 ? flow_graph->GetConstant(Bool::False())
2781 : flow_graph->GetConstant(Bool::True());
2782 }
2783
2755 // TODO(sra): Handle nullable input, possibly canonicalizing to a compare 2784 // TODO(sra): Handle nullable input, possibly canonicalizing to a compare
2756 // against `null`. 2785 // against `null`.
2757 return this; 2786 return this;
2758 } 2787 }
2759 2788
2760 2789
2761 Instruction* GuardFieldClassInstr::Canonicalize(FlowGraph* flow_graph) { 2790 Instruction* GuardFieldClassInstr::Canonicalize(FlowGraph* flow_graph) {
2762 if (field().guarded_cid() == kDynamicCid) { 2791 if (field().guarded_cid() == kDynamicCid) {
2763 return NULL; // Nothing to guard. 2792 return NULL; // Nothing to guard.
2764 } 2793 }
(...skipping 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after
3853 return new TestCidsInstr(token_pos(), kind(), new_left, cid_results(), 3882 return new TestCidsInstr(token_pos(), kind(), new_left, cid_results(),
3854 deopt_id()); 3883 deopt_id());
3855 } 3884 }
3856 3885
3857 3886
3858 bool TestCidsInstr::AttributesEqual(Instruction* other) const { 3887 bool TestCidsInstr::AttributesEqual(Instruction* other) const {
3859 TestCidsInstr* other_instr = other->AsTestCids(); 3888 TestCidsInstr* other_instr = other->AsTestCids();
3860 if (!ComparisonInstr::AttributesEqual(other)) { 3889 if (!ComparisonInstr::AttributesEqual(other)) {
3861 return false; 3890 return false;
3862 } 3891 }
3892 if (CanDeoptimize() != other->CanDeoptimize()) {
Vyacheslav Egorov (Google) 2017/05/30 10:54:20 I don't think CanDeoptimize() should be compared h
3893 return false;
3894 }
3863 if (cid_results().length() != other_instr->cid_results().length()) { 3895 if (cid_results().length() != other_instr->cid_results().length()) {
3864 return false; 3896 return false;
3865 } 3897 }
3866 for (intptr_t i = 0; i < cid_results().length(); i++) { 3898 for (intptr_t i = 0; i < cid_results().length(); i++) {
3867 if (cid_results()[i] != other_instr->cid_results()[i]) { 3899 if (cid_results()[i] != other_instr->cid_results()[i]) {
3868 return false; 3900 return false;
3869 } 3901 }
3870 } 3902 }
3871 return true; 3903 return true;
3872 } 3904 }
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
4331 "native function '%s' (%" Pd " arguments) cannot be found", 4363 "native function '%s' (%" Pd " arguments) cannot be found",
4332 native_name().ToCString(), function().NumParameters()); 4364 native_name().ToCString(), function().NumParameters());
4333 } 4365 }
4334 set_is_auto_scope(auto_setup_scope); 4366 set_is_auto_scope(auto_setup_scope);
4335 set_native_c_function(native_function); 4367 set_native_c_function(native_function);
4336 } 4368 }
4337 4369
4338 #undef __ 4370 #undef __
4339 4371
4340 } // namespace dart 4372 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/intermediate_language.h ('k') | runtime/vm/intermediate_language_arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698