Reviewers: jarin,
Message:
PTAL
Description:
[turbofan] Transform x * -1.0 to -0.0 - x.
TEST=msjunit/asm,unittests
Please review this at https://codereview.chromium.org/683753004/
Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+53, -0 lines):
M src/compiler/machine-operator-reducer.cc
A test/mjsunit/asm/float64mul.js
M test/unittests/compiler/machine-operator-reducer-unittest.cc
M test/unittests/compiler/node-test-utils.h
M test/unittests/compiler/node-test-utils.cc
Index: src/compiler/machine-operator-reducer.cc
diff --git a/src/compiler/machine-operator-reducer.cc
b/src/compiler/machine-operator-reducer.cc
index
d1a275d56a07e4289934941122cac808c6cddd6d..900fadfe5073861be8e3cb4e51178afc10c2481b
100644
--- a/src/compiler/machine-operator-reducer.cc
+++ b/src/compiler/machine-operator-reducer.cc
@@ -441,6 +441,12 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
}
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());
Index: test/mjsunit/asm/float64mul.js
diff --git a/test/mjsunit/asm/float64mul.js b/test/mjsunit/asm/float64mul.js
new file mode 100644
index
0000000000000000000000000000000000000000..2035bde20022e08e9f3ca1c336975b6daa15c006
--- /dev/null
+++ b/test/mjsunit/asm/float64mul.js
@@ -0,0 +1,23 @@
+// 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));
+
+for (var i = -2147483648; i < 2147483648; i += 3999777) {
+ assertEquals(-i, m.f1(i));
+ assertEquals(-i, m.f2(i));
+}
Index: test/unittests/compiler/machine-operator-reducer-unittest.cc
diff --git a/test/unittests/compiler/machine-operator-reducer-unittest.cc
b/test/unittests/compiler/machine-operator-reducer-unittest.cc
index
268afc4b275135aa2e407eb98f935a8ab3fe5b13..d811808adf51320bf6a52cffbca157cea8b70863
100644
--- a/test/unittests/compiler/machine-operator-reducer-unittest.cc
+++ b/test/unittests/compiler/machine-operator-reducer-unittest.cc
@@ -1107,6 +1107,27 @@ TEST_F(MachineOperatorReducerTest,
Uint32LessThanWithWord32Sar) {
//
-----------------------------------------------------------------------------
+// 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));
+ }
+}
+
+
+//
-----------------------------------------------------------------------------
// Store
Index: test/unittests/compiler/node-test-utils.cc
diff --git a/test/unittests/compiler/node-test-utils.cc
b/test/unittests/compiler/node-test-utils.cc
index
5f1dea3886cea6503933f1901f2f5b3119810695..fde7f03c3c458ef3426196db11f51f2710c2dc6b
100644
--- a/test/unittests/compiler/node-test-utils.cc
+++ b/test/unittests/compiler/node-test-utils.cc
@@ -1040,6 +1040,7 @@ IS_BINOP_MATCHER(Int32MulHigh)
IS_BINOP_MATCHER(Int32LessThan)
IS_BINOP_MATCHER(Uint32LessThan)
IS_BINOP_MATCHER(Uint32LessThanOrEqual)
+IS_BINOP_MATCHER(Float64Sub)
#undef IS_BINOP_MATCHER
Index: test/unittests/compiler/node-test-utils.h
diff --git a/test/unittests/compiler/node-test-utils.h
b/test/unittests/compiler/node-test-utils.h
index
89fcc4b87cfb7463c378ec28711e316853b8f8a8..870d55513d9754eef09a46375a9e38b70bc43195
100644
--- a/test/unittests/compiler/node-test-utils.h
+++ b/test/unittests/compiler/node-test-utils.h
@@ -156,6 +156,8 @@ Matcher<Node*> IsChangeUint32ToUint64(const
Matcher<Node*>& input_matcher);
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.