Reviewers: Sven Panne,
Description:
Do not remove HAdd with zero if the other operand is a double.
The other operand might be minus zero, and -0 + 0 = +0
[email protected]
BUG=
Please review this at https://codereview.chromium.org/52173003/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+15, -13 lines):
M src/hydrogen-instructions.cc
A + test/mjsunit/regress/regress-add-minus-zero.js
Index: src/hydrogen-instructions.cc
diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc
index
6da6774aa8e87302bdd2a03a9f4f31f88d8216e7..206ab7e2accf5e496b6cd814eb1071c511cb21e7
100644
--- a/src/hydrogen-instructions.cc
+++ b/src/hydrogen-instructions.cc
@@ -1255,8 +1255,15 @@ static bool IsIdentityOperation(HValue* arg1,
HValue* arg2, int32_t identity) {
HValue* HAdd::Canonicalize() {
- if (IsIdentityOperation(left(), right(), 0)) return left();
- if (IsIdentityOperation(right(), left(), 0)) return right();
+ // Adding 0 is an identity operation except in case of -0: -0 + 0 = +0
+ if (IsIdentityOperation(left(), right(), 0) &&
+ !left()->representation().IsDouble()) { // Left could be -0.
+ return left();
+ }
+ if (IsIdentityOperation(right(), left(), 0) &&
+ !left()->representation().IsDouble()) { // Right could be -0.
+ return right();
+ }
return this;
}
Index: test/mjsunit/regress/regress-add-minus-zero.js
diff --git a/test/mjsunit/regress/regress-crbug-242870.js
b/test/mjsunit/regress/regress-add-minus-zero.js
similarity index 90%
copy from test/mjsunit/regress/regress-crbug-242870.js
copy to test/mjsunit/regress/regress-add-minus-zero.js
index
7183375ca811cedc81c870d34e694e98cf727f9b..0b4af754245f17b063b33f6afa517bffe1bed699
100644
--- a/test/mjsunit/regress/regress-crbug-242870.js
+++ b/test/mjsunit/regress/regress-add-minus-zero.js
@@ -27,17 +27,12 @@
// Flags: --allow-natives-syntax
-var non_const_true = true;
+var o = { a: 0 };
-function f() {
- return (non_const_true || true && g());
-}
+function f(x) { return -o.a + 0; };
-function g() {
- for (;;) {}
-}
-
-assertTrue(f());
-assertTrue(f());
+assertEquals("Infinity", String(1/f()));
+assertEquals("Infinity", String(1/f()));
%OptimizeFunctionOnNextCall(f);
-assertTrue(f());
+assertEquals("Infinity", String(1/f()));
+
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.