Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: test/unittests/compiler/machine-operator-reducer-unittest.cc

Issue 697663003: [turbofan] Also optimize unsigned division by constant. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Slight improvement Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/base/bits.h" 5 #include "src/base/bits.h"
6 #include "src/base/division-by-constant.h" 6 #include "src/base/division-by-constant.h"
7 #include "src/compiler/js-graph.h" 7 #include "src/compiler/js-graph.h"
8 #include "src/compiler/machine-operator-reducer.h" 8 #include "src/compiler/machine-operator-reducer.h"
9 #include "src/compiler/typer.h" 9 #include "src/compiler/typer.h"
10 #include "test/unittests/compiler/graph-unittest.h" 10 #include "test/unittests/compiler/graph-unittest.h"
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 } 673 }
674 674
675 675
676 // ----------------------------------------------------------------------------- 676 // -----------------------------------------------------------------------------
677 // Int32Div 677 // Int32Div
678 678
679 679
680 TEST_F(MachineOperatorReducerTest, Int32DivWithConstant) { 680 TEST_F(MachineOperatorReducerTest, Int32DivWithConstant) {
681 Node* const p0 = Parameter(0); 681 Node* const p0 = Parameter(0);
682 { 682 {
683 Reduction const r = 683 Reduction const r = Reduce(graph()->NewNode(
684 Reduce(graph()->NewNode(machine()->Int32Div(), p0, Int32Constant(0))); 684 machine()->Int32Div(), p0, Int32Constant(0), graph()->start()));
685 ASSERT_TRUE(r.Changed()); 685 ASSERT_TRUE(r.Changed());
686 EXPECT_THAT(r.replacement(), IsInt32Constant(0)); 686 EXPECT_THAT(r.replacement(), IsInt32Constant(0));
687 } 687 }
688 { 688 {
689 Reduction const r = 689 Reduction const r = Reduce(graph()->NewNode(
690 Reduce(graph()->NewNode(machine()->Int32Div(), p0, Int32Constant(1))); 690 machine()->Int32Div(), p0, Int32Constant(1), graph()->start()));
691 ASSERT_TRUE(r.Changed()); 691 ASSERT_TRUE(r.Changed());
692 EXPECT_EQ(r.replacement(), p0); 692 EXPECT_EQ(r.replacement(), p0);
693 } 693 }
694 { 694 {
695 Reduction const r = 695 Reduction const r = Reduce(graph()->NewNode(
696 Reduce(graph()->NewNode(machine()->Int32Div(), p0, Int32Constant(-1))); 696 machine()->Int32Div(), p0, Int32Constant(-1), graph()->start()));
697 ASSERT_TRUE(r.Changed()); 697 ASSERT_TRUE(r.Changed());
698 EXPECT_THAT(r.replacement(), IsInt32Sub(IsInt32Constant(0), p0)); 698 EXPECT_THAT(r.replacement(), IsInt32Sub(IsInt32Constant(0), p0));
699 } 699 }
700 { 700 {
701 Reduction const r = 701 Reduction const r = Reduce(graph()->NewNode(
702 Reduce(graph()->NewNode(machine()->Int32Div(), p0, Int32Constant(2))); 702 machine()->Int32Div(), p0, Int32Constant(2), graph()->start()));
703 ASSERT_TRUE(r.Changed()); 703 ASSERT_TRUE(r.Changed());
704 EXPECT_THAT( 704 EXPECT_THAT(
705 r.replacement(), 705 r.replacement(),
706 IsWord32Sar(IsInt32Add(IsWord32Shr(p0, IsInt32Constant(31)), p0), 706 IsWord32Sar(IsInt32Add(IsWord32Shr(p0, IsInt32Constant(31)), p0),
707 IsInt32Constant(1))); 707 IsInt32Constant(1)));
708 } 708 }
709 { 709 {
710 Reduction const r = 710 Reduction const r = Reduce(graph()->NewNode(
711 Reduce(graph()->NewNode(machine()->Int32Div(), p0, Int32Constant(-2))); 711 machine()->Int32Div(), p0, Int32Constant(-2), graph()->start()));
712 ASSERT_TRUE(r.Changed()); 712 ASSERT_TRUE(r.Changed());
713 EXPECT_THAT( 713 EXPECT_THAT(
714 r.replacement(), 714 r.replacement(),
715 IsInt32Sub( 715 IsInt32Sub(
716 IsInt32Constant(0), 716 IsInt32Constant(0),
717 IsWord32Sar(IsInt32Add(IsWord32Shr(p0, IsInt32Constant(31)), p0), 717 IsWord32Sar(IsInt32Add(IsWord32Shr(p0, IsInt32Constant(31)), p0),
718 IsInt32Constant(1)))); 718 IsInt32Constant(1))));
719 } 719 }
720 TRACED_FORRANGE(int32_t, shift, 2, 30) { 720 TRACED_FORRANGE(int32_t, shift, 2, 30) {
721 Reduction const r = Reduce( 721 Reduction const r =
722 graph()->NewNode(machine()->Int32Div(), p0, Int32Constant(1 << shift))); 722 Reduce(graph()->NewNode(machine()->Int32Div(), p0,
723 Int32Constant(1 << shift), graph()->start()));
723 ASSERT_TRUE(r.Changed()); 724 ASSERT_TRUE(r.Changed());
724 EXPECT_THAT( 725 EXPECT_THAT(
725 r.replacement(), 726 r.replacement(),
726 IsWord32Sar(IsInt32Add(IsWord32Shr(IsWord32Sar(p0, IsInt32Constant(31)), 727 IsWord32Sar(IsInt32Add(IsWord32Shr(IsWord32Sar(p0, IsInt32Constant(31)),
727 IsInt32Constant(32 - shift)), 728 IsInt32Constant(32 - shift)),
728 p0), 729 p0),
729 IsInt32Constant(shift))); 730 IsInt32Constant(shift)));
730 } 731 }
731 TRACED_FORRANGE(int32_t, shift, 2, 31) { 732 TRACED_FORRANGE(int32_t, shift, 2, 31) {
732 Reduction const r = Reduce(graph()->NewNode( 733 Reduction const r = Reduce(graph()->NewNode(
733 machine()->Int32Div(), p0, 734 machine()->Int32Div(), p0,
734 Uint32Constant(bit_cast<uint32_t, int32_t>(-1) << shift))); 735 Uint32Constant(bit_cast<uint32_t, int32_t>(-1) << shift),
736 graph()->start()));
735 ASSERT_TRUE(r.Changed()); 737 ASSERT_TRUE(r.Changed());
736 EXPECT_THAT( 738 EXPECT_THAT(
737 r.replacement(), 739 r.replacement(),
738 IsInt32Sub( 740 IsInt32Sub(
739 IsInt32Constant(0), 741 IsInt32Constant(0),
740 IsWord32Sar( 742 IsWord32Sar(
741 IsInt32Add(IsWord32Shr(IsWord32Sar(p0, IsInt32Constant(31)), 743 IsInt32Add(IsWord32Shr(IsWord32Sar(p0, IsInt32Constant(31)),
742 IsInt32Constant(32 - shift)), 744 IsInt32Constant(32 - shift)),
743 p0), 745 p0),
744 IsInt32Constant(shift)))); 746 IsInt32Constant(shift))));
745 } 747 }
746 TRACED_FOREACH(int32_t, divisor, kInt32Values) { 748 TRACED_FOREACH(int32_t, divisor, kInt32Values) {
747 if (divisor < 0) { 749 if (divisor < 0) {
748 if (base::bits::IsPowerOfTwo32(-divisor)) continue; 750 if (base::bits::IsPowerOfTwo32(-divisor)) continue;
749 Reduction const r = Reduce( 751 Reduction const r = Reduce(graph()->NewNode(
750 graph()->NewNode(machine()->Int32Div(), p0, Int32Constant(divisor))); 752 machine()->Int32Div(), p0, Int32Constant(divisor), graph()->start()));
751 ASSERT_TRUE(r.Changed()); 753 ASSERT_TRUE(r.Changed());
752 EXPECT_THAT(r.replacement(), IsInt32Sub(IsInt32Constant(0), 754 EXPECT_THAT(r.replacement(), IsInt32Sub(IsInt32Constant(0),
753 IsTruncatingDiv(p0, -divisor))); 755 IsTruncatingDiv(p0, -divisor)));
754 } else if (divisor > 0) { 756 } else if (divisor > 0) {
755 if (base::bits::IsPowerOfTwo32(divisor)) continue; 757 if (base::bits::IsPowerOfTwo32(divisor)) continue;
756 Reduction const r = Reduce( 758 Reduction const r = Reduce(graph()->NewNode(
757 graph()->NewNode(machine()->Int32Div(), p0, Int32Constant(divisor))); 759 machine()->Int32Div(), p0, Int32Constant(divisor), graph()->start()));
758 ASSERT_TRUE(r.Changed()); 760 ASSERT_TRUE(r.Changed());
759 EXPECT_THAT(r.replacement(), IsTruncatingDiv(p0, divisor)); 761 EXPECT_THAT(r.replacement(), IsTruncatingDiv(p0, divisor));
760 } 762 }
761 } 763 }
762 } 764 }
763 765
764 766
765 TEST_F(MachineOperatorReducerTest, Int32DivWithParameters) { 767 TEST_F(MachineOperatorReducerTest, Int32DivWithParameters) {
766 Node* const p0 = Parameter(0); 768 Node* const p0 = Parameter(0);
767 Reduction const r = Reduce(graph()->NewNode(machine()->Int32Div(), p0, p0)); 769 Reduction const r =
770 Reduce(graph()->NewNode(machine()->Int32Div(), p0, p0, graph()->start()));
768 ASSERT_TRUE(r.Changed()); 771 ASSERT_TRUE(r.Changed());
769 EXPECT_THAT( 772 EXPECT_THAT(
770 r.replacement(), 773 r.replacement(),
771 IsWord32Equal(IsWord32Equal(p0, IsInt32Constant(0)), IsInt32Constant(0))); 774 IsWord32Equal(IsWord32Equal(p0, IsInt32Constant(0)), IsInt32Constant(0)));
772 } 775 }
773 776
774 777
775 // ----------------------------------------------------------------------------- 778 // -----------------------------------------------------------------------------
776 // Uint32Div 779 // Uint32Div
777 780
778 781
779 TEST_F(MachineOperatorReducerTest, Uint32DivWithConstant) { 782 TEST_F(MachineOperatorReducerTest, Uint32DivWithConstant) {
780 Node* const p0 = Parameter(0); 783 Node* const p0 = Parameter(0);
781 { 784 {
782 Reduction const r = 785 Reduction const r = Reduce(graph()->NewNode(
783 Reduce(graph()->NewNode(machine()->Uint32Div(), Int32Constant(0), p0)); 786 machine()->Uint32Div(), Int32Constant(0), p0, graph()->start()));
784 ASSERT_TRUE(r.Changed()); 787 ASSERT_TRUE(r.Changed());
785 EXPECT_THAT(r.replacement(), IsInt32Constant(0)); 788 EXPECT_THAT(r.replacement(), IsInt32Constant(0));
786 } 789 }
787 { 790 {
788 Reduction const r = 791 Reduction const r = Reduce(graph()->NewNode(
789 Reduce(graph()->NewNode(machine()->Uint32Div(), p0, Int32Constant(0))); 792 machine()->Uint32Div(), p0, Int32Constant(0), graph()->start()));
790 ASSERT_TRUE(r.Changed()); 793 ASSERT_TRUE(r.Changed());
791 EXPECT_THAT(r.replacement(), IsInt32Constant(0)); 794 EXPECT_THAT(r.replacement(), IsInt32Constant(0));
792 } 795 }
793 { 796 {
794 Reduction const r = 797 Reduction const r = Reduce(graph()->NewNode(
795 Reduce(graph()->NewNode(machine()->Uint32Div(), p0, Int32Constant(1))); 798 machine()->Uint32Div(), p0, Int32Constant(1), graph()->start()));
796 ASSERT_TRUE(r.Changed()); 799 ASSERT_TRUE(r.Changed());
797 EXPECT_EQ(r.replacement(), p0); 800 EXPECT_EQ(r.replacement(), p0);
798 } 801 }
799 TRACED_FOREACH(uint32_t, dividend, kUint32Values) { 802 TRACED_FOREACH(uint32_t, dividend, kUint32Values) {
800 TRACED_FOREACH(uint32_t, divisor, kUint32Values) { 803 TRACED_FOREACH(uint32_t, divisor, kUint32Values) {
801 Reduction const r = Reduce(graph()->NewNode(machine()->Uint32Div(), 804 Reduction const r = Reduce(
802 Uint32Constant(dividend), 805 graph()->NewNode(machine()->Uint32Div(), Uint32Constant(dividend),
803 Uint32Constant(divisor))); 806 Uint32Constant(divisor), graph()->start()));
804 ASSERT_TRUE(r.Changed()); 807 ASSERT_TRUE(r.Changed());
805 EXPECT_THAT(r.replacement(), 808 EXPECT_THAT(r.replacement(),
806 IsInt32Constant(bit_cast<int32_t>( 809 IsInt32Constant(bit_cast<int32_t>(
807 base::bits::UnsignedDiv32(dividend, divisor)))); 810 base::bits::UnsignedDiv32(dividend, divisor))));
808 } 811 }
809 } 812 }
810 TRACED_FORRANGE(uint32_t, shift, 1, 31) { 813 TRACED_FORRANGE(uint32_t, shift, 1, 31) {
811 Reduction const r = Reduce(graph()->NewNode(machine()->Uint32Div(), p0, 814 Reduction const r =
812 Uint32Constant(1u << shift))); 815 Reduce(graph()->NewNode(machine()->Uint32Div(), p0,
816 Uint32Constant(1u << shift), graph()->start()));
813 ASSERT_TRUE(r.Changed()); 817 ASSERT_TRUE(r.Changed());
814 EXPECT_THAT(r.replacement(), 818 EXPECT_THAT(r.replacement(),
815 IsWord32Shr(p0, IsInt32Constant(bit_cast<int32_t>(shift)))); 819 IsWord32Shr(p0, IsInt32Constant(bit_cast<int32_t>(shift))));
816 } 820 }
817 } 821 }
818 822
819 823
820 TEST_F(MachineOperatorReducerTest, Uint32DivWithParameters) { 824 TEST_F(MachineOperatorReducerTest, Uint32DivWithParameters) {
821 Node* const p0 = Parameter(0); 825 Node* const p0 = Parameter(0);
822 Reduction const r = Reduce(graph()->NewNode(machine()->Uint32Div(), p0, p0)); 826 Reduction const r = Reduce(
827 graph()->NewNode(machine()->Uint32Div(), p0, p0, graph()->start()));
823 ASSERT_TRUE(r.Changed()); 828 ASSERT_TRUE(r.Changed());
824 EXPECT_THAT( 829 EXPECT_THAT(
825 r.replacement(), 830 r.replacement(),
826 IsWord32Equal(IsWord32Equal(p0, IsInt32Constant(0)), IsInt32Constant(0))); 831 IsWord32Equal(IsWord32Equal(p0, IsInt32Constant(0)), IsInt32Constant(0)));
827 } 832 }
828 833
829 834
830 // ----------------------------------------------------------------------------- 835 // -----------------------------------------------------------------------------
831 // Int32Mod 836 // Int32Mod
832 837
833 838
834 TEST_F(MachineOperatorReducerTest, Int32ModWithConstant) { 839 TEST_F(MachineOperatorReducerTest, Int32ModWithConstant) {
835 Node* const p0 = Parameter(0); 840 Node* const p0 = Parameter(0);
836 { 841 {
837 Reduction const r = 842 Reduction const r = Reduce(graph()->NewNode(
838 Reduce(graph()->NewNode(machine()->Int32Mod(), Int32Constant(0), p0)); 843 machine()->Int32Mod(), Int32Constant(0), p0, graph()->start()));
839 ASSERT_TRUE(r.Changed()); 844 ASSERT_TRUE(r.Changed());
840 EXPECT_THAT(r.replacement(), IsInt32Constant(0)); 845 EXPECT_THAT(r.replacement(), IsInt32Constant(0));
841 } 846 }
842 { 847 {
843 Reduction const r = 848 Reduction const r = Reduce(graph()->NewNode(
844 Reduce(graph()->NewNode(machine()->Int32Mod(), p0, Int32Constant(0))); 849 machine()->Int32Mod(), p0, Int32Constant(0), graph()->start()));
845 ASSERT_TRUE(r.Changed()); 850 ASSERT_TRUE(r.Changed());
846 EXPECT_THAT(r.replacement(), IsInt32Constant(0)); 851 EXPECT_THAT(r.replacement(), IsInt32Constant(0));
847 } 852 }
848 { 853 {
849 Reduction const r = 854 Reduction const r = Reduce(graph()->NewNode(
850 Reduce(graph()->NewNode(machine()->Int32Mod(), p0, Int32Constant(1))); 855 machine()->Int32Mod(), p0, Int32Constant(1), graph()->start()));
851 ASSERT_TRUE(r.Changed()); 856 ASSERT_TRUE(r.Changed());
852 EXPECT_THAT(r.replacement(), IsInt32Constant(0)); 857 EXPECT_THAT(r.replacement(), IsInt32Constant(0));
853 } 858 }
854 { 859 {
855 Reduction const r = 860 Reduction const r = Reduce(graph()->NewNode(
856 Reduce(graph()->NewNode(machine()->Int32Mod(), p0, Int32Constant(-1))); 861 machine()->Int32Mod(), p0, Int32Constant(-1), graph()->start()));
857 ASSERT_TRUE(r.Changed()); 862 ASSERT_TRUE(r.Changed());
858 EXPECT_THAT(r.replacement(), IsInt32Constant(0)); 863 EXPECT_THAT(r.replacement(), IsInt32Constant(0));
859 } 864 }
860 TRACED_FOREACH(int32_t, dividend, kInt32Values) { 865 TRACED_FOREACH(int32_t, dividend, kInt32Values) {
861 TRACED_FOREACH(int32_t, divisor, kInt32Values) { 866 TRACED_FOREACH(int32_t, divisor, kInt32Values) {
862 Reduction const r = Reduce(graph()->NewNode(machine()->Int32Mod(), 867 Reduction const r = Reduce(
863 Int32Constant(dividend), 868 graph()->NewNode(machine()->Int32Mod(), Int32Constant(dividend),
864 Int32Constant(divisor))); 869 Int32Constant(divisor), graph()->start()));
865 ASSERT_TRUE(r.Changed()); 870 ASSERT_TRUE(r.Changed());
866 EXPECT_THAT(r.replacement(), 871 EXPECT_THAT(r.replacement(),
867 IsInt32Constant(base::bits::SignedMod32(dividend, divisor))); 872 IsInt32Constant(base::bits::SignedMod32(dividend, divisor)));
868 } 873 }
869 } 874 }
870 TRACED_FORRANGE(int32_t, shift, 1, 30) { 875 TRACED_FORRANGE(int32_t, shift, 1, 30) {
871 Reduction const r = Reduce( 876 Reduction const r =
872 graph()->NewNode(machine()->Int32Mod(), p0, Int32Constant(1 << shift))); 877 Reduce(graph()->NewNode(machine()->Int32Mod(), p0,
878 Int32Constant(1 << shift), graph()->start()));
873 ASSERT_TRUE(r.Changed()); 879 ASSERT_TRUE(r.Changed());
874 880
875 Capture<Node*> branch; 881 Capture<Node*> branch;
876 Node* const phi = r.replacement(); 882 Node* const phi = r.replacement();
877 int32_t const mask = (1 << shift) - 1; 883 int32_t const mask = (1 << shift) - 1;
878 EXPECT_THAT( 884 EXPECT_THAT(
879 phi, IsPhi(kMachInt32, 885 phi, IsPhi(kMachInt32,
880 IsInt32Sub(IsInt32Constant(0), 886 IsInt32Sub(IsInt32Constant(0),
881 IsWord32And(IsInt32Sub(IsInt32Constant(0), p0), 887 IsWord32And(IsInt32Sub(IsInt32Constant(0), p0),
882 IsInt32Constant(mask))), 888 IsInt32Constant(mask))),
883 IsWord32And(p0, IsInt32Constant(mask)), 889 IsWord32And(p0, IsInt32Constant(mask)),
884 IsMerge(IsIfTrue(CaptureEq(&branch)), 890 IsMerge(IsIfTrue(CaptureEq(&branch)),
885 IsIfFalse(AllOf( 891 IsIfFalse(AllOf(
886 CaptureEq(&branch), 892 CaptureEq(&branch),
887 IsBranch(IsInt32LessThan(p0, IsInt32Constant(0)), 893 IsBranch(IsInt32LessThan(p0, IsInt32Constant(0)),
888 graph()->start())))))); 894 graph()->start()))))));
889 } 895 }
890 TRACED_FORRANGE(int32_t, shift, 1, 31) { 896 TRACED_FORRANGE(int32_t, shift, 1, 31) {
891 Reduction const r = Reduce(graph()->NewNode( 897 Reduction const r = Reduce(graph()->NewNode(
892 machine()->Int32Mod(), p0, 898 machine()->Int32Mod(), p0,
893 Uint32Constant(bit_cast<uint32_t, int32_t>(-1) << shift))); 899 Uint32Constant(bit_cast<uint32_t, int32_t>(-1) << shift),
900 graph()->start()));
894 ASSERT_TRUE(r.Changed()); 901 ASSERT_TRUE(r.Changed());
895 902
896 Capture<Node*> branch; 903 Capture<Node*> branch;
897 Node* const phi = r.replacement(); 904 Node* const phi = r.replacement();
898 int32_t const mask = bit_cast<int32_t, uint32_t>((1U << shift) - 1); 905 int32_t const mask = bit_cast<int32_t, uint32_t>((1U << shift) - 1);
899 EXPECT_THAT( 906 EXPECT_THAT(
900 phi, IsPhi(kMachInt32, 907 phi, IsPhi(kMachInt32,
901 IsInt32Sub(IsInt32Constant(0), 908 IsInt32Sub(IsInt32Constant(0),
902 IsWord32And(IsInt32Sub(IsInt32Constant(0), p0), 909 IsWord32And(IsInt32Sub(IsInt32Constant(0), p0),
903 IsInt32Constant(mask))), 910 IsInt32Constant(mask))),
904 IsWord32And(p0, IsInt32Constant(mask)), 911 IsWord32And(p0, IsInt32Constant(mask)),
905 IsMerge(IsIfTrue(CaptureEq(&branch)), 912 IsMerge(IsIfTrue(CaptureEq(&branch)),
906 IsIfFalse(AllOf( 913 IsIfFalse(AllOf(
907 CaptureEq(&branch), 914 CaptureEq(&branch),
908 IsBranch(IsInt32LessThan(p0, IsInt32Constant(0)), 915 IsBranch(IsInt32LessThan(p0, IsInt32Constant(0)),
909 graph()->start())))))); 916 graph()->start()))))));
910 } 917 }
911 TRACED_FOREACH(int32_t, divisor, kInt32Values) { 918 TRACED_FOREACH(int32_t, divisor, kInt32Values) {
912 if (divisor == 0 || base::bits::IsPowerOfTwo32(Abs(divisor))) continue; 919 if (divisor == 0 || base::bits::IsPowerOfTwo32(Abs(divisor))) continue;
913 Reduction const r = Reduce( 920 Reduction const r = Reduce(graph()->NewNode(
914 graph()->NewNode(machine()->Int32Mod(), p0, Int32Constant(divisor))); 921 machine()->Int32Mod(), p0, Int32Constant(divisor), graph()->start()));
915 ASSERT_TRUE(r.Changed()); 922 ASSERT_TRUE(r.Changed());
916 EXPECT_THAT(r.replacement(), 923 EXPECT_THAT(r.replacement(),
917 IsInt32Sub(p0, IsInt32Mul(IsTruncatingDiv(p0, Abs(divisor)), 924 IsInt32Sub(p0, IsInt32Mul(IsTruncatingDiv(p0, Abs(divisor)),
918 IsInt32Constant(Abs(divisor))))); 925 IsInt32Constant(Abs(divisor)))));
919 } 926 }
920 } 927 }
921 928
922 929
923 TEST_F(MachineOperatorReducerTest, Int32ModWithParameters) { 930 TEST_F(MachineOperatorReducerTest, Int32ModWithParameters) {
924 Node* const p0 = Parameter(0); 931 Node* const p0 = Parameter(0);
925 Reduction const r = Reduce(graph()->NewNode(machine()->Int32Mod(), p0, p0)); 932 Reduction const r =
933 Reduce(graph()->NewNode(machine()->Int32Mod(), p0, p0, graph()->start()));
926 ASSERT_TRUE(r.Changed()); 934 ASSERT_TRUE(r.Changed());
927 EXPECT_THAT(r.replacement(), IsInt32Constant(0)); 935 EXPECT_THAT(r.replacement(), IsInt32Constant(0));
928 } 936 }
929 937
930 938
931 // ----------------------------------------------------------------------------- 939 // -----------------------------------------------------------------------------
932 // Uint32Mod 940 // Uint32Mod
933 941
934 942
935 TEST_F(MachineOperatorReducerTest, Uint32ModWithConstant) { 943 TEST_F(MachineOperatorReducerTest, Uint32ModWithConstant) {
936 Node* const p0 = Parameter(0); 944 Node* const p0 = Parameter(0);
937 { 945 {
938 Reduction const r = 946 Reduction const r = Reduce(graph()->NewNode(
939 Reduce(graph()->NewNode(machine()->Uint32Mod(), p0, Int32Constant(0))); 947 machine()->Uint32Mod(), p0, Int32Constant(0), graph()->start()));
940 ASSERT_TRUE(r.Changed()); 948 ASSERT_TRUE(r.Changed());
941 EXPECT_THAT(r.replacement(), IsInt32Constant(0)); 949 EXPECT_THAT(r.replacement(), IsInt32Constant(0));
942 } 950 }
943 { 951 {
944 Reduction const r = 952 Reduction const r = Reduce(graph()->NewNode(
945 Reduce(graph()->NewNode(machine()->Uint32Mod(), Int32Constant(0), p0)); 953 machine()->Uint32Mod(), Int32Constant(0), p0, graph()->start()));
946 ASSERT_TRUE(r.Changed()); 954 ASSERT_TRUE(r.Changed());
947 EXPECT_THAT(r.replacement(), IsInt32Constant(0)); 955 EXPECT_THAT(r.replacement(), IsInt32Constant(0));
948 } 956 }
949 { 957 {
950 Reduction const r = 958 Reduction const r = Reduce(graph()->NewNode(
951 Reduce(graph()->NewNode(machine()->Uint32Mod(), p0, Int32Constant(1))); 959 machine()->Uint32Mod(), p0, Int32Constant(1), graph()->start()));
952 ASSERT_TRUE(r.Changed()); 960 ASSERT_TRUE(r.Changed());
953 EXPECT_THAT(r.replacement(), IsInt32Constant(0)); 961 EXPECT_THAT(r.replacement(), IsInt32Constant(0));
954 } 962 }
955 TRACED_FOREACH(uint32_t, dividend, kUint32Values) { 963 TRACED_FOREACH(uint32_t, dividend, kUint32Values) {
956 TRACED_FOREACH(uint32_t, divisor, kUint32Values) { 964 TRACED_FOREACH(uint32_t, divisor, kUint32Values) {
957 Reduction const r = Reduce(graph()->NewNode(machine()->Uint32Mod(), 965 Reduction const r = Reduce(
958 Uint32Constant(dividend), 966 graph()->NewNode(machine()->Uint32Mod(), Uint32Constant(dividend),
959 Uint32Constant(divisor))); 967 Uint32Constant(divisor), graph()->start()));
960 ASSERT_TRUE(r.Changed()); 968 ASSERT_TRUE(r.Changed());
961 EXPECT_THAT(r.replacement(), 969 EXPECT_THAT(r.replacement(),
962 IsInt32Constant(bit_cast<int32_t>( 970 IsInt32Constant(bit_cast<int32_t>(
963 base::bits::UnsignedMod32(dividend, divisor)))); 971 base::bits::UnsignedMod32(dividend, divisor))));
964 } 972 }
965 } 973 }
966 TRACED_FORRANGE(uint32_t, shift, 1, 31) { 974 TRACED_FORRANGE(uint32_t, shift, 1, 31) {
967 Reduction const r = Reduce(graph()->NewNode(machine()->Uint32Mod(), p0, 975 Reduction const r =
968 Uint32Constant(1u << shift))); 976 Reduce(graph()->NewNode(machine()->Uint32Mod(), p0,
977 Uint32Constant(1u << shift), graph()->start()));
969 ASSERT_TRUE(r.Changed()); 978 ASSERT_TRUE(r.Changed());
970 EXPECT_THAT(r.replacement(), 979 EXPECT_THAT(r.replacement(),
971 IsWord32And(p0, IsInt32Constant( 980 IsWord32And(p0, IsInt32Constant(
972 bit_cast<int32_t>((1u << shift) - 1u)))); 981 bit_cast<int32_t>((1u << shift) - 1u))));
973 } 982 }
974 } 983 }
975 984
976 985
977 TEST_F(MachineOperatorReducerTest, Uint32ModWithParameters) { 986 TEST_F(MachineOperatorReducerTest, Uint32ModWithParameters) {
978 Node* const p0 = Parameter(0); 987 Node* const p0 = Parameter(0);
979 Reduction const r = Reduce(graph()->NewNode(machine()->Uint32Mod(), p0, p0)); 988 Reduction const r = Reduce(
989 graph()->NewNode(machine()->Uint32Mod(), p0, p0, graph()->start()));
980 ASSERT_TRUE(r.Changed()); 990 ASSERT_TRUE(r.Changed());
981 EXPECT_THAT(r.replacement(), IsInt32Constant(0)); 991 EXPECT_THAT(r.replacement(), IsInt32Constant(0));
982 } 992 }
983 993
984 994
985 // ----------------------------------------------------------------------------- 995 // -----------------------------------------------------------------------------
986 // Int32AddWithOverflow 996 // Int32AddWithOverflow
987 997
988 998
989 TEST_F(MachineOperatorReducerTest, Int32AddWithOverflowWithZero) { 999 TEST_F(MachineOperatorReducerTest, Int32AddWithOverflowWithZero) {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 Reduction r = Reduce(node); 1149 Reduction r = Reduce(node);
1140 ASSERT_TRUE(r.Changed()); 1150 ASSERT_TRUE(r.Changed());
1141 EXPECT_THAT(r.replacement(), 1151 EXPECT_THAT(r.replacement(),
1142 IsStore(rep, base, index, value, effect, control)); 1152 IsStore(rep, base, index, value, effect, control));
1143 } 1153 }
1144 } 1154 }
1145 1155
1146 } // namespace compiler 1156 } // namespace compiler
1147 } // namespace internal 1157 } // namespace internal
1148 } // namespace v8 1158 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/compiler/change-lowering-unittest.cc ('k') | test/unittests/compiler/x64/instruction-selector-x64-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698