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

Unified Diff: runtime/vm/intermediate_language_arm64.cc

Issue 2466643002: AOT: Enable branch merging for checked smi comparisons (Closed)
Patch Set: ported to all architectures Created 4 years, 1 month 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_arm64.cc
diff --git a/runtime/vm/intermediate_language_arm64.cc b/runtime/vm/intermediate_language_arm64.cc
index 8894e20bea0bae40bad8a20a8cfa5650d4d57cea..1e4baa2673825cf84df5182a5843281c0fd81d62 100644
--- a/runtime/vm/intermediate_language_arm64.cc
+++ b/runtime/vm/intermediate_language_arm64.cc
@@ -2954,24 +2954,6 @@ void CheckedSmiOpInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
case Token::kBIT_XOR:
__ eor(result, left, Operand(right));
break;
- case Token::kEQ:
- case Token::kLT:
- case Token::kLTE:
- case Token::kGT:
- case Token::kGTE: {
- Label true_label, false_label, done;
- BranchLabels labels = { &true_label, &false_label, &false_label };
- Condition true_condition =
- EmitSmiComparisonOp(compiler, locs(), op_kind());
- EmitBranchOnCondition(compiler, true_condition, labels);
- __ Bind(&false_label);
- __ LoadObject(result, Bool::False());
- __ b(&done);
- __ Bind(&true_label);
- __ LoadObject(result, Bool::True());
- __ Bind(&done);
- break;
- }
default:
UNIMPLEMENTED();
}
@@ -2979,6 +2961,137 @@ void CheckedSmiOpInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
}
+class CheckedSmiComparisonSlowPath : public SlowPathCode {
+ public:
+ CheckedSmiComparisonSlowPath(CheckedSmiComparisonInstr* instruction,
+ intptr_t try_index,
+ BranchLabels labels,
+ bool merged)
+ : instruction_(instruction),
+ try_index_(try_index),
+ labels_(labels),
+ merged_(merged) { }
+
+ virtual void EmitNativeCode(FlowGraphCompiler* compiler) {
+ if (Assembler::EmittingComments()) {
+ __ Comment("slow path smi operation");
+ }
+ __ Bind(entry_label());
+ LocationSummary* locs = instruction_->locs();
+ Register result = merged_ ? locs->temp(0).reg() : locs->out(0).reg();
+ locs->live_registers()->Remove(Location::RegisterLocation(result));
+
+ compiler->SaveLiveRegisters(locs);
+ __ Push(locs->in(0).reg());
+ __ Push(locs->in(1).reg());
+ compiler->EmitMegamorphicInstanceCall(
+ *instruction_->call()->ic_data(),
+ instruction_->call()->ArgumentCount(),
+ instruction_->call()->deopt_id(),
+ instruction_->call()->token_pos(),
+ locs,
+ try_index_,
+ /* slow_path_argument_count = */ 2);
+ __ mov(result, R0);
+ compiler->RestoreLiveRegisters(locs);
+ if (merged_) {
+ __ CompareObject(result, Bool::True());
+ __ b(instruction_->is_negated()
+ ? labels_.false_label : labels_.true_label, EQ);
+ __ b(instruction_->is_negated()
+ ? labels_.true_label : labels_.false_label);
+ } else {
+ __ b(exit_label());
+ }
+ }
+
+ private:
+ CheckedSmiComparisonInstr* instruction_;
+ intptr_t try_index_;
+ BranchLabels labels_;
+ bool merged_;
+};
+
+
+LocationSummary* CheckedSmiComparisonInstr::MakeLocationSummary(
+ Zone* zone, bool opt) const {
+ const intptr_t kNumInputs = 2;
+ const intptr_t kNumTemps = 1;
+ LocationSummary* summary = new(zone) LocationSummary(
+ zone, kNumInputs, kNumTemps, LocationSummary::kCallOnSlowPath);
+ summary->set_in(0, Location::RequiresRegister());
+ summary->set_in(1, Location::RequiresRegister());
+ summary->set_temp(0, Location::RequiresRegister());
+ summary->set_out(0, Location::RequiresRegister());
+ return summary;
+}
+
+
+Condition CheckedSmiComparisonInstr::EmitComparisonCode(
+ FlowGraphCompiler* compiler, BranchLabels labels) {
+ return EmitSmiComparisonOp(compiler, locs(), kind());
+}
+
+
+#define EMIT_SMI_CHECK \
+ Register left = locs()->in(0).reg(); \
+ Register right = locs()->in(1).reg(); \
+ Register temp = locs()->temp(0).reg(); \
+ intptr_t left_cid = this->left()->Type()->ToCid(); \
+ intptr_t right_cid = this->right()->Type()->ToCid(); \
+ if (this->left()->definition() == this->right()->definition()) { \
+ __ tsti(left, Immediate(kSmiTagMask)); \
+ } else if (left_cid == kSmiCid) { \
+ __ tsti(right, Immediate(kSmiTagMask)); \
+ } else if (right_cid == kSmiCid) { \
+ __ tsti(left, Immediate(kSmiTagMask)); \
+ } else { \
+ __ orr(temp, left, Operand(right)); \
+ __ tsti(temp, Immediate(kSmiTagMask)); \
+ } \
+ __ b(slow_path->entry_label(), NE)
+
+
+void CheckedSmiComparisonInstr::EmitBranchCode(FlowGraphCompiler* compiler,
+ BranchInstr* branch) {
+ BranchLabels labels = compiler->CreateBranchLabels(branch);
+ CheckedSmiComparisonSlowPath* slow_path =
+ new CheckedSmiComparisonSlowPath(this,
+ compiler->CurrentTryIndex(),
+ labels,
+ /* merged = */ true);
+ compiler->AddSlowPathCode(slow_path);
+ EMIT_SMI_CHECK;
+ Condition true_condition = EmitComparisonCode(compiler, labels);
+ EmitBranchOnCondition(compiler, true_condition, labels);
+ __ Bind(slow_path->exit_label());
+}
+
+
+void CheckedSmiComparisonInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
+ Label true_label, false_label, done;
+ BranchLabels labels = { &true_label, &false_label, &false_label };
+ CheckedSmiComparisonSlowPath* slow_path =
+ new CheckedSmiComparisonSlowPath(this,
+ compiler->CurrentTryIndex(),
+ labels,
+ /* merged = */ false);
+ compiler->AddSlowPathCode(slow_path);
+ EMIT_SMI_CHECK;
+ Condition true_condition =
+ EmitComparisonCode(compiler, labels);
+ EmitBranchOnCondition(compiler, true_condition, labels);
+ Register result = locs()->out(0).reg();
+ __ Bind(&false_label);
+ __ LoadObject(result, Bool::False());
+ __ b(&done);
+ __ Bind(&true_label);
+ __ LoadObject(result, Bool::True());
+ __ Bind(&done);
+ __ Bind(slow_path->exit_label());
+}
+
+
LocationSummary* BinarySmiOpInstr::MakeLocationSummary(Zone* zone,
bool opt) const {
const intptr_t kNumInputs = 2;

Powered by Google App Engine
This is Rietveld 408576698