Revision: 24147
Author:   [email protected]
Date:     Tue Sep 23 11:40:00 2014 UTC
Log:      Move test for reduction of Math.max to unittest.

[email protected]
TEST=compiler-unittests/JSBuiltinReducerTest.MathMax

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

Modified:
 /branches/bleeding_edge/src/compiler/graph-unittest.cc
 /branches/bleeding_edge/src/compiler/graph-unittest.h
 /branches/bleeding_edge/src/compiler/js-builtin-reducer-unittest.cc
 /branches/bleeding_edge/test/cctest/compiler/test-js-typed-lowering.cc

=======================================
--- /branches/bleeding_edge/src/compiler/graph-unittest.cc Tue Sep 23 11:26:49 2014 UTC +++ /branches/bleeding_edge/src/compiler/graph-unittest.cc Tue Sep 23 11:40:00 2014 UTC
@@ -743,6 +743,7 @@
     return MakeMatcher(                                                   \
         new IsBinopMatcher(IrOpcode::k##Name, lhs_matcher, rhs_matcher)); \
   }
+IS_BINOP_MATCHER(NumberLessThan)
 IS_BINOP_MATCHER(Word32And)
 IS_BINOP_MATCHER(Word32Sar)
 IS_BINOP_MATCHER(Word32Shl)
=======================================
--- /branches/bleeding_edge/src/compiler/graph-unittest.h Tue Sep 23 11:26:49 2014 UTC +++ /branches/bleeding_edge/src/compiler/graph-unittest.h Tue Sep 23 11:40:00 2014 UTC
@@ -85,6 +85,9 @@
                       const Matcher<Node*>& effect_matcher,
                       const Matcher<Node*>& control_matcher);

+Matcher<Node*> IsNumberLessThan(const Matcher<Node*>& lhs_matcher,
+                                const Matcher<Node*>& rhs_matcher);
+
 Matcher<Node*> IsLoad(const Matcher<LoadRepresentation>& rep_matcher,
                       const Matcher<Node*>& base_matcher,
                       const Matcher<Node*>& index_matcher,
=======================================
--- /branches/bleeding_edge/src/compiler/js-builtin-reducer-unittest.cc Tue Sep 23 11:26:49 2014 UTC +++ /branches/bleeding_edge/src/compiler/js-builtin-reducer-unittest.cc Tue Sep 23 11:40:00 2014 UTC
@@ -7,6 +7,9 @@
 #include "src/compiler/js-graph.h"
 #include "src/compiler/node-properties-inl.h"
 #include "src/compiler/typer.h"
+#include "testing/gmock-support.h"
+
+using testing::Capture;

 namespace v8 {
 namespace internal {
@@ -54,6 +57,71 @@
     Type::OrderedNumber(),   Type::Number()};

 }  // namespace
+
+
+// -----------------------------------------------------------------------------
+// Math.max
+
+
+TEST_F(JSBuiltinReducerTest, MathMax0) {
+  Handle<JSFunction> f(isolate()->context()->math_max_fun());
+
+  Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
+ Node* call = graph()->NewNode(javascript()->Call(2, NO_CALL_FUNCTION_FLAGS),
+                                fun, UndefinedConstant());
+  Reduction r = Reduce(call);
+
+  EXPECT_TRUE(r.Changed());
+  EXPECT_THAT(r.replacement(), IsNumberConstant(-V8_INFINITY));
+}
+
+
+TEST_F(JSBuiltinReducerTest, MathMax1) {
+  Handle<JSFunction> f(isolate()->context()->math_max_fun());
+
+  TRACED_FOREACH(Type*, t0, kNumberTypes) {
+    Node* p0 = Parameter(t0, 0);
+    Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
+ Node* call = graph()->NewNode(javascript()->Call(3, NO_CALL_FUNCTION_FLAGS),
+                                  fun, UndefinedConstant(), p0);
+    Reduction r = Reduce(call);
+
+    EXPECT_TRUE(r.Changed());
+    EXPECT_THAT(r.replacement(), p0);
+  }
+}
+
+
+TEST_F(JSBuiltinReducerTest, MathMax2) {
+  Handle<JSFunction> f(isolate()->context()->math_max_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())) {
+        Capture<Node*> branch;
+        EXPECT_TRUE(r.Changed());
+        EXPECT_THAT(
+            r.replacement(),
+            IsPhi(kMachNone, p1, p0,
+                  IsMerge(IsIfTrue(CaptureEq(&branch)),
+                          IsIfFalse(AllOf(CaptureEq(&branch),
+ IsBranch(IsNumberLessThan(p0, p1),
+                                                   graph()->start()))))));
+      } else {
+        EXPECT_FALSE(r.Changed());
+        EXPECT_EQ(IrOpcode::kJSCallFunction, call->opcode());
+      }
+    }
+  }
+}


// -----------------------------------------------------------------------------
=======================================
--- /branches/bleeding_edge/test/cctest/compiler/test-js-typed-lowering.cc Tue Sep 23 11:26:49 2014 UTC +++ /branches/bleeding_edge/test/cctest/compiler/test-js-typed-lowering.cc Tue Sep 23 11:40:00 2014 UTC
@@ -1383,45 +1383,3 @@
     }
   }
 }
-
-
-TEST(BuiltinMathMax) {
-  JSTypedLoweringTester R;
-
-  Node* fun = R.HeapConstant(handle(R.isolate->context()->math_max_fun()));
- Node* call = R.graph.NewNode(R.javascript.Call(2, NO_CALL_FUNCTION_FLAGS),
-                               fun, R.UndefinedConstant());
-  Node* r = R.reduce(call);
-  R.CheckNumberConstant(-V8_INFINITY, r);
-
-  for (size_t i = 0; i < arraysize(kNumberTypes); i++) {
-    Type* t0 = kNumberTypes[i];
-    Node* p0 = R.Parameter(t0, 0);
- Node* call = R.graph.NewNode(R.javascript.Call(3, NO_CALL_FUNCTION_FLAGS),
-                                 fun, R.UndefinedConstant(), p0);
-    Node* r = R.reduce(call);
-    CHECK_EQ(IrOpcode::kParameter, r->opcode());
-    CHECK_EQ(p0, 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* 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())) {
-        CHECK_EQ(IrOpcode::kPhi, r->opcode());
-        CHECK(p0 == r->InputAt(0) || p1 == r->InputAt(0));
-        CHECK(p1 == r->InputAt(1) || p0 == r->InputAt(1));
-      } else {
-        CHECK_EQ(IrOpcode::kJSCallFunction, r->opcode());
-        CHECK_EQ(call, r);
-      }
-    }
-  }
-}

--
--
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