| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 2537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2548 // For phis, we must propagate the check to all of its inputs. | 2548 // For phis, we must propagate the check to all of its inputs. |
| 2549 if (current->IsPhi()) { | 2549 if (current->IsPhi()) { |
| 2550 visited->Add(current->id()); | 2550 visited->Add(current->id()); |
| 2551 HPhi* phi = HPhi::cast(current); | 2551 HPhi* phi = HPhi::cast(current); |
| 2552 for (int i = 0; i < phi->OperandCount(); ++i) { | 2552 for (int i = 0; i < phi->OperandCount(); ++i) { |
| 2553 PropagateMinusZeroChecks(phi->OperandAt(i), visited); | 2553 PropagateMinusZeroChecks(phi->OperandAt(i), visited); |
| 2554 } | 2554 } |
| 2555 break; | 2555 break; |
| 2556 } | 2556 } |
| 2557 | 2557 |
| 2558 // For multiplication and division, we must propagate to the left and | 2558 // For multiplication, division, and Math.min/max(), we must propagate |
| 2559 // the right side. | 2559 // to the left and the right side. |
| 2560 if (current->IsMul()) { | 2560 if (current->IsMul()) { |
| 2561 HMul* mul = HMul::cast(current); | 2561 HMul* mul = HMul::cast(current); |
| 2562 mul->EnsureAndPropagateNotMinusZero(visited); | 2562 mul->EnsureAndPropagateNotMinusZero(visited); |
| 2563 PropagateMinusZeroChecks(mul->left(), visited); | 2563 PropagateMinusZeroChecks(mul->left(), visited); |
| 2564 PropagateMinusZeroChecks(mul->right(), visited); | 2564 PropagateMinusZeroChecks(mul->right(), visited); |
| 2565 } else if (current->IsDiv()) { | 2565 } else if (current->IsDiv()) { |
| 2566 HDiv* div = HDiv::cast(current); | 2566 HDiv* div = HDiv::cast(current); |
| 2567 div->EnsureAndPropagateNotMinusZero(visited); | 2567 div->EnsureAndPropagateNotMinusZero(visited); |
| 2568 PropagateMinusZeroChecks(div->left(), visited); | 2568 PropagateMinusZeroChecks(div->left(), visited); |
| 2569 PropagateMinusZeroChecks(div->right(), visited); | 2569 PropagateMinusZeroChecks(div->right(), visited); |
| 2570 } else if (current->IsMathMinMax()) { |
| 2571 HMathMinMax* minmax = HMathMinMax::cast(current); |
| 2572 visited->Add(minmax->id()); |
| 2573 PropagateMinusZeroChecks(minmax->left(), visited); |
| 2574 PropagateMinusZeroChecks(minmax->right(), visited); |
| 2570 } | 2575 } |
| 2571 | 2576 |
| 2572 current = current->EnsureAndPropagateNotMinusZero(visited); | 2577 current = current->EnsureAndPropagateNotMinusZero(visited); |
| 2573 } | 2578 } |
| 2574 } | 2579 } |
| 2575 | 2580 |
| 2576 | 2581 |
| 2577 void HGraph::InsertRepresentationChangeForUse(HValue* value, | 2582 void HGraph::InsertRepresentationChangeForUse(HValue* value, |
| 2578 HValue* use_value, | 2583 HValue* use_value, |
| 2579 int use_index, | 2584 int use_index, |
| (...skipping 4496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7076 ast_context()->ReturnInstruction(result, expr->id()); | 7081 ast_context()->ReturnInstruction(result, expr->id()); |
| 7077 return true; | 7082 return true; |
| 7078 } | 7083 } |
| 7079 break; | 7084 break; |
| 7080 case kMathMax: | 7085 case kMathMax: |
| 7081 case kMathMin: | 7086 case kMathMin: |
| 7082 if (argument_count == 3 && check_type == RECEIVER_MAP_CHECK) { | 7087 if (argument_count == 3 && check_type == RECEIVER_MAP_CHECK) { |
| 7083 AddCheckConstantFunction(expr->holder(), receiver, receiver_map, true); | 7088 AddCheckConstantFunction(expr->holder(), receiver, receiver_map, true); |
| 7084 HValue* right = Pop(); | 7089 HValue* right = Pop(); |
| 7085 HValue* left = Pop(); | 7090 HValue* left = Pop(); |
| 7086 Pop(); // Pop receiver. | 7091 Drop(1); // Receiver. |
| 7087 | 7092 HValue* context = environment()->LookupContext(); |
| 7088 HValue* left_operand = left; | 7093 HMathMinMax::Operation op = (id == kMathMin) ? HMathMinMax::kMathMin |
| 7089 HValue* right_operand = right; | 7094 : HMathMinMax::kMathMax; |
| 7090 | 7095 HMathMinMax* result = new(zone()) HMathMinMax(context, left, right, op); |
| 7091 // If we do not have two integers, we convert to double for comparison. | 7096 ast_context()->ReturnInstruction(result, expr->id()); |
| 7092 if (!left->representation().IsInteger32() || | |
| 7093 !right->representation().IsInteger32()) { | |
| 7094 if (!left->representation().IsDouble()) { | |
| 7095 HChange* left_convert = new(zone()) HChange( | |
| 7096 left, | |
| 7097 Representation::Double(), | |
| 7098 false, // Do not truncate when converting to double. | |
| 7099 true); // Deoptimize for undefined. | |
| 7100 left_convert->SetFlag(HValue::kBailoutOnMinusZero); | |
| 7101 left_operand = AddInstruction(left_convert); | |
| 7102 } | |
| 7103 if (!right->representation().IsDouble()) { | |
| 7104 HChange* right_convert = new(zone()) HChange( | |
| 7105 right, | |
| 7106 Representation::Double(), | |
| 7107 false, // Do not truncate when converting to double. | |
| 7108 true); // Deoptimize for undefined. | |
| 7109 right_convert->SetFlag(HValue::kBailoutOnMinusZero); | |
| 7110 right_operand = AddInstruction(right_convert); | |
| 7111 } | |
| 7112 } | |
| 7113 | |
| 7114 ASSERT(left_operand->representation().Equals( | |
| 7115 right_operand->representation())); | |
| 7116 ASSERT(!left_operand->representation().IsTagged()); | |
| 7117 | |
| 7118 Token::Value op = (id == kMathMin) ? Token::LT : Token::GT; | |
| 7119 | |
| 7120 HCompareIDAndBranch* compare = | |
| 7121 new(zone()) HCompareIDAndBranch(left_operand, right_operand, op); | |
| 7122 compare->SetInputRepresentation(left_operand->representation()); | |
| 7123 | |
| 7124 HBasicBlock* return_left = graph()->CreateBasicBlock(); | |
| 7125 HBasicBlock* return_right = graph()->CreateBasicBlock(); | |
| 7126 | |
| 7127 compare->SetSuccessorAt(0, return_left); | |
| 7128 compare->SetSuccessorAt(1, return_right); | |
| 7129 current_block()->Finish(compare); | |
| 7130 | |
| 7131 set_current_block(return_left); | |
| 7132 Push(left); | |
| 7133 set_current_block(return_right); | |
| 7134 // The branch above always returns the right operand if either of | |
| 7135 // them is NaN, but the spec requires that max/min(NaN, X) = NaN. | |
| 7136 // We add another branch that checks if the left operand is NaN or not. | |
| 7137 if (left_operand->representation().IsDouble()) { | |
| 7138 // If left_operand != left_operand then it is NaN. | |
| 7139 HCompareIDAndBranch* compare_nan = new(zone()) HCompareIDAndBranch( | |
| 7140 left_operand, left_operand, Token::EQ); | |
| 7141 compare_nan->SetInputRepresentation(left_operand->representation()); | |
| 7142 HBasicBlock* left_is_number = graph()->CreateBasicBlock(); | |
| 7143 HBasicBlock* left_is_nan = graph()->CreateBasicBlock(); | |
| 7144 compare_nan->SetSuccessorAt(0, left_is_number); | |
| 7145 compare_nan->SetSuccessorAt(1, left_is_nan); | |
| 7146 current_block()->Finish(compare_nan); | |
| 7147 set_current_block(left_is_nan); | |
| 7148 Push(left); | |
| 7149 set_current_block(left_is_number); | |
| 7150 Push(right); | |
| 7151 return_right = CreateJoin(left_is_number, left_is_nan, expr->id()); | |
| 7152 } else { | |
| 7153 Push(right); | |
| 7154 } | |
| 7155 | |
| 7156 HBasicBlock* join = CreateJoin(return_left, return_right, expr->id()); | |
| 7157 set_current_block(join); | |
| 7158 ast_context()->ReturnValue(Pop()); | |
| 7159 return true; | 7097 return true; |
| 7160 } | 7098 } |
| 7161 break; | 7099 break; |
| 7162 default: | 7100 default: |
| 7163 // Not yet supported for inlining. | 7101 // Not yet supported for inlining. |
| 7164 break; | 7102 break; |
| 7165 } | 7103 } |
| 7166 return false; | 7104 return false; |
| 7167 } | 7105 } |
| 7168 | 7106 |
| (...skipping 2495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9664 } | 9602 } |
| 9665 } | 9603 } |
| 9666 | 9604 |
| 9667 #ifdef DEBUG | 9605 #ifdef DEBUG |
| 9668 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 9606 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
| 9669 if (allocator_ != NULL) allocator_->Verify(); | 9607 if (allocator_ != NULL) allocator_->Verify(); |
| 9670 #endif | 9608 #endif |
| 9671 } | 9609 } |
| 9672 | 9610 |
| 9673 } } // namespace v8::internal | 9611 } } // namespace v8::internal |
| OLD | NEW |