| 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/base/bits.h" | 8 #include "src/base/bits.h" |
| 9 #include "src/compiler/common-operator.h" | 9 #include "src/compiler/common-operator.h" |
| 10 #include "src/compiler/control-reducer.h" | 10 #include "src/compiler/control-reducer.h" |
| (...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1207 // if (0) { while (p0) ; } else { } | 1207 // if (0) { while (p0) ; } else { } |
| 1208 w.branch->ReplaceInput(1, d.if_true); | 1208 w.branch->ReplaceInput(1, d.if_true); |
| 1209 d.merge->ReplaceInput(0, w.exit); | 1209 d.merge->ReplaceInput(0, w.exit); |
| 1210 | 1210 |
| 1211 R.ReduceMergeIterative(R.start, d.merge); | 1211 R.ReduceMergeIterative(R.start, d.merge); |
| 1212 CHECK(d.if_true->IsDead()); | 1212 CHECK(d.if_true->IsDead()); |
| 1213 CHECK(d.if_false->IsDead()); | 1213 CHECK(d.if_false->IsDead()); |
| 1214 } | 1214 } |
| 1215 | 1215 |
| 1216 | 1216 |
| 1217 TEST(CNonTermLoop1) { | |
| 1218 ControlReducerTester R; | |
| 1219 Node* loop = | |
| 1220 R.SetSelfReferences(R.graph.NewNode(R.common.Loop(2), R.start, R.self)); | |
| 1221 R.ReduceGraph(); | |
| 1222 Node* end = R.graph.end(); | |
| 1223 CheckLoop(loop, R.start, loop); | |
| 1224 Node* merge = end->InputAt(0); | |
| 1225 CheckMerge(merge, R.start, loop); | |
| 1226 } | |
| 1227 | |
| 1228 | |
| 1229 TEST(CNonTermLoop2) { | |
| 1230 ControlReducerTester R; | |
| 1231 Diamond d(R, R.p0); | |
| 1232 Node* loop = R.SetSelfReferences( | |
| 1233 R.graph.NewNode(R.common.Loop(2), d.if_false, R.self)); | |
| 1234 d.merge->ReplaceInput(1, R.dead); | |
| 1235 Node* end = R.graph.end(); | |
| 1236 end->ReplaceInput(0, d.merge); | |
| 1237 R.ReduceGraph(); | |
| 1238 CHECK_EQ(end, R.graph.end()); | |
| 1239 CheckLoop(loop, d.if_false, loop); | |
| 1240 Node* merge = end->InputAt(0); | |
| 1241 CheckMerge(merge, d.if_true, loop); | |
| 1242 } | |
| 1243 | |
| 1244 | |
| 1245 TEST(NonTermLoop3) { | |
| 1246 ControlReducerTester R; | |
| 1247 Node* loop = R.graph.NewNode(R.common.Loop(2), R.start, R.start); | |
| 1248 Branch b(R, R.one, loop); | |
| 1249 loop->ReplaceInput(1, b.if_true); | |
| 1250 Node* end = R.graph.end(); | |
| 1251 end->ReplaceInput(0, b.if_false); | |
| 1252 | |
| 1253 R.ReduceGraph(); | |
| 1254 | |
| 1255 CHECK_EQ(end, R.graph.end()); | |
| 1256 CheckInputs(end, loop); | |
| 1257 CheckInputs(loop, R.start, loop); | |
| 1258 } | |
| 1259 | |
| 1260 | |
| 1261 TEST(CNonTermLoop_terminate1) { | |
| 1262 ControlReducerTester R; | |
| 1263 Node* loop = R.graph.NewNode(R.common.Loop(2), R.start, R.start); | |
| 1264 Node* effect = R.SetSelfReferences( | |
| 1265 R.graph.NewNode(R.common.EffectPhi(2), R.start, R.self, loop)); | |
| 1266 Branch b(R, R.one, loop); | |
| 1267 loop->ReplaceInput(1, b.if_true); | |
| 1268 Node* end = R.graph.end(); | |
| 1269 end->ReplaceInput(0, b.if_false); | |
| 1270 | |
| 1271 R.ReduceGraph(); | |
| 1272 | |
| 1273 CHECK_EQ(end, R.graph.end()); | |
| 1274 CheckLoop(loop, R.start, loop); | |
| 1275 Node* terminate = end->InputAt(0); | |
| 1276 CHECK_EQ(IrOpcode::kTerminate, terminate->opcode()); | |
| 1277 CHECK_EQ(2, terminate->InputCount()); | |
| 1278 CHECK_EQ(1, terminate->op()->EffectInputCount()); | |
| 1279 CHECK_EQ(1, terminate->op()->ControlInputCount()); | |
| 1280 CheckInputs(terminate, effect, loop); | |
| 1281 } | |
| 1282 | |
| 1283 | |
| 1284 TEST(CNonTermLoop_terminate2) { | |
| 1285 ControlReducerTester R; | |
| 1286 Node* loop = R.graph.NewNode(R.common.Loop(2), R.start, R.start); | |
| 1287 Node* effect1 = R.SetSelfReferences( | |
| 1288 R.graph.NewNode(R.common.EffectPhi(2), R.start, R.self, loop)); | |
| 1289 Node* effect2 = R.SetSelfReferences( | |
| 1290 R.graph.NewNode(R.common.EffectPhi(2), R.start, R.self, loop)); | |
| 1291 Branch b(R, R.one, loop); | |
| 1292 loop->ReplaceInput(1, b.if_true); | |
| 1293 Node* end = R.graph.end(); | |
| 1294 end->ReplaceInput(0, b.if_false); | |
| 1295 | |
| 1296 R.ReduceGraph(); | |
| 1297 | |
| 1298 CheckLoop(loop, R.start, loop); | |
| 1299 CHECK_EQ(end, R.graph.end()); | |
| 1300 Node* terminate = end->InputAt(0); | |
| 1301 CHECK_EQ(IrOpcode::kTerminate, terminate->opcode()); | |
| 1302 CHECK_EQ(3, terminate->InputCount()); | |
| 1303 CHECK_EQ(2, terminate->op()->EffectInputCount()); | |
| 1304 CHECK_EQ(1, terminate->op()->ControlInputCount()); | |
| 1305 Node* e0 = terminate->InputAt(0); | |
| 1306 Node* e1 = terminate->InputAt(1); | |
| 1307 CHECK(e0 == effect1 || e1 == effect1); | |
| 1308 CHECK(e0 == effect2 || e1 == effect2); | |
| 1309 CHECK_EQ(loop, terminate->InputAt(2)); | |
| 1310 } | |
| 1311 | |
| 1312 | |
| 1313 TEST(CNonTermLoop_terminate_m1) { | |
| 1314 ControlReducerTester R; | |
| 1315 Node* loop = | |
| 1316 R.SetSelfReferences(R.graph.NewNode(R.common.Loop(2), R.start, R.self)); | |
| 1317 Node* effect = R.SetSelfReferences( | |
| 1318 R.graph.NewNode(R.common.EffectPhi(2), R.start, R.self, loop)); | |
| 1319 R.ReduceGraph(); | |
| 1320 Node* end = R.graph.end(); | |
| 1321 CHECK_EQ(R.start, loop->InputAt(0)); | |
| 1322 CHECK_EQ(loop, loop->InputAt(1)); | |
| 1323 Node* merge = end->InputAt(0); | |
| 1324 CHECK_EQ(IrOpcode::kMerge, merge->opcode()); | |
| 1325 CHECK_EQ(2, merge->InputCount()); | |
| 1326 CHECK_EQ(2, merge->op()->ControlInputCount()); | |
| 1327 CHECK_EQ(R.start, merge->InputAt(0)); | |
| 1328 | |
| 1329 Node* terminate = merge->InputAt(1); | |
| 1330 CHECK_EQ(IrOpcode::kTerminate, terminate->opcode()); | |
| 1331 CHECK_EQ(2, terminate->InputCount()); | |
| 1332 CHECK_EQ(1, terminate->op()->EffectInputCount()); | |
| 1333 CHECK_EQ(1, terminate->op()->ControlInputCount()); | |
| 1334 CHECK_EQ(effect, terminate->InputAt(0)); | |
| 1335 CHECK_EQ(loop, terminate->InputAt(1)); | |
| 1336 } | |
| 1337 | |
| 1338 | |
| 1339 TEST(CNonTermLoop_big1) { | |
| 1340 ControlReducerTester R; | |
| 1341 Branch b1(R, R.p0); | |
| 1342 Node* rt = R.graph.NewNode(R.common.Return(), R.one, R.start, b1.if_true); | |
| 1343 | |
| 1344 Branch b2(R, R.p0, b1.if_false); | |
| 1345 Node* rf = R.graph.NewNode(R.common.Return(), R.zero, R.start, b2.if_true); | |
| 1346 Node* loop = R.SetSelfReferences( | |
| 1347 R.graph.NewNode(R.common.Loop(2), b2.if_false, R.self)); | |
| 1348 Node* merge = R.graph.NewNode(R.common.Merge(2), rt, rf); | |
| 1349 R.end->ReplaceInput(0, merge); | |
| 1350 | |
| 1351 R.ReduceGraph(); | |
| 1352 | |
| 1353 CheckInputs(R.end, merge); | |
| 1354 CheckInputs(merge, rt, rf, loop); | |
| 1355 CheckInputs(loop, b2.if_false, loop); | |
| 1356 } | |
| 1357 | |
| 1358 | |
| 1359 TEST(CNonTermLoop_big2) { | |
| 1360 ControlReducerTester R; | |
| 1361 Branch b1(R, R.p0); | |
| 1362 Node* rt = R.graph.NewNode(R.common.Return(), R.one, R.start, b1.if_true); | |
| 1363 | |
| 1364 Node* loop = R.graph.NewNode(R.common.Loop(2), b1.if_false, R.start); | |
| 1365 Branch b2(R, R.zero, loop); | |
| 1366 loop->ReplaceInput(1, b2.if_false); | |
| 1367 Node* rf = R.graph.NewNode(R.common.Return(), R.zero, R.start, b2.if_true); | |
| 1368 Node* merge = R.graph.NewNode(R.common.Merge(2), rt, rf); | |
| 1369 R.end->ReplaceInput(0, merge); | |
| 1370 | |
| 1371 R.ReduceGraph(); | |
| 1372 | |
| 1373 Node* new_merge = R.end->InputAt(0); // old merge was reduced. | |
| 1374 CHECK_NE(merge, new_merge); | |
| 1375 CheckInputs(new_merge, rt, loop); | |
| 1376 CheckInputs(loop, b1.if_false, loop); | |
| 1377 CHECK(merge->IsDead()); | |
| 1378 CHECK(rf->IsDead()); | |
| 1379 CHECK(b2.if_true->IsDead()); | |
| 1380 } | |
| 1381 | |
| 1382 | |
| 1383 TEST(Return1) { | 1217 TEST(Return1) { |
| 1384 ControlReducerTester R; | 1218 ControlReducerTester R; |
| 1385 Node* ret = R.Return(R.one, R.start, R.start); | 1219 Node* ret = R.Return(R.one, R.start, R.start); |
| 1386 R.ReduceGraph(); | 1220 R.ReduceGraph(); |
| 1387 CheckInputs(R.graph.end(), ret); | 1221 CheckInputs(R.graph.end(), ret); |
| 1388 CheckInputs(ret, R.one, R.start, R.start); | 1222 CheckInputs(ret, R.one, R.start, R.start); |
| 1389 } | 1223 } |
| 1390 | 1224 |
| 1391 | 1225 |
| 1392 TEST(Return2) { | 1226 TEST(Return2) { |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1672 | 1506 |
| 1673 Node* ret = R.Return(d1.phi, R.start, d1.merge); | 1507 Node* ret = R.Return(d1.phi, R.start, d1.merge); |
| 1674 | 1508 |
| 1675 R.ReduceGraph(); // d1 gets folded true. | 1509 R.ReduceGraph(); // d1 gets folded true. |
| 1676 | 1510 |
| 1677 CheckInputs(ret, y2, R.start, R.start); | 1511 CheckInputs(ret, y2, R.start, R.start); |
| 1678 CheckDeadDiamond(d1); | 1512 CheckDeadDiamond(d1); |
| 1679 CheckDeadDiamond(d2); | 1513 CheckDeadDiamond(d2); |
| 1680 CheckDeadDiamond(d3); | 1514 CheckDeadDiamond(d3); |
| 1681 } | 1515 } |
| OLD | NEW |