blob: c713815466d892d487b1976991af201e8ce8fadf [file] [log] [blame]
Emily Bernier958fae72015-03-24 16:35:39 -04001// 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
3// found in the LICENSE file.
4
5#include "src/compiler/common-operator.h"
6#include "src/compiler/common-operator-reducer.h"
7#include "src/compiler/machine-type.h"
8#include "test/unittests/compiler/graph-unittest.h"
9
10namespace v8 {
11namespace internal {
12namespace compiler {
13
14class CommonOperatorReducerTest : public GraphTest {
15 public:
16 explicit CommonOperatorReducerTest(int num_parameters = 1)
17 : GraphTest(num_parameters) {}
18 ~CommonOperatorReducerTest() OVERRIDE {}
19
20 protected:
21 Reduction Reduce(Node* node) {
22 CommonOperatorReducer reducer;
23 return reducer.Reduce(node);
24 }
25};
26
27
28namespace {
29
30const BranchHint kBranchHints[] = {BranchHint::kNone, BranchHint::kFalse,
31 BranchHint::kTrue};
32
33
34const MachineType kMachineTypes[] = {
35 kMachFloat32, kMachFloat64, kMachInt8, kMachUint8, kMachInt16,
36 kMachUint16, kMachInt32, kMachUint32, kMachInt64, kMachUint64,
37 kMachPtr, kMachAnyTagged, kRepBit, kRepWord8, kRepWord16,
38 kRepWord32, kRepWord64, kRepFloat32, kRepFloat64, kRepTagged};
39
40
41const Operator kOp0(0, Operator::kNoProperties, "Op0", 0, 0, 0, 1, 1, 0);
42
43} // namespace
44
45
46// -----------------------------------------------------------------------------
47// EffectPhi
48
49
50TEST_F(CommonOperatorReducerTest, RedundantEffectPhi) {
51 const int kMaxInputs = 64;
52 Node* inputs[kMaxInputs];
53 Node* const input = graph()->NewNode(&kOp0);
54 TRACED_FORRANGE(int, input_count, 2, kMaxInputs - 1) {
55 int const value_input_count = input_count - 1;
56 for (int i = 0; i < value_input_count; ++i) {
57 inputs[i] = input;
58 }
59 inputs[value_input_count] = graph()->start();
60 Reduction r = Reduce(graph()->NewNode(
61 common()->EffectPhi(value_input_count), input_count, inputs));
62 ASSERT_TRUE(r.Changed());
63 EXPECT_EQ(input, r.replacement());
64 }
65}
66
67
68// -----------------------------------------------------------------------------
69// Phi
70
71
72TEST_F(CommonOperatorReducerTest, RedundantPhi) {
73 const int kMaxInputs = 64;
74 Node* inputs[kMaxInputs];
75 Node* const input = graph()->NewNode(&kOp0);
76 TRACED_FORRANGE(int, input_count, 2, kMaxInputs - 1) {
77 int const value_input_count = input_count - 1;
78 TRACED_FOREACH(MachineType, type, kMachineTypes) {
79 for (int i = 0; i < value_input_count; ++i) {
80 inputs[i] = input;
81 }
82 inputs[value_input_count] = graph()->start();
83 Reduction r = Reduce(graph()->NewNode(
84 common()->Phi(type, value_input_count), input_count, inputs));
85 ASSERT_TRUE(r.Changed());
86 EXPECT_EQ(input, r.replacement());
87 }
88 }
89}
90
91
92// -----------------------------------------------------------------------------
93// Select
94
95
96TEST_F(CommonOperatorReducerTest, RedundantSelect) {
97 Node* const input = graph()->NewNode(&kOp0);
98 TRACED_FOREACH(BranchHint, hint, kBranchHints) {
99 TRACED_FOREACH(MachineType, type, kMachineTypes) {
100 Reduction r = Reduce(
101 graph()->NewNode(common()->Select(type, hint), input, input, input));
102 ASSERT_TRUE(r.Changed());
103 EXPECT_EQ(input, r.replacement());
104 }
105 }
106}
107
108} // namespace compiler
109} // namespace internal
110} // namespace v8