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/js-builtin-reducer.h" | 5 #include "src/compiler/js-builtin-reducer.h" |
6 #include "src/compiler/js-graph.h" | 6 #include "src/compiler/js-graph.h" |
7 #include "src/compiler/node-properties.h" | 7 #include "src/compiler/node-properties.h" |
8 #include "src/compiler/simplified-operator.h" | 8 #include "src/compiler/simplified-operator.h" |
9 #include "src/compiler/typer.h" | 9 #include "src/compiler/typer.h" |
10 #include "src/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 } | 882 } |
883 | 883 |
884 TEST_F(JSBuiltinReducerTest, MathMaxWithPlainPrimitive) { | 884 TEST_F(JSBuiltinReducerTest, MathMaxWithPlainPrimitive) { |
885 Node* function = MathFunction("max"); | 885 Node* function = MathFunction("max"); |
886 | 886 |
887 Node* effect = graph()->start(); | 887 Node* effect = graph()->start(); |
888 Node* control = graph()->start(); | 888 Node* control = graph()->start(); |
889 Node* context = UndefinedConstant(); | 889 Node* context = UndefinedConstant(); |
890 Node* frame_state = graph()->start(); | 890 Node* frame_state = graph()->start(); |
891 Node* p0 = Parameter(Type::PlainPrimitive(), 0); | 891 Node* p0 = Parameter(Type::PlainPrimitive(), 0); |
892 Node* call = graph()->NewNode(javascript()->CallFunction(3), function, | 892 Node* p1 = Parameter(Type::PlainPrimitive(), 1); |
893 UndefinedConstant(), p0, context, frame_state, | 893 Node* call = graph()->NewNode(javascript()->CallFunction(4), function, |
894 effect, control); | 894 UndefinedConstant(), p0, p1, context, |
| 895 frame_state, effect, control); |
895 Reduction r = Reduce(call); | 896 Reduction r = Reduce(call); |
896 | 897 |
897 ASSERT_TRUE(r.Changed()); | 898 ASSERT_TRUE(r.Changed()); |
898 EXPECT_THAT(r.replacement(), IsPlainPrimitiveToNumber(p0)); | 899 EXPECT_THAT(r.replacement(), IsNumberMax(IsPlainPrimitiveToNumber(p0), |
899 } | 900 IsPlainPrimitiveToNumber(p1))); |
900 | |
901 TEST_F(JSBuiltinReducerTest, MathMaxWithIntegral32) { | |
902 Node* function = MathFunction("max"); | |
903 | |
904 Node* effect = graph()->start(); | |
905 Node* control = graph()->start(); | |
906 Node* context = UndefinedConstant(); | |
907 Node* frame_state = graph()->start(); | |
908 TRACED_FOREACH(Type*, t0, kIntegral32Types) { | |
909 TRACED_FOREACH(Type*, t1, kIntegral32Types) { | |
910 Node* p0 = Parameter(t0, 0); | |
911 Node* p1 = Parameter(t1, 1); | |
912 Node* call = graph()->NewNode(javascript()->CallFunction(4), function, | |
913 UndefinedConstant(), p0, p1, context, | |
914 frame_state, effect, control); | |
915 Reduction r = Reduce(call); | |
916 | |
917 ASSERT_TRUE(r.Changed()); | |
918 EXPECT_THAT(r.replacement(), IsSelect(MachineRepresentation::kNone, | |
919 IsNumberLessThan(p1, p0), p0, p1)); | |
920 } | |
921 } | |
922 } | 901 } |
923 | 902 |
924 // ----------------------------------------------------------------------------- | 903 // ----------------------------------------------------------------------------- |
925 // Math.min | 904 // Math.min |
926 | 905 |
927 TEST_F(JSBuiltinReducerTest, MathMinWithNoArguments) { | 906 TEST_F(JSBuiltinReducerTest, MathMinWithNoArguments) { |
928 Node* function = MathFunction("min"); | 907 Node* function = MathFunction("min"); |
929 | 908 |
930 Node* effect = graph()->start(); | 909 Node* effect = graph()->start(); |
931 Node* control = graph()->start(); | 910 Node* control = graph()->start(); |
(...skipping 28 matching lines...) Expand all Loading... |
960 } | 939 } |
961 | 940 |
962 TEST_F(JSBuiltinReducerTest, MathMinWithPlainPrimitive) { | 941 TEST_F(JSBuiltinReducerTest, MathMinWithPlainPrimitive) { |
963 Node* function = MathFunction("min"); | 942 Node* function = MathFunction("min"); |
964 | 943 |
965 Node* effect = graph()->start(); | 944 Node* effect = graph()->start(); |
966 Node* control = graph()->start(); | 945 Node* control = graph()->start(); |
967 Node* context = UndefinedConstant(); | 946 Node* context = UndefinedConstant(); |
968 Node* frame_state = graph()->start(); | 947 Node* frame_state = graph()->start(); |
969 Node* p0 = Parameter(Type::PlainPrimitive(), 0); | 948 Node* p0 = Parameter(Type::PlainPrimitive(), 0); |
970 Node* call = graph()->NewNode(javascript()->CallFunction(3), function, | 949 Node* p1 = Parameter(Type::PlainPrimitive(), 1); |
971 UndefinedConstant(), p0, context, frame_state, | 950 Node* call = graph()->NewNode(javascript()->CallFunction(4), function, |
972 effect, control); | 951 UndefinedConstant(), p0, p1, context, |
| 952 frame_state, effect, control); |
973 Reduction r = Reduce(call); | 953 Reduction r = Reduce(call); |
974 | 954 |
975 ASSERT_TRUE(r.Changed()); | 955 ASSERT_TRUE(r.Changed()); |
976 EXPECT_THAT(r.replacement(), IsPlainPrimitiveToNumber(p0)); | 956 EXPECT_THAT(r.replacement(), IsNumberMin(IsPlainPrimitiveToNumber(p0), |
977 } | 957 IsPlainPrimitiveToNumber(p1))); |
978 | |
979 TEST_F(JSBuiltinReducerTest, MathMinWithIntegral32) { | |
980 Node* function = MathFunction("min"); | |
981 | |
982 Node* effect = graph()->start(); | |
983 Node* control = graph()->start(); | |
984 Node* context = UndefinedConstant(); | |
985 Node* frame_state = graph()->start(); | |
986 TRACED_FOREACH(Type*, t0, kIntegral32Types) { | |
987 TRACED_FOREACH(Type*, t1, kIntegral32Types) { | |
988 Node* p0 = Parameter(t0, 0); | |
989 Node* p1 = Parameter(t1, 1); | |
990 Node* call = graph()->NewNode(javascript()->CallFunction(4), function, | |
991 UndefinedConstant(), p0, p1, context, | |
992 frame_state, effect, control); | |
993 Reduction r = Reduce(call); | |
994 | |
995 ASSERT_TRUE(r.Changed()); | |
996 EXPECT_THAT(r.replacement(), IsSelect(MachineRepresentation::kNone, | |
997 IsNumberLessThan(p1, p0), p1, p0)); | |
998 } | |
999 } | |
1000 } | 958 } |
1001 | 959 |
1002 // ----------------------------------------------------------------------------- | 960 // ----------------------------------------------------------------------------- |
1003 // Math.round | 961 // Math.round |
1004 | 962 |
1005 TEST_F(JSBuiltinReducerTest, MathRoundWithNumber) { | 963 TEST_F(JSBuiltinReducerTest, MathRoundWithNumber) { |
1006 Node* function = MathFunction("round"); | 964 Node* function = MathFunction("round"); |
1007 | 965 |
1008 Node* effect = graph()->start(); | 966 Node* effect = graph()->start(); |
1009 Node* control = graph()->start(); | 967 Node* control = graph()->start(); |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1433 Reduction r = Reduce(call); | 1391 Reduction r = Reduce(call); |
1434 | 1392 |
1435 ASSERT_TRUE(r.Changed()); | 1393 ASSERT_TRUE(r.Changed()); |
1436 EXPECT_THAT(r.replacement(), | 1394 EXPECT_THAT(r.replacement(), |
1437 IsStringFromCharCode(IsPlainPrimitiveToNumber(p0))); | 1395 IsStringFromCharCode(IsPlainPrimitiveToNumber(p0))); |
1438 } | 1396 } |
1439 | 1397 |
1440 } // namespace compiler | 1398 } // namespace compiler |
1441 } // namespace internal | 1399 } // namespace internal |
1442 } // namespace v8 | 1400 } // namespace v8 |
OLD | NEW |