Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: src/compiler/js-builtin-reducer-unittest.cc

Issue 595963002: Extend JSBuiltinReducer to cover Math.sqrt as well. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comment by Benedikt. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/compiler/js-builtin-reducer.cc ('k') | src/compiler/machine-operator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" 10 #include "testing/gmock-support.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 Type::UnsignedSmall(), Type::OtherSignedSmall(), Type::OtherUnsigned31(), 53 Type::UnsignedSmall(), Type::OtherSignedSmall(), Type::OtherUnsigned31(),
54 Type::OtherUnsigned32(), Type::OtherSigned32(), Type::SignedSmall(), 54 Type::OtherUnsigned32(), Type::OtherSigned32(), Type::SignedSmall(),
55 Type::Signed32(), Type::Unsigned32(), Type::Integral32(), 55 Type::Signed32(), Type::Unsigned32(), Type::Integral32(),
56 Type::MinusZero(), Type::NaN(), Type::OtherNumber(), 56 Type::MinusZero(), Type::NaN(), Type::OtherNumber(),
57 Type::OrderedNumber(), Type::Number()}; 57 Type::OrderedNumber(), Type::Number()};
58 58
59 } // namespace 59 } // namespace
60 60
61 61
62 // ----------------------------------------------------------------------------- 62 // -----------------------------------------------------------------------------
63 // Math.sqrt
64
65
66 TEST_F(JSBuiltinReducerTest, MathSqrt) {
67 Handle<JSFunction> f(isolate()->context()->math_sqrt_fun());
68
69 TRACED_FOREACH(Type*, t0, kNumberTypes) {
70 Node* p0 = Parameter(t0, 0);
71 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
72 Node* call = graph()->NewNode(javascript()->Call(3, NO_CALL_FUNCTION_FLAGS),
73 fun, UndefinedConstant(), p0);
74 Reduction r = Reduce(call);
75
76 ASSERT_TRUE(r.Changed());
77 EXPECT_THAT(r.replacement(), IsFloat64Sqrt(p0));
78 }
79 }
80
81
82 // -----------------------------------------------------------------------------
63 // Math.max 83 // Math.max
64 84
65 85
66 TEST_F(JSBuiltinReducerTest, MathMax0) { 86 TEST_F(JSBuiltinReducerTest, MathMax0) {
67 Handle<JSFunction> f(isolate()->context()->math_max_fun()); 87 Handle<JSFunction> f(isolate()->context()->math_max_fun());
68 88
69 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); 89 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
70 Node* call = graph()->NewNode(javascript()->Call(2, NO_CALL_FUNCTION_FLAGS), 90 Node* call = graph()->NewNode(javascript()->Call(2, NO_CALL_FUNCTION_FLAGS),
71 fun, UndefinedConstant()); 91 fun, UndefinedConstant());
72 Reduction r = Reduce(call); 92 Reduction r = Reduce(call);
73 93
74 EXPECT_TRUE(r.Changed()); 94 ASSERT_TRUE(r.Changed());
75 EXPECT_THAT(r.replacement(), IsNumberConstant(-V8_INFINITY)); 95 EXPECT_THAT(r.replacement(), IsNumberConstant(-V8_INFINITY));
76 } 96 }
77 97
78 98
79 TEST_F(JSBuiltinReducerTest, MathMax1) { 99 TEST_F(JSBuiltinReducerTest, MathMax1) {
80 Handle<JSFunction> f(isolate()->context()->math_max_fun()); 100 Handle<JSFunction> f(isolate()->context()->math_max_fun());
81 101
82 TRACED_FOREACH(Type*, t0, kNumberTypes) { 102 TRACED_FOREACH(Type*, t0, kNumberTypes) {
83 Node* p0 = Parameter(t0, 0); 103 Node* p0 = Parameter(t0, 0);
84 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); 104 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
85 Node* call = graph()->NewNode(javascript()->Call(3, NO_CALL_FUNCTION_FLAGS), 105 Node* call = graph()->NewNode(javascript()->Call(3, NO_CALL_FUNCTION_FLAGS),
86 fun, UndefinedConstant(), p0); 106 fun, UndefinedConstant(), p0);
87 Reduction r = Reduce(call); 107 Reduction r = Reduce(call);
88 108
89 EXPECT_TRUE(r.Changed()); 109 ASSERT_TRUE(r.Changed());
90 EXPECT_THAT(r.replacement(), p0); 110 EXPECT_THAT(r.replacement(), p0);
91 } 111 }
92 } 112 }
93 113
94 114
95 TEST_F(JSBuiltinReducerTest, MathMax2) { 115 TEST_F(JSBuiltinReducerTest, MathMax2) {
96 Handle<JSFunction> f(isolate()->context()->math_max_fun()); 116 Handle<JSFunction> f(isolate()->context()->math_max_fun());
97 117
98 TRACED_FOREACH(Type*, t0, kNumberTypes) { 118 TRACED_FOREACH(Type*, t0, kNumberTypes) {
99 TRACED_FOREACH(Type*, t1, kNumberTypes) { 119 TRACED_FOREACH(Type*, t1, kNumberTypes) {
100 Node* p0 = Parameter(t0, 0); 120 Node* p0 = Parameter(t0, 0);
101 Node* p1 = Parameter(t1, 1); 121 Node* p1 = Parameter(t1, 1);
102 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); 122 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
103 Node* call = 123 Node* call =
104 graph()->NewNode(javascript()->Call(4, NO_CALL_FUNCTION_FLAGS), fun, 124 graph()->NewNode(javascript()->Call(4, NO_CALL_FUNCTION_FLAGS), fun,
105 UndefinedConstant(), p0, p1); 125 UndefinedConstant(), p0, p1);
106 Reduction r = Reduce(call); 126 Reduction r = Reduce(call);
107 127
108 if (t0->Is(Type::Integral32()) && t1->Is(Type::Integral32())) { 128 if (t0->Is(Type::Integral32()) && t1->Is(Type::Integral32())) {
109 Capture<Node*> branch; 129 Capture<Node*> branch;
110 EXPECT_TRUE(r.Changed()); 130 ASSERT_TRUE(r.Changed());
111 EXPECT_THAT( 131 EXPECT_THAT(
112 r.replacement(), 132 r.replacement(),
113 IsPhi(kMachNone, p1, p0, 133 IsPhi(kMachNone, p1, p0,
114 IsMerge(IsIfTrue(CaptureEq(&branch)), 134 IsMerge(IsIfTrue(CaptureEq(&branch)),
115 IsIfFalse(AllOf(CaptureEq(&branch), 135 IsIfFalse(AllOf(CaptureEq(&branch),
116 IsBranch(IsNumberLessThan(p0, p1), 136 IsBranch(IsNumberLessThan(p0, p1),
117 graph()->start())))))); 137 graph()->start()))))));
118 } else { 138 } else {
119 EXPECT_FALSE(r.Changed()); 139 ASSERT_FALSE(r.Changed());
120 EXPECT_EQ(IrOpcode::kJSCallFunction, call->opcode()); 140 EXPECT_EQ(IrOpcode::kJSCallFunction, call->opcode());
121 } 141 }
122 } 142 }
123 } 143 }
124 } 144 }
125 145
126 146
127 // ----------------------------------------------------------------------------- 147 // -----------------------------------------------------------------------------
128 // Math.imul 148 // Math.imul
129 149
130 150
131 TEST_F(JSBuiltinReducerTest, MathImul) { 151 TEST_F(JSBuiltinReducerTest, MathImul) {
132 Handle<JSFunction> f(isolate()->context()->math_imul_fun()); 152 Handle<JSFunction> f(isolate()->context()->math_imul_fun());
133 153
134 TRACED_FOREACH(Type*, t0, kNumberTypes) { 154 TRACED_FOREACH(Type*, t0, kNumberTypes) {
135 TRACED_FOREACH(Type*, t1, kNumberTypes) { 155 TRACED_FOREACH(Type*, t1, kNumberTypes) {
136 Node* p0 = Parameter(t0, 0); 156 Node* p0 = Parameter(t0, 0);
137 Node* p1 = Parameter(t1, 1); 157 Node* p1 = Parameter(t1, 1);
138 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); 158 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
139 Node* call = 159 Node* call =
140 graph()->NewNode(javascript()->Call(4, NO_CALL_FUNCTION_FLAGS), fun, 160 graph()->NewNode(javascript()->Call(4, NO_CALL_FUNCTION_FLAGS), fun,
141 UndefinedConstant(), p0, p1); 161 UndefinedConstant(), p0, p1);
142 Reduction r = Reduce(call); 162 Reduction r = Reduce(call);
143 163
144 if (t0->Is(Type::Integral32()) && t1->Is(Type::Integral32())) { 164 if (t0->Is(Type::Integral32()) && t1->Is(Type::Integral32())) {
145 EXPECT_TRUE(r.Changed()); 165 ASSERT_TRUE(r.Changed());
146 EXPECT_THAT(r.replacement(), IsInt32Mul(p0, p1)); 166 EXPECT_THAT(r.replacement(), IsInt32Mul(p0, p1));
147 } else { 167 } else {
148 EXPECT_FALSE(r.Changed()); 168 ASSERT_FALSE(r.Changed());
149 EXPECT_EQ(IrOpcode::kJSCallFunction, call->opcode()); 169 EXPECT_EQ(IrOpcode::kJSCallFunction, call->opcode());
150 } 170 }
151 } 171 }
152 } 172 }
153 } 173 }
154 174
155 } // namespace compiler 175 } // namespace compiler
156 } // namespace internal 176 } // namespace internal
157 } // namespace v8 177 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/js-builtin-reducer.cc ('k') | src/compiler/machine-operator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698