From: bmeurer@chromium.org Date: Wed, 5 Feb 2014 09:30:53 +0000 (+0000) Subject: Optimize redundant HCompareMap instructions with known successors. X-Git-Tag: upstream/4.7.83~10872 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8150c34c829961842fdb72e003395e741a91457e;p=platform%2Fupstream%2Fv8.git 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 --- diff --git a/src/arm/lithium-arm.cc b/src/arm/lithium-arm.cc index e670d34..38509a6 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(); diff --git a/src/hydrogen-check-elimination.cc b/src/hydrogen-check-elimination.cc index cd002a1..e12f14a 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_); } } diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc index 8f1c62b..c25dff1 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]"); + } } diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h index cfd5444..a6da1c3 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, 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() 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)) { + known_successor_index_(kNoKnownSuccessorIndex), map_(Unique(map)) { ASSERT(!map.is_null()); } + int known_successor_index_; Unique map_; }; diff --git a/src/ia32/lithium-ia32.cc b/src/ia32/lithium-ia32.cc index 4ebcb30..27a5672 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); diff --git a/src/mips/lithium-mips.cc b/src/mips/lithium-mips.cc index 6b1b982..bb8e750 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(); diff --git a/src/x64/lithium-x64.cc b/src/x64/lithium-x64.cc index 3c9eb2d..666b688 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);