Chromium Code Reviews| Index: src/ia32/lithium-codegen-ia32.cc |
| diff --git a/src/ia32/lithium-codegen-ia32.cc b/src/ia32/lithium-codegen-ia32.cc |
| index 9472722ecb550d052e0f1ca45ed824a421bb7224..b490eb1b0e2fa39b4d065369e0abe181cea84057 100644 |
| --- a/src/ia32/lithium-codegen-ia32.cc |
| +++ b/src/ia32/lithium-codegen-ia32.cc |
| @@ -582,9 +582,18 @@ XMMRegister LCodeGen::ToDoubleRegister(LOperand* op) const { |
| } |
| -int LCodeGen::ToInteger32(LConstantOperand* op) const { |
| +int32_t LCodeGen::ToInteger32(LConstantOperand* op) const { |
| + return ToRepresentation(op, Representation::Integer32()); |
| +} |
| + |
| + |
| +int32_t LCodeGen::ToRepresentation(LConstantOperand* op, |
| + const Representation& r) const { |
| HConstant* constant = chunk_->LookupConstant(op); |
|
danno
2013/06/06 12:32:13
why do you need to pass in the representation? Can
|
| - return constant->Integer32Value(); |
| + int32_t value = constant->Integer32Value(); |
| + if (r.IsInteger32()) return value; |
| + ASSERT(r.IsSmiOrTagged()); |
| + return reinterpret_cast<int32_t>(Smi::FromInt(value)); |
| } |
| @@ -1551,7 +1560,9 @@ void LCodeGen::DoMulI(LMulI* instr) { |
| // Try strength reductions on the multiplication. |
| // All replacement instructions are at most as long as the imul |
| // and have better latency. |
| - int constant = ToInteger32(LConstantOperand::cast(right)); |
| + int constant = ToRepresentation( |
| + LConstantOperand::cast(right), |
| + instr->hydrogen()->BetterRightOperand()->representation()); |
| if (constant == -1) { |
| __ neg(left); |
| } else if (constant == 0) { |
| @@ -1605,9 +1616,11 @@ void LCodeGen::DoMulI(LMulI* instr) { |
| __ test(left, Operand(left)); |
| __ j(not_zero, &done, Label::kNear); |
| if (right->IsConstantOperand()) { |
| - if (ToInteger32(LConstantOperand::cast(right)) < 0) { |
| + Representation r = |
| + instr->hydrogen()->BetterRightOperand()->representation(); |
| + if (ToRepresentation(LConstantOperand::cast(right), r) < 0) { |
| DeoptimizeIf(no_condition, instr->environment()); |
| - } else if (ToInteger32(LConstantOperand::cast(right)) == 0) { |
| + } else if (ToRepresentation(LConstantOperand::cast(right), r) == 0) { |
| __ cmp(ToRegister(instr->temp()), Immediate(0)); |
| DeoptimizeIf(less, instr->environment()); |
| } |
| @@ -1628,7 +1641,8 @@ void LCodeGen::DoBitI(LBitI* instr) { |
| ASSERT(left->IsRegister()); |
| if (right->IsConstantOperand()) { |
| - int right_operand = ToInteger32(LConstantOperand::cast(right)); |
| + int right_operand = ToRepresentation(LConstantOperand::cast(right), |
| + instr->hydrogen()->representation()); |
| switch (instr->op()) { |
| case Token::BIT_AND: |
| __ and_(ToRegister(left), right_operand); |
| @@ -1739,7 +1753,8 @@ void LCodeGen::DoSubI(LSubI* instr) { |
| ASSERT(left->Equals(instr->result())); |
| if (right->IsConstantOperand()) { |
| - __ sub(ToOperand(left), ToInteger32Immediate(right)); |
| + __ sub(ToOperand(left), |
| + ToImmediate(right, instr->hydrogen()->representation())); |
| } else { |
| __ sub(ToRegister(left), ToOperand(right)); |
| } |
| @@ -1958,7 +1973,8 @@ void LCodeGen::DoAddI(LAddI* instr) { |
| if (LAddI::UseLea(instr->hydrogen()) && !left->Equals(instr->result())) { |
| if (right->IsConstantOperand()) { |
| - int32_t offset = ToInteger32(LConstantOperand::cast(right)); |
| + int32_t offset = ToRepresentation(LConstantOperand::cast(right), |
| + instr->hydrogen()->representation()); |
| __ lea(ToRegister(instr->result()), MemOperand(ToRegister(left), offset)); |
| } else { |
| Operand address(ToRegister(left), ToRegister(right), times_1, 0); |
| @@ -1966,7 +1982,8 @@ void LCodeGen::DoAddI(LAddI* instr) { |
| } |
| } else { |
| if (right->IsConstantOperand()) { |
| - __ add(ToOperand(left), ToInteger32Immediate(right)); |
| + __ add(ToOperand(left), |
| + ToImmediate(right, instr->hydrogen()->representation())); |
| } else { |
| __ add(ToRegister(left), ToOperand(right)); |
| } |
| @@ -1983,17 +2000,18 @@ void LCodeGen::DoMathMinMax(LMathMinMax* instr) { |
| LOperand* right = instr->right(); |
| ASSERT(left->Equals(instr->result())); |
| HMathMinMax::Operation operation = instr->hydrogen()->operation(); |
| - if (instr->hydrogen()->representation().IsInteger32()) { |
| + if (instr->hydrogen()->representation().IsSmiOrInteger32()) { |
| Label return_left; |
| Condition condition = (operation == HMathMinMax::kMathMin) |
| ? less_equal |
| : greater_equal; |
| if (right->IsConstantOperand()) { |
| Operand left_op = ToOperand(left); |
| - Immediate right_imm = ToInteger32Immediate(right); |
| - __ cmp(left_op, right_imm); |
| + Immediate immediate = ToImmediate(LConstantOperand::cast(instr->right()), |
| + instr->hydrogen()->representation()); |
| + __ cmp(left_op, immediate); |
| __ j(condition, &return_left, Label::kNear); |
| - __ mov(left_op, right_imm); |
| + __ mov(left_op, immediate); |
| } else { |
| Register left_reg = ToRegister(left); |
| Operand right_op = ToOperand(right); |
| @@ -2319,19 +2337,11 @@ void LCodeGen::DoCmpIDAndBranch(LCmpIDAndBranch* instr) { |
| __ j(parity_even, chunk_->GetAssemblyLabel(false_block)); |
| } else { |
| if (right->IsConstantOperand()) { |
| - int32_t const_value = ToInteger32(LConstantOperand::cast(right)); |
| - if (instr->hydrogen_value()->representation().IsSmi()) { |
| - __ cmp(ToOperand(left), Immediate(Smi::FromInt(const_value))); |
| - } else { |
| - __ cmp(ToOperand(left), Immediate(const_value)); |
| - } |
| + __ cmp(ToOperand(left), |
| + ToImmediate(right, instr->hydrogen()->representation())); |
| } else if (left->IsConstantOperand()) { |
| - int32_t const_value = ToInteger32(LConstantOperand::cast(left)); |
| - if (instr->hydrogen_value()->representation().IsSmi()) { |
| - __ cmp(ToOperand(right), Immediate(Smi::FromInt(const_value))); |
| - } else { |
| - __ cmp(ToOperand(right), Immediate(const_value)); |
| - } |
| + __ cmp(ToOperand(right), |
| + ToImmediate(left, instr->hydrogen()->representation())); |
| // We transposed the operands. Reverse the condition. |
| cc = ReverseCondition(cc); |
| } else { |
| @@ -4385,14 +4395,10 @@ void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) { |
| if (instr->hydrogen()->skip_check()) return; |
| if (instr->index()->IsConstantOperand()) { |
| - int constant_index = |
| - ToInteger32(LConstantOperand::cast(instr->index())); |
| - if (instr->hydrogen()->length()->representation().IsSmi()) { |
| - __ cmp(ToOperand(instr->length()), |
| - Immediate(Smi::FromInt(constant_index))); |
| - } else { |
| - __ cmp(ToOperand(instr->length()), Immediate(constant_index)); |
| - } |
| + Immediate immediate = |
| + ToImmediate(LConstantOperand::cast(instr->index()), |
| + instr->hydrogen()->length()->representation()); |
| + __ cmp(ToOperand(instr->length()), immediate); |
| DeoptimizeIf(below_equal, instr->environment()); |
| } else { |
| __ cmp(ToRegister(instr->index()), ToOperand(instr->length())); |
| @@ -4555,10 +4561,11 @@ void LCodeGen::DoStoreKeyedFixedArray(LStoreKeyed* instr) { |
| __ mov(operand, ToRegister(instr->value())); |
| } else { |
| LConstantOperand* operand_value = LConstantOperand::cast(instr->value()); |
| - if (IsInteger32(operand_value)) { |
| - Smi* smi_value = Smi::FromInt(ToInteger32(operand_value)); |
| - __ mov(operand, Immediate(smi_value)); |
| + if (IsSmi(operand_value)) { |
| + Immediate immediate = ToImmediate(operand_value, Representation::Smi()); |
| + __ mov(operand, immediate); |
| } else { |
| + ASSERT(!IsInteger32(operand_value)); |
| Handle<Object> handle_value = ToHandle(operand_value); |
| __ mov(operand, handle_value); |
| } |
| @@ -4721,8 +4728,9 @@ void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) { |
| // DoStringCharCodeAt above. |
| STATIC_ASSERT(String::kMaxLength <= Smi::kMaxValue); |
| if (instr->index()->IsConstantOperand()) { |
| - int const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| - __ push(Immediate(Smi::FromInt(const_index))); |
| + Immediate immediate = ToImmediate(LConstantOperand::cast(instr->index()), |
| + Representation::Smi()); |
| + __ push(immediate); |
| } else { |
| Register index = ToRegister(instr->index()); |
| __ SmiTag(index); |