Move test for reduction of Math.imul to unittest.
authormstarzinger@chromium.org <mstarzinger@chromium.org>
Tue, 23 Sep 2014 11:26:49 +0000 (11:26 +0000)
committermstarzinger@chromium.org <mstarzinger@chromium.org>
Tue, 23 Sep 2014 11:26:49 +0000 (11:26 +0000)
R=bmeurer@chromium.org
TEST=compiler-unittests/JSBuiltinReducerTest.MathImul

Review URL: https://codereview.chromium.org/591373003

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24144 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/compiler/compiler.gyp
src/compiler/graph-unittest.cc
src/compiler/graph-unittest.h
src/compiler/js-builtin-reducer-unittest.cc [new file with mode: 0644]
test/cctest/compiler/test-js-typed-lowering.cc
testing/gtest-support.h

index fc1916844fe76c78635ceb4771afac40ac4b98df..ec5ec285cc26cb073f34c182b3fe4280330cd1c2 100644 (file)
@@ -26,6 +26,7 @@
         'graph-unittest.h',
         'instruction-selector-unittest.cc',
         'instruction-selector-unittest.h',
+        'js-builtin-reducer-unittest.cc',
         'machine-operator-reducer-unittest.cc',
         'machine-operator-unittest.cc',
         'simplified-operator-reducer-unittest.cc',
index 58adb112c731600fd9b29aa93d2540a3ab8f4b0b..82473f5e74483b3c11a4d986206cc3d172fd29be 100644 (file)
@@ -753,6 +753,7 @@ IS_BINOP_MATCHER(Word64Sar)
 IS_BINOP_MATCHER(Word64Shl)
 IS_BINOP_MATCHER(Word64Equal)
 IS_BINOP_MATCHER(Int32AddWithOverflow)
+IS_BINOP_MATCHER(Int32Mul)
 IS_BINOP_MATCHER(Uint32LessThanOrEqual)
 #undef IS_BINOP_MATCHER
 
index 3cda9b7b190a32ce1767dfae596ac97f937d6fa8..3d8f92bb87ffc82919fccd6ef69345c182089c3d 100644 (file)
@@ -116,6 +116,8 @@ Matcher<Node*> IsWord64Equal(const Matcher<Node*>& lhs_matcher,
                              const Matcher<Node*>& rhs_matcher);
 Matcher<Node*> IsInt32AddWithOverflow(const Matcher<Node*>& lhs_matcher,
                                       const Matcher<Node*>& rhs_matcher);
+Matcher<Node*> IsInt32Mul(const Matcher<Node*>& lhs_matcher,
+                          const Matcher<Node*>& rhs_matcher);
 Matcher<Node*> IsUint32LessThanOrEqual(const Matcher<Node*>& lhs_matcher,
                                        const Matcher<Node*>& rhs_matcher);
 Matcher<Node*> IsChangeFloat64ToInt32(const Matcher<Node*>& input_matcher);
