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

Side by Side Diff: test/unittests/compiler/machine-operator-reducer-unittest.cc

Issue 1225993002: [turbofan] Add TruncationMode for TruncateFloat64ToInt32. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 5 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 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/base/bits.h" 5 #include "src/base/bits.h"
6 #include "src/base/division-by-constant.h" 6 #include "src/base/division-by-constant.h"
7 #include "src/compiler/js-graph.h" 7 #include "src/compiler/js-graph.h"
8 #include "src/compiler/machine-operator-reducer.h" 8 #include "src/compiler/machine-operator-reducer.h"
9 #include "src/compiler/typer.h" 9 #include "src/compiler/typer.h"
10 #include "test/unittests/compiler/graph-unittest.h" 10 #include "test/unittests/compiler/graph-unittest.h"
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 0x00000000, 0x00000001, 0xffffffff, 0x1b09788b, 0x04c5fce8, 0xcc0de5bf, 227 0x00000000, 0x00000001, 0xffffffff, 0x1b09788b, 0x04c5fce8, 0xcc0de5bf,
228 0x273a798e, 0x187937a3, 0xece3af83, 0x5495a16b, 0x0b668ecc, 0x11223344, 228 0x273a798e, 0x187937a3, 0xece3af83, 0x5495a16b, 0x0b668ecc, 0x11223344,
229 0x0000009e, 0x00000043, 0x0000af73, 0x0000116b, 0x00658ecc, 0x002b3b4c, 229 0x0000009e, 0x00000043, 0x0000af73, 0x0000116b, 0x00658ecc, 0x002b3b4c,
230 0x88776655, 0x70000000, 0x07200000, 0x7fffffff, 0x56123761, 0x7fffff00, 230 0x88776655, 0x70000000, 0x07200000, 0x7fffffff, 0x56123761, 0x7fffff00,
231 0x761c4761, 0x80000000, 0x88888888, 0xa0000000, 0xdddddddd, 0xe0000000, 231 0x761c4761, 0x80000000, 0x88888888, 0xa0000000, 0xdddddddd, 0xe0000000,
232 0xeeeeeeee, 0xfffffffd, 0xf0000000, 0x007fffff, 0x003fffff, 0x001fffff, 232 0xeeeeeeee, 0xfffffffd, 0xf0000000, 0x007fffff, 0x003fffff, 0x001fffff,
233 0x000fffff, 0x0007ffff, 0x0003ffff, 0x0001ffff, 0x0000ffff, 0x00007fff, 233 0x000fffff, 0x0007ffff, 0x0003ffff, 0x0001ffff, 0x0000ffff, 0x00007fff,
234 0x00003fff, 0x00001fff, 0x00000fff, 0x000007ff, 0x000003ff, 0x000001ff}; 234 0x00003fff, 0x00001fff, 0x00000fff, 0x000007ff, 0x000003ff, 0x000001ff};
235 235
236 236
237 const TruncationMode kTruncationModes[] = {TruncationMode::kJavaScript,
238 TruncationMode::kRoundToZero};
239
240
237 struct ComparisonBinaryOperator { 241 struct ComparisonBinaryOperator {
238 const Operator* (MachineOperatorBuilder::*constructor)(); 242 const Operator* (MachineOperatorBuilder::*constructor)();
239 const char* constructor_name; 243 const char* constructor_name;
240 }; 244 };
241 245
242 246
243 std::ostream& operator<<(std::ostream& os, 247 std::ostream& operator<<(std::ostream& os,
244 ComparisonBinaryOperator const& cbop) { 248 ComparisonBinaryOperator const& cbop) {
245 return os << cbop.constructor_name; 249 return os << cbop.constructor_name;
246 } 250 }
247 251
248 252
249 const ComparisonBinaryOperator kComparisonBinaryOperators[] = { 253 const ComparisonBinaryOperator kComparisonBinaryOperators[] = {
250 #define OPCODE(Opcode) \ 254 #define OPCODE(Opcode) \
251 { &MachineOperatorBuilder::Opcode, #Opcode } \ 255 { &MachineOperatorBuilder::Opcode, #Opcode } \
252 , 256 ,
253 MACHINE_COMPARE_BINOP_LIST(OPCODE) 257 MACHINE_COMPARE_BINOP_LIST(OPCODE)
254 #undef OPCODE 258 #undef OPCODE
255 }; 259 };
256 260
257 } // namespace 261 } // namespace
258 262
259 263
260 // ----------------------------------------------------------------------------- 264 // -----------------------------------------------------------------------------
261 // Unary operators
262
263
264 namespace {
265
266 struct UnaryOperator {
267 const Operator* (MachineOperatorBuilder::*constructor)();
268 const char* constructor_name;
269 };
270
271
272 std::ostream& operator<<(std::ostream& os, const UnaryOperator& unop) {
273 return os << unop.constructor_name;
274 }
275
276
277 static const UnaryOperator kUnaryOperators[] = {
278 {&MachineOperatorBuilder::ChangeInt32ToFloat64, "ChangeInt32ToFloat64"},
279 {&MachineOperatorBuilder::ChangeUint32ToFloat64, "ChangeUint32ToFloat64"},
280 {&MachineOperatorBuilder::ChangeFloat64ToInt32, "ChangeFloat64ToInt32"},
281 {&MachineOperatorBuilder::ChangeFloat64ToUint32, "ChangeFloat64ToUint32"},
282 {&MachineOperatorBuilder::ChangeInt32ToInt64, "ChangeInt32ToInt64"},
283 {&MachineOperatorBuilder::ChangeUint32ToUint64, "ChangeUint32ToUint64"},
284 {&MachineOperatorBuilder::TruncateFloat64ToInt32, "TruncateFloat64ToInt32"},
285 {&MachineOperatorBuilder::TruncateInt64ToInt32, "TruncateInt64ToInt32"}};
286
287 } // namespace
288
289
290 typedef MachineOperatorReducerTestWithParam<UnaryOperator>
291 MachineUnaryOperatorReducerTest;
292
293
294 TEST_P(MachineUnaryOperatorReducerTest, Parameter) {
295 const UnaryOperator unop = GetParam();
296 Reduction reduction =
297 Reduce(graph()->NewNode((machine()->*unop.constructor)(), Parameter(0)));
298 EXPECT_FALSE(reduction.Changed());
299 }
300
301
302 INSTANTIATE_TEST_CASE_P(MachineOperatorReducerTest,
303 MachineUnaryOperatorReducerTest,
304 ::testing::ValuesIn(kUnaryOperators));
305
306
307 // -----------------------------------------------------------------------------
308 // ChangeFloat64ToFloat32 265 // ChangeFloat64ToFloat32
309 266
310 267
311 TEST_F(MachineOperatorReducerTest, ChangeFloat64ToFloat32WithConstant) { 268 TEST_F(MachineOperatorReducerTest, ChangeFloat64ToFloat32WithConstant) {
312 TRACED_FOREACH(float, x, kFloat32Values) { 269 TRACED_FOREACH(float, x, kFloat32Values) {
313 Reduction reduction = Reduce(graph()->NewNode( 270 Reduction reduction = Reduce(graph()->NewNode(
314 machine()->ChangeFloat32ToFloat64(), Float32Constant(x))); 271 machine()->ChangeFloat32ToFloat64(), Float32Constant(x)));
315 ASSERT_TRUE(reduction.Changed()); 272 ASSERT_TRUE(reduction.Changed());
316 EXPECT_THAT(reduction.replacement(), IsFloat64Constant(BitEq<double>(x))); 273 EXPECT_THAT(reduction.replacement(), IsFloat64Constant(BitEq<double>(x)));
317 } 274 }
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 } 409 }
453 } 410 }
454 411
455 412
456 // ----------------------------------------------------------------------------- 413 // -----------------------------------------------------------------------------
457 // TruncateFloat64ToInt32 414 // TruncateFloat64ToInt32
458 415
459 416
460 TEST_F(MachineOperatorReducerTest, 417 TEST_F(MachineOperatorReducerTest,
461 TruncateFloat64ToInt32WithChangeInt32ToFloat64) { 418 TruncateFloat64ToInt32WithChangeInt32ToFloat64) {
462 Node* value = Parameter(0); 419 TRACED_FOREACH(TruncationMode, mode, kTruncationModes) {
463 Reduction reduction = Reduce(graph()->NewNode( 420 Node* value = Parameter(0);
464 machine()->TruncateFloat64ToInt32(), 421 Reduction reduction = Reduce(graph()->NewNode(
465 graph()->NewNode(machine()->ChangeInt32ToFloat64(), value))); 422 machine()->TruncateFloat64ToInt32(mode),
466 ASSERT_TRUE(reduction.Changed()); 423 graph()->NewNode(machine()->ChangeInt32ToFloat64(), value)));
467 EXPECT_EQ(value, reduction.replacement()); 424 ASSERT_TRUE(reduction.Changed());
425 EXPECT_EQ(value, reduction.replacement());
426 }
468 } 427 }
469 428
470 429
471 TEST_F(MachineOperatorReducerTest, TruncateFloat64ToInt32WithConstant) { 430 TEST_F(MachineOperatorReducerTest, TruncateFloat64ToInt32WithConstant) {
472 TRACED_FOREACH(double, x, kFloat64Values) { 431 TRACED_FOREACH(double, x, kFloat64Values) {
473 Reduction reduction = Reduce(graph()->NewNode( 432 Reduction reduction = Reduce(graph()->NewNode(
474 machine()->TruncateFloat64ToInt32(), Float64Constant(x))); 433 machine()->TruncateFloat64ToInt32(TruncationMode::kJavaScript),
434 Float64Constant(x)));
475 ASSERT_TRUE(reduction.Changed()); 435 ASSERT_TRUE(reduction.Changed());
476 EXPECT_THAT(reduction.replacement(), IsInt32Constant(DoubleToInt32(x))); 436 EXPECT_THAT(reduction.replacement(), IsInt32Constant(DoubleToInt32(x)));
477 } 437 }
478 } 438 }
479 439
480 440
481 TEST_F(MachineOperatorReducerTest, TruncateFloat64ToInt32WithPhi) { 441 TEST_F(MachineOperatorReducerTest, TruncateFloat64ToInt32WithPhi) {
482 Node* const p0 = Parameter(0); 442 Node* const p0 = Parameter(0);
483 Node* const p1 = Parameter(1); 443 Node* const p1 = Parameter(1);
484 Node* const merge = graph()->start(); 444 Node* const merge = graph()->start();
485 Reduction reduction = Reduce(graph()->NewNode( 445 TRACED_FOREACH(TruncationMode, mode, kTruncationModes) {
486 machine()->TruncateFloat64ToInt32(), 446 Reduction reduction = Reduce(graph()->NewNode(
487 graph()->NewNode(common()->Phi(kMachFloat64, 2), p0, p1, merge))); 447 machine()->TruncateFloat64ToInt32(mode),
488 ASSERT_TRUE(reduction.Changed()); 448 graph()->NewNode(common()->Phi(kMachFloat64, 2), p0, p1, merge)));
489 EXPECT_THAT(reduction.replacement(), 449 ASSERT_TRUE(reduction.Changed());
490 IsPhi(kMachInt32, IsTruncateFloat64ToInt32(p0), 450 EXPECT_THAT(reduction.replacement(),
491 IsTruncateFloat64ToInt32(p1), merge)); 451 IsPhi(kMachInt32, IsTruncateFloat64ToInt32(p0),
452 IsTruncateFloat64ToInt32(p1), merge));
453 }
492 } 454 }
493 455
494 456
495 // ----------------------------------------------------------------------------- 457 // -----------------------------------------------------------------------------
496 // TruncateInt64ToInt32 458 // TruncateInt64ToInt32
497 459
498 460
499 TEST_F(MachineOperatorReducerTest, TruncateInt64ToInt32WithChangeInt32ToInt64) { 461 TEST_F(MachineOperatorReducerTest, TruncateInt64ToInt32WithChangeInt32ToInt64) {
500 Node* value = Parameter(0); 462 Node* value = Parameter(0);
501 Reduction reduction = Reduce(graph()->NewNode( 463 Reduction reduction = Reduce(graph()->NewNode(
(...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after
1566 Reduction r = Reduce(node); 1528 Reduction r = Reduce(node);
1567 ASSERT_TRUE(r.Changed()); 1529 ASSERT_TRUE(r.Changed());
1568 EXPECT_THAT(r.replacement(), 1530 EXPECT_THAT(r.replacement(),
1569 IsStore(rep, base, index, value, effect, control)); 1531 IsStore(rep, base, index, value, effect, control));
1570 } 1532 }
1571 } 1533 }
1572 1534
1573 } // namespace compiler 1535 } // namespace compiler
1574 } // namespace internal 1536 } // namespace internal
1575 } // namespace v8 1537 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/compiler/instruction-selector-unittest.cc ('k') | test/unittests/compiler/machine-operator-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698