OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "src/compiler/binary-operator-reducer.h" | |
6 #include "src/compiler/common-operator.h" | |
7 #include "src/compiler/machine-operator.h" | |
8 #include "src/compiler/machine-type.h" | |
9 #include "src/compiler/node-properties.h" | |
10 #include "src/compiler/operator.h" | |
11 #include "src/compiler/simplified-operator.h" | |
12 #include "src/types-inl.h" | |
13 #include "test/unittests/compiler/graph-reducer-unittest.h" | |
14 #include "test/unittests/compiler/graph-unittest.h" | |
15 #include "test/unittests/compiler/node-test-utils.h" | |
16 | |
17 using testing::StrictMock; | |
18 | |
19 namespace v8 { | |
20 namespace internal { | |
21 namespace compiler { | |
22 | |
23 class BinaryOperatorReducerTest : public TypedGraphTest { | |
24 public: | |
25 explicit BinaryOperatorReducerTest(int num_parameters = 1) | |
26 : TypedGraphTest(num_parameters), machine_(zone()), simplified_(zone()) {} | |
27 ~BinaryOperatorReducerTest() override {} | |
28 | |
29 protected: | |
30 Reduction Reduce(AdvancedReducer::Editor* editor, Node* node) { | |
31 BinaryOperatorReducer reducer(editor, graph(), common(), machine()); | |
32 return reducer.Reduce(node); | |
33 } | |
34 | |
35 Reduction Reduce(Node* node) { | |
36 StrictMock<MockAdvancedReducerEditor> editor; | |
37 return Reduce(&editor, node); | |
38 } | |
39 | |
40 MachineOperatorBuilder* machine() { return &machine_; } | |
41 SimplifiedOperatorBuilder* simplified() { return &simplified_; } | |
42 | |
43 private: | |
44 MachineOperatorBuilder machine_; | |
45 SimplifiedOperatorBuilder simplified_; | |
46 }; | |
47 | |
48 | |
49 TEST_F(BinaryOperatorReducerTest, Div52OfMul52) { | |
50 // This reduction applies only to 64bit arch | |
51 if (!machine()->Is64()) return; | |
52 | |
53 Node* p0 = Parameter(0); | |
54 Node* p1 = Parameter(1); | |
55 Node* t0 = graph()->NewNode(machine()->ChangeInt32ToFloat64(), p0); | |
56 Node* t1 = graph()->NewNode(machine()->ChangeInt32ToFloat64(), p1); | |
57 | |
58 Type* mul_range = Type::Range(0x0, 0xFFFFFFFFFFFFFULL, graph()->zone()); | |
59 Node* mul = graph()->NewNode(machine()->Float64Mul(), t0, t1); | |
60 NodeProperties::SetType( | |
61 mul, Type::Intersect(mul_range, Type::Number(), graph()->zone())); | |
62 | |
63 Node* mul_replacement; | |
64 auto mul_matcher = IsInt64Mul(p0, p1); | |
65 { | |
66 StrictMock<MockAdvancedReducerEditor> editor; | |
67 | |
68 EXPECT_CALL(editor, Revisit(mul_matcher)); | |
69 | |
70 Reduction r = Reduce(&editor, mul); | |
71 ASSERT_TRUE(r.Changed()); | |
72 mul_replacement = r.replacement(); | |
73 EXPECT_THAT(mul_replacement, IsRoundInt64ToFloat64(mul_matcher)); | |
74 } | |
75 | |
76 { | |
77 StrictMock<MockAdvancedReducerEditor> editor; | |
78 | |
79 Node* power = Float64Constant(0x4000000); | |
80 Node* div = | |
81 graph()->NewNode(machine()->Float64Div(), mul_replacement, power); | |
82 | |
83 auto shr_matcher = IsWord64Shr(mul_matcher, IsInt64Constant(26)); | |
84 EXPECT_CALL(editor, Revisit(shr_matcher)); | |
85 | |
86 Reduction r = Reduce(&editor, div); | |
87 ASSERT_TRUE(r.Changed()); | |
88 EXPECT_THAT(r.replacement(), IsRoundInt64ToFloat64(shr_matcher)); | |
89 } | |
90 } | |
91 | |
92 } // namespace compiler | |
93 } // namespace internal | |
94 } // namespace v8 | |
OLD | NEW |