Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(436)

Unified Diff: src/hydrogen.cc

Issue 10006008: Check for NaN in inlined versions of Math.min, Math.max. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rearrange Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-2056.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 2255ab6f971f6d679d92253f2a567d5fb01aa6f4..ae31a148a19c871b9757cffe1094b4c3d3a0ce49 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -5730,7 +5730,27 @@ bool HGraphBuilder::TryInlineBuiltinMethodCall(Call* expr,
set_current_block(return_left);
Push(left);
set_current_block(return_right);
- Push(right);
+ // The branch above always returns the right operand if either of
+ // them is NaN, but the spec requires that max/min(NaN, X) = NaN.
+ // We add another branch that checks if the left operand is NaN or not.
+ if (left_operand->representation().IsDouble()) {
+ // If left_operand != left_operand then it is NaN.
+ HCompareIDAndBranch* compare_nan = new(zone()) HCompareIDAndBranch(
+ left_operand, left_operand, Token::EQ);
+ compare_nan->SetInputRepresentation(left_operand->representation());
+ HBasicBlock* left_is_number = graph()->CreateBasicBlock();
+ HBasicBlock* left_is_nan = graph()->CreateBasicBlock();
+ compare_nan->SetSuccessorAt(0, left_is_number);
+ compare_nan->SetSuccessorAt(1, left_is_nan);
+ current_block()->Finish(compare_nan);
+ set_current_block(left_is_nan);
+ Push(left);
+ set_current_block(left_is_number);
+ Push(right);
+ return_right = CreateJoin(left_is_number, left_is_nan, expr->id());
+ } else {
+ Push(right);
+ }
HBasicBlock* join = CreateJoin(return_left, return_right, expr->id());
set_current_block(join);
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-2056.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698