Optimize redundant HCompareMap instructions with known successors.

R=ishell@chromium.org

Review URL: https://codereview.chromium.org/150663005

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19094 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
bmeurer@chromium.org 2014-02-05 09:30:53 +00:00
parent f6d1a4fef1
commit 8150c34c82
7 changed files with 40 additions and 3 deletions

View File

@ -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();

View File

@ -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_);
}
}

View File

@ -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]");
}
}

View File

@ -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_;
};

View File

@ -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);

View File

@ -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();

View File

@ -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);