| 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.h" | 5 #include "src/compiler/common-operator.h" |
| 6 #include "src/compiler/common-operator-reducer.h" | 6 #include "src/compiler/common-operator-reducer.h" |
| 7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
| 8 #include "src/compiler/js-operator.h" | 8 #include "src/compiler/js-operator.h" |
| 9 #include "src/compiler/machine-operator.h" | 9 #include "src/compiler/machine-operator.h" |
| 10 #include "src/compiler/machine-type.h" | 10 #include "src/compiler/machine-type.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 Node* c0 = Float32Constant(0.0); | 113 Node* c0 = Float32Constant(0.0); |
| 114 Node* check = graph()->NewNode(machine()->Float32LessThan(), c0, p0); | 114 Node* check = graph()->NewNode(machine()->Float32LessThan(), c0, p0); |
| 115 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); | 115 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); |
| 116 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 116 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 117 Node* vtrue = p0; | 117 Node* vtrue = p0; |
| 118 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 118 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 119 Node* vfalse = graph()->NewNode(machine()->Float32Sub(), c0, p0); | 119 Node* vfalse = graph()->NewNode(machine()->Float32Sub(), c0, p0); |
| 120 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | 120 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
| 121 Node* phi = | 121 Node* phi = |
| 122 graph()->NewNode(common()->Phi(kMachFloat32, 2), vtrue, vfalse, merge); | 122 graph()->NewNode(common()->Phi(kMachFloat32, 2), vtrue, vfalse, merge); |
| 123 Reduction r = Reduce(phi, MachineOperatorBuilder::kFloat32Abs); | 123 Reduction r = Reduce(phi); |
| 124 ASSERT_TRUE(r.Changed()); | 124 ASSERT_TRUE(r.Changed()); |
| 125 EXPECT_THAT(r.replacement(), IsFloat32Abs(p0)); | 125 EXPECT_THAT(r.replacement(), IsFloat32Abs(p0)); |
| 126 } | 126 } |
| 127 | 127 |
| 128 | 128 |
| 129 TEST_F(CommonOperatorReducerTest, PhiToFloat64Abs) { | 129 TEST_F(CommonOperatorReducerTest, PhiToFloat64Abs) { |
| 130 Node* p0 = Parameter(0); | 130 Node* p0 = Parameter(0); |
| 131 Node* c0 = Float64Constant(0.0); | 131 Node* c0 = Float64Constant(0.0); |
| 132 Node* check = graph()->NewNode(machine()->Float64LessThan(), c0, p0); | 132 Node* check = graph()->NewNode(machine()->Float64LessThan(), c0, p0); |
| 133 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); | 133 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); |
| 134 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 134 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 135 Node* vtrue = p0; | 135 Node* vtrue = p0; |
| 136 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 136 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 137 Node* vfalse = graph()->NewNode(machine()->Float64Sub(), c0, p0); | 137 Node* vfalse = graph()->NewNode(machine()->Float64Sub(), c0, p0); |
| 138 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | 138 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
| 139 Node* phi = | 139 Node* phi = |
| 140 graph()->NewNode(common()->Phi(kMachFloat64, 2), vtrue, vfalse, merge); | 140 graph()->NewNode(common()->Phi(kMachFloat64, 2), vtrue, vfalse, merge); |
| 141 Reduction r = Reduce(phi, MachineOperatorBuilder::kFloat64Abs); | 141 Reduction r = Reduce(phi); |
| 142 ASSERT_TRUE(r.Changed()); | 142 ASSERT_TRUE(r.Changed()); |
| 143 EXPECT_THAT(r.replacement(), IsFloat64Abs(p0)); | 143 EXPECT_THAT(r.replacement(), IsFloat64Abs(p0)); |
| 144 } | 144 } |
| 145 | 145 |
| 146 | 146 |
| 147 TEST_F(CommonOperatorReducerTest, PhiToFloat32Max) { | 147 TEST_F(CommonOperatorReducerTest, PhiToFloat32Max) { |
| 148 Node* p0 = Parameter(0); | 148 Node* p0 = Parameter(0); |
| 149 Node* p1 = Parameter(1); | 149 Node* p1 = Parameter(1); |
| 150 Node* check = graph()->NewNode(machine()->Float32LessThan(), p0, p1); | 150 Node* check = graph()->NewNode(machine()->Float32LessThan(), p0, p1); |
| 151 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); | 151 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 } | 243 } |
| 244 | 244 |
| 245 | 245 |
| 246 TEST_F(CommonOperatorReducerTest, SelectToFloat32Abs) { | 246 TEST_F(CommonOperatorReducerTest, SelectToFloat32Abs) { |
| 247 Node* p0 = Parameter(0); | 247 Node* p0 = Parameter(0); |
| 248 Node* c0 = Float32Constant(0.0); | 248 Node* c0 = Float32Constant(0.0); |
| 249 Node* check = graph()->NewNode(machine()->Float32LessThan(), c0, p0); | 249 Node* check = graph()->NewNode(machine()->Float32LessThan(), c0, p0); |
| 250 Node* select = | 250 Node* select = |
| 251 graph()->NewNode(common()->Select(kMachFloat32), check, p0, | 251 graph()->NewNode(common()->Select(kMachFloat32), check, p0, |
| 252 graph()->NewNode(machine()->Float32Sub(), c0, p0)); | 252 graph()->NewNode(machine()->Float32Sub(), c0, p0)); |
| 253 Reduction r = Reduce(select, MachineOperatorBuilder::kFloat32Abs); | 253 Reduction r = Reduce(select); |
| 254 ASSERT_TRUE(r.Changed()); | 254 ASSERT_TRUE(r.Changed()); |
| 255 EXPECT_THAT(r.replacement(), IsFloat32Abs(p0)); | 255 EXPECT_THAT(r.replacement(), IsFloat32Abs(p0)); |
| 256 } | 256 } |
| 257 | 257 |
| 258 | 258 |
| 259 TEST_F(CommonOperatorReducerTest, SelectToFloat64Abs) { | 259 TEST_F(CommonOperatorReducerTest, SelectToFloat64Abs) { |
| 260 Node* p0 = Parameter(0); | 260 Node* p0 = Parameter(0); |
| 261 Node* c0 = Float64Constant(0.0); | 261 Node* c0 = Float64Constant(0.0); |
| 262 Node* check = graph()->NewNode(machine()->Float64LessThan(), c0, p0); | 262 Node* check = graph()->NewNode(machine()->Float64LessThan(), c0, p0); |
| 263 Node* select = | 263 Node* select = |
| 264 graph()->NewNode(common()->Select(kMachFloat64), check, p0, | 264 graph()->NewNode(common()->Select(kMachFloat64), check, p0, |
| 265 graph()->NewNode(machine()->Float64Sub(), c0, p0)); | 265 graph()->NewNode(machine()->Float64Sub(), c0, p0)); |
| 266 Reduction r = Reduce(select, MachineOperatorBuilder::kFloat64Abs); | 266 Reduction r = Reduce(select); |
| 267 ASSERT_TRUE(r.Changed()); | 267 ASSERT_TRUE(r.Changed()); |
| 268 EXPECT_THAT(r.replacement(), IsFloat64Abs(p0)); | 268 EXPECT_THAT(r.replacement(), IsFloat64Abs(p0)); |
| 269 } | 269 } |
| 270 | 270 |
| 271 | 271 |
| 272 TEST_F(CommonOperatorReducerTest, SelectToFloat32Max) { | 272 TEST_F(CommonOperatorReducerTest, SelectToFloat32Max) { |
| 273 Node* p0 = Parameter(0); | 273 Node* p0 = Parameter(0); |
| 274 Node* p1 = Parameter(1); | 274 Node* p1 = Parameter(1); |
| 275 Node* check = graph()->NewNode(machine()->Float32LessThan(), p0, p1); | 275 Node* check = graph()->NewNode(machine()->Float32LessThan(), p0, p1); |
| 276 Node* select = | 276 Node* select = |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 Node* select = | 312 Node* select = |
| 313 graph()->NewNode(common()->Select(kMachFloat64), check, p0, p1); | 313 graph()->NewNode(common()->Select(kMachFloat64), check, p0, p1); |
| 314 Reduction r = Reduce(select, MachineOperatorBuilder::kFloat64Min); | 314 Reduction r = Reduce(select, MachineOperatorBuilder::kFloat64Min); |
| 315 ASSERT_TRUE(r.Changed()); | 315 ASSERT_TRUE(r.Changed()); |
| 316 EXPECT_THAT(r.replacement(), IsFloat64Min(p0, p1)); | 316 EXPECT_THAT(r.replacement(), IsFloat64Min(p0, p1)); |
| 317 } | 317 } |
| 318 | 318 |
| 319 } // namespace compiler | 319 } // namespace compiler |
| 320 } // namespace internal | 320 } // namespace internal |
| 321 } // namespace v8 | 321 } // namespace v8 |
| OLD | NEW |