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/code-stubs.h" | 5 #include "src/code-stubs.h" |
6 #include "src/compiler/change-lowering.h" | 6 #include "src/compiler/change-lowering.h" |
7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
8 #include "src/compiler/linkage.h" | 8 #include "src/compiler/linkage.h" |
9 #include "src/compiler/node-properties.h" | 9 #include "src/compiler/node-properties.h" |
10 #include "src/compiler/simplified-operator.h" | 10 #include "src/compiler/simplified-operator.h" |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 | 328 |
329 class ChangeLowering32Test : public ChangeLoweringTest { | 329 class ChangeLowering32Test : public ChangeLoweringTest { |
330 public: | 330 public: |
331 ~ChangeLowering32Test() override {} | 331 ~ChangeLowering32Test() override {} |
332 MachineRepresentation WordRepresentation() const final { | 332 MachineRepresentation WordRepresentation() const final { |
333 return MachineRepresentation::kWord32; | 333 return MachineRepresentation::kWord32; |
334 } | 334 } |
335 }; | 335 }; |
336 | 336 |
337 | 337 |
338 TARGET_TEST_F(ChangeLowering32Test, ChangeInt32ToTagged) { | |
339 Node* value = Parameter(Type::Integral32()); | |
340 Node* node = graph()->NewNode(simplified()->ChangeInt32ToTagged(), value); | |
341 Reduction r = Reduce(node); | |
342 ASSERT_TRUE(r.Changed()); | |
343 Capture<Node*> add, branch, heap_number, if_true; | |
344 EXPECT_THAT( | |
345 r.replacement(), | |
346 IsPhi(MachineRepresentation::kTagged, | |
347 IsFinishRegion( | |
348 AllOf(CaptureEq(&heap_number), | |
349 IsAllocateHeapNumber(_, CaptureEq(&if_true))), | |
350 IsStore( | |
351 StoreRepresentation(MachineRepresentation::kFloat64, | |
352 kNoWriteBarrier), | |
353 CaptureEq(&heap_number), | |
354 IsIntPtrConstant(HeapNumber::kValueOffset - kHeapObjectTag), | |
355 IsChangeInt32ToFloat64(value), CaptureEq(&heap_number), | |
356 CaptureEq(&if_true))), | |
357 IsProjection(0, AllOf(CaptureEq(&add), | |
358 IsInt32AddWithOverflow(value, value))), | |
359 IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))), | |
360 IsIfFalse(AllOf(CaptureEq(&branch), | |
361 IsBranch(IsProjection(1, CaptureEq(&add)), | |
362 graph()->start())))))); | |
363 } | |
364 | |
365 | |
366 TARGET_TEST_F(ChangeLowering32Test, ChangeTaggedToFloat64) { | 338 TARGET_TEST_F(ChangeLowering32Test, ChangeTaggedToFloat64) { |
367 STATIC_ASSERT(kSmiTag == 0); | 339 STATIC_ASSERT(kSmiTag == 0); |
368 STATIC_ASSERT(kSmiTagSize == 1); | 340 STATIC_ASSERT(kSmiTagSize == 1); |
369 | 341 |
370 Node* value = Parameter(Type::Number()); | 342 Node* value = Parameter(Type::Number()); |
371 Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), value); | 343 Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), value); |
372 Reduction r = Reduce(node); | 344 Reduction r = Reduce(node); |
373 ASSERT_TRUE(r.Changed()); | 345 ASSERT_TRUE(r.Changed()); |
374 Capture<Node*> branch, if_true; | 346 Capture<Node*> branch, if_true; |
375 EXPECT_THAT( | 347 EXPECT_THAT( |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 IsChangeFloat64ToUint32(IsLoadHeapNumber(value, CaptureEq(&if_true))), | 399 IsChangeFloat64ToUint32(IsLoadHeapNumber(value, CaptureEq(&if_true))), |
428 IsWord32Sar(value, IsInt32Constant(kSmiTagSize + kSmiShiftSize)), | 400 IsWord32Sar(value, IsInt32Constant(kSmiTagSize + kSmiShiftSize)), |
429 IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))), | 401 IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))), |
430 IsIfFalse(AllOf( | 402 IsIfFalse(AllOf( |
431 CaptureEq(&branch), | 403 CaptureEq(&branch), |
432 IsBranch(IsWord32And(value, IsInt32Constant(kSmiTagMask)), | 404 IsBranch(IsWord32And(value, IsInt32Constant(kSmiTagMask)), |
433 graph()->start())))))); | 405 graph()->start())))))); |
434 } | 406 } |
435 | 407 |
436 | 408 |
437 TARGET_TEST_F(ChangeLowering32Test, ChangeUint32ToTagged) { | |
438 STATIC_ASSERT(kSmiTag == 0); | |
439 STATIC_ASSERT(kSmiTagSize == 1); | |
440 | |
441 Node* value = Parameter(Type::Number()); | |
442 Node* node = graph()->NewNode(simplified()->ChangeUint32ToTagged(), value); | |
443 Reduction r = Reduce(node); | |
444 ASSERT_TRUE(r.Changed()); | |
445 Capture<Node*> branch, heap_number, if_false; | |
446 EXPECT_THAT( | |
447 r.replacement(), | |
448 IsPhi( | |
449 MachineRepresentation::kTagged, | |
450 IsWord32Shl(value, IsInt32Constant(kSmiTagSize + kSmiShiftSize)), | |
451 IsFinishRegion( | |
452 AllOf(CaptureEq(&heap_number), | |
453 IsAllocateHeapNumber(_, CaptureEq(&if_false))), | |
454 IsStore( | |
455 StoreRepresentation(MachineRepresentation::kFloat64, | |
456 kNoWriteBarrier), | |
457 CaptureEq(&heap_number), | |
458 IsInt32Constant(HeapNumber::kValueOffset - kHeapObjectTag), | |
459 IsChangeUint32ToFloat64(value), CaptureEq(&heap_number), | |
460 CaptureEq(&if_false))), | |
461 IsMerge(IsIfTrue(AllOf( | |
462 CaptureEq(&branch), | |
463 IsBranch(IsUint32LessThanOrEqual( | |
464 value, IsInt32Constant(Smi::kMaxValue)), | |
465 graph()->start()))), | |
466 AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch)))))); | |
467 } | |
468 | |
469 | |
470 // ----------------------------------------------------------------------------- | 409 // ----------------------------------------------------------------------------- |
471 // 64-bit | 410 // 64-bit |
472 | 411 |
473 | 412 |
474 class ChangeLowering64Test : public ChangeLoweringTest { | 413 class ChangeLowering64Test : public ChangeLoweringTest { |
475 public: | 414 public: |
476 ~ChangeLowering64Test() override {} | 415 ~ChangeLowering64Test() override {} |
477 MachineRepresentation WordRepresentation() const final { | 416 MachineRepresentation WordRepresentation() const final { |
478 return MachineRepresentation::kWord64; | 417 return MachineRepresentation::kWord64; |
479 } | 418 } |
480 }; | 419 }; |
481 | 420 |
482 | 421 |
483 TARGET_TEST_F(ChangeLowering64Test, ChangeInt32ToTagged) { | |
484 Node* value = Parameter(Type::Signed32()); | |
485 Node* node = graph()->NewNode(simplified()->ChangeInt32ToTagged(), value); | |
486 Reduction r = Reduce(node); | |
487 ASSERT_TRUE(r.Changed()); | |
488 EXPECT_THAT(r.replacement(), IsChangeInt32ToSmi(value)); | |
489 } | |
490 | |
491 | |
492 TARGET_TEST_F(ChangeLowering64Test, ChangeTaggedToFloat64) { | 422 TARGET_TEST_F(ChangeLowering64Test, ChangeTaggedToFloat64) { |
493 STATIC_ASSERT(kSmiTag == 0); | 423 STATIC_ASSERT(kSmiTag == 0); |
494 STATIC_ASSERT(kSmiTagSize == 1); | 424 STATIC_ASSERT(kSmiTagSize == 1); |
495 | 425 |
496 Node* value = Parameter(Type::Number()); | 426 Node* value = Parameter(Type::Number()); |
497 Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), value); | 427 Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), value); |
498 Reduction r = Reduce(node); | 428 Reduction r = Reduce(node); |
499 ASSERT_TRUE(r.Changed()); | 429 ASSERT_TRUE(r.Changed()); |
500 Capture<Node*> branch, if_true; | 430 Capture<Node*> branch, if_true; |
501 EXPECT_THAT( | 431 EXPECT_THAT( |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 IsChangeFloat64ToUint32(IsLoadHeapNumber(value, CaptureEq(&if_true))), | 484 IsChangeFloat64ToUint32(IsLoadHeapNumber(value, CaptureEq(&if_true))), |
555 IsTruncateInt64ToInt32( | 485 IsTruncateInt64ToInt32( |
556 IsWord64Sar(value, IsInt64Constant(kSmiTagSize + kSmiShiftSize))), | 486 IsWord64Sar(value, IsInt64Constant(kSmiTagSize + kSmiShiftSize))), |
557 IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))), | 487 IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))), |
558 IsIfFalse(AllOf( | 488 IsIfFalse(AllOf( |
559 CaptureEq(&branch), | 489 CaptureEq(&branch), |
560 IsBranch(IsWord64And(value, IsInt64Constant(kSmiTagMask)), | 490 IsBranch(IsWord64And(value, IsInt64Constant(kSmiTagMask)), |
561 graph()->start())))))); | 491 graph()->start())))))); |
562 } | 492 } |
563 | 493 |
564 | |
565 TARGET_TEST_F(ChangeLowering64Test, ChangeUint32ToTagged) { | |
566 STATIC_ASSERT(kSmiTag == 0); | |
567 STATIC_ASSERT(kSmiTagSize == 1); | |
568 | |
569 Node* value = Parameter(Type::Number()); | |
570 Node* node = graph()->NewNode(simplified()->ChangeUint32ToTagged(), value); | |
571 Reduction r = Reduce(node); | |
572 ASSERT_TRUE(r.Changed()); | |
573 Capture<Node*> branch, heap_number, if_false; | |
574 EXPECT_THAT( | |
575 r.replacement(), | |
576 IsPhi( | |
577 MachineRepresentation::kTagged, | |
578 IsWord64Shl(IsChangeUint32ToUint64(value), | |
579 IsInt64Constant(kSmiTagSize + kSmiShiftSize)), | |
580 IsFinishRegion( | |
581 AllOf(CaptureEq(&heap_number), | |
582 IsAllocateHeapNumber(_, CaptureEq(&if_false))), | |
583 IsStore( | |
584 StoreRepresentation(MachineRepresentation::kFloat64, | |
585 kNoWriteBarrier), | |
586 CaptureEq(&heap_number), | |
587 IsInt64Constant(HeapNumber::kValueOffset - kHeapObjectTag), | |
588 IsChangeUint32ToFloat64(value), CaptureEq(&heap_number), | |
589 CaptureEq(&if_false))), | |
590 IsMerge(IsIfTrue(AllOf( | |
591 CaptureEq(&branch), | |
592 IsBranch(IsUint32LessThanOrEqual( | |
593 value, IsInt32Constant(Smi::kMaxValue)), | |
594 graph()->start()))), | |
595 AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch)))))); | |
596 } | |
597 | |
598 } // namespace compiler | 494 } // namespace compiler |
599 } // namespace internal | 495 } // namespace internal |
600 } // namespace v8 | 496 } // namespace v8 |
OLD | NEW |