Reviewers: Igor Sheludko,
Message:
Hey Igor,
This removes two redundant HCompareMap instructions in DeltaBlue, giving
some
2-3% improvement. We may want to generalize this to HIsStringAndBranch,
HIsSmiAndBranch, and friends later.
PTAL
-- Benedikt
Description:
Optimize redundant HCompareMap instructions with known successors.
Please review this at https://codereview.chromium.org/150663005/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+40, -3 lines):
M src/arm/lithium-arm.cc
M src/hydrogen-check-elimination.cc
M src/hydrogen-instructions.h
M src/hydrogen-instructions.cc
M src/ia32/lithium-ia32.cc
M src/mips/lithium-mips.cc
M src/x64/lithium-x64.cc
Index: src/arm/lithium-arm.cc
diff --git a/src/arm/lithium-arm.cc b/src/arm/lithium-arm.cc
index
e670d343d9d8dee26068c29912258588dc2cfd2a..38509a6ea8f2e43b1bb19b5e68f603a720fd2f12
100644
--- a/src/arm/lithium-arm.cc
+++ b/src/arm/lithium-arm.cc
@@ -942,6 +942,9 @@ LInstruction* LChunkBuilder::DoDebugBreak(HDebugBreak*
instr) {
LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) {
+ LInstruction* goto_instr = CheckElideControlInstruction(instr);
+ if (goto_instr != NULL) return goto_instr;
+
ASSERT(instr->value()->representation().IsTagged());
LOperand* value = UseRegisterAtStart(instr->value());
LOperand* temp = TempRegister();
Index: src/hydrogen-check-elimination.cc
diff --git a/src/hydrogen-check-elimination.cc
b/src/hydrogen-check-elimination.cc
index
cd002a1d5c80a5d9a76ee4eded2f889461958dc6..e12f14a13fb16b740fe6f4327970c5d77f7edca2
100644
--- a/src/hydrogen-check-elimination.cc
+++ b/src/hydrogen-check-elimination.cc
@@ -341,11 +341,15 @@ class HCheckTable : public ZoneObject {
if (maps == NULL) return;
if (maps->Contains(instr->map())) {
if (maps->size() == 1) {
- // TODO(titzer): replace with goto true branch
+ TRACE(("Marking redundant CompareMap #%d at B%d as true\n",
+ instr->id(), instr->block()->block_id()));
+ instr->set_known_successor_index(0);
INC_STAT(compares_true_);
}
} else {
- // TODO(titzer): replace with goto false branch
+ TRACE(("Marking redundant CompareMap #%d at B%d as false\n",
+ instr->id(), instr->block()->block_id()));
+ instr->set_known_successor_index(1);
INC_STAT(compares_false_);
}
}
Index: src/hydrogen-instructions.cc
diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc
index
8f1c62be9ea5cde55773b77300aa4050a5d3d359..c25dff121734a72538da33a13daec2db7110459c
100644
--- a/src/hydrogen-instructions.cc
+++ b/src/hydrogen-instructions.cc
@@ -1117,6 +1117,11 @@ void HCompareMap::PrintDataTo(StringStream* stream) {
value()->PrintNameTo(stream);
stream->Add(" (%p)", *map().handle());
HControlInstruction::PrintDataTo(stream);
+ if (known_successor_index() == 0) {
+ stream->Add(" [true]");
+ } else if (known_successor_index() == 1) {
+ stream->Add(" [false]");
+ }
}
Index: src/hydrogen-instructions.h
diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h
index
cfd5444cd5101ccac70b895980fd9b295ae69cba..a6da1c3a75e9b3ceb3abc8264608687180e8f9da
100644
--- a/src/hydrogen-instructions.h
+++ b/src/hydrogen-instructions.h
@@ -1529,8 +1529,23 @@ class HCompareMap V8_FINAL : public
HUnaryControlInstruction {
DECLARE_INSTRUCTION_FACTORY_P4(HCompareMap, HValue*, Handle<Map>,
HBasicBlock*, HBasicBlock*);
+ virtual bool KnownSuccessorBlock(HBasicBlock** block) V8_OVERRIDE {
+ if (known_successor_index() != kNoKnownSuccessorIndex) {
+ *block = SuccessorAt(known_successor_index());
+ return true;
+ }
+ *block = NULL;
+ return false;
+ }
+
virtual void PrintDataTo(StringStream* stream) V8_OVERRIDE;
+ static const int kNoKnownSuccessorIndex = -1;
+ int known_successor_index() const { return known_successor_index_; }
+ void set_known_successor_index(int known_successor_index) {
+ known_successor_index_ = known_successor_index;
+ }
+
Unique<Map> map() const { return map_; }
virtual Representation RequiredInputRepresentation(int index)
V8_OVERRIDE {
@@ -1548,10 +1563,11 @@ class HCompareMap V8_FINAL : public
HUnaryControlInstruction {
HBasicBlock* true_target = NULL,
HBasicBlock* false_target = NULL)
: HUnaryControlInstruction(value, true_target, false_target),
- map_(Unique<Map>(map)) {
+ known_successor_index_(kNoKnownSuccessorIndex),
map_(Unique<Map>(map)) {
ASSERT(!map.is_null());
}
+ int known_successor_index_;
Unique<Map> map_;
};
Index: src/ia32/lithium-ia32.cc
diff --git a/src/ia32/lithium-ia32.cc b/src/ia32/lithium-ia32.cc
index
4ebcb30ff8896a6e8c038fb74bd3ac3ff18583d5..27a5672901f0cd3287e61b768b26dac8c03d4294
100644
--- a/src/ia32/lithium-ia32.cc
+++ b/src/ia32/lithium-ia32.cc
@@ -1027,6 +1027,9 @@ LInstruction*
LChunkBuilder::DoDebugBreak(HDebugBreak* instr) {
LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) {
+ LInstruction* goto_instr = CheckElideControlInstruction(instr);
+ if (goto_instr != NULL) return goto_instr;
+
ASSERT(instr->value()->representation().IsTagged());
LOperand* value = UseRegisterAtStart(instr->value());
return new(zone()) LCmpMapAndBranch(value);
Index: src/mips/lithium-mips.cc
diff --git a/src/mips/lithium-mips.cc b/src/mips/lithium-mips.cc
index
6b1b982dc0106a0c3a08bd2389bb16fdd6881fa9..bb8e7502d80e4a19b5499778ceb2ce536344da4a
100644
--- a/src/mips/lithium-mips.cc
+++ b/src/mips/lithium-mips.cc
@@ -945,6 +945,9 @@ LInstruction* LChunkBuilder::DoBranch(HBranch* instr) {
LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) {
+ LInstruction* goto_instr = CheckElideControlInstruction(instr);
+ if (goto_instr != NULL) return goto_instr;
+
ASSERT(instr->value()->representation().IsTagged());
LOperand* value = UseRegisterAtStart(instr->value());
LOperand* temp = TempRegister();
Index: src/x64/lithium-x64.cc
diff --git a/src/x64/lithium-x64.cc b/src/x64/lithium-x64.cc
index
3c9eb2d796fa1a74ba133f7b577fe5744fa4988a..666b688c92abf61b066343076bd0466b39be47e7
100644
--- a/src/x64/lithium-x64.cc
+++ b/src/x64/lithium-x64.cc
@@ -952,6 +952,9 @@ LInstruction* LChunkBuilder::DoBranch(HBranch* instr) {
LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) {
+ LInstruction* goto_instr = CheckElideControlInstruction(instr);
+ if (goto_instr != NULL) return goto_instr;
+
ASSERT(instr->value()->representation().IsTagged());
LOperand* value = UseRegisterAtStart(instr->value());
return new(zone()) LCmpMapAndBranch(value);
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.