OLD | NEW |
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/compiler/common-operator-reducer.h" | 5 #include "src/compiler/common-operator-reducer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "src/compiler/common-operator.h" | 9 #include "src/compiler/common-operator.h" |
10 #include "src/compiler/js-graph.h" | 10 #include "src/compiler/js-graph.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 DCHECK_EQ(IrOpcode::kPhi, node->opcode()); | 48 DCHECK_EQ(IrOpcode::kPhi, node->opcode()); |
49 int const input_count = node->InputCount(); | 49 int const input_count = node->InputCount(); |
50 if (input_count == 3) { | 50 if (input_count == 3) { |
51 Node* vtrue = NodeProperties::GetValueInput(node, 0); | 51 Node* vtrue = NodeProperties::GetValueInput(node, 0); |
52 Node* vfalse = NodeProperties::GetValueInput(node, 1); | 52 Node* vfalse = NodeProperties::GetValueInput(node, 1); |
53 Node* merge = NodeProperties::GetControlInput(node); | 53 Node* merge = NodeProperties::GetControlInput(node); |
54 DiamondMatcher matcher(merge); | 54 DiamondMatcher matcher(merge); |
55 if (matcher.Matched()) { | 55 if (matcher.Matched()) { |
56 if (matcher.IfTrue() == merge->InputAt(1)) std::swap(vtrue, vfalse); | 56 if (matcher.IfTrue() == merge->InputAt(1)) std::swap(vtrue, vfalse); |
57 Node* cond = matcher.Branch()->InputAt(0); | 57 Node* cond = matcher.Branch()->InputAt(0); |
58 if (cond->opcode() == IrOpcode::kFloat64LessThan) { | 58 if (cond->opcode() == IrOpcode::kFloat32LessThan) { |
59 if (cond->InputAt(0) == vtrue && cond->InputAt(1) == vfalse && | 59 Float32BinopMatcher mcond(cond); |
| 60 if (mcond.left().Is(0.0) && mcond.right().Equals(vtrue) && |
| 61 vfalse->opcode() == IrOpcode::kFloat32Sub && |
| 62 machine()->HasFloat32Abs()) { |
| 63 Float32BinopMatcher mvfalse(vfalse); |
| 64 if (mvfalse.left().IsZero() && mvfalse.right().Equals(vtrue)) { |
| 65 return Change(node, machine()->Float32Abs(), vtrue); |
| 66 } |
| 67 } |
| 68 if (mcond.left().Equals(vtrue) && mcond.right().Equals(vfalse) && |
| 69 machine()->HasFloat32Min()) { |
| 70 return Change(node, machine()->Float32Min(), vtrue, vfalse); |
| 71 } else if (mcond.left().Equals(vfalse) && mcond.right().Equals(vtrue) && |
| 72 machine()->HasFloat32Max()) { |
| 73 return Change(node, machine()->Float32Max(), vtrue, vfalse); |
| 74 } |
| 75 } else if (cond->opcode() == IrOpcode::kFloat64LessThan) { |
| 76 Float64BinopMatcher mcond(cond); |
| 77 if (mcond.left().Is(0.0) && mcond.right().Equals(vtrue) && |
| 78 vfalse->opcode() == IrOpcode::kFloat64Sub && |
| 79 machine()->HasFloat64Abs()) { |
| 80 Float64BinopMatcher mvfalse(vfalse); |
| 81 if (mvfalse.left().IsZero() && mvfalse.right().Equals(vtrue)) { |
| 82 return Change(node, machine()->Float64Abs(), vtrue); |
| 83 } |
| 84 } |
| 85 if (mcond.left().Equals(vtrue) && mcond.right().Equals(vfalse) && |
60 machine()->HasFloat64Min()) { | 86 machine()->HasFloat64Min()) { |
61 node->set_op(machine()->Float64Min()); | 87 return Change(node, machine()->Float64Min(), vtrue, vfalse); |
62 node->ReplaceInput(0, vtrue); | 88 } else if (mcond.left().Equals(vfalse) && mcond.right().Equals(vtrue) && |
63 node->ReplaceInput(1, vfalse); | |
64 node->TrimInputCount(2); | |
65 return Changed(node); | |
66 } else if (cond->InputAt(0) == vfalse && cond->InputAt(1) == vtrue && | |
67 machine()->HasFloat64Max()) { | 89 machine()->HasFloat64Max()) { |
68 node->set_op(machine()->Float64Max()); | 90 return Change(node, machine()->Float64Max(), vtrue, vfalse); |
69 node->ReplaceInput(0, vtrue); | |
70 node->ReplaceInput(1, vfalse); | |
71 node->TrimInputCount(2); | |
72 return Changed(node); | |
73 } | 91 } |
74 } | 92 } |
75 } | 93 } |
76 } | 94 } |
77 if (input_count > 1) { | 95 if (input_count > 1) { |
78 Node* const replacement = node->InputAt(0); | 96 Node* const replacement = node->InputAt(0); |
79 for (int i = 1; i < input_count - 1; ++i) { | 97 for (int i = 1; i < input_count - 1; ++i) { |
80 if (node->InputAt(i) != replacement) return NoChange(); | 98 if (node->InputAt(i) != replacement) return NoChange(); |
81 } | 99 } |
82 return Replace(replacement); | 100 return Replace(replacement); |
83 } | 101 } |
84 return NoChange(); | 102 return NoChange(); |
85 } | 103 } |
86 | 104 |
87 | 105 |
88 Reduction CommonOperatorReducer::ReduceSelect(Node* node) { | 106 Reduction CommonOperatorReducer::ReduceSelect(Node* node) { |
89 DCHECK_EQ(IrOpcode::kSelect, node->opcode()); | 107 DCHECK_EQ(IrOpcode::kSelect, node->opcode()); |
90 Node* cond = NodeProperties::GetValueInput(node, 0); | 108 Node* cond = NodeProperties::GetValueInput(node, 0); |
91 Node* vtrue = NodeProperties::GetValueInput(node, 1); | 109 Node* vtrue = NodeProperties::GetValueInput(node, 1); |
92 Node* vfalse = NodeProperties::GetValueInput(node, 2); | 110 Node* vfalse = NodeProperties::GetValueInput(node, 2); |
93 if (vtrue == vfalse) return Replace(vtrue); | 111 if (vtrue == vfalse) return Replace(vtrue); |
94 if (cond->opcode() == IrOpcode::kFloat64LessThan) { | 112 if (cond->opcode() == IrOpcode::kFloat32LessThan) { |
95 if (cond->InputAt(0) == vtrue && cond->InputAt(1) == vfalse && | 113 Float32BinopMatcher mcond(cond); |
| 114 if (mcond.left().Is(0.0) && mcond.right().Equals(vtrue) && |
| 115 vfalse->opcode() == IrOpcode::kFloat32Sub && |
| 116 machine()->HasFloat32Abs()) { |
| 117 Float32BinopMatcher mvfalse(vfalse); |
| 118 if (mvfalse.left().IsZero() && mvfalse.right().Equals(vtrue)) { |
| 119 return Change(node, machine()->Float32Abs(), vtrue); |
| 120 } |
| 121 } |
| 122 if (mcond.left().Equals(vtrue) && mcond.right().Equals(vfalse) && |
| 123 machine()->HasFloat32Min()) { |
| 124 return Change(node, machine()->Float32Min(), vtrue, vfalse); |
| 125 } else if (mcond.left().Equals(vfalse) && mcond.right().Equals(vtrue) && |
| 126 machine()->HasFloat32Max()) { |
| 127 return Change(node, machine()->Float32Max(), vtrue, vfalse); |
| 128 } |
| 129 } else if (cond->opcode() == IrOpcode::kFloat64LessThan) { |
| 130 Float64BinopMatcher mcond(cond); |
| 131 if (mcond.left().Is(0.0) && mcond.right().Equals(vtrue) && |
| 132 vfalse->opcode() == IrOpcode::kFloat64Sub && |
| 133 machine()->HasFloat64Abs()) { |
| 134 Float64BinopMatcher mvfalse(vfalse); |
| 135 if (mvfalse.left().IsZero() && mvfalse.right().Equals(vtrue)) { |
| 136 return Change(node, machine()->Float64Abs(), vtrue); |
| 137 } |
| 138 } |
| 139 if (mcond.left().Equals(vtrue) && mcond.right().Equals(vfalse) && |
96 machine()->HasFloat64Min()) { | 140 machine()->HasFloat64Min()) { |
97 node->set_op(machine()->Float64Min()); | 141 return Change(node, machine()->Float64Min(), vtrue, vfalse); |
98 node->ReplaceInput(0, vtrue); | 142 } else if (mcond.left().Equals(vfalse) && mcond.right().Equals(vtrue) && |
99 node->ReplaceInput(1, vfalse); | |
100 node->TrimInputCount(2); | |
101 return Changed(node); | |
102 } else if (cond->InputAt(0) == vfalse && cond->InputAt(1) == vtrue && | |
103 machine()->HasFloat64Max()) { | 143 machine()->HasFloat64Max()) { |
104 node->set_op(machine()->Float64Max()); | 144 return Change(node, machine()->Float64Max(), vtrue, vfalse); |
105 node->ReplaceInput(0, vtrue); | |
106 node->ReplaceInput(1, vfalse); | |
107 node->TrimInputCount(2); | |
108 return Changed(node); | |
109 } | 145 } |
110 } | 146 } |
111 return NoChange(); | 147 return NoChange(); |
112 } | 148 } |
113 | 149 |
114 | 150 |
| 151 Reduction CommonOperatorReducer::Change(Node* node, Operator const* op, |
| 152 Node* a) { |
| 153 node->set_op(op); |
| 154 node->ReplaceInput(0, a); |
| 155 node->TrimInputCount(1); |
| 156 return Changed(node); |
| 157 } |
| 158 |
| 159 |
| 160 Reduction CommonOperatorReducer::Change(Node* node, Operator const* op, Node* a, |
| 161 Node* b) { |
| 162 node->set_op(op); |
| 163 node->ReplaceInput(0, a); |
| 164 node->ReplaceInput(1, b); |
| 165 node->TrimInputCount(2); |
| 166 return Changed(node); |
| 167 } |
| 168 |
| 169 |
115 CommonOperatorBuilder* CommonOperatorReducer::common() const { | 170 CommonOperatorBuilder* CommonOperatorReducer::common() const { |
116 return jsgraph()->common(); | 171 return jsgraph()->common(); |
117 } | 172 } |
118 | 173 |
119 | 174 |
120 Graph* CommonOperatorReducer::graph() const { return jsgraph()->graph(); } | 175 Graph* CommonOperatorReducer::graph() const { return jsgraph()->graph(); } |
121 | 176 |
122 | 177 |
123 MachineOperatorBuilder* CommonOperatorReducer::machine() const { | 178 MachineOperatorBuilder* CommonOperatorReducer::machine() const { |
124 return jsgraph()->machine(); | 179 return jsgraph()->machine(); |
125 } | 180 } |
126 | 181 |
127 } // namespace compiler | 182 } // namespace compiler |
128 } // namespace internal | 183 } // namespace internal |
129 } // namespace v8 | 184 } // namespace v8 |
OLD | NEW |