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

Unified Diff: runtime/vm/intermediate_language_x64.cc

Issue 10823278: Use type propagation for removing Smi checks in binary operations and comparisons. Regis will adapt… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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
Index: runtime/vm/intermediate_language_x64.cc
===================================================================
--- runtime/vm/intermediate_language_x64.cc (revision 10522)
+++ runtime/vm/intermediate_language_x64.cc (working copy)
@@ -447,6 +447,12 @@
}
+static intptr_t GetCid(const Value& v) {
+ const AbstractType& type = AbstractType::Handle(v.CompileType());
+ return Class::Handle(type.type_class()).id();
+}
+
+
static void EmitSmiComparisonOp(FlowGraphCompiler* compiler,
const LocationSummary& locs,
Token::Kind kind,
@@ -456,16 +462,22 @@
intptr_t try_index) {
Register left = locs.in(0).reg();
Register right = locs.in(1).reg();
- Register temp = locs.temp(0).reg();
- Label* deopt = compiler->AddDeoptStub(deopt_id,
- try_index,
- kDeoptSmiCompareSmi,
- left,
- right);
- __ movq(temp, left);
- __ orq(temp, right);
- __ testq(temp, Immediate(kSmiTagMask));
- __ j(NOT_ZERO, deopt);
+ const bool left_is_smi = (branch == NULL) ?
+ false : (GetCid(*branch->left()) == kSmiCid);
+ const bool right_is_smi = (branch == NULL) ?
+ false : (GetCid(*branch->left()) == kSmiCid);
+ if (!left_is_smi || !right_is_smi) {
+ Register temp = locs.temp(0).reg();
+ Label* deopt = compiler->AddDeoptStub(deopt_id,
+ try_index,
+ kDeoptSmiCompareSmi,
+ left,
+ right);
+ __ movq(temp, left);
+ __ orq(temp, right);
+ __ testq(temp, Immediate(kSmiTagMask));
+ __ j(NOT_ZERO, deopt);
+ }
Condition true_condition = TokenKindToSmiCondition(kind);
__ cmpq(left, right);
@@ -1440,19 +1452,41 @@
Register result = comp->locs()->out().reg();
Register temp = comp->locs()->temp(0).reg();
ASSERT(left == result);
- Label* deopt = compiler->AddDeoptStub(comp->instance_call()->deopt_id(),
- comp->instance_call()->try_index(),
- kDeoptSmiBinaryOp,
- temp,
- right);
- // TODO(vegorov): for many binary operations this pattern can be rearranged
- // to save one move.
- __ movq(temp, left);
- __ orq(left, right);
- __ testq(left, Immediate(kSmiTagMask));
- __ j(NOT_ZERO, deopt);
- __ movq(left, temp);
+ const bool left_is_smi = (GetCid(*comp->left()) == kSmiCid);
+ const bool right_is_smi = (GetCid(*comp->left()) == kSmiCid);
+ bool can_deopt;
switch (comp->op_kind()) {
+ case Token::kBIT_AND:
+ case Token::kBIT_OR:
+ case Token::kBIT_XOR:
+ can_deopt = !(right_is_smi && left_is_smi);
+ break;
+ default:
+ can_deopt = true;
+ }
+ Label* deopt = NULL;
+ if (can_deopt) {
+ deopt = compiler->AddDeoptStub(comp->instance_call()->deopt_id(),
+ comp->instance_call()->try_index(),
+ kDeoptSmiBinaryOp,
+ temp,
+ right);
+ }
+ if (left_is_smi && right_is_smi) {
+ if (can_deopt) {
+ // Preserve left for deopt.
+ __ movq(temp, left);
+ }
+ } else {
+ // TODO(vegorov): for many binary operations this pattern can be rearranged
+ // to save one move.
+ __ movq(temp, left);
+ __ orq(left, right);
+ __ testq(left, Immediate(kSmiTagMask));
+ __ j(NOT_ZERO, deopt);
+ __ movq(left, temp);
+ }
+ switch (comp->op_kind()) {
case Token::kADD: {
__ addq(left, right);
__ j(OVERFLOW, deopt);

Powered by Google App Engine
This is Rietveld 408576698