From 5b2282c69144919f34f70f25cd01a8c60b3bcbfc Mon Sep 17 00:00:00 2001 From: "verwaest@chromium.org" Date: Fri, 24 Aug 2012 09:06:23 +0000 Subject: [PATCH] MIPS: Check that index and length are Smi in bounds check. Port r12362 (cd39337c) BUG= TEST= Review URL: https://chromiumcodereview.appspot.com/10876053 Patch from Akos Palfi . git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12376 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/mips/lithium-codegen-mips.cc | 22 ++++++++++++++++++++++ src/mips/lithium-codegen-mips.h | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/src/mips/lithium-codegen-mips.cc b/src/mips/lithium-codegen-mips.cc index 380be11d89..aaca69f45b 100644 --- a/src/mips/lithium-codegen-mips.cc +++ b/src/mips/lithium-codegen-mips.cc @@ -3660,7 +3660,29 @@ void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) { } +void LCodeGen::DeoptIfTaggedButNotSmi(LEnvironment* environment, + HValue* value, + LOperand* operand) { + if (value->representation().IsTagged() && !value->type().IsSmi()) { + if (operand->IsRegister()) { + __ And(at, ToRegister(operand), Operand(kSmiTagMask)); + DeoptimizeIf(ne, environment, at, Operand(zero_reg)); + } else { + __ li(at, ToOperand(operand)); + __ And(at, at, Operand(kSmiTagMask)); + DeoptimizeIf(ne, environment, at, Operand(zero_reg)); + } + } +} + + void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) { + DeoptIfTaggedButNotSmi(instr->environment(), + instr->hydrogen()->length(), + instr->length()); + DeoptIfTaggedButNotSmi(instr->environment(), + instr->hydrogen()->index(), + instr->index()); if (instr->index()->IsConstantOperand()) { int constant_index = ToInteger32(LConstantOperand::cast(instr->index())); diff --git a/src/mips/lithium-codegen-mips.h b/src/mips/lithium-codegen-mips.h index 570fb0732a..7b10d9f629 100644 --- a/src/mips/lithium-codegen-mips.h +++ b/src/mips/lithium-codegen-mips.h @@ -307,6 +307,10 @@ class LCodeGen BASE_EMBEDDED { bool deoptimize_on_minus_zero, LEnvironment* env); + void DeoptIfTaggedButNotSmi(LEnvironment* environment, + HValue* value, + LOperand* operand); + // Emits optimized code for typeof x == "y". Modifies input register. // Returns the condition on which a final split to // true and false label should be made, to optimize fallthrough.