From 376bff2411cc740765f4cbb321fa800f16b09b13 Mon Sep 17 00:00:00 2001 From: "bmeurer@chromium.org" Date: Tue, 22 Apr 2014 10:49:28 +0000 Subject: [PATCH] Optimize numeric comparison with known successors. R=svenpanne@chromium.org Review URL: https://codereview.chromium.org/246133005 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20880 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/lithium-arm.cc | 2 ++ src/arm64/lithium-arm64.cc | 3 ++- src/hydrogen-instructions.cc | 15 +++++++++++++++ src/hydrogen-instructions.h | 3 +++ src/hydrogen.cc | 7 ++----- src/ia32/lithium-ia32.cc | 2 ++ src/mips/lithium-mips.cc | 2 ++ src/x64/lithium-x64.cc | 2 ++ 8 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/arm/lithium-arm.cc b/src/arm/lithium-arm.cc index 79a5cd5..b8050d4 100644 --- a/src/arm/lithium-arm.cc +++ b/src/arm/lithium-arm.cc @@ -1676,6 +1676,8 @@ LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) { LInstruction* LChunkBuilder::DoCompareNumericAndBranch( HCompareNumericAndBranch* instr) { + LInstruction* goto_instr = CheckElideControlInstruction(instr); + if (goto_instr != NULL) return goto_instr; Representation r = instr->representation(); if (r.IsSmiOrInteger32()) { ASSERT(instr->left()->representation().Equals(r)); diff --git a/src/arm64/lithium-arm64.cc b/src/arm64/lithium-arm64.cc index 8682e2b..68f839f 100644 --- a/src/arm64/lithium-arm64.cc +++ b/src/arm64/lithium-arm64.cc @@ -1251,8 +1251,9 @@ LInstruction* LChunkBuilder::DoClassOfTestAndBranch( LInstruction* LChunkBuilder::DoCompareNumericAndBranch( HCompareNumericAndBranch* instr) { + LInstruction* goto_instr = CheckElideControlInstruction(instr); + if (goto_instr != NULL) return goto_instr; Representation r = instr->representation(); - if (r.IsSmiOrInteger32()) { ASSERT(instr->left()->representation().Equals(r)); ASSERT(instr->right()->representation().Equals(r)); diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc index 22a7586..495a435 100644 --- a/src/hydrogen-instructions.cc +++ b/src/hydrogen-instructions.cc @@ -3303,6 +3303,21 @@ void HCompareHoleAndBranch::InferRepresentation( } +bool HCompareNumericAndBranch::KnownSuccessorBlock(HBasicBlock** block) { + if (left() == right() && + left()->representation().IsSmiOrInteger32()) { + *block = (token() == Token::EQ || + token() == Token::EQ_STRICT || + token() == Token::LTE || + token() == Token::GTE) + ? FirstSuccessor() : SecondSuccessor(); + return true; + } + *block = NULL; + return false; +} + + bool HCompareMinusZeroAndBranch::KnownSuccessorBlock(HBasicBlock** block) { if (FLAG_fold_constants && value()->IsConstant()) { HConstant* constant = HConstant::cast(value()); diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h index ee4056b..6f3dabd 100644 --- a/src/hydrogen-instructions.h +++ b/src/hydrogen-instructions.h @@ -4218,6 +4218,9 @@ class HCompareNumericAndBranch : public HTemplateControlInstruction<2, 2> { virtual Representation observed_input_representation(int index) V8_OVERRIDE { return observed_input_representation_[index]; } + + virtual bool KnownSuccessorBlock(HBasicBlock** block) V8_OVERRIDE; + virtual void PrintDataTo(StringStream* stream) V8_OVERRIDE; void SetOperandPositions(Zone* zone, diff --git a/src/hydrogen.cc b/src/hydrogen.cc index 9096837..d262416 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -1314,11 +1314,8 @@ HValue* HGraphBuilder::BuildCheckForCapacityGrow( HValue* max_gap = Add(static_cast(JSObject::kMaxGap)); HValue* max_capacity = AddUncasted(current_capacity, max_gap); - IfBuilder key_checker(this); - key_checker.If(key, max_capacity, Token::LT); - key_checker.Then(); - key_checker.ElseDeopt("Key out of capacity range"); - key_checker.End(); + + Add(key, max_capacity); HValue* new_capacity = BuildNewElementsCapacity(key); HValue* new_elements = BuildGrowElementsCapacity(object, elements, diff --git a/src/ia32/lithium-ia32.cc b/src/ia32/lithium-ia32.cc index f61fd9a..ffd8d86 100644 --- a/src/ia32/lithium-ia32.cc +++ b/src/ia32/lithium-ia32.cc @@ -1677,6 +1677,8 @@ LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) { LInstruction* LChunkBuilder::DoCompareNumericAndBranch( HCompareNumericAndBranch* instr) { + LInstruction* goto_instr = CheckElideControlInstruction(instr); + if (goto_instr != NULL) return goto_instr; Representation r = instr->representation(); if (r.IsSmiOrInteger32()) { ASSERT(instr->left()->representation().Equals(r)); diff --git a/src/mips/lithium-mips.cc b/src/mips/lithium-mips.cc index e4a7a65..a5fed5f 100644 --- a/src/mips/lithium-mips.cc +++ b/src/mips/lithium-mips.cc @@ -1626,6 +1626,8 @@ LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) { LInstruction* LChunkBuilder::DoCompareNumericAndBranch( HCompareNumericAndBranch* instr) { + LInstruction* goto_instr = CheckElideControlInstruction(instr); + if (goto_instr != NULL) return goto_instr; Representation r = instr->representation(); if (r.IsSmiOrInteger32()) { ASSERT(instr->left()->representation().Equals(r)); diff --git a/src/x64/lithium-x64.cc b/src/x64/lithium-x64.cc index 5b13e39..256268b 100644 --- a/src/x64/lithium-x64.cc +++ b/src/x64/lithium-x64.cc @@ -1621,6 +1621,8 @@ LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) { LInstruction* LChunkBuilder::DoCompareNumericAndBranch( HCompareNumericAndBranch* instr) { + LInstruction* goto_instr = CheckElideControlInstruction(instr); + if (goto_instr != NULL) return goto_instr; Representation r = instr->representation(); if (r.IsSmiOrInteger32()) { ASSERT(instr->left()->representation().Equals(r)); -- 2.7.4