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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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::kFloat32LessThan) { | 58 if (cond->opcode() == IrOpcode::kFloat32LessThan) { |
59 Float32BinopMatcher mcond(cond); | 59 Float32BinopMatcher mcond(cond); |
60 if (mcond.left().Is(0.0) && mcond.right().Equals(vtrue) && | 60 if (mcond.left().Is(0.0) && mcond.right().Equals(vtrue) && |
61 vfalse->opcode() == IrOpcode::kFloat32Sub && | 61 vfalse->opcode() == IrOpcode::kFloat32Sub) { |
62 machine()->HasFloat32Abs()) { | |
63 Float32BinopMatcher mvfalse(vfalse); | 62 Float32BinopMatcher mvfalse(vfalse); |
64 if (mvfalse.left().IsZero() && mvfalse.right().Equals(vtrue)) { | 63 if (mvfalse.left().IsZero() && mvfalse.right().Equals(vtrue)) { |
65 return Change(node, machine()->Float32Abs(), vtrue); | 64 return Change(node, machine()->Float32Abs(), vtrue); |
66 } | 65 } |
67 } | 66 } |
68 if (mcond.left().Equals(vtrue) && mcond.right().Equals(vfalse) && | 67 if (mcond.left().Equals(vtrue) && mcond.right().Equals(vfalse) && |
69 machine()->HasFloat32Min()) { | 68 machine()->HasFloat32Min()) { |
70 return Change(node, machine()->Float32Min(), vtrue, vfalse); | 69 return Change(node, machine()->Float32Min(), vtrue, vfalse); |
71 } else if (mcond.left().Equals(vfalse) && mcond.right().Equals(vtrue) && | 70 } else if (mcond.left().Equals(vfalse) && mcond.right().Equals(vtrue) && |
72 machine()->HasFloat32Max()) { | 71 machine()->HasFloat32Max()) { |
73 return Change(node, machine()->Float32Max(), vtrue, vfalse); | 72 return Change(node, machine()->Float32Max(), vtrue, vfalse); |
74 } | 73 } |
75 } else if (cond->opcode() == IrOpcode::kFloat64LessThan) { | 74 } else if (cond->opcode() == IrOpcode::kFloat64LessThan) { |
76 Float64BinopMatcher mcond(cond); | 75 Float64BinopMatcher mcond(cond); |
77 if (mcond.left().Is(0.0) && mcond.right().Equals(vtrue) && | 76 if (mcond.left().Is(0.0) && mcond.right().Equals(vtrue) && |
78 vfalse->opcode() == IrOpcode::kFloat64Sub && | 77 vfalse->opcode() == IrOpcode::kFloat64Sub) { |
79 machine()->HasFloat64Abs()) { | |
80 Float64BinopMatcher mvfalse(vfalse); | 78 Float64BinopMatcher mvfalse(vfalse); |
81 if (mvfalse.left().IsZero() && mvfalse.right().Equals(vtrue)) { | 79 if (mvfalse.left().IsZero() && mvfalse.right().Equals(vtrue)) { |
82 return Change(node, machine()->Float64Abs(), vtrue); | 80 return Change(node, machine()->Float64Abs(), vtrue); |
83 } | 81 } |
84 } | 82 } |
85 if (mcond.left().Equals(vtrue) && mcond.right().Equals(vfalse) && | 83 if (mcond.left().Equals(vtrue) && mcond.right().Equals(vfalse) && |
86 machine()->HasFloat64Min()) { | 84 machine()->HasFloat64Min()) { |
87 return Change(node, machine()->Float64Min(), vtrue, vfalse); | 85 return Change(node, machine()->Float64Min(), vtrue, vfalse); |
88 } else if (mcond.left().Equals(vfalse) && mcond.right().Equals(vtrue) && | 86 } else if (mcond.left().Equals(vfalse) && mcond.right().Equals(vtrue) && |
89 machine()->HasFloat64Max()) { | 87 machine()->HasFloat64Max()) { |
(...skipping 20 matching lines...) Expand all Loading... |
110 Node* vfalse = NodeProperties::GetValueInput(node, 2); | 108 Node* vfalse = NodeProperties::GetValueInput(node, 2); |
111 if (vtrue == vfalse) return Replace(vtrue); | 109 if (vtrue == vfalse) return Replace(vtrue); |
112 switch (cond->opcode()) { | 110 switch (cond->opcode()) { |
113 case IrOpcode::kHeapConstant: { | 111 case IrOpcode::kHeapConstant: { |
114 HeapObjectMatcher<HeapObject> mcond(cond); | 112 HeapObjectMatcher<HeapObject> mcond(cond); |
115 return Replace(mcond.Value().handle()->BooleanValue() ? vtrue : vfalse); | 113 return Replace(mcond.Value().handle()->BooleanValue() ? vtrue : vfalse); |
116 } | 114 } |
117 case IrOpcode::kFloat32LessThan: { | 115 case IrOpcode::kFloat32LessThan: { |
118 Float32BinopMatcher mcond(cond); | 116 Float32BinopMatcher mcond(cond); |
119 if (mcond.left().Is(0.0) && mcond.right().Equals(vtrue) && | 117 if (mcond.left().Is(0.0) && mcond.right().Equals(vtrue) && |
120 vfalse->opcode() == IrOpcode::kFloat32Sub && | 118 vfalse->opcode() == IrOpcode::kFloat32Sub) { |
121 machine()->HasFloat32Abs()) { | |
122 Float32BinopMatcher mvfalse(vfalse); | 119 Float32BinopMatcher mvfalse(vfalse); |
123 if (mvfalse.left().IsZero() && mvfalse.right().Equals(vtrue)) { | 120 if (mvfalse.left().IsZero() && mvfalse.right().Equals(vtrue)) { |
124 return Change(node, machine()->Float32Abs(), vtrue); | 121 return Change(node, machine()->Float32Abs(), vtrue); |
125 } | 122 } |
126 } | 123 } |
127 if (mcond.left().Equals(vtrue) && mcond.right().Equals(vfalse) && | 124 if (mcond.left().Equals(vtrue) && mcond.right().Equals(vfalse) && |
128 machine()->HasFloat32Min()) { | 125 machine()->HasFloat32Min()) { |
129 return Change(node, machine()->Float32Min(), vtrue, vfalse); | 126 return Change(node, machine()->Float32Min(), vtrue, vfalse); |
130 } else if (mcond.left().Equals(vfalse) && mcond.right().Equals(vtrue) && | 127 } else if (mcond.left().Equals(vfalse) && mcond.right().Equals(vtrue) && |
131 machine()->HasFloat32Max()) { | 128 machine()->HasFloat32Max()) { |
132 return Change(node, machine()->Float32Max(), vtrue, vfalse); | 129 return Change(node, machine()->Float32Max(), vtrue, vfalse); |
133 } | 130 } |
134 break; | 131 break; |
135 } | 132 } |
136 case IrOpcode::kFloat64LessThan: { | 133 case IrOpcode::kFloat64LessThan: { |
137 Float64BinopMatcher mcond(cond); | 134 Float64BinopMatcher mcond(cond); |
138 if (mcond.left().Is(0.0) && mcond.right().Equals(vtrue) && | 135 if (mcond.left().Is(0.0) && mcond.right().Equals(vtrue) && |
139 vfalse->opcode() == IrOpcode::kFloat64Sub && | 136 vfalse->opcode() == IrOpcode::kFloat64Sub) { |
140 machine()->HasFloat64Abs()) { | |
141 Float64BinopMatcher mvfalse(vfalse); | 137 Float64BinopMatcher mvfalse(vfalse); |
142 if (mvfalse.left().IsZero() && mvfalse.right().Equals(vtrue)) { | 138 if (mvfalse.left().IsZero() && mvfalse.right().Equals(vtrue)) { |
143 return Change(node, machine()->Float64Abs(), vtrue); | 139 return Change(node, machine()->Float64Abs(), vtrue); |
144 } | 140 } |
145 } | 141 } |
146 if (mcond.left().Equals(vtrue) && mcond.right().Equals(vfalse) && | 142 if (mcond.left().Equals(vtrue) && mcond.right().Equals(vfalse) && |
147 machine()->HasFloat64Min()) { | 143 machine()->HasFloat64Min()) { |
148 return Change(node, machine()->Float64Min(), vtrue, vfalse); | 144 return Change(node, machine()->Float64Min(), vtrue, vfalse); |
149 } else if (mcond.left().Equals(vfalse) && mcond.right().Equals(vtrue) && | 145 } else if (mcond.left().Equals(vfalse) && mcond.right().Equals(vtrue) && |
150 machine()->HasFloat64Max()) { | 146 machine()->HasFloat64Max()) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 Graph* CommonOperatorReducer::graph() const { return jsgraph()->graph(); } | 182 Graph* CommonOperatorReducer::graph() const { return jsgraph()->graph(); } |
187 | 183 |
188 | 184 |
189 MachineOperatorBuilder* CommonOperatorReducer::machine() const { | 185 MachineOperatorBuilder* CommonOperatorReducer::machine() const { |
190 return jsgraph()->machine(); | 186 return jsgraph()->machine(); |
191 } | 187 } |
192 | 188 |
193 } // namespace compiler | 189 } // namespace compiler |
194 } // namespace internal | 190 } // namespace internal |
195 } // namespace v8 | 191 } // namespace v8 |
OLD | NEW |