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/machine-operator.h" | 7 #include "src/compiler/machine-operator.h" |
8 #include "src/compiler/operator.h" | 8 #include "src/compiler/operator.h" |
9 #include "src/compiler/simplified-operator.h" | 9 #include "src/compiler/simplified-operator.h" |
10 #include "src/machine-type.h" | 10 #include "src/machine-type.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 class CommonOperatorReducerTest : public GraphTest { | 21 class CommonOperatorReducerTest : public GraphTest { |
22 public: | 22 public: |
23 explicit CommonOperatorReducerTest(int num_parameters = 1) | 23 explicit CommonOperatorReducerTest(int num_parameters = 1) |
24 : GraphTest(num_parameters), machine_(zone()), simplified_(zone()) {} | 24 : GraphTest(num_parameters), machine_(zone()), simplified_(zone()) {} |
25 ~CommonOperatorReducerTest() override {} | 25 ~CommonOperatorReducerTest() override {} |
26 | 26 |
27 protected: | 27 protected: |
28 Reduction Reduce( | 28 Reduction Reduce( |
29 AdvancedReducer::Editor* editor, Node* node, | 29 AdvancedReducer::Editor* editor, Node* node, |
30 MachineOperatorBuilder::Flags flags = MachineOperatorBuilder::kNoFlags) { | 30 MachineOperatorBuilder::Flags flags = MachineOperatorBuilder::kNoFlags) { |
31 MachineOperatorBuilder machine(zone(), kMachPtr, flags); | 31 MachineOperatorBuilder machine(zone(), MachineType::PointerRepresentation(), |
| 32 flags); |
32 CommonOperatorReducer reducer(editor, graph(), common(), &machine); | 33 CommonOperatorReducer reducer(editor, graph(), common(), &machine); |
33 return reducer.Reduce(node); | 34 return reducer.Reduce(node); |
34 } | 35 } |
35 | 36 |
36 Reduction Reduce(Node* node, MachineOperatorBuilder::Flags flags = | 37 Reduction Reduce(Node* node, MachineOperatorBuilder::Flags flags = |
37 MachineOperatorBuilder::kNoFlags) { | 38 MachineOperatorBuilder::kNoFlags) { |
38 StrictMock<MockAdvancedReducerEditor> editor; | 39 StrictMock<MockAdvancedReducerEditor> editor; |
39 return Reduce(&editor, node, flags); | 40 return Reduce(&editor, node, flags); |
40 } | 41 } |
41 | 42 |
42 MachineOperatorBuilder* machine() { return &machine_; } | 43 MachineOperatorBuilder* machine() { return &machine_; } |
43 SimplifiedOperatorBuilder* simplified() { return &simplified_; } | 44 SimplifiedOperatorBuilder* simplified() { return &simplified_; } |
44 | 45 |
45 private: | 46 private: |
46 MachineOperatorBuilder machine_; | 47 MachineOperatorBuilder machine_; |
47 SimplifiedOperatorBuilder simplified_; | 48 SimplifiedOperatorBuilder simplified_; |
48 }; | 49 }; |
49 | 50 |
50 | 51 |
51 namespace { | 52 namespace { |
52 | 53 |
53 const BranchHint kBranchHints[] = {BranchHint::kNone, BranchHint::kFalse, | 54 const BranchHint kBranchHints[] = {BranchHint::kNone, BranchHint::kFalse, |
54 BranchHint::kTrue}; | 55 BranchHint::kTrue}; |
55 | 56 |
56 | 57 |
57 const MachineType kMachineTypes[] = { | 58 const MachineRepresentation kMachineRepresentations[] = { |
58 kMachFloat32, kMachFloat64, kMachInt8, kMachUint8, kMachInt16, | 59 MachineRepresentation::kBit, MachineRepresentation::kWord8, |
59 kMachUint16, kMachInt32, kMachUint32, kMachInt64, kMachUint64, | 60 MachineRepresentation::kWord16, MachineRepresentation::kWord32, |
60 kMachPtr, kMachAnyTagged, kRepBit, kRepWord8, kRepWord16, | 61 MachineRepresentation::kWord64, MachineRepresentation::kFloat32, |
61 kRepWord32, kRepWord64, kRepFloat32, kRepFloat64, kRepTagged}; | 62 MachineRepresentation::kFloat64, MachineRepresentation::kTagged}; |
62 | 63 |
63 | 64 |
64 const Operator kOp0(0, Operator::kNoProperties, "Op0", 0, 0, 0, 1, 1, 0); | 65 const Operator kOp0(0, Operator::kNoProperties, "Op0", 0, 0, 0, 1, 1, 0); |
65 | 66 |
66 } // namespace | 67 } // namespace |
67 | 68 |
68 | 69 |
69 // ----------------------------------------------------------------------------- | 70 // ----------------------------------------------------------------------------- |
70 // Branch | 71 // Branch |
71 | 72 |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 // ----------------------------------------------------------------------------- | 273 // ----------------------------------------------------------------------------- |
273 // Phi | 274 // Phi |
274 | 275 |
275 | 276 |
276 TEST_F(CommonOperatorReducerTest, PhiWithMerge) { | 277 TEST_F(CommonOperatorReducerTest, PhiWithMerge) { |
277 const int kMaxInputs = 64; | 278 const int kMaxInputs = 64; |
278 Node* inputs[kMaxInputs]; | 279 Node* inputs[kMaxInputs]; |
279 Node* const input = graph()->NewNode(&kOp0); | 280 Node* const input = graph()->NewNode(&kOp0); |
280 TRACED_FORRANGE(int, input_count, 2, kMaxInputs - 1) { | 281 TRACED_FORRANGE(int, input_count, 2, kMaxInputs - 1) { |
281 int const value_input_count = input_count - 1; | 282 int const value_input_count = input_count - 1; |
282 TRACED_FOREACH(MachineType, type, kMachineTypes) { | 283 TRACED_FOREACH(MachineRepresentation, rep, kMachineRepresentations) { |
283 for (int i = 0; i < value_input_count; ++i) { | 284 for (int i = 0; i < value_input_count; ++i) { |
284 inputs[i] = graph()->start(); | 285 inputs[i] = graph()->start(); |
285 } | 286 } |
286 Node* const merge = graph()->NewNode(common()->Merge(value_input_count), | 287 Node* const merge = graph()->NewNode(common()->Merge(value_input_count), |
287 value_input_count, inputs); | 288 value_input_count, inputs); |
288 for (int i = 0; i < value_input_count; ++i) { | 289 for (int i = 0; i < value_input_count; ++i) { |
289 inputs[i] = input; | 290 inputs[i] = input; |
290 } | 291 } |
291 inputs[value_input_count] = merge; | 292 inputs[value_input_count] = merge; |
292 StrictMock<MockAdvancedReducerEditor> editor; | 293 StrictMock<MockAdvancedReducerEditor> editor; |
293 EXPECT_CALL(editor, Revisit(merge)); | 294 EXPECT_CALL(editor, Revisit(merge)); |
294 Reduction r = Reduce( | 295 Reduction r = Reduce( |
295 &editor, graph()->NewNode(common()->Phi(type, value_input_count), | 296 &editor, graph()->NewNode(common()->Phi(rep, value_input_count), |
296 input_count, inputs)); | 297 input_count, inputs)); |
297 ASSERT_TRUE(r.Changed()); | 298 ASSERT_TRUE(r.Changed()); |
298 EXPECT_EQ(input, r.replacement()); | 299 EXPECT_EQ(input, r.replacement()); |
299 } | 300 } |
300 } | 301 } |
301 } | 302 } |
302 | 303 |
303 | 304 |
304 TEST_F(CommonOperatorReducerTest, PhiWithLoop) { | 305 TEST_F(CommonOperatorReducerTest, PhiWithLoop) { |
305 Node* const p0 = Parameter(0); | 306 Node* const p0 = Parameter(0); |
306 Node* const loop = | 307 Node* const loop = |
307 graph()->NewNode(common()->Loop(2), graph()->start(), graph()->start()); | 308 graph()->NewNode(common()->Loop(2), graph()->start(), graph()->start()); |
308 loop->ReplaceInput(1, loop); | 309 loop->ReplaceInput(1, loop); |
309 Node* const phi = | 310 Node* const phi = graph()->NewNode( |
310 graph()->NewNode(common()->Phi(kMachAnyTagged, 2), p0, p0, loop); | 311 common()->Phi(MachineRepresentation::kTagged, 2), p0, p0, loop); |
311 phi->ReplaceInput(1, phi); | 312 phi->ReplaceInput(1, phi); |
312 StrictMock<MockAdvancedReducerEditor> editor; | 313 StrictMock<MockAdvancedReducerEditor> editor; |
313 EXPECT_CALL(editor, Revisit(loop)); | 314 EXPECT_CALL(editor, Revisit(loop)); |
314 Reduction const r = Reduce(&editor, phi); | 315 Reduction const r = Reduce(&editor, phi); |
315 ASSERT_TRUE(r.Changed()); | 316 ASSERT_TRUE(r.Changed()); |
316 EXPECT_EQ(p0, r.replacement()); | 317 EXPECT_EQ(p0, r.replacement()); |
317 } | 318 } |
318 | 319 |
319 | 320 |
320 TEST_F(CommonOperatorReducerTest, PhiToFloat32Abs) { | 321 TEST_F(CommonOperatorReducerTest, PhiToFloat32Abs) { |
321 Node* p0 = Parameter(0); | 322 Node* p0 = Parameter(0); |
322 Node* c0 = Float32Constant(0.0); | 323 Node* c0 = Float32Constant(0.0); |
323 Node* check = graph()->NewNode(machine()->Float32LessThan(), c0, p0); | 324 Node* check = graph()->NewNode(machine()->Float32LessThan(), c0, p0); |
324 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); | 325 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); |
325 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 326 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
326 Node* vtrue = p0; | 327 Node* vtrue = p0; |
327 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 328 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
328 Node* vfalse = graph()->NewNode(machine()->Float32Sub(), c0, p0); | 329 Node* vfalse = graph()->NewNode(machine()->Float32Sub(), c0, p0); |
329 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | 330 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
330 Node* phi = | 331 Node* phi = graph()->NewNode( |
331 graph()->NewNode(common()->Phi(kMachFloat32, 2), vtrue, vfalse, merge); | 332 common()->Phi(MachineRepresentation::kFloat32, 2), vtrue, vfalse, merge); |
332 StrictMock<MockAdvancedReducerEditor> editor; | 333 StrictMock<MockAdvancedReducerEditor> editor; |
333 EXPECT_CALL(editor, Revisit(merge)); | 334 EXPECT_CALL(editor, Revisit(merge)); |
334 Reduction r = Reduce(&editor, phi); | 335 Reduction r = Reduce(&editor, phi); |
335 ASSERT_TRUE(r.Changed()); | 336 ASSERT_TRUE(r.Changed()); |
336 EXPECT_THAT(r.replacement(), IsFloat32Abs(p0)); | 337 EXPECT_THAT(r.replacement(), IsFloat32Abs(p0)); |
337 } | 338 } |
338 | 339 |
339 | 340 |
340 TEST_F(CommonOperatorReducerTest, PhiToFloat64Abs) { | 341 TEST_F(CommonOperatorReducerTest, PhiToFloat64Abs) { |
341 Node* p0 = Parameter(0); | 342 Node* p0 = Parameter(0); |
342 Node* c0 = Float64Constant(0.0); | 343 Node* c0 = Float64Constant(0.0); |
343 Node* check = graph()->NewNode(machine()->Float64LessThan(), c0, p0); | 344 Node* check = graph()->NewNode(machine()->Float64LessThan(), c0, p0); |
344 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); | 345 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); |
345 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 346 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
346 Node* vtrue = p0; | 347 Node* vtrue = p0; |
347 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 348 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
348 Node* vfalse = graph()->NewNode(machine()->Float64Sub(), c0, p0); | 349 Node* vfalse = graph()->NewNode(machine()->Float64Sub(), c0, p0); |
349 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | 350 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
350 Node* phi = | 351 Node* phi = graph()->NewNode( |
351 graph()->NewNode(common()->Phi(kMachFloat64, 2), vtrue, vfalse, merge); | 352 common()->Phi(MachineRepresentation::kFloat64, 2), vtrue, vfalse, merge); |
352 StrictMock<MockAdvancedReducerEditor> editor; | 353 StrictMock<MockAdvancedReducerEditor> editor; |
353 EXPECT_CALL(editor, Revisit(merge)); | 354 EXPECT_CALL(editor, Revisit(merge)); |
354 Reduction r = Reduce(&editor, phi); | 355 Reduction r = Reduce(&editor, phi); |
355 ASSERT_TRUE(r.Changed()); | 356 ASSERT_TRUE(r.Changed()); |
356 EXPECT_THAT(r.replacement(), IsFloat64Abs(p0)); | 357 EXPECT_THAT(r.replacement(), IsFloat64Abs(p0)); |
357 } | 358 } |
358 | 359 |
359 | 360 |
360 TEST_F(CommonOperatorReducerTest, PhiToFloat32Max) { | 361 TEST_F(CommonOperatorReducerTest, PhiToFloat32Max) { |
361 Node* p0 = Parameter(0); | 362 Node* p0 = Parameter(0); |
362 Node* p1 = Parameter(1); | 363 Node* p1 = Parameter(1); |
363 Node* check = graph()->NewNode(machine()->Float32LessThan(), p0, p1); | 364 Node* check = graph()->NewNode(machine()->Float32LessThan(), p0, p1); |
364 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); | 365 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); |
365 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 366 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
366 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 367 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
367 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | 368 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
368 Node* phi = graph()->NewNode(common()->Phi(kMachFloat32, 2), p1, p0, merge); | 369 Node* phi = graph()->NewNode( |
| 370 common()->Phi(MachineRepresentation::kFloat32, 2), p1, p0, merge); |
369 StrictMock<MockAdvancedReducerEditor> editor; | 371 StrictMock<MockAdvancedReducerEditor> editor; |
370 EXPECT_CALL(editor, Revisit(merge)); | 372 EXPECT_CALL(editor, Revisit(merge)); |
371 Reduction r = Reduce(&editor, phi, MachineOperatorBuilder::kFloat32Max); | 373 Reduction r = Reduce(&editor, phi, MachineOperatorBuilder::kFloat32Max); |
372 ASSERT_TRUE(r.Changed()); | 374 ASSERT_TRUE(r.Changed()); |
373 EXPECT_THAT(r.replacement(), IsFloat32Max(p1, p0)); | 375 EXPECT_THAT(r.replacement(), IsFloat32Max(p1, p0)); |
374 } | 376 } |
375 | 377 |
376 | 378 |
377 TEST_F(CommonOperatorReducerTest, PhiToFloat64Max) { | 379 TEST_F(CommonOperatorReducerTest, PhiToFloat64Max) { |
378 Node* p0 = Parameter(0); | 380 Node* p0 = Parameter(0); |
379 Node* p1 = Parameter(1); | 381 Node* p1 = Parameter(1); |
380 Node* check = graph()->NewNode(machine()->Float64LessThan(), p0, p1); | 382 Node* check = graph()->NewNode(machine()->Float64LessThan(), p0, p1); |
381 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); | 383 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); |
382 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 384 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
383 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 385 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
384 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | 386 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
385 Node* phi = graph()->NewNode(common()->Phi(kMachFloat64, 2), p1, p0, merge); | 387 Node* phi = graph()->NewNode( |
| 388 common()->Phi(MachineRepresentation::kFloat64, 2), p1, p0, merge); |
386 StrictMock<MockAdvancedReducerEditor> editor; | 389 StrictMock<MockAdvancedReducerEditor> editor; |
387 EXPECT_CALL(editor, Revisit(merge)); | 390 EXPECT_CALL(editor, Revisit(merge)); |
388 Reduction r = Reduce(&editor, phi, MachineOperatorBuilder::kFloat64Max); | 391 Reduction r = Reduce(&editor, phi, MachineOperatorBuilder::kFloat64Max); |
389 ASSERT_TRUE(r.Changed()); | 392 ASSERT_TRUE(r.Changed()); |
390 EXPECT_THAT(r.replacement(), IsFloat64Max(p1, p0)); | 393 EXPECT_THAT(r.replacement(), IsFloat64Max(p1, p0)); |
391 } | 394 } |
392 | 395 |
393 | 396 |
394 TEST_F(CommonOperatorReducerTest, PhiToFloat32Min) { | 397 TEST_F(CommonOperatorReducerTest, PhiToFloat32Min) { |
395 Node* p0 = Parameter(0); | 398 Node* p0 = Parameter(0); |
396 Node* p1 = Parameter(1); | 399 Node* p1 = Parameter(1); |
397 Node* check = graph()->NewNode(machine()->Float32LessThan(), p0, p1); | 400 Node* check = graph()->NewNode(machine()->Float32LessThan(), p0, p1); |
398 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); | 401 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); |
399 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 402 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
400 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 403 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
401 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | 404 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
402 Node* phi = graph()->NewNode(common()->Phi(kMachFloat32, 2), p0, p1, merge); | 405 Node* phi = graph()->NewNode( |
| 406 common()->Phi(MachineRepresentation::kFloat32, 2), p0, p1, merge); |
403 StrictMock<MockAdvancedReducerEditor> editor; | 407 StrictMock<MockAdvancedReducerEditor> editor; |
404 EXPECT_CALL(editor, Revisit(merge)); | 408 EXPECT_CALL(editor, Revisit(merge)); |
405 Reduction r = Reduce(&editor, phi, MachineOperatorBuilder::kFloat32Min); | 409 Reduction r = Reduce(&editor, phi, MachineOperatorBuilder::kFloat32Min); |
406 ASSERT_TRUE(r.Changed()); | 410 ASSERT_TRUE(r.Changed()); |
407 EXPECT_THAT(r.replacement(), IsFloat32Min(p0, p1)); | 411 EXPECT_THAT(r.replacement(), IsFloat32Min(p0, p1)); |
408 } | 412 } |
409 | 413 |
410 | 414 |
411 TEST_F(CommonOperatorReducerTest, PhiToFloat64Min) { | 415 TEST_F(CommonOperatorReducerTest, PhiToFloat64Min) { |
412 Node* p0 = Parameter(0); | 416 Node* p0 = Parameter(0); |
413 Node* p1 = Parameter(1); | 417 Node* p1 = Parameter(1); |
414 Node* check = graph()->NewNode(machine()->Float64LessThan(), p0, p1); | 418 Node* check = graph()->NewNode(machine()->Float64LessThan(), p0, p1); |
415 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); | 419 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); |
416 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 420 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
417 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 421 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
418 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | 422 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
419 Node* phi = graph()->NewNode(common()->Phi(kMachFloat64, 2), p0, p1, merge); | 423 Node* phi = graph()->NewNode( |
| 424 common()->Phi(MachineRepresentation::kFloat64, 2), p0, p1, merge); |
420 StrictMock<MockAdvancedReducerEditor> editor; | 425 StrictMock<MockAdvancedReducerEditor> editor; |
421 EXPECT_CALL(editor, Revisit(merge)); | 426 EXPECT_CALL(editor, Revisit(merge)); |
422 Reduction r = Reduce(&editor, phi, MachineOperatorBuilder::kFloat64Min); | 427 Reduction r = Reduce(&editor, phi, MachineOperatorBuilder::kFloat64Min); |
423 ASSERT_TRUE(r.Changed()); | 428 ASSERT_TRUE(r.Changed()); |
424 EXPECT_THAT(r.replacement(), IsFloat64Min(p0, p1)); | 429 EXPECT_THAT(r.replacement(), IsFloat64Min(p0, p1)); |
425 } | 430 } |
426 | 431 |
427 | 432 |
428 // ----------------------------------------------------------------------------- | 433 // ----------------------------------------------------------------------------- |
429 // Return | 434 // Return |
430 | 435 |
431 | 436 |
432 TEST_F(CommonOperatorReducerTest, ReturnWithPhiAndEffectPhiAndMerge) { | 437 TEST_F(CommonOperatorReducerTest, ReturnWithPhiAndEffectPhiAndMerge) { |
433 Node* cond = Parameter(2); | 438 Node* cond = Parameter(2); |
434 Node* branch = graph()->NewNode(common()->Branch(), cond, graph()->start()); | 439 Node* branch = graph()->NewNode(common()->Branch(), cond, graph()->start()); |
435 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 440 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
436 Node* etrue = graph()->start(); | 441 Node* etrue = graph()->start(); |
437 Node* vtrue = Parameter(0); | 442 Node* vtrue = Parameter(0); |
438 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 443 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
439 Node* efalse = graph()->start(); | 444 Node* efalse = graph()->start(); |
440 Node* vfalse = Parameter(1); | 445 Node* vfalse = Parameter(1); |
441 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | 446 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
442 Node* ephi = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, merge); | 447 Node* ephi = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, merge); |
443 Node* phi = | 448 Node* phi = graph()->NewNode(common()->Phi(MachineRepresentation::kTagged, 2), |
444 graph()->NewNode(common()->Phi(kMachAnyTagged, 2), vtrue, vfalse, merge); | 449 vtrue, vfalse, merge); |
445 Node* ret = graph()->NewNode(common()->Return(), phi, ephi, merge); | 450 Node* ret = graph()->NewNode(common()->Return(), phi, ephi, merge); |
446 graph()->SetEnd(graph()->NewNode(common()->End(1), ret)); | 451 graph()->SetEnd(graph()->NewNode(common()->End(1), ret)); |
447 StrictMock<MockAdvancedReducerEditor> editor; | 452 StrictMock<MockAdvancedReducerEditor> editor; |
448 EXPECT_CALL(editor, Replace(merge, IsDead())); | 453 EXPECT_CALL(editor, Replace(merge, IsDead())); |
449 Reduction const r = Reduce(&editor, ret); | 454 Reduction const r = Reduce(&editor, ret); |
450 ASSERT_TRUE(r.Changed()); | 455 ASSERT_TRUE(r.Changed()); |
451 EXPECT_THAT(r.replacement(), IsDead()); | 456 EXPECT_THAT(r.replacement(), IsDead()); |
452 EXPECT_THAT(graph()->end(), IsEnd(ret, IsReturn(vtrue, etrue, if_true), | 457 EXPECT_THAT(graph()->end(), IsEnd(ret, IsReturn(vtrue, etrue, if_true), |
453 IsReturn(vfalse, efalse, if_false))); | 458 IsReturn(vfalse, efalse, if_false))); |
454 } | 459 } |
455 | 460 |
456 | 461 |
457 // ----------------------------------------------------------------------------- | 462 // ----------------------------------------------------------------------------- |
458 // Select | 463 // Select |
459 | 464 |
460 | 465 |
461 TEST_F(CommonOperatorReducerTest, SelectWithSameThenAndElse) { | 466 TEST_F(CommonOperatorReducerTest, SelectWithSameThenAndElse) { |
462 Node* const input = graph()->NewNode(&kOp0); | 467 Node* const input = graph()->NewNode(&kOp0); |
463 TRACED_FOREACH(BranchHint, hint, kBranchHints) { | 468 TRACED_FOREACH(BranchHint, hint, kBranchHints) { |
464 TRACED_FOREACH(MachineType, type, kMachineTypes) { | 469 TRACED_FOREACH(MachineRepresentation, rep, kMachineRepresentations) { |
465 Reduction r = Reduce( | 470 Reduction r = Reduce( |
466 graph()->NewNode(common()->Select(type, hint), input, input, input)); | 471 graph()->NewNode(common()->Select(rep, hint), input, input, input)); |
467 ASSERT_TRUE(r.Changed()); | 472 ASSERT_TRUE(r.Changed()); |
468 EXPECT_EQ(input, r.replacement()); | 473 EXPECT_EQ(input, r.replacement()); |
469 } | 474 } |
470 } | 475 } |
471 } | 476 } |
472 | 477 |
473 | 478 |
474 TEST_F(CommonOperatorReducerTest, SelectWithInt32ZeroConstant) { | 479 TEST_F(CommonOperatorReducerTest, SelectWithInt32ZeroConstant) { |
475 Node* p0 = Parameter(0); | 480 Node* p0 = Parameter(0); |
476 Node* p1 = Parameter(1); | 481 Node* p1 = Parameter(1); |
477 Node* select = graph()->NewNode(common()->Select(kMachAnyTagged), | 482 Node* select = |
478 Int32Constant(0), p0, p1); | 483 graph()->NewNode(common()->Select(MachineRepresentation::kTagged), |
| 484 Int32Constant(0), p0, p1); |
479 Reduction r = Reduce(select); | 485 Reduction r = Reduce(select); |
480 ASSERT_TRUE(r.Changed()); | 486 ASSERT_TRUE(r.Changed()); |
481 EXPECT_EQ(p1, r.replacement()); | 487 EXPECT_EQ(p1, r.replacement()); |
482 } | 488 } |
483 | 489 |
484 | 490 |
485 TEST_F(CommonOperatorReducerTest, SelectWithInt32OneConstant) { | 491 TEST_F(CommonOperatorReducerTest, SelectWithInt32OneConstant) { |
486 Node* p0 = Parameter(0); | 492 Node* p0 = Parameter(0); |
487 Node* p1 = Parameter(1); | 493 Node* p1 = Parameter(1); |
488 Node* select = graph()->NewNode(common()->Select(kMachAnyTagged), | 494 Node* select = |
489 Int32Constant(1), p0, p1); | 495 graph()->NewNode(common()->Select(MachineRepresentation::kTagged), |
| 496 Int32Constant(1), p0, p1); |
490 Reduction r = Reduce(select); | 497 Reduction r = Reduce(select); |
491 ASSERT_TRUE(r.Changed()); | 498 ASSERT_TRUE(r.Changed()); |
492 EXPECT_EQ(p0, r.replacement()); | 499 EXPECT_EQ(p0, r.replacement()); |
493 } | 500 } |
494 | 501 |
495 | 502 |
496 TEST_F(CommonOperatorReducerTest, SelectWithInt64ZeroConstant) { | 503 TEST_F(CommonOperatorReducerTest, SelectWithInt64ZeroConstant) { |
497 Node* p0 = Parameter(0); | 504 Node* p0 = Parameter(0); |
498 Node* p1 = Parameter(1); | 505 Node* p1 = Parameter(1); |
499 Node* select = graph()->NewNode(common()->Select(kMachAnyTagged), | 506 Node* select = |
500 Int64Constant(0), p0, p1); | 507 graph()->NewNode(common()->Select(MachineRepresentation::kTagged), |
| 508 Int64Constant(0), p0, p1); |
501 Reduction r = Reduce(select); | 509 Reduction r = Reduce(select); |
502 ASSERT_TRUE(r.Changed()); | 510 ASSERT_TRUE(r.Changed()); |
503 EXPECT_EQ(p1, r.replacement()); | 511 EXPECT_EQ(p1, r.replacement()); |
504 } | 512 } |
505 | 513 |
506 | 514 |
507 TEST_F(CommonOperatorReducerTest, SelectWithInt64OneConstant) { | 515 TEST_F(CommonOperatorReducerTest, SelectWithInt64OneConstant) { |
508 Node* p0 = Parameter(0); | 516 Node* p0 = Parameter(0); |
509 Node* p1 = Parameter(1); | 517 Node* p1 = Parameter(1); |
510 Node* select = graph()->NewNode(common()->Select(kMachAnyTagged), | 518 Node* select = |
511 Int64Constant(1), p0, p1); | 519 graph()->NewNode(common()->Select(MachineRepresentation::kTagged), |
| 520 Int64Constant(1), p0, p1); |
512 Reduction r = Reduce(select); | 521 Reduction r = Reduce(select); |
513 ASSERT_TRUE(r.Changed()); | 522 ASSERT_TRUE(r.Changed()); |
514 EXPECT_EQ(p0, r.replacement()); | 523 EXPECT_EQ(p0, r.replacement()); |
515 } | 524 } |
516 | 525 |
517 | 526 |
518 TEST_F(CommonOperatorReducerTest, SelectWithFalseConstant) { | 527 TEST_F(CommonOperatorReducerTest, SelectWithFalseConstant) { |
519 Node* p0 = Parameter(0); | 528 Node* p0 = Parameter(0); |
520 Node* p1 = Parameter(1); | 529 Node* p1 = Parameter(1); |
521 Node* select = graph()->NewNode(common()->Select(kMachAnyTagged), | 530 Node* select = |
522 FalseConstant(), p0, p1); | 531 graph()->NewNode(common()->Select(MachineRepresentation::kTagged), |
| 532 FalseConstant(), p0, p1); |
523 Reduction r = Reduce(select); | 533 Reduction r = Reduce(select); |
524 ASSERT_TRUE(r.Changed()); | 534 ASSERT_TRUE(r.Changed()); |
525 EXPECT_EQ(p1, r.replacement()); | 535 EXPECT_EQ(p1, r.replacement()); |
526 } | 536 } |
527 | 537 |
528 | 538 |
529 TEST_F(CommonOperatorReducerTest, SelectWithTrueConstant) { | 539 TEST_F(CommonOperatorReducerTest, SelectWithTrueConstant) { |
530 Node* p0 = Parameter(0); | 540 Node* p0 = Parameter(0); |
531 Node* p1 = Parameter(1); | 541 Node* p1 = Parameter(1); |
532 Node* select = graph()->NewNode(common()->Select(kMachAnyTagged), | 542 Node* select = graph()->NewNode( |
533 TrueConstant(), p0, p1); | 543 common()->Select(MachineRepresentation::kTagged), TrueConstant(), p0, p1); |
534 Reduction r = Reduce(select); | 544 Reduction r = Reduce(select); |
535 ASSERT_TRUE(r.Changed()); | 545 ASSERT_TRUE(r.Changed()); |
536 EXPECT_EQ(p0, r.replacement()); | 546 EXPECT_EQ(p0, r.replacement()); |
537 } | 547 } |
538 | 548 |
539 | 549 |
540 TEST_F(CommonOperatorReducerTest, SelectToFloat32Abs) { | 550 TEST_F(CommonOperatorReducerTest, SelectToFloat32Abs) { |
541 Node* p0 = Parameter(0); | 551 Node* p0 = Parameter(0); |
542 Node* c0 = Float32Constant(0.0); | 552 Node* c0 = Float32Constant(0.0); |
543 Node* check = graph()->NewNode(machine()->Float32LessThan(), c0, p0); | 553 Node* check = graph()->NewNode(machine()->Float32LessThan(), c0, p0); |
544 Node* select = | 554 Node* select = |
545 graph()->NewNode(common()->Select(kMachFloat32), check, p0, | 555 graph()->NewNode(common()->Select(MachineRepresentation::kFloat32), check, |
546 graph()->NewNode(machine()->Float32Sub(), c0, p0)); | 556 p0, graph()->NewNode(machine()->Float32Sub(), c0, p0)); |
547 Reduction r = Reduce(select); | 557 Reduction r = Reduce(select); |
548 ASSERT_TRUE(r.Changed()); | 558 ASSERT_TRUE(r.Changed()); |
549 EXPECT_THAT(r.replacement(), IsFloat32Abs(p0)); | 559 EXPECT_THAT(r.replacement(), IsFloat32Abs(p0)); |
550 } | 560 } |
551 | 561 |
552 | 562 |
553 TEST_F(CommonOperatorReducerTest, SelectToFloat64Abs) { | 563 TEST_F(CommonOperatorReducerTest, SelectToFloat64Abs) { |
554 Node* p0 = Parameter(0); | 564 Node* p0 = Parameter(0); |
555 Node* c0 = Float64Constant(0.0); | 565 Node* c0 = Float64Constant(0.0); |
556 Node* check = graph()->NewNode(machine()->Float64LessThan(), c0, p0); | 566 Node* check = graph()->NewNode(machine()->Float64LessThan(), c0, p0); |
557 Node* select = | 567 Node* select = |
558 graph()->NewNode(common()->Select(kMachFloat64), check, p0, | 568 graph()->NewNode(common()->Select(MachineRepresentation::kFloat64), check, |
559 graph()->NewNode(machine()->Float64Sub(), c0, p0)); | 569 p0, graph()->NewNode(machine()->Float64Sub(), c0, p0)); |
560 Reduction r = Reduce(select); | 570 Reduction r = Reduce(select); |
561 ASSERT_TRUE(r.Changed()); | 571 ASSERT_TRUE(r.Changed()); |
562 EXPECT_THAT(r.replacement(), IsFloat64Abs(p0)); | 572 EXPECT_THAT(r.replacement(), IsFloat64Abs(p0)); |
563 } | 573 } |
564 | 574 |
565 | 575 |
566 TEST_F(CommonOperatorReducerTest, SelectToFloat32Max) { | 576 TEST_F(CommonOperatorReducerTest, SelectToFloat32Max) { |
567 Node* p0 = Parameter(0); | 577 Node* p0 = Parameter(0); |
568 Node* p1 = Parameter(1); | 578 Node* p1 = Parameter(1); |
569 Node* check = graph()->NewNode(machine()->Float32LessThan(), p0, p1); | 579 Node* check = graph()->NewNode(machine()->Float32LessThan(), p0, p1); |
570 Node* select = | 580 Node* select = graph()->NewNode( |
571 graph()->NewNode(common()->Select(kMachFloat32), check, p1, p0); | 581 common()->Select(MachineRepresentation::kFloat32), check, p1, p0); |
572 Reduction r = Reduce(select, MachineOperatorBuilder::kFloat32Max); | 582 Reduction r = Reduce(select, MachineOperatorBuilder::kFloat32Max); |
573 ASSERT_TRUE(r.Changed()); | 583 ASSERT_TRUE(r.Changed()); |
574 EXPECT_THAT(r.replacement(), IsFloat32Max(p1, p0)); | 584 EXPECT_THAT(r.replacement(), IsFloat32Max(p1, p0)); |
575 } | 585 } |
576 | 586 |
577 | 587 |
578 TEST_F(CommonOperatorReducerTest, SelectToFloat64Max) { | 588 TEST_F(CommonOperatorReducerTest, SelectToFloat64Max) { |
579 Node* p0 = Parameter(0); | 589 Node* p0 = Parameter(0); |
580 Node* p1 = Parameter(1); | 590 Node* p1 = Parameter(1); |
581 Node* check = graph()->NewNode(machine()->Float64LessThan(), p0, p1); | 591 Node* check = graph()->NewNode(machine()->Float64LessThan(), p0, p1); |
582 Node* select = | 592 Node* select = graph()->NewNode( |
583 graph()->NewNode(common()->Select(kMachFloat64), check, p1, p0); | 593 common()->Select(MachineRepresentation::kFloat64), check, p1, p0); |
584 Reduction r = Reduce(select, MachineOperatorBuilder::kFloat64Max); | 594 Reduction r = Reduce(select, MachineOperatorBuilder::kFloat64Max); |
585 ASSERT_TRUE(r.Changed()); | 595 ASSERT_TRUE(r.Changed()); |
586 EXPECT_THAT(r.replacement(), IsFloat64Max(p1, p0)); | 596 EXPECT_THAT(r.replacement(), IsFloat64Max(p1, p0)); |
587 } | 597 } |
588 | 598 |
589 | 599 |
590 TEST_F(CommonOperatorReducerTest, SelectToFloat32Min) { | 600 TEST_F(CommonOperatorReducerTest, SelectToFloat32Min) { |
591 Node* p0 = Parameter(0); | 601 Node* p0 = Parameter(0); |
592 Node* p1 = Parameter(1); | 602 Node* p1 = Parameter(1); |
593 Node* check = graph()->NewNode(machine()->Float32LessThan(), p0, p1); | 603 Node* check = graph()->NewNode(machine()->Float32LessThan(), p0, p1); |
594 Node* select = | 604 Node* select = graph()->NewNode( |
595 graph()->NewNode(common()->Select(kMachFloat32), check, p0, p1); | 605 common()->Select(MachineRepresentation::kFloat32), check, p0, p1); |
596 Reduction r = Reduce(select, MachineOperatorBuilder::kFloat32Min); | 606 Reduction r = Reduce(select, MachineOperatorBuilder::kFloat32Min); |
597 ASSERT_TRUE(r.Changed()); | 607 ASSERT_TRUE(r.Changed()); |
598 EXPECT_THAT(r.replacement(), IsFloat32Min(p0, p1)); | 608 EXPECT_THAT(r.replacement(), IsFloat32Min(p0, p1)); |
599 } | 609 } |
600 | 610 |
601 | 611 |
602 TEST_F(CommonOperatorReducerTest, SelectToFloat64Min) { | 612 TEST_F(CommonOperatorReducerTest, SelectToFloat64Min) { |
603 Node* p0 = Parameter(0); | 613 Node* p0 = Parameter(0); |
604 Node* p1 = Parameter(1); | 614 Node* p1 = Parameter(1); |
605 Node* check = graph()->NewNode(machine()->Float64LessThan(), p0, p1); | 615 Node* check = graph()->NewNode(machine()->Float64LessThan(), p0, p1); |
606 Node* select = | 616 Node* select = graph()->NewNode( |
607 graph()->NewNode(common()->Select(kMachFloat64), check, p0, p1); | 617 common()->Select(MachineRepresentation::kFloat64), check, p0, p1); |
608 Reduction r = Reduce(select, MachineOperatorBuilder::kFloat64Min); | 618 Reduction r = Reduce(select, MachineOperatorBuilder::kFloat64Min); |
609 ASSERT_TRUE(r.Changed()); | 619 ASSERT_TRUE(r.Changed()); |
610 EXPECT_THAT(r.replacement(), IsFloat64Min(p0, p1)); | 620 EXPECT_THAT(r.replacement(), IsFloat64Min(p0, p1)); |
611 } | 621 } |
612 | 622 |
613 } // namespace compiler | 623 } // namespace compiler |
614 } // namespace internal | 624 } // namespace internal |
615 } // namespace v8 | 625 } // namespace v8 |
OLD | NEW |