[llvm] c006b90 - [VPlan] Add test for dump of recipe not inserted in VPlan. (NFC)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 15 03:30:51 PDT 2024
Author: Florian Hahn
Date: 2024-04-15T11:30:36+01:00
New Revision: c006b9088fa564fe343550a8dd5f9b0ad0c15b75
URL: https://github.com/llvm/llvm-project/commit/c006b9088fa564fe343550a8dd5f9b0ad0c15b75
DIFF: https://github.com/llvm/llvm-project/commit/c006b9088fa564fe343550a8dd5f9b0ad0c15b75.diff
LOG: [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.
https://github.com/llvm/llvm-project/pull/81411.
Added:
Modified:
llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
Removed:
################################################################################
diff --git a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
index 73687846e281a9..ff0f482b833c83 100644
--- a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
+++ b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
@@ -1227,7 +1227,7 @@ TEST(VPRecipeTest, MayHaveSideEffectsAndMayReadWriteMemory) {
}
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
-TEST(VPRecipeTest, dump) {
+TEST(VPRecipeTest, dumpRecipeInPlan) {
VPBasicBlock *VPBB0 = new VPBasicBlock("preheader");
VPBasicBlock *VPBB1 = new VPBasicBlock();
VPlan Plan(VPBB0, VPBB1);
@@ -1280,6 +1280,167 @@ TEST(VPRecipeTest, dump) {
delete AI;
}
+
+TEST(VPRecipeTest, dumpRecipeUnnamedVPValuesInPlan) {
+ VPBasicBlock *VPBB0 = new VPBasicBlock("preheader");
+ VPBasicBlock *VPBB1 = new VPBasicBlock();
+ VPlan Plan(VPBB0, VPBB1);
+
+ LLVMContext C;
+
+ IntegerType *Int32 = IntegerType::get(C, 32);
+ SmallVector<VPValue *, 2> Args;
+ VPValue *ExtVPV1 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *ExtVPV2 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
+ Args.push_back(ExtVPV1);
+ Args.push_back(ExtVPV2);
+ VPInstruction *I1 = new VPInstruction(Instruction::Add, {ExtVPV1, ExtVPV2});
+ VPInstruction *I2 = new VPInstruction(Instruction::Mul, {I1, I1});
+ VPBB1->appendRecipe(I1);
+ VPBB1->appendRecipe(I2);
+
+ // Check printing I1.
+ {
+ // Use EXPECT_EXIT to capture stderr and compare against expected output.
+ //
+ // Test VPValue::dump().
+ VPValue *VPV = I1;
+ EXPECT_EXIT(
+ {
+ VPV->dump();
+ exit(0);
+ },
+ testing::ExitedWithCode(0), "EMIT vp<%1> = add ir<1>, ir<2>");
+
+ // Test VPRecipeBase::dump().
+ VPRecipeBase *R = I1;
+ EXPECT_EXIT(
+ {
+ R->dump();
+ exit(0);
+ },
+ testing::ExitedWithCode(0), "EMIT vp<%1> = add ir<1>, ir<2>");
+
+ // Test VPDef::dump().
+ VPDef *D = I1;
+ EXPECT_EXIT(
+ {
+ D->dump();
+ exit(0);
+ },
+ testing::ExitedWithCode(0), "EMIT vp<%1> = add ir<1>, ir<2>");
+ }
+ // Check printing I2.
+ {
+ // Use EXPECT_EXIT to capture stderr and compare against expected output.
+ //
+ // Test VPValue::dump().
+ VPValue *VPV = I2;
+ EXPECT_EXIT(
+ {
+ VPV->dump();
+ exit(0);
+ },
+ testing::ExitedWithCode(0), "EMIT vp<%2> = mul vp<%1>, vp<%1>");
+
+ // Test VPRecipeBase::dump().
+ VPRecipeBase *R = I2;
+ EXPECT_EXIT(
+ {
+ R->dump();
+ exit(0);
+ },
+ testing::ExitedWithCode(0), "EMIT vp<%2> = mul vp<%1>, vp<%1>");
+
+ // Test VPDef::dump().
+ VPDef *D = I2;
+ EXPECT_EXIT(
+ {
+ D->dump();
+ exit(0);
+ },
+ testing::ExitedWithCode(0), "EMIT vp<%2> = mul vp<%1>, vp<%1>");
+ }
+}
+
+TEST(VPRecipeTest, dumpRecipeUnnamedVPValuesNotInPlanOrBlock) {
+ LLVMContext C;
+ IntegerType *Int32 = IntegerType::get(C, 32);
+ VPValue *ExtVPV1 = new VPValue(ConstantInt::get(Int32, 1));
+ VPValue *ExtVPV2 = new VPValue(ConstantInt::get(Int32, 2));
+
+ VPInstruction *I1 = new VPInstruction(Instruction::Add, {ExtVPV1, ExtVPV2});
+ VPInstruction *I2 = new VPInstruction(Instruction::Mul, {I1, I1});
+
+ // Check printing I1.
+ {
+ // Use EXPECT_EXIT to capture stderr and compare against expected output.
+ //
+ // Test VPValue::dump().
+ VPValue *VPV = I1;
+ EXPECT_EXIT(
+ {
+ VPV->dump();
+ exit(0);
+ },
+ testing::ExitedWithCode(0), "EMIT <badref> = add ir<1>, ir<2>");
+
+ // Test VPRecipeBase::dump().
+ VPRecipeBase *R = I1;
+ EXPECT_EXIT(
+ {
+ R->dump();
+ exit(0);
+ },
+ testing::ExitedWithCode(0), "EMIT <badref> = add ir<1>, ir<2>");
+
+ // Test VPDef::dump().
+ VPDef *D = I1;
+ EXPECT_EXIT(
+ {
+ D->dump();
+ exit(0);
+ },
+ testing::ExitedWithCode(0), "EMIT <badref> = add ir<1>, ir<2>");
+ }
+ // Check printing I2.
+ {
+ // Use EXPECT_EXIT to capture stderr and compare against expected output.
+ //
+ // Test VPValue::dump().
+ VPValue *VPV = I2;
+ EXPECT_EXIT(
+ {
+ VPV->dump();
+ exit(0);
+ },
+ testing::ExitedWithCode(0), "EMIT <badref> = mul <badref>, <badref>");
+
+ // Test VPRecipeBase::dump().
+ VPRecipeBase *R = I2;
+ EXPECT_EXIT(
+ {
+ R->dump();
+ exit(0);
+ },
+ testing::ExitedWithCode(0), "EMIT <badref> = mul <badref>, <badref>");
+
+ // Test VPDef::dump().
+ VPDef *D = I2;
+ EXPECT_EXIT(
+ {
+ D->dump();
+ exit(0);
+ },
+ testing::ExitedWithCode(0), "EMIT <badref> = mul <badref>, <badref>");
+ }
+
+ delete I2;
+ delete I1;
+ delete ExtVPV2;
+ delete ExtVPV1;
+}
+
#endif
TEST(VPRecipeTest, CastVPReductionRecipeToVPUser) {
More information about the llvm-commits
mailing list