Revision: 25176
Author:   [email protected]
Date:     Thu Nov  6 06:13:10 2014 UTC
Log:      [turbofan] Transform x * -1.0 to -0.0 - x.

TEST=msjunit/asm,unittests
[email protected]

Review URL: https://codereview.chromium.org/683753004
https://code.google.com/p/v8/source/detail?r=25176

Added:
 /branches/bleeding_edge/test/mjsunit/asm/float64mul.js
Modified:
 /branches/bleeding_edge/src/compiler/machine-operator-reducer.cc
/branches/bleeding_edge/test/unittests/compiler/machine-operator-reducer-unittest.cc
 /branches/bleeding_edge/test/unittests/compiler/node-test-utils.cc
 /branches/bleeding_edge/test/unittests/compiler/node-test-utils.h

=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/mjsunit/asm/float64mul.js Thu Nov 6 06:13:10 2014 UTC
@@ -0,0 +1,33 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+function Module(stdlib, foreign, heap) {
+  "use asm";
+  function f1(i) {
+    i = +i;
+    return +(i * -1);
+  }
+  function f2(i) {
+    i = +i;
+    return +(-1 * i);
+  }
+  return { f1: f1, f2: f2 };
+}
+
+var m = Module(this, {}, new ArrayBuffer(64 * 1024));
+
+assertEquals(NaN, m.f1(NaN));
+assertEquals(NaN, m.f2(NaN));
+assertEquals(Infinity, 1 / m.f1(-0));
+assertEquals(Infinity, 1 / m.f2(-0));
+assertEquals(Infinity, m.f1(-Infinity));
+assertEquals(Infinity, m.f2(-Infinity));
+assertEquals(-Infinity, 1 / m.f1(0));
+assertEquals(-Infinity, 1 / m.f2(0));
+assertEquals(-Infinity, m.f1(Infinity));
+assertEquals(-Infinity, m.f2(Infinity));
+for (var i = -2147483648; i < 2147483648; i += 3999777) {
+  assertEquals(-i, m.f1(i));
+  assertEquals(-i, m.f2(i));
+}
=======================================
--- /branches/bleeding_edge/src/compiler/machine-operator-reducer.cc Tue Nov 4 14:37:22 2014 UTC +++ /branches/bleeding_edge/src/compiler/machine-operator-reducer.cc Thu Nov 6 06:13:10 2014 UTC
@@ -441,6 +441,12 @@
     }
     case IrOpcode::kFloat64Mul: {
       Float64BinopMatcher m(node);
+      if (m.right().Is(-1)) {  // x * -1.0 => -0.0 - x
+        node->set_op(machine()->Float64Sub());
+        node->ReplaceInput(0, Float64Constant(-0.0));
+        node->ReplaceInput(1, m.left().node());
+        return Changed(node);
+      }
if (m.right().Is(1)) return Replace(m.left().node()); // x * 1.0 => x if (m.right().IsNaN()) { // x * NaN => NaN
         return Replace(m.right().node());
=======================================
--- /branches/bleeding_edge/test/unittests/compiler/machine-operator-reducer-unittest.cc Tue Nov 4 07:35:29 2014 UTC +++ /branches/bleeding_edge/test/unittests/compiler/machine-operator-reducer-unittest.cc Thu Nov 6 06:13:10 2014 UTC
@@ -1104,6 +1104,27 @@
p0, IsInt32Constant(bit_cast<int32_t>(limit << shift))));
   }
 }
+
+
+// -----------------------------------------------------------------------------
+// Float64Mul
+
+
+TEST_F(MachineOperatorReducerTest, Float64MulWithMinusOne) {
+  Node* const p0 = Parameter(0);
+  {
+    Reduction r = Reduce(
+ graph()->NewNode(machine()->Float64Mul(), p0, Float64Constant(-1.0)));
+    ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(), IsFloat64Sub(IsFloat64Constant(-0.0), p0));
+  }
+  {
+    Reduction r = Reduce(
+ graph()->NewNode(machine()->Float64Mul(), Float64Constant(-1.0), p0));
+    ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(), IsFloat64Sub(IsFloat64Constant(-0.0), p0));
+  }
+}


// -----------------------------------------------------------------------------
=======================================
--- /branches/bleeding_edge/test/unittests/compiler/node-test-utils.cc Tue Nov 4 14:37:22 2014 UTC +++ /branches/bleeding_edge/test/unittests/compiler/node-test-utils.cc Thu Nov 6 06:13:10 2014 UTC
@@ -1040,6 +1040,7 @@
 IS_BINOP_MATCHER(Int32LessThan)
 IS_BINOP_MATCHER(Uint32LessThan)
 IS_BINOP_MATCHER(Uint32LessThanOrEqual)
+IS_BINOP_MATCHER(Float64Sub)
 #undef IS_BINOP_MATCHER


=======================================
--- /branches/bleeding_edge/test/unittests/compiler/node-test-utils.h Tue Nov 4 14:37:22 2014 UTC +++ /branches/bleeding_edge/test/unittests/compiler/node-test-utils.h Thu Nov 6 06:13:10 2014 UTC
@@ -156,6 +156,8 @@
Matcher<Node*> IsTruncateFloat64ToFloat32(const Matcher<Node*>& input_matcher); Matcher<Node*> IsTruncateFloat64ToInt32(const Matcher<Node*>& input_matcher);
 Matcher<Node*> IsTruncateInt64ToInt32(const Matcher<Node*>& input_matcher);
+Matcher<Node*> IsFloat64Sub(const Matcher<Node*>& lhs_matcher,
+                            const Matcher<Node*>& rhs_matcher);
 Matcher<Node*> IsFloat64Sqrt(const Matcher<Node*>& input_matcher);
 Matcher<Node*> IsFloat64Floor(const Matcher<Node*>& input_matcher);
 Matcher<Node*> IsFloat64Ceil(const Matcher<Node*>& input_matcher);

--
--
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/d/optout.

Reply via email to