Index: src/hydrogen.cc |
diff --git a/src/hydrogen.cc b/src/hydrogen.cc |
index 34fd6da060ae05cd576a1c0ee63073d7060ad4b0..f2d7fe18a6afbeead8e3c97e8aac964e0ac4c14a 100644 |
--- a/src/hydrogen.cc |
+++ b/src/hydrogen.cc |
@@ -5140,6 +5140,57 @@ bool HGraphBuilder::TryInlineBuiltinFunction(Call* expr, |
return true; |
} |
break; |
+ case kMathMax: |
+ case kMathMin: |
+ if (argument_count == 3 && check_type == RECEIVER_MAP_CHECK) { |
+ AddCheckConstantFunction(expr, receiver, receiver_map, true); |
+ HValue* right = Pop(); |
+ HValue* left = Pop(); |
+ // Do not inline if the return representation is not certain. |
+ if (!left->representation().Equals(right->representation())) { |
+ Push(left); |
+ Push(right); |
+ return false; |
+ } |
+ |
+ Pop(); // Pop receiver. |
+ Token::Value op = (id == kMathMin) ? Token::LT : Token::GT; |
+ HCompareIDAndBranch* compare = NULL; |
+ |
+ if (left->representation().IsTagged()) { |
+ HChange* left_cvt = |
+ new(zone()) HChange(left, Representation::Double(), false, true); |
+ left_cvt->SetFlag(HValue::kBailoutOnMinusZero); |
+ AddInstruction(left_cvt); |
+ HChange* right_cvt = |
+ new(zone()) HChange(right, Representation::Double(), false, true); |
+ right_cvt->SetFlag(HValue::kBailoutOnMinusZero); |
+ AddInstruction(right_cvt); |
+ compare = new(zone()) HCompareIDAndBranch(left_cvt, right_cvt, op); |
+ compare->SetInputRepresentation(Representation::Double()); |
+ } else { |
+ compare = new(zone()) HCompareIDAndBranch(left, right, op); |
+ compare->SetInputRepresentation(left->representation()); |
+ } |
+ |
+ HBasicBlock* return_left = graph()->CreateBasicBlock(); |
+ HBasicBlock* return_right = graph()->CreateBasicBlock(); |
+ |
+ compare->SetSuccessorAt(0, return_left); |
+ compare->SetSuccessorAt(1, return_right); |
+ current_block()->Finish(compare); |
+ |
+ set_current_block(return_left); |
+ Push(left); |
+ set_current_block(return_right); |
+ Push(right); |
+ |
+ HBasicBlock* join = CreateJoin(return_left, return_right, expr->id()); |
+ set_current_block(join); |
+ ast_context()->ReturnValue(Pop()); |
+ return true; |
+ } |
+ break; |
default: |
// Not yet supported for inlining. |
break; |