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

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

Issue 555833002: [turbofan] Add support for overflow add/sub to the MachineOperatorReducer. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address nit. 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/machine-operator-reducer.cc ('k') | test/cctest/compiler/test-run-machops.cc » ('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/base/bits.h" 5 #include "src/base/bits.h"
6 #include "src/compiler/graph-unittest.h" 6 #include "src/compiler/graph-unittest.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 10
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 Node* node = graph()->NewNode(machine()->Word32Ror(), Int32Constant(x), 435 Node* node = graph()->NewNode(machine()->Word32Ror(), Int32Constant(x),
436 Int32Constant(y)); 436 Int32Constant(y));
437 Reduction reduction = Reduce(node); 437 Reduction reduction = Reduce(node);
438 EXPECT_TRUE(reduction.Changed()); 438 EXPECT_TRUE(reduction.Changed());
439 EXPECT_THAT(reduction.replacement(), 439 EXPECT_THAT(reduction.replacement(),
440 IsInt32Constant(base::bits::RotateRight32(x, y))); 440 IsInt32Constant(base::bits::RotateRight32(x, y)));
441 } 441 }
442 } 442 }
443 } 443 }
444 444
445
446 // -----------------------------------------------------------------------------
447 // Int32AddWithOverflow
448
449
450 TEST_F(MachineOperatorReducerTest, Int32AddWithOverflowWithZero) {
451 Node* p0 = Parameter(0);
452 {
453 Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(),
454 Int32Constant(0), p0);
455
456 Reduction r = Reduce(graph()->NewNode(common()->Projection(1), add));
457 ASSERT_TRUE(r.Changed());
458 EXPECT_THAT(r.replacement(), IsInt32Constant(0));
459
460 r = Reduce(graph()->NewNode(common()->Projection(0), add));
461 ASSERT_TRUE(r.Changed());
462 EXPECT_EQ(p0, r.replacement());
463 }
464 {
465 Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(), p0,
466 Int32Constant(0));
467
468 Reduction r = Reduce(graph()->NewNode(common()->Projection(1), add));
469 ASSERT_TRUE(r.Changed());
470 EXPECT_THAT(r.replacement(), IsInt32Constant(0));
471
472 r = Reduce(graph()->NewNode(common()->Projection(0), add));
473 ASSERT_TRUE(r.Changed());
474 EXPECT_EQ(p0, r.replacement());
475 }
476 }
477
478
479 TEST_F(MachineOperatorReducerTest, Int32AddWithOverflowWithConstant) {
480 TRACED_FOREACH(int32_t, x, kInt32Values) {
481 TRACED_FOREACH(int32_t, y, kInt32Values) {
482 int32_t z;
483 Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(),
484 Int32Constant(x), Int32Constant(y));
485
486 Reduction r = Reduce(graph()->NewNode(common()->Projection(1), add));
487 ASSERT_TRUE(r.Changed());
488 EXPECT_THAT(r.replacement(),
489 IsInt32Constant(base::bits::SignedAddOverflow32(x, y, &z)));
490
491 r = Reduce(graph()->NewNode(common()->Projection(0), add));
492 ASSERT_TRUE(r.Changed());
493 EXPECT_THAT(r.replacement(), IsInt32Constant(z));
494 }
495 }
496 }
497
498
499 // -----------------------------------------------------------------------------
500 // Int32SubWithOverflow
501
502
503 TEST_F(MachineOperatorReducerTest, Int32SubWithOverflowWithZero) {
504 Node* p0 = Parameter(0);
505 Node* add =
506 graph()->NewNode(machine()->Int32SubWithOverflow(), p0, Int32Constant(0));
507
508 Reduction r = Reduce(graph()->NewNode(common()->Projection(1), add));
509 ASSERT_TRUE(r.Changed());
510 EXPECT_THAT(r.replacement(), IsInt32Constant(0));
511
512 r = Reduce(graph()->NewNode(common()->Projection(0), add));
513 ASSERT_TRUE(r.Changed());
514 EXPECT_EQ(p0, r.replacement());
515 }
516
517
518 TEST_F(MachineOperatorReducerTest, Int32SubWithOverflowWithConstant) {
519 TRACED_FOREACH(int32_t, x, kInt32Values) {
520 TRACED_FOREACH(int32_t, y, kInt32Values) {
521 int32_t z;
522 Node* add = graph()->NewNode(machine()->Int32SubWithOverflow(),
523 Int32Constant(x), Int32Constant(y));
524
525 Reduction r = Reduce(graph()->NewNode(common()->Projection(1), add));
526 ASSERT_TRUE(r.Changed());
527 EXPECT_THAT(r.replacement(),
528 IsInt32Constant(base::bits::SignedSubOverflow32(x, y, &z)));
529
530 r = Reduce(graph()->NewNode(common()->Projection(0), add));
531 ASSERT_TRUE(r.Changed());
532 EXPECT_THAT(r.replacement(), IsInt32Constant(z));
533 }
534 }
535 }
536
445 } // namespace compiler 537 } // namespace compiler
446 } // namespace internal 538 } // namespace internal
447 } // namespace v8 539 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/machine-operator-reducer.cc ('k') | test/cctest/compiler/test-run-machops.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698