From 010d68cfd37fee8080cf3c269e0dd09fdcf826c9 Mon Sep 17 00:00:00 2001 From: "plind44@gmail.com" Date: Thu, 31 Oct 2013 14:32:08 +0000 Subject: [PATCH] MIPS: Fix uint32-to-smi conversion in Lithium. Port r17441 (f1968f4) BUG=chromium:309623 TEST=mjsunit/regress/regress-crbug-309623 R=plind44@gmail.com Review URL: https://codereview.chromium.org/49783010 Patch from Balazs Kilvady . git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17451 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/mips/lithium-codegen-mips.cc | 15 +++++++++++++-- src/mips/lithium-mips.cc | 5 +++-- src/mips/lithium-mips.h | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/mips/lithium-codegen-mips.cc b/src/mips/lithium-codegen-mips.cc index f54d4a5..ecbfc73 100644 --- a/src/mips/lithium-codegen-mips.cc +++ b/src/mips/lithium-codegen-mips.cc @@ -4584,9 +4584,7 @@ void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) { void LCodeGen::DoInteger32ToSmi(LInteger32ToSmi* instr) { LOperand* input = instr->value(); - ASSERT(input->IsRegister()); LOperand* output = instr->result(); - ASSERT(output->IsRegister()); Register scratch = scratch0(); __ SmiTagCheckOverflow(ToRegister(output), ToRegister(input), scratch); @@ -4607,6 +4605,19 @@ void LCodeGen::DoUint32ToDouble(LUint32ToDouble* instr) { } +void LCodeGen::DoUint32ToSmi(LUint32ToSmi* instr) { + LOperand* input = instr->value(); + LOperand* output = instr->result(); + if (!instr->hydrogen()->value()->HasRange() || + !instr->hydrogen()->value()->range()->IsInSmiRange()) { + Register scratch = scratch0(); + __ And(scratch, ToRegister(input), Operand(0xc0000000)); + DeoptimizeIf(ne, instr->environment(), scratch, Operand(zero_reg)); + } + __ SmiTag(ToRegister(output), ToRegister(input)); +} + + void LCodeGen::DoNumberTagI(LNumberTagI* instr) { class DeferredNumberTagI V8_FINAL : public LDeferredCode { public: diff --git a/src/mips/lithium-mips.cc b/src/mips/lithium-mips.cc index fb94bc3..ba7346f 100644 --- a/src/mips/lithium-mips.cc +++ b/src/mips/lithium-mips.cc @@ -1934,8 +1934,9 @@ LInstruction* LChunkBuilder::DoChange(HChange* instr) { } else if (to.IsSmi()) { HValue* val = instr->value(); LOperand* value = UseRegister(val); - LInstruction* result = - DefineSameAsFirst(new(zone()) LInteger32ToSmi(value)); + LInstruction* result = val->CheckFlag(HInstruction::kUint32) + ? DefineSameAsFirst(new(zone()) LUint32ToSmi(value)) + : DefineSameAsFirst(new(zone()) LInteger32ToSmi(value)); if (val->HasRange() && val->range()->IsInSmiRange()) { return result; } diff --git a/src/mips/lithium-mips.h b/src/mips/lithium-mips.h index 301be8f..7254d83 100644 --- a/src/mips/lithium-mips.h +++ b/src/mips/lithium-mips.h @@ -182,6 +182,7 @@ class LCodeGen; V(Typeof) \ V(TypeofIsAndBranch) \ V(Uint32ToDouble) \ + V(Uint32ToSmi) \ V(UnknownOSRValue) \ V(ValueOf) \ V(WrapReceiver) @@ -2052,6 +2053,19 @@ class LUint32ToDouble V8_FINAL : public LTemplateInstruction<1, 1, 0> { }; +class LUint32ToSmi V8_FINAL : public LTemplateInstruction<1, 1, 0> { + public: + explicit LUint32ToSmi(LOperand* value) { + inputs_[0] = value; + } + + LOperand* value() { return inputs_[0]; } + + DECLARE_CONCRETE_INSTRUCTION(Uint32ToSmi, "uint32-to-smi") + DECLARE_HYDROGEN_ACCESSOR(Change) +}; + + class LNumberTagI V8_FINAL : public LTemplateInstruction<1, 1, 0> { public: explicit LNumberTagI(LOperand* value) { -- 2.7.4