diff --git a/src/compiler/js-builtin-reducer-unittest.cc b/src/compiler/js-builtin-reducer-unittest.cc
new file mode 100644 (file)
index 0000000..ca12c50
--- /dev/null
@@ -0,0 +1,89 @@
+// 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.
+
+#include "src/compiler/graph-unittest.h"
+#include "src/compiler/js-builtin-reducer.h"
+#include "src/compiler/js-graph.h"
+#include "src/compiler/node-properties-inl.h"
+#include "src/compiler/typer.h"
+
+namespace v8 {
+namespace internal {
+namespace compiler {
+
+class JSBuiltinReducerTest : public GraphTest {
+ public:
+  JSBuiltinReducerTest() : javascript_(zone()) {}
+
+ protected:
+  Reduction Reduce(Node* node) {
+    Typer typer(zone());
+    MachineOperatorBuilder machine;
+    JSGraph jsgraph(graph(), common(), javascript(), &typer, &machine);
+    JSBuiltinReducer reducer(&jsgraph);
+    return reducer.Reduce(node);
+  }
+
+  Node* Parameter(Type* t, int32_t index = 0) {
+    Node* n = graph()->NewNode(common()->Parameter(index), graph()->start());
+    NodeProperties::SetBounds(n, Bounds(Type::None(), t));
+    return n;
+  }
+
+  Node* UndefinedConstant() {
+    return HeapConstant(
+        Unique<HeapObject>::CreateImmovable(factory()->undefined_value()));
+  }
+
+  JSOperatorBuilder* javascript() { return &javascript_; }
+
+ private:
+  JSOperatorBuilder javascript_;
+};
+
+
+namespace {
+
+// TODO(mstarzinger): Find a common place and unify with test-js-typed-lowering.
+Type* const kNumberTypes[] = {
+    Type::UnsignedSmall(),   Type::OtherSignedSmall(), Type::OtherUnsigned31(),
+    Type::OtherUnsigned32(), Type::OtherSigned32(),    Type::SignedSmall(),
+    Type::Signed32(),        Type::Unsigned32(),       Type::Integral32(),
+    Type::MinusZero(),       Type::NaN(),              Type::OtherNumber(),
+    Type::OrderedNumber(),   Type::Number()};
+
+}  // namespace
+
+
+// -----------------------------------------------------------------------------
+// Math.imul
+
+
+TEST_F(JSBuiltinReducerTest, MathImul) {
+  Handle<JSFunction> f(isolate()->context()->math_imul_fun());
+
+  TRACED_FOREACH(Type*, t0, kNumberTypes) {
+    TRACED_FOREACH(Type*, t1, kNumberTypes) {
+      Node* p0 = Parameter(t0, 0);
+      Node* p1 = Parameter(t1, 1);
+      Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
+      Node* call =
+          graph()->NewNode(javascript()->Call(4, NO_CALL_FUNCTION_FLAGS), fun,
+                           UndefinedConstant(), p0, p1);
+      Reduction r = Reduce(call);
+
+      if (t0->Is(Type::Integral32()) && t1->Is(Type::Integral32())) {
+        EXPECT_TRUE(r.Changed());
+        EXPECT_THAT(r.replacement(), IsInt32Mul(p0, p1));
+      } else {
+        EXPECT_FALSE(r.Changed());
+        EXPECT_EQ(IrOpcode::kJSCallFunction, call->opcode());
+      }
+    }
+  }
+}
+
+}  // namespace compiler
+}  // namespace internal
+}  // namespace v8
index 5dc32fb52785b68dd18aebbae86b769ed5cdcf75..92edf9beaf2b7b1c3280870df9656d8f97d3d680 100644 (file)
@@ -174,7 +174,7 @@ static Type* kNumberTypes[] = {
     Type::OtherUnsigned32(), Type::OtherSigned32(),    Type::SignedSmall(),
     Type::Signed32(),        Type::Unsigned32(),       Type::Integral32(),
     Type::MinusZero(),       Type::NaN(),              Type::OtherNumber(),
-    Type::Number()};
+    Type::OrderedNumber(),   Type::Number()};
 
 
 static Type* kJSTypes[] = {Type::Undefined(), Type::Null(),   Type::Boolean(),
@@ -1425,30 +1425,3 @@ TEST(BuiltinMathMax) {
     }
   }
 }
-
-
-TEST(BuiltinMathImul) {
-  JSTypedLoweringTester R;
-
-  for (size_t i = 0; i < arraysize(kNumberTypes); i++) {
-    for (size_t j = 0; j < arraysize(kNumberTypes); j++) {
-      Type* t0 = kNumberTypes[i];
-      Node* p0 = R.Parameter(t0, 0);
-      Type* t1 = kNumberTypes[j];
-      Node* p1 = R.Parameter(t1, 1);
-      Node* fun = R.HeapConstant(handle(R.isolate->context()->math_imul_fun()));
-      Node* call = R.graph.NewNode(R.javascript.Call(4, NO_CALL_FUNCTION_FLAGS),
-                                   fun, R.UndefinedConstant(), p0, p1);
-      Node* r = R.reduce(call);
-
-      if (t0->Is(Type::Integral32()) && t1->Is(Type::Integral32())) {
-        R.CheckPureBinop(R.machine.Int32Mul(), r);
-        CHECK_EQ(p0, r->InputAt(0));
-        CHECK_EQ(p1, r->InputAt(1));
-      } else {
-        CHECK_EQ(IrOpcode::kJSCallFunction, r->opcode());
-        CHECK_EQ(call, r);
-      }
-    }
-  }
-}
index 159858eb6218d221696b7af3453684270202f4e7..66b1094ff4d1869e4cee2b93d69cac9a07f1e7cb 100644 (file)
@@ -36,7 +36,7 @@ GET_TYPE_NAME(double)
 #define TRACED_FOREACH(_type, _var, _array)                                \
   for (size_t _i = 0; _i < arraysize(_array); ++_i)                        \
     for (bool _done = false; !_done;)                                      \
-      for (const _type _var = _array[_i]; !_done;)                         \
+      for (_type const _var = _array[_i]; !_done;)                         \
         for (SCOPED_TRACE(::testing::Message() << #_var << " = " << _var); \
              !_done; _done = true)
 
@@ -48,7 +48,7 @@ GET_TYPE_NAME(double)
 #define TRACED_FORRANGE(_type, _var, _low, _high)                          \
   for (_type _i = _low; _i <= _high; ++_i)                                 \
     for (bool _done = false; !_done;)                                      \
-      for (const _type _var = _i; !_done;)                                 \
+      for (_type const _var = _i; !_done;)                                 \
         for (SCOPED_TRACE(::testing::Message() << #_var << " = " << _var); \
              !_done; _done = true)