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

Side by Side Diff: test/unittests/compiler/typed-optimization-unittest.cc

Issue 2381523002: [Turbofan] Introduce OtherNumberConstant. (Closed)
Patch Set: Better DCHECK in HeapConstantType(). Created 4 years, 2 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
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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/typed-optimization.h" 5 #include "src/compiler/typed-optimization.h"
6 #include "src/code-factory.h" 6 #include "src/code-factory.h"
7 #include "src/compilation-dependencies.h" 7 #include "src/compilation-dependencies.h"
8 #include "src/compiler/access-builder.h" 8 #include "src/compiler/access-builder.h"
9 #include "src/compiler/js-graph.h" 9 #include "src/compiler/js-graph.h"
10 #include "src/compiler/js-operator.h" 10 #include "src/compiler/js-operator.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 JSOperatorBuilder* javascript() { return &javascript_; } 81 JSOperatorBuilder* javascript() { return &javascript_; }
82 82
83 private: 83 private:
84 JSOperatorBuilder javascript_; 84 JSOperatorBuilder javascript_;
85 CompilationDependencies deps_; 85 CompilationDependencies deps_;
86 }; 86 };
87 87
88 TEST_F(TypedOptimizationTest, ParameterWithMinusZero) { 88 TEST_F(TypedOptimizationTest, ParameterWithMinusZero) {
89 { 89 {
90 Reduction r = Reduce( 90 Reduction r = Reduce(
91 Parameter(Type::Constant(factory()->minus_zero_value(), zone()))); 91 Parameter(Type::NewConstant(factory()->minus_zero_value(), zone())));
92 ASSERT_TRUE(r.Changed()); 92 ASSERT_TRUE(r.Changed());
93 EXPECT_THAT(r.replacement(), IsNumberConstant(-0.0)); 93 EXPECT_THAT(r.replacement(), IsNumberConstant(-0.0));
94 } 94 }
95 { 95 {
96 Reduction r = Reduce(Parameter(Type::MinusZero())); 96 Reduction r = Reduce(Parameter(Type::MinusZero()));
97 ASSERT_TRUE(r.Changed()); 97 ASSERT_TRUE(r.Changed());
98 EXPECT_THAT(r.replacement(), IsNumberConstant(-0.0)); 98 EXPECT_THAT(r.replacement(), IsNumberConstant(-0.0));
99 } 99 }
100 { 100 {
101 Reduction r = Reduce(Parameter( 101 Reduction r = Reduce(Parameter(Type::Union(
102 Type::Union(Type::MinusZero(), 102 Type::MinusZero(), Type::NewConstant(factory()->NewNumber(0), zone()),
103 Type::Constant(factory()->NewNumber(0), zone()), zone()))); 103 zone())));
104 EXPECT_FALSE(r.Changed()); 104 EXPECT_FALSE(r.Changed());
105 } 105 }
106 } 106 }
107 107
108 TEST_F(TypedOptimizationTest, ParameterWithNull) { 108 TEST_F(TypedOptimizationTest, ParameterWithNull) {
109 Handle<HeapObject> null = factory()->null_value(); 109 Handle<HeapObject> null = factory()->null_value();
110 { 110 {
111 Reduction r = Reduce(Parameter(Type::Constant(null, zone()))); 111 Reduction r = Reduce(Parameter(Type::NewConstant(null, zone())));
112 ASSERT_TRUE(r.Changed()); 112 ASSERT_TRUE(r.Changed());
113 EXPECT_THAT(r.replacement(), IsHeapConstant(null)); 113 EXPECT_THAT(r.replacement(), IsHeapConstant(null));
114 } 114 }
115 { 115 {
116 Reduction r = Reduce(Parameter(Type::Null())); 116 Reduction r = Reduce(Parameter(Type::Null()));
117 ASSERT_TRUE(r.Changed()); 117 ASSERT_TRUE(r.Changed());
118 EXPECT_THAT(r.replacement(), IsHeapConstant(null)); 118 EXPECT_THAT(r.replacement(), IsHeapConstant(null));
119 } 119 }
120 } 120 }
121 121
122 TEST_F(TypedOptimizationTest, ParameterWithNaN) { 122 TEST_F(TypedOptimizationTest, ParameterWithNaN) {
123 const double kNaNs[] = {-std::numeric_limits<double>::quiet_NaN(), 123 const double kNaNs[] = {-std::numeric_limits<double>::quiet_NaN(),
124 std::numeric_limits<double>::quiet_NaN(), 124 std::numeric_limits<double>::quiet_NaN(),
125 std::numeric_limits<double>::signaling_NaN()}; 125 std::numeric_limits<double>::signaling_NaN()};
126 TRACED_FOREACH(double, nan, kNaNs) { 126 TRACED_FOREACH(double, nan, kNaNs) {
127 Handle<Object> constant = factory()->NewNumber(nan); 127 Handle<Object> constant = factory()->NewNumber(nan);
128 Reduction r = Reduce(Parameter(Type::Constant(constant, zone()))); 128 Reduction r = Reduce(Parameter(Type::NewConstant(constant, zone())));
129 ASSERT_TRUE(r.Changed()); 129 ASSERT_TRUE(r.Changed());
130 EXPECT_THAT(r.replacement(), IsNumberConstant(IsNaN())); 130 EXPECT_THAT(r.replacement(), IsNumberConstant(IsNaN()));
131 } 131 }
132 { 132 {
133 Reduction r = 133 Reduction r =
134 Reduce(Parameter(Type::Constant(factory()->nan_value(), zone()))); 134 Reduce(Parameter(Type::NewConstant(factory()->nan_value(), zone())));
135 ASSERT_TRUE(r.Changed()); 135 ASSERT_TRUE(r.Changed());
136 EXPECT_THAT(r.replacement(), IsNumberConstant(IsNaN())); 136 EXPECT_THAT(r.replacement(), IsNumberConstant(IsNaN()));
137 } 137 }
138 { 138 {
139 Reduction r = Reduce(Parameter(Type::NaN())); 139 Reduction r = Reduce(Parameter(Type::NaN()));
140 ASSERT_TRUE(r.Changed()); 140 ASSERT_TRUE(r.Changed());
141 EXPECT_THAT(r.replacement(), IsNumberConstant(IsNaN())); 141 EXPECT_THAT(r.replacement(), IsNumberConstant(IsNaN()));
142 } 142 }
143 } 143 }
144 144
145 TEST_F(TypedOptimizationTest, ParameterWithPlainNumber) { 145 TEST_F(TypedOptimizationTest, ParameterWithPlainNumber) {
146 TRACED_FOREACH(double, value, kFloat64Values) { 146 TRACED_FOREACH(double, value, kFloat64Values) {
147 Handle<Object> constant = factory()->NewNumber(value); 147 Handle<Object> constant = factory()->NewNumber(value);
148 Reduction r = Reduce(Parameter(Type::Constant(constant, zone()))); 148 Reduction r = Reduce(Parameter(Type::NewConstant(constant, zone())));
149 ASSERT_TRUE(r.Changed()); 149 ASSERT_TRUE(r.Changed());
150 EXPECT_THAT(r.replacement(), IsNumberConstant(value)); 150 EXPECT_THAT(r.replacement(), IsNumberConstant(value));
151 } 151 }
152 TRACED_FOREACH(double, value, kIntegerValues) { 152 TRACED_FOREACH(double, value, kIntegerValues) {
153 Reduction r = Reduce(Parameter(Type::Range(value, value, zone()))); 153 Reduction r = Reduce(Parameter(Type::Range(value, value, zone())));
154 ASSERT_TRUE(r.Changed()); 154 ASSERT_TRUE(r.Changed());
155 EXPECT_THAT(r.replacement(), IsNumberConstant(value)); 155 EXPECT_THAT(r.replacement(), IsNumberConstant(value));
156 } 156 }
157 } 157 }
158 158
159 TEST_F(TypedOptimizationTest, ParameterWithUndefined) { 159 TEST_F(TypedOptimizationTest, ParameterWithUndefined) {
160 Handle<HeapObject> undefined = factory()->undefined_value(); 160 Handle<HeapObject> undefined = factory()->undefined_value();
161 { 161 {
162 Reduction r = Reduce(Parameter(Type::Undefined())); 162 Reduction r = Reduce(Parameter(Type::Undefined()));
163 ASSERT_TRUE(r.Changed()); 163 ASSERT_TRUE(r.Changed());
164 EXPECT_THAT(r.replacement(), IsHeapConstant(undefined)); 164 EXPECT_THAT(r.replacement(), IsHeapConstant(undefined));
165 } 165 }
166 { 166 {
167 Reduction r = Reduce(Parameter(Type::Constant(undefined, zone()))); 167 Reduction r = Reduce(Parameter(Type::NewConstant(undefined, zone())));
168 ASSERT_TRUE(r.Changed()); 168 ASSERT_TRUE(r.Changed());
169 EXPECT_THAT(r.replacement(), IsHeapConstant(undefined)); 169 EXPECT_THAT(r.replacement(), IsHeapConstant(undefined));
170 } 170 }
171 } 171 }
172 172
173 TEST_F(TypedOptimizationTest, JSToBooleanWithFalsish) { 173 TEST_F(TypedOptimizationTest, JSToBooleanWithFalsish) {
174 Node* input = Parameter( 174 Node* input = Parameter(
175 Type::Union( 175 Type::Union(
176 Type::MinusZero(), 176 Type::MinusZero(),
177 Type::Union( 177 Type::Union(
178 Type::NaN(), 178 Type::NaN(),
179 Type::Union( 179 Type::Union(
180 Type::Null(), 180 Type::Null(),
181 Type::Union( 181 Type::Union(
182 Type::Undefined(), 182 Type::Undefined(),
183 Type::Union( 183 Type::Union(
184 Type::Undetectable(), 184 Type::Undetectable(),
185 Type::Union( 185 Type::Union(Type::NewConstant(
186 Type::Constant(factory()->false_value(), zone()), 186 factory()->false_value(), zone()),
187 Type::Range(0.0, 0.0, zone()), zone()), 187 Type::Range(0.0, 0.0, zone()), zone()),
188 zone()), 188 zone()),
189 zone()), 189 zone()),
190 zone()), 190 zone()),
191 zone()), 191 zone()),
192 zone()), 192 zone()),
193 0); 193 0);
194 Node* context = Parameter(Type::Any(), 1); 194 Node* context = Parameter(Type::Any(), 1);
195 Reduction r = Reduce(graph()->NewNode( 195 Reduction r = Reduce(graph()->NewNode(
196 javascript()->ToBoolean(ToBooleanHint::kAny), input, context)); 196 javascript()->ToBoolean(ToBooleanHint::kAny), input, context));
197 ASSERT_TRUE(r.Changed()); 197 ASSERT_TRUE(r.Changed());
198 EXPECT_THAT(r.replacement(), IsFalseConstant()); 198 EXPECT_THAT(r.replacement(), IsFalseConstant());
199 } 199 }
200 200
201 TEST_F(TypedOptimizationTest, JSToBooleanWithTruish) { 201 TEST_F(TypedOptimizationTest, JSToBooleanWithTruish) {
202 Node* input = Parameter( 202 Node* input = Parameter(
203 Type::Union( 203 Type::Union(
204 Type::Constant(factory()->true_value(), zone()), 204 Type::NewConstant(factory()->true_value(), zone()),
205 Type::Union(Type::DetectableReceiver(), Type::Symbol(), zone()), 205 Type::Union(Type::DetectableReceiver(), Type::Symbol(), zone()),
206 zone()), 206 zone()),
207 0); 207 0);
208 Node* context = Parameter(Type::Any(), 1); 208 Node* context = Parameter(Type::Any(), 1);
209 Reduction r = Reduce(graph()->NewNode( 209 Reduction r = Reduce(graph()->NewNode(
210 javascript()->ToBoolean(ToBooleanHint::kAny), input, context)); 210 javascript()->ToBoolean(ToBooleanHint::kAny), input, context));
211 ASSERT_TRUE(r.Changed()); 211 ASSERT_TRUE(r.Changed());
212 EXPECT_THAT(r.replacement(), IsTrueConstant()); 212 EXPECT_THAT(r.replacement(), IsTrueConstant());
213 } 213 }
214 214
215 TEST_F(TypedOptimizationTest, JSToBooleanWithNonZeroPlainNumber) { 215 TEST_F(TypedOptimizationTest, JSToBooleanWithNonZeroPlainNumber) {
216 Node* input = Parameter(Type::Range(1, V8_INFINITY, zone()), 0); 216 Node* input = Parameter(Type::Range(1, V8_INFINITY, zone()), 0);
217 Node* context = Parameter(Type::Any(), 1); 217 Node* context = Parameter(Type::Any(), 1);
218 Reduction r = Reduce(graph()->NewNode( 218 Reduction r = Reduce(graph()->NewNode(
219 javascript()->ToBoolean(ToBooleanHint::kAny), input, context)); 219 javascript()->ToBoolean(ToBooleanHint::kAny), input, context));
220 ASSERT_TRUE(r.Changed()); 220 ASSERT_TRUE(r.Changed());
221 EXPECT_THAT(r.replacement(), IsTrueConstant()); 221 EXPECT_THAT(r.replacement(), IsTrueConstant());
222 } 222 }
223 223
224 } // namespace compiler 224 } // namespace compiler
225 } // namespace internal 225 } // namespace internal
226 } // namespace v8 226 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/compiler/js-create-lowering-unittest.cc ('k') | test/unittests/compiler/typer-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698