| 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/v8.h" | 5 #include "src/v8.h" |
| 6 #include "test/cctest/cctest.h" | 6 #include "test/cctest/cctest.h" |
| 7 | 7 |
| 8 #include "src/compiler/graph-inl.h" | 8 #include "src/compiler/graph-inl.h" |
| 9 #include "src/compiler/js-typed-lowering.h" | 9 #include "src/compiler/js-typed-lowering.h" |
| 10 #include "src/compiler/node-properties-inl.h" | 10 #include "src/compiler/node-properties-inl.h" |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 } | 658 } |
| 659 } | 659 } |
| 660 } | 660 } |
| 661 } | 661 } |
| 662 } | 662 } |
| 663 | 663 |
| 664 | 664 |
| 665 static void CheckIsConvertedToNumber(Node* val, Node* converted) { | 665 static void CheckIsConvertedToNumber(Node* val, Node* converted) { |
| 666 if (NodeProperties::GetBounds(val).upper->Is(Type::Number())) { | 666 if (NodeProperties::GetBounds(val).upper->Is(Type::Number())) { |
| 667 CHECK_EQ(val, converted); | 667 CHECK_EQ(val, converted); |
| 668 } else if (NodeProperties::GetBounds(val).upper->Is(Type::Boolean())) { |
| 669 CHECK_EQ(IrOpcode::kBooleanToNumber, converted->opcode()); |
| 670 CHECK_EQ(val, converted->InputAt(0)); |
| 668 } else { | 671 } else { |
| 669 if (converted->opcode() == IrOpcode::kNumberConstant) return; | 672 if (converted->opcode() == IrOpcode::kNumberConstant) return; |
| 670 CHECK_EQ(IrOpcode::kJSToNumber, converted->opcode()); | 673 CHECK_EQ(IrOpcode::kJSToNumber, converted->opcode()); |
| 671 CHECK_EQ(val, converted->InputAt(0)); | 674 CHECK_EQ(val, converted->InputAt(0)); |
| 672 } | 675 } |
| 673 } | 676 } |
| 674 | 677 |
| 675 | 678 |
| 676 TEST(NumberComparison) { | 679 TEST(NumberComparison) { |
| 677 JSTypedLoweringTester R; | 680 JSTypedLoweringTester R; |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 | 1045 |
| 1043 const Operator* ops[] = { | 1046 const Operator* ops[] = { |
| 1044 R.javascript.Add(), R.simplified.NumberAdd(), | 1047 R.javascript.Add(), R.simplified.NumberAdd(), |
| 1045 R.javascript.Subtract(), R.simplified.NumberSubtract(), | 1048 R.javascript.Subtract(), R.simplified.NumberSubtract(), |
| 1046 R.javascript.Multiply(), R.simplified.NumberMultiply(), | 1049 R.javascript.Multiply(), R.simplified.NumberMultiply(), |
| 1047 R.javascript.Divide(), R.simplified.NumberDivide(), | 1050 R.javascript.Divide(), R.simplified.NumberDivide(), |
| 1048 R.javascript.Modulus(), R.simplified.NumberModulus(), | 1051 R.javascript.Modulus(), R.simplified.NumberModulus(), |
| 1049 }; | 1052 }; |
| 1050 | 1053 |
| 1051 for (size_t j = 0; j < arraysize(ops); j += 2) { | 1054 for (size_t j = 0; j < arraysize(ops); j += 2) { |
| 1052 BinopEffectsTester B(ops[j], Type::Number(), Type::Boolean()); | 1055 BinopEffectsTester B(ops[j], Type::Number(), Type::Symbol()); |
| 1053 | 1056 |
| 1054 Node* i0 = B.CheckNoOp(0); | 1057 Node* i0 = B.CheckNoOp(0); |
| 1055 Node* i1 = B.CheckConvertedInput(IrOpcode::kJSToNumber, 1, true); | 1058 Node* i1 = B.CheckConvertedInput(IrOpcode::kJSToNumber, 1, true); |
| 1056 | 1059 |
| 1057 CHECK_EQ(B.p0, i0); | 1060 CHECK_EQ(B.p0, i0); |
| 1058 CHECK_EQ(B.p1, i1->InputAt(0)); | 1061 CHECK_EQ(B.p1, i1->InputAt(0)); |
| 1059 | 1062 |
| 1060 // Effects should be ordered start -> i1 -> effect_use | 1063 // Effects should be ordered start -> i1 -> effect_use |
| 1061 B.CheckEffectOrdering(i1); | 1064 B.CheckEffectOrdering(i1); |
| 1062 } | 1065 } |
| 1063 | 1066 |
| 1064 for (size_t j = 0; j < arraysize(ops); j += 2) { | 1067 for (size_t j = 0; j < arraysize(ops); j += 2) { |
| 1065 BinopEffectsTester B(ops[j], Type::Boolean(), Type::Number()); | 1068 BinopEffectsTester B(ops[j], Type::Symbol(), Type::Number()); |
| 1066 | 1069 |
| 1067 Node* i0 = B.CheckConvertedInput(IrOpcode::kJSToNumber, 0, true); | 1070 Node* i0 = B.CheckConvertedInput(IrOpcode::kJSToNumber, 0, true); |
| 1068 Node* i1 = B.CheckNoOp(1); | 1071 Node* i1 = B.CheckNoOp(1); |
| 1069 | 1072 |
| 1070 CHECK_EQ(B.p0, i0->InputAt(0)); | 1073 CHECK_EQ(B.p0, i0->InputAt(0)); |
| 1071 CHECK_EQ(B.p1, i1); | 1074 CHECK_EQ(B.p1, i1); |
| 1072 | 1075 |
| 1073 // Effects should be ordered start -> i0 -> effect_use | 1076 // Effects should be ordered start -> i0 -> effect_use |
| 1074 B.CheckEffectOrdering(i0); | 1077 B.CheckEffectOrdering(i0); |
| 1075 } | 1078 } |
| 1076 } | 1079 } |
| 1077 | 1080 |
| 1078 | 1081 |
| 1079 TEST(OrderCompareEffects) { | 1082 TEST(OrderCompareEffects) { |
| 1080 JSTypedLoweringTester R; | 1083 JSTypedLoweringTester R; |
| 1081 | 1084 |
| 1082 const Operator* ops[] = { | 1085 const Operator* ops[] = { |
| 1083 R.javascript.GreaterThan(), R.simplified.NumberLessThan(), | 1086 R.javascript.GreaterThan(), R.simplified.NumberLessThan(), |
| 1084 R.javascript.GreaterThanOrEqual(), R.simplified.NumberLessThanOrEqual(), | 1087 R.javascript.GreaterThanOrEqual(), R.simplified.NumberLessThanOrEqual(), |
| 1085 }; | 1088 }; |
| 1086 | 1089 |
| 1087 for (size_t j = 0; j < arraysize(ops); j += 2) { | 1090 for (size_t j = 0; j < arraysize(ops); j += 2) { |
| 1088 BinopEffectsTester B(ops[j], Type::Boolean(), Type::String()); | 1091 BinopEffectsTester B(ops[j], Type::Symbol(), Type::String()); |
| 1089 CHECK_EQ(ops[j + 1]->opcode(), B.result->op()->opcode()); | 1092 CHECK_EQ(ops[j + 1]->opcode(), B.result->op()->opcode()); |
| 1090 | 1093 |
| 1091 Node* i0 = B.CheckConvertedInput(IrOpcode::kJSToNumber, 0, true); | 1094 Node* i0 = B.CheckConvertedInput(IrOpcode::kJSToNumber, 0, true); |
| 1092 Node* i1 = B.CheckConvertedInput(IrOpcode::kJSToNumber, 1, true); | 1095 Node* i1 = B.CheckConvertedInput(IrOpcode::kJSToNumber, 1, true); |
| 1093 | 1096 |
| 1094 // Inputs should be commuted. | 1097 // Inputs should be commuted. |
| 1095 CHECK_EQ(B.p1, i0->InputAt(0)); | 1098 CHECK_EQ(B.p1, i0->InputAt(0)); |
| 1096 CHECK_EQ(B.p0, i1->InputAt(0)); | 1099 CHECK_EQ(B.p0, i1->InputAt(0)); |
| 1097 | 1100 |
| 1098 // But effects should be ordered start -> i1 -> i0 -> effect_use | 1101 // But effects should be ordered start -> i1 -> i0 -> effect_use |
| 1099 B.CheckEffectOrdering(i1, i0); | 1102 B.CheckEffectOrdering(i1, i0); |
| 1100 } | 1103 } |
| 1101 | 1104 |
| 1102 for (size_t j = 0; j < arraysize(ops); j += 2) { | 1105 for (size_t j = 0; j < arraysize(ops); j += 2) { |
| 1103 BinopEffectsTester B(ops[j], Type::Number(), Type::Boolean()); | 1106 BinopEffectsTester B(ops[j], Type::Number(), Type::Symbol()); |
| 1104 | 1107 |
| 1105 Node* i0 = B.CheckConvertedInput(IrOpcode::kJSToNumber, 0, true); | 1108 Node* i0 = B.CheckConvertedInput(IrOpcode::kJSToNumber, 0, true); |
| 1106 Node* i1 = B.result->InputAt(1); | 1109 Node* i1 = B.result->InputAt(1); |
| 1107 | 1110 |
| 1108 CHECK_EQ(B.p1, i0->InputAt(0)); // Should be commuted. | 1111 CHECK_EQ(B.p1, i0->InputAt(0)); // Should be commuted. |
| 1109 CHECK_EQ(B.p0, i1); | 1112 CHECK_EQ(B.p0, i1); |
| 1110 | 1113 |
| 1111 // Effects should be ordered start -> i1 -> effect_use | 1114 // Effects should be ordered start -> i1 -> effect_use |
| 1112 B.CheckEffectOrdering(i0); | 1115 B.CheckEffectOrdering(i0); |
| 1113 } | 1116 } |
| 1114 | 1117 |
| 1115 for (size_t j = 0; j < arraysize(ops); j += 2) { | 1118 for (size_t j = 0; j < arraysize(ops); j += 2) { |
| 1116 BinopEffectsTester B(ops[j], Type::Boolean(), Type::Number()); | 1119 BinopEffectsTester B(ops[j], Type::Symbol(), Type::Number()); |
| 1117 | 1120 |
| 1118 Node* i0 = B.result->InputAt(0); | 1121 Node* i0 = B.result->InputAt(0); |
| 1119 Node* i1 = B.CheckConvertedInput(IrOpcode::kJSToNumber, 1, true); | 1122 Node* i1 = B.CheckConvertedInput(IrOpcode::kJSToNumber, 1, true); |
| 1120 | 1123 |
| 1121 CHECK_EQ(B.p1, i0); // Should be commuted. | 1124 CHECK_EQ(B.p1, i0); // Should be commuted. |
| 1122 CHECK_EQ(B.p0, i1->InputAt(0)); | 1125 CHECK_EQ(B.p0, i1->InputAt(0)); |
| 1123 | 1126 |
| 1124 // Effects should be ordered start -> i0 -> effect_use | 1127 // Effects should be ordered start -> i0 -> effect_use |
| 1125 B.CheckEffectOrdering(i1); | 1128 B.CheckEffectOrdering(i1); |
| 1126 } | 1129 } |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1368 CHECK_EQ(p1, r->InputAt(0)); | 1371 CHECK_EQ(p1, r->InputAt(0)); |
| 1369 CHECK_EQ(p0, r->InputAt(1)); | 1372 CHECK_EQ(p0, r->InputAt(1)); |
| 1370 } else { | 1373 } else { |
| 1371 CHECK_EQ(p0, r->InputAt(0)); | 1374 CHECK_EQ(p0, r->InputAt(0)); |
| 1372 CHECK_EQ(p1, r->InputAt(1)); | 1375 CHECK_EQ(p1, r->InputAt(1)); |
| 1373 } | 1376 } |
| 1374 } | 1377 } |
| 1375 } | 1378 } |
| 1376 } | 1379 } |
| 1377 } | 1380 } |
| OLD | NEW |