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

Unified Diff: runtime/vm/jit_optimizer.cc

Issue 2904543002: Fix misoptimization of 'is' test (Closed)
Patch Set: Feedback from Slava, do same optimization on AOT and JIT Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/intermediate_language_x64.cc ('k') | runtime/vm/optimizer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/jit_optimizer.cc
diff --git a/runtime/vm/jit_optimizer.cc b/runtime/vm/jit_optimizer.cc
index 151e187e1e5c7a1399fb2464b7729e493c05247d..dbe305337841260bd5d3562ecfe0df1885a9552f 100644
--- a/runtime/vm/jit_optimizer.cc
+++ b/runtime/vm/jit_optimizer.cc
@@ -19,6 +19,7 @@
#include "vm/il_printer.h"
#include "vm/intermediate_language.h"
#include "vm/object_store.h"
+#include "vm/optimizer.h"
#include "vm/parser.h"
#include "vm/resolver.h"
#include "vm/scopes.h"
@@ -1241,61 +1242,6 @@ bool JitOptimizer::TypeCheckAsClassEquality(const AbstractType& type) {
}
-static bool CidTestResultsContains(const ZoneGrowableArray<intptr_t>& results,
- intptr_t test_cid) {
- for (intptr_t i = 0; i < results.length(); i += 2) {
- if (results[i] == test_cid) return true;
- }
- return false;
-}
-
-
-static void TryAddTest(ZoneGrowableArray<intptr_t>* results,
- intptr_t test_cid,
- bool result) {
- if (!CidTestResultsContains(*results, test_cid)) {
- results->Add(test_cid);
- results->Add(result);
- }
-}
-
-
-// Tries to add cid tests to 'results' so that no deoptimization is
-// necessary.
-// TODO(srdjan): Do also for other than 'int' type.
-static bool TryExpandTestCidsResult(ZoneGrowableArray<intptr_t>* results,
- const AbstractType& type) {
- ASSERT(results->length() >= 2); // At least on eentry.
- const ClassTable& class_table = *Isolate::Current()->class_table();
- if ((*results)[0] != kSmiCid) {
- const Class& cls = Class::Handle(class_table.At(kSmiCid));
- const Class& type_class = Class::Handle(type.type_class());
- const bool smi_is_subtype =
- cls.IsSubtypeOf(Object::null_type_arguments(), type_class,
- Object::null_type_arguments(), NULL, NULL, Heap::kOld);
- results->Add((*results)[results->length() - 2]);
- results->Add((*results)[results->length() - 2]);
- for (intptr_t i = results->length() - 3; i > 1; --i) {
- (*results)[i] = (*results)[i - 2];
- }
- (*results)[0] = kSmiCid;
- (*results)[1] = smi_is_subtype;
- }
-
- ASSERT(type.IsInstantiated() && !type.IsMalformedOrMalbounded());
- ASSERT(results->length() >= 2);
- if (type.IsIntType()) {
- ASSERT((*results)[0] == kSmiCid);
- TryAddTest(results, kMintCid, true);
- TryAddTest(results, kBigintCid, true);
- // Cannot deoptimize since all tests returning true have been added.
- return false;
- }
-
- return true; // May deoptimize since we have not identified all 'true' tests.
-}
-
-
// TODO(srdjan): Use ICData to check if always true or false.
void JitOptimizer::ReplaceWithInstanceOf(InstanceCallInstr* call) {
ASSERT(Token::IsTypeTestOperator(call->token_kind()));
@@ -1324,7 +1270,8 @@ void JitOptimizer::ReplaceWithInstanceOf(InstanceCallInstr* call) {
Bool::ZoneHandle(Z, InstanceOfAsBool(unary_checks, type, results));
if (as_bool.IsNull()) {
if (results->length() == number_of_checks * 2) {
- const bool can_deopt = TryExpandTestCidsResult(results, type);
+ const bool can_deopt =
+ Optimizer::SpecializeTestCidsForNumericTypes(results, type);
TestCidsInstr* test_cids = new (Z) TestCidsInstr(
call->token_pos(), Token::kIS, new (Z) Value(left), *results,
can_deopt ? call->deopt_id() : Thread::kNoDeoptId);
« no previous file with comments | « runtime/vm/intermediate_language_x64.cc ('k') | runtime/vm/optimizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698