From 45d07bcd32b929149e8a93f53939af0ad2a642dc Mon Sep 17 00:00:00 2001 From: "fschneider@chromium.org" Date: Mon, 9 May 2011 15:21:40 +0000 Subject: [PATCH] Simple elimination of redundant array-hole checks. If the result of an fast elements load is converted to an untagged representation we can omit the hole check if the value is not used anywhere else except for HChange instructions converting it to an untagged representation since those will deoptimize for the hole value anyway. Review URL: http://codereview.chromium.org/6964012 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7827 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/lithium-codegen-arm.cc | 8 +++++--- src/hydrogen-instructions.cc | 9 +++++++++ src/hydrogen-instructions.h | 2 ++ src/ia32/lithium-codegen-ia32.cc | 6 ++++-- src/x64/lithium-codegen-x64.cc | 6 ++++-- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/arm/lithium-codegen-arm.cc b/src/arm/lithium-codegen-arm.cc index 4b045385a..c47fc11de 100644 --- a/src/arm/lithium-codegen-arm.cc +++ b/src/arm/lithium-codegen-arm.cc @@ -2473,9 +2473,11 @@ void LCodeGen::DoLoadKeyedFastElement(LLoadKeyedFastElement* instr) { __ ldr(result, FieldMemOperand(scratch, FixedArray::kHeaderSize)); // Check for the hole value. - __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex); - __ cmp(result, scratch); - DeoptimizeIf(eq, instr->environment()); + if (instr->hydrogen()->RequiresHoleCheck()) { + __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex); + __ cmp(result, scratch); + DeoptimizeIf(eq, instr->environment()); + } } diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc index caeebae67..c03e544a4 100644 --- a/src/hydrogen-instructions.cc +++ b/src/hydrogen-instructions.cc @@ -1263,6 +1263,15 @@ void HLoadKeyedFastElement::PrintDataTo(StringStream* stream) { } +bool HLoadKeyedFastElement::RequiresHoleCheck() const { + for (HUseIterator it(uses()); !it.Done(); it.Advance()) { + HValue* use = it.value(); + if (!use->IsChange()) return true; + } + return false; +} + + void HLoadKeyedGeneric::PrintDataTo(StringStream* stream) { object()->PrintNameTo(stream); stream->Add("["); diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h index 5a502e5cd..5a1583957 100644 --- a/src/hydrogen-instructions.h +++ b/src/hydrogen-instructions.h @@ -3255,6 +3255,8 @@ class HLoadKeyedFastElement: public HBinaryOperation { virtual void PrintDataTo(StringStream* stream); + bool RequiresHoleCheck() const; + DECLARE_CONCRETE_INSTRUCTION(LoadKeyedFastElement) protected: diff --git a/src/ia32/lithium-codegen-ia32.cc b/src/ia32/lithium-codegen-ia32.cc index b07a006bb..ff3c09dfe 100644 --- a/src/ia32/lithium-codegen-ia32.cc +++ b/src/ia32/lithium-codegen-ia32.cc @@ -2384,8 +2384,10 @@ void LCodeGen::DoLoadKeyedFastElement(LLoadKeyedFastElement* instr) { FixedArray::kHeaderSize)); // Check for the hole value. - __ cmp(result, factory()->the_hole_value()); - DeoptimizeIf(equal, instr->environment()); + if (instr->hydrogen()->RequiresHoleCheck()) { + __ cmp(result, factory()->the_hole_value()); + DeoptimizeIf(equal, instr->environment()); + } } diff --git a/src/x64/lithium-codegen-x64.cc b/src/x64/lithium-codegen-x64.cc index 47c77b7e0..3169d441d 100644 --- a/src/x64/lithium-codegen-x64.cc +++ b/src/x64/lithium-codegen-x64.cc @@ -2394,8 +2394,10 @@ void LCodeGen::DoLoadKeyedFastElement(LLoadKeyedFastElement* instr) { FixedArray::kHeaderSize)); // Check for the hole value. - __ CompareRoot(result, Heap::kTheHoleValueRootIndex); - DeoptimizeIf(equal, instr->environment()); + if (instr->hydrogen()->RequiresHoleCheck()) { + __ CompareRoot(result, Heap::kTheHoleValueRootIndex); + DeoptimizeIf(equal, instr->environment()); + } } -- 2.34.1