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 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 Node* n1 = R.Parameter(kInt32Types[j]); | 1224 Node* n1 = R.Parameter(kInt32Types[j]); |
1225 Node* one = R.graph.NewNode(R.common.NumberConstant(1)); | 1225 Node* one = R.graph.NewNode(R.common.NumberConstant(1)); |
1226 | 1226 |
1227 for (int l = 0; l < 2; l++) { | 1227 for (int l = 0; l < 2; l++) { |
1228 Node* add_node = R.Binop(R.simplified.NumberAdd(), n0, n1); | 1228 Node* add_node = R.Binop(R.simplified.NumberAdd(), n0, n1); |
1229 Node* or_node = | 1229 Node* or_node = |
1230 R.Binop(R.ops[o], l ? add_node : one, l ? one : add_node); | 1230 R.Binop(R.ops[o], l ? add_node : one, l ? one : add_node); |
1231 Node* r = R.reduce(or_node); | 1231 Node* r = R.reduce(or_node); |
1232 | 1232 |
1233 CHECK_EQ(R.ops[o + 1]->opcode(), r->op()->opcode()); | 1233 CHECK_EQ(R.ops[o + 1]->opcode(), r->op()->opcode()); |
1234 CHECK_EQ(IrOpcode::kInt32Add, add_node->opcode()); | 1234 CHECK_EQ(IrOpcode::kNumberAdd, add_node->opcode()); |
1235 bool is_signed = l ? R.signedness[o] : R.signedness[o + 1]; | |
1236 | |
1237 Type* add_type = NodeProperties::GetBounds(add_node).upper; | |
1238 CHECK(add_type->Is(I32Type(is_signed))); | |
1239 } | 1235 } |
1240 } | 1236 } |
1241 } | 1237 } |
1242 } | 1238 } |
1243 } | 1239 } |
1244 { | 1240 { |
1245 JSBitwiseShiftTypedLoweringTester R; | 1241 JSBitwiseShiftTypedLoweringTester R; |
1246 | 1242 |
1247 for (int o = 0; o < R.kNumberOps; o += 2) { | 1243 for (int o = 0; o < R.kNumberOps; o += 2) { |
1248 for (size_t i = 0; i < arraysize(kInt32Types); i++) { | 1244 for (size_t i = 0; i < arraysize(kInt32Types); i++) { |
1249 Node* n0 = R.Parameter(kInt32Types[i]); | 1245 Node* n0 = R.Parameter(kInt32Types[i]); |
1250 for (size_t j = 0; j < arraysize(kInt32Types); j++) { | 1246 for (size_t j = 0; j < arraysize(kInt32Types); j++) { |
1251 Node* n1 = R.Parameter(kInt32Types[j]); | 1247 Node* n1 = R.Parameter(kInt32Types[j]); |
1252 Node* one = R.graph.NewNode(R.common.NumberConstant(1)); | 1248 Node* one = R.graph.NewNode(R.common.NumberConstant(1)); |
1253 | 1249 |
1254 for (int l = 0; l < 2; l++) { | 1250 for (int l = 0; l < 2; l++) { |
1255 Node* add_node = R.Binop(R.simplified.NumberAdd(), n0, n1); | 1251 Node* add_node = R.Binop(R.simplified.NumberAdd(), n0, n1); |
1256 Node* or_node = | 1252 Node* or_node = |
1257 R.Binop(R.ops[o], l ? add_node : one, l ? one : add_node); | 1253 R.Binop(R.ops[o], l ? add_node : one, l ? one : add_node); |
1258 Node* r = R.reduce(or_node); | 1254 Node* r = R.reduce(or_node); |
1259 | 1255 |
1260 CHECK_EQ(R.ops[o + 1]->opcode(), r->op()->opcode()); | 1256 CHECK_EQ(R.ops[o + 1]->opcode(), r->op()->opcode()); |
1261 CHECK_EQ(IrOpcode::kInt32Add, add_node->opcode()); | 1257 CHECK_EQ(IrOpcode::kNumberAdd, add_node->opcode()); |
1262 bool is_signed = l ? R.signedness[o] : R.signedness[o + 1]; | |
1263 | |
1264 Type* add_type = NodeProperties::GetBounds(add_node).upper; | |
1265 CHECK(add_type->Is(I32Type(is_signed))); | |
1266 } | 1258 } |
1267 } | 1259 } |
1268 } | 1260 } |
1269 } | 1261 } |
1270 } | 1262 } |
1271 } | 1263 { |
| 1264 JSBitwiseTypedLoweringTester R; |
1272 | 1265 |
| 1266 for (int o = 0; o < R.kNumberOps; o += 2) { |
| 1267 Node* n0 = R.Parameter(I32Type(R.signedness[o])); |
| 1268 Node* n1 = R.Parameter(I32Type(R.signedness[o + 1])); |
| 1269 Node* one = R.graph.NewNode(R.common.NumberConstant(1)); |
1273 | 1270 |
1274 TEST(Int32AddNarrowingNotOwned) { | 1271 Node* add_node = R.Binop(R.simplified.NumberAdd(), n0, n1); |
1275 JSBitwiseTypedLoweringTester R; | 1272 Node* or_node = R.Binop(R.ops[o], add_node, one); |
1276 | 1273 Node* other_use = R.Binop(R.simplified.NumberAdd(), add_node, one); |
1277 for (int o = 0; o < R.kNumberOps; o += 2) { | 1274 Node* r = R.reduce(or_node); |
1278 Node* n0 = R.Parameter(I32Type(R.signedness[o])); | 1275 CHECK_EQ(R.ops[o + 1]->opcode(), r->op()->opcode()); |
1279 Node* n1 = R.Parameter(I32Type(R.signedness[o + 1])); | 1276 CHECK_EQ(IrOpcode::kNumberAdd, add_node->opcode()); |
1280 Node* one = R.graph.NewNode(R.common.NumberConstant(1)); | 1277 // Conversion to int32 should be done. |
1281 | 1278 CheckToI32(add_node, r->InputAt(0), R.signedness[o]); |
1282 Node* add_node = R.Binop(R.simplified.NumberAdd(), n0, n1); | 1279 CheckToI32(one, r->InputAt(1), R.signedness[o + 1]); |
1283 Node* or_node = R.Binop(R.ops[o], add_node, one); | 1280 // The other use should also not be touched. |
1284 Node* other_use = R.Binop(R.simplified.NumberAdd(), add_node, one); | 1281 CHECK_EQ(add_node, other_use->InputAt(0)); |
1285 Node* r = R.reduce(or_node); | 1282 CHECK_EQ(one, other_use->InputAt(1)); |
1286 CHECK_EQ(R.ops[o + 1]->opcode(), r->op()->opcode()); | 1283 } |
1287 // Should not be reduced to Int32Add because of the other number add. | |
1288 CHECK_EQ(IrOpcode::kNumberAdd, add_node->opcode()); | |
1289 // Conversion to int32 should be done. | |
1290 CheckToI32(add_node, r->InputAt(0), R.signedness[o]); | |
1291 CheckToI32(one, r->InputAt(1), R.signedness[o + 1]); | |
1292 // The other use should also not be touched. | |
1293 CHECK_EQ(add_node, other_use->InputAt(0)); | |
1294 CHECK_EQ(one, other_use->InputAt(1)); | |
1295 } | 1284 } |
1296 } | 1285 } |
1297 | 1286 |
1298 | 1287 |
1299 TEST(Int32Comparisons) { | 1288 TEST(Int32Comparisons) { |
1300 JSTypedLoweringTester R; | 1289 JSTypedLoweringTester R; |
1301 | 1290 |
1302 struct Entry { | 1291 struct Entry { |
1303 const Operator* js_op; | 1292 const Operator* js_op; |
1304 const Operator* uint_op; | 1293 const Operator* uint_op; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1344 CHECK_EQ(p1, r->InputAt(0)); | 1333 CHECK_EQ(p1, r->InputAt(0)); |
1345 CHECK_EQ(p0, r->InputAt(1)); | 1334 CHECK_EQ(p0, r->InputAt(1)); |
1346 } else { | 1335 } else { |
1347 CHECK_EQ(p0, r->InputAt(0)); | 1336 CHECK_EQ(p0, r->InputAt(0)); |
1348 CHECK_EQ(p1, r->InputAt(1)); | 1337 CHECK_EQ(p1, r->InputAt(1)); |
1349 } | 1338 } |
1350 } | 1339 } |
1351 } | 1340 } |
1352 } | 1341 } |
1353 } | 1342 } |
OLD | NEW |