Skip to content

Commit c006b90

Browse files
committed
[VPlan] Add test for dump of recipe not inserted in VPlan. (NFC)
Add extra tests for printing recipes not inserted in a VPlan yet, e.g. when using a debugger. Guard against regressions in changes to printing, i.e. #81411.
1 parent 7dbba39 commit c006b90

File tree

1 file changed

+162
-1
lines changed

1 file changed

+162
-1
lines changed

llvm/unittests/Transforms/Vectorize/VPlanTest.cpp

Lines changed: 162 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ TEST(VPRecipeTest, MayHaveSideEffectsAndMayReadWriteMemory) {
12271227
}
12281228

12291229
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1230-
TEST(VPRecipeTest, dump) {
1230+
TEST(VPRecipeTest, dumpRecipeInPlan) {
12311231
VPBasicBlock *VPBB0 = new VPBasicBlock("preheader");
12321232
VPBasicBlock *VPBB1 = new VPBasicBlock();
12331233
VPlan Plan(VPBB0, VPBB1);
@@ -1280,6 +1280,167 @@ TEST(VPRecipeTest, dump) {
12801280

12811281
delete AI;
12821282
}
1283+
1284+
TEST(VPRecipeTest, dumpRecipeUnnamedVPValuesInPlan) {
1285+
VPBasicBlock *VPBB0 = new VPBasicBlock("preheader");
1286+
VPBasicBlock *VPBB1 = new VPBasicBlock();
1287+
VPlan Plan(VPBB0, VPBB1);
1288+
1289+
LLVMContext C;
1290+
1291+
IntegerType *Int32 = IntegerType::get(C, 32);
1292+
SmallVector<VPValue *, 2> Args;
1293+
VPValue *ExtVPV1 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
1294+
VPValue *ExtVPV2 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
1295+
Args.push_back(ExtVPV1);
1296+
Args.push_back(ExtVPV2);
1297+
VPInstruction *I1 = new VPInstruction(Instruction::Add, {ExtVPV1, ExtVPV2});
1298+
VPInstruction *I2 = new VPInstruction(Instruction::Mul, {I1, I1});
1299+
VPBB1->appendRecipe(I1);
1300+
VPBB1->appendRecipe(I2);
1301+
1302+
// Check printing I1.
1303+
{
1304+
// Use EXPECT_EXIT to capture stderr and compare against expected output.
1305+
//
1306+
// Test VPValue::dump().
1307+
VPValue *VPV = I1;
1308+
EXPECT_EXIT(
1309+
{
1310+
VPV->dump();
1311+
exit(0);
1312+
},
1313+
testing::ExitedWithCode(0), "EMIT vp<%1> = add ir<1>, ir<2>");
1314+
1315+
// Test VPRecipeBase::dump().
1316+
VPRecipeBase *R = I1;
1317+
EXPECT_EXIT(
1318+
{
1319+
R->dump();
1320+
exit(0);
1321+
},
1322+
testing::ExitedWithCode(0), "EMIT vp<%1> = add ir<1>, ir<2>");
1323+
1324+
// Test VPDef::dump().
1325+
VPDef *D = I1;
1326+
EXPECT_EXIT(
1327+
{
1328+
D->dump();
1329+
exit(0);
1330+
},
1331+
testing::ExitedWithCode(0), "EMIT vp<%1> = add ir<1>, ir<2>");
1332+
}
1333+
// Check printing I2.
1334+
{
1335+
// Use EXPECT_EXIT to capture stderr and compare against expected output.
1336+
//
1337+
// Test VPValue::dump().
1338+
VPValue *VPV = I2;
1339+
EXPECT_EXIT(
1340+
{
1341+
VPV->dump();
1342+
exit(0);
1343+
},
1344+
testing::ExitedWithCode(0), "EMIT vp<%2> = mul vp<%1>, vp<%1>");
1345+
1346+
// Test VPRecipeBase::dump().
1347+
VPRecipeBase *R = I2;
1348+
EXPECT_EXIT(
1349+
{
1350+
R->dump();
1351+
exit(0);
1352+
},
1353+
testing::ExitedWithCode(0), "EMIT vp<%2> = mul vp<%1>, vp<%1>");
1354+
1355+
// Test VPDef::dump().
1356+
VPDef *D = I2;
1357+
EXPECT_EXIT(
1358+
{
1359+
D->dump();
1360+
exit(0);
1361+
},
1362+
testing::ExitedWithCode(0), "EMIT vp<%2> = mul vp<%1>, vp<%1>");
1363+
}
1364+
}
1365+
1366+
TEST(VPRecipeTest, dumpRecipeUnnamedVPValuesNotInPlanOrBlock) {
1367+
LLVMContext C;
1368+
IntegerType *Int32 = IntegerType::get(C, 32);
1369+
VPValue *ExtVPV1 = new VPValue(ConstantInt::get(Int32, 1));
1370+
VPValue *ExtVPV2 = new VPValue(ConstantInt::get(Int32, 2));
1371+
1372+
VPInstruction *I1 = new VPInstruction(Instruction::Add, {ExtVPV1, ExtVPV2});
1373+
VPInstruction *I2 = new VPInstruction(Instruction::Mul, {I1, I1});
1374+
1375+
// Check printing I1.
1376+
{
1377+
// Use EXPECT_EXIT to capture stderr and compare against expected output.
1378+
//
1379+
// Test VPValue::dump().
1380+
VPValue *VPV = I1;
1381+
EXPECT_EXIT(
1382+
{
1383+
VPV->dump();
1384+
exit(0);
1385+
},
1386+
testing::ExitedWithCode(0), "EMIT <badref> = add ir<1>, ir<2>");
1387+
1388+
// Test VPRecipeBase::dump().
1389+
VPRecipeBase *R = I1;
1390+
EXPECT_EXIT(
1391+
{
1392+
R->dump();
1393+
exit(0);
1394+
},
1395+
testing::ExitedWithCode(0), "EMIT <badref> = add ir<1>, ir<2>");
1396+
1397+
// Test VPDef::dump().
1398+
VPDef *D = I1;
1399+
EXPECT_EXIT(
1400+
{
1401+
D->dump();
1402+
exit(0);
1403+
},
1404+
testing::ExitedWithCode(0), "EMIT <badref> = add ir<1>, ir<2>");
1405+
}
1406+
// Check printing I2.
1407+
{
1408+
// Use EXPECT_EXIT to capture stderr and compare against expected output.
1409+
//
1410+
// Test VPValue::dump().
1411+
VPValue *VPV = I2;
1412+
EXPECT_EXIT(
1413+
{
1414+
VPV->dump();
1415+
exit(0);
1416+
},
1417+
testing::ExitedWithCode(0), "EMIT <badref> = mul <badref>, <badref>");
1418+
1419+
// Test VPRecipeBase::dump().
1420+
VPRecipeBase *R = I2;
1421+
EXPECT_EXIT(
1422+
{
1423+
R->dump();
1424+
exit(0);
1425+
},
1426+
testing::ExitedWithCode(0), "EMIT <badref> = mul <badref>, <badref>");
1427+
1428+
// Test VPDef::dump().
1429+
VPDef *D = I2;
1430+
EXPECT_EXIT(
1431+
{
1432+
D->dump();
1433+
exit(0);
1434+
},
1435+
testing::ExitedWithCode(0), "EMIT <badref> = mul <badref>, <badref>");
1436+
}
1437+
1438+
delete I2;
1439+
delete I1;
1440+
delete ExtVPV2;
1441+
delete ExtVPV1;
1442+
}
1443+
12831444
#endif
12841445

12851446
TEST(VPRecipeTest, CastVPReductionRecipeToVPUser) {

0 commit comments

Comments
 (0)