OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/graph-unittest.h" | 5 #include "src/compiler/graph-unittest.h" |
6 #include "src/compiler/js-builtin-reducer.h" | 6 #include "src/compiler/js-builtin-reducer.h" |
7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
8 #include "src/compiler/node-properties-inl.h" | 8 #include "src/compiler/node-properties-inl.h" |
9 #include "src/compiler/typer.h" | 9 #include "src/compiler/typer.h" |
| 10 #include "testing/gmock-support.h" |
| 11 |
| 12 using testing::Capture; |
10 | 13 |
11 namespace v8 { | 14 namespace v8 { |
12 namespace internal { | 15 namespace internal { |
13 namespace compiler { | 16 namespace compiler { |
14 | 17 |
15 class JSBuiltinReducerTest : public GraphTest { | 18 class JSBuiltinReducerTest : public GraphTest { |
16 public: | 19 public: |
17 JSBuiltinReducerTest() : javascript_(zone()) {} | 20 JSBuiltinReducerTest() : javascript_(zone()) {} |
18 | 21 |
19 protected: | 22 protected: |
(...skipping 30 matching lines...) Expand all Loading... |
50 Type::UnsignedSmall(), Type::OtherSignedSmall(), Type::OtherUnsigned31(), | 53 Type::UnsignedSmall(), Type::OtherSignedSmall(), Type::OtherUnsigned31(), |
51 Type::OtherUnsigned32(), Type::OtherSigned32(), Type::SignedSmall(), | 54 Type::OtherUnsigned32(), Type::OtherSigned32(), Type::SignedSmall(), |
52 Type::Signed32(), Type::Unsigned32(), Type::Integral32(), | 55 Type::Signed32(), Type::Unsigned32(), Type::Integral32(), |
53 Type::MinusZero(), Type::NaN(), Type::OtherNumber(), | 56 Type::MinusZero(), Type::NaN(), Type::OtherNumber(), |
54 Type::OrderedNumber(), Type::Number()}; | 57 Type::OrderedNumber(), Type::Number()}; |
55 | 58 |
56 } // namespace | 59 } // namespace |
57 | 60 |
58 | 61 |
59 // ----------------------------------------------------------------------------- | 62 // ----------------------------------------------------------------------------- |
| 63 // Math.max |
| 64 |
| 65 |
| 66 TEST_F(JSBuiltinReducerTest, MathMax0) { |
| 67 Handle<JSFunction> f(isolate()->context()->math_max_fun()); |
| 68 |
| 69 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); |
| 70 Node* call = graph()->NewNode(javascript()->Call(2, NO_CALL_FUNCTION_FLAGS), |
| 71 fun, UndefinedConstant()); |
| 72 Reduction r = Reduce(call); |
| 73 |
| 74 EXPECT_TRUE(r.Changed()); |
| 75 EXPECT_THAT(r.replacement(), IsNumberConstant(-V8_INFINITY)); |
| 76 } |
| 77 |
| 78 |
| 79 TEST_F(JSBuiltinReducerTest, MathMax1) { |
| 80 Handle<JSFunction> f(isolate()->context()->math_max_fun()); |
| 81 |
| 82 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
| 83 Node* p0 = Parameter(t0, 0); |
| 84 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); |
| 85 Node* call = graph()->NewNode(javascript()->Call(3, NO_CALL_FUNCTION_FLAGS), |
| 86 fun, UndefinedConstant(), p0); |
| 87 Reduction r = Reduce(call); |
| 88 |
| 89 EXPECT_TRUE(r.Changed()); |
| 90 EXPECT_THAT(r.replacement(), p0); |
| 91 } |
| 92 } |
| 93 |
| 94 |
| 95 TEST_F(JSBuiltinReducerTest, MathMax2) { |
| 96 Handle<JSFunction> f(isolate()->context()->math_max_fun()); |
| 97 |
| 98 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
| 99 TRACED_FOREACH(Type*, t1, kNumberTypes) { |
| 100 Node* p0 = Parameter(t0, 0); |
| 101 Node* p1 = Parameter(t1, 1); |
| 102 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); |
| 103 Node* call = |
| 104 graph()->NewNode(javascript()->Call(4, NO_CALL_FUNCTION_FLAGS), fun, |
| 105 UndefinedConstant(), p0, p1); |
| 106 Reduction r = Reduce(call); |
| 107 |
| 108 if (t0->Is(Type::Integral32()) && t1->Is(Type::Integral32())) { |
| 109 Capture<Node*> branch; |
| 110 EXPECT_TRUE(r.Changed()); |
| 111 EXPECT_THAT( |
| 112 r.replacement(), |
| 113 IsPhi(kMachNone, p1, p0, |
| 114 IsMerge(IsIfTrue(CaptureEq(&branch)), |
| 115 IsIfFalse(AllOf(CaptureEq(&branch), |
| 116 IsBranch(IsNumberLessThan(p0, p1), |
| 117 graph()->start())))))); |
| 118 } else { |
| 119 EXPECT_FALSE(r.Changed()); |
| 120 EXPECT_EQ(IrOpcode::kJSCallFunction, call->opcode()); |
| 121 } |
| 122 } |
| 123 } |
| 124 } |
| 125 |
| 126 |
| 127 // ----------------------------------------------------------------------------- |
60 // Math.imul | 128 // Math.imul |
61 | 129 |
62 | 130 |
63 TEST_F(JSBuiltinReducerTest, MathImul) { | 131 TEST_F(JSBuiltinReducerTest, MathImul) { |
64 Handle<JSFunction> f(isolate()->context()->math_imul_fun()); | 132 Handle<JSFunction> f(isolate()->context()->math_imul_fun()); |
65 | 133 |
66 TRACED_FOREACH(Type*, t0, kNumberTypes) { | 134 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
67 TRACED_FOREACH(Type*, t1, kNumberTypes) { | 135 TRACED_FOREACH(Type*, t1, kNumberTypes) { |
68 Node* p0 = Parameter(t0, 0); | 136 Node* p0 = Parameter(t0, 0); |
69 Node* p1 = Parameter(t1, 1); | 137 Node* p1 = Parameter(t1, 1); |
(...skipping 10 matching lines...) Expand all Loading... |
80 EXPECT_FALSE(r.Changed()); | 148 EXPECT_FALSE(r.Changed()); |
81 EXPECT_EQ(IrOpcode::kJSCallFunction, call->opcode()); | 149 EXPECT_EQ(IrOpcode::kJSCallFunction, call->opcode()); |
82 } | 150 } |
83 } | 151 } |
84 } | 152 } |
85 } | 153 } |
86 | 154 |
87 } // namespace compiler | 155 } // namespace compiler |
88 } // namespace internal | 156 } // namespace internal |
89 } // namespace v8 | 157 } // namespace v8 |
OLD | NEW |