Skip to content

Commit 8d5541b

Browse files
fhahngithub-actions[bot]
authored andcommitted
Automerge: [VPlan] Delegate to other VPInstruction constructors. (NFCI)
Update VPInstruction constructor to delegate to constructor with more comprehensive checking and validation. This required updating some unit tests, to make sure the constructed VPInstructions are valid.
2 parents 0fe4036 + 67c8e38 commit 8d5541b

File tree

5 files changed

+65
-57
lines changed

5 files changed

+65
-57
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,8 +1105,7 @@ class LLVM_ABI_FOR_TEST VPInstruction : public VPRecipeWithIRFlags,
11051105
public:
11061106
VPInstruction(unsigned Opcode, ArrayRef<VPValue *> Operands,
11071107
DebugLoc DL = DebugLoc::getUnknown(), const Twine &Name = "")
1108-
: VPRecipeWithIRFlags(VPDef::VPInstructionSC, Operands, DL),
1109-
VPIRMetadata(), Opcode(Opcode), Name(Name.str()) {}
1108+
: VPInstruction(Opcode, Operands, {}, {}, DL, Name) {}
11101109

11111110
VPInstruction(unsigned Opcode, ArrayRef<VPValue *> Operands,
11121111
const VPIRFlags &Flags, const VPIRMetadata &MD = {},

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ unsigned VPInstruction::getNumOperandsForOpcode(unsigned Opcode) {
538538
case Instruction::Load:
539539
case VPInstruction::AnyOf:
540540
case VPInstruction::BranchOnCond:
541+
case VPInstruction::Broadcast:
541542
case VPInstruction::BuildStructVector:
542543
case VPInstruction::BuildVector:
543544
case VPInstruction::CalculateTripCountMinusVF:
@@ -548,13 +549,16 @@ unsigned VPInstruction::getNumOperandsForOpcode(unsigned Opcode) {
548549
case VPInstruction::ExtractPenultimateElement:
549550
case VPInstruction::FirstActiveLane:
550551
case VPInstruction::Not:
552+
case VPInstruction::ResumeForEpilogue:
551553
case VPInstruction::Unpack:
552554
return 1;
553555
case Instruction::ICmp:
554556
case Instruction::FCmp:
557+
case Instruction::ExtractElement:
555558
case Instruction::Store:
556559
case VPInstruction::BranchOnCount:
557560
case VPInstruction::ComputeReductionResult:
561+
case VPInstruction::ExtractLane:
558562
case VPInstruction::FirstOrderRecurrenceSplice:
559563
case VPInstruction::LogicalAnd:
560564
case VPInstruction::PtrAdd:
@@ -572,6 +576,8 @@ unsigned VPInstruction::getNumOperandsForOpcode(unsigned Opcode) {
572576
case Instruction::GetElementPtr:
573577
case Instruction::PHI:
574578
case Instruction::Switch:
579+
case VPInstruction::SLPLoad:
580+
case VPInstruction::SLPStore:
575581
// Cannot determine the number of operands from the opcode.
576582
return -1u;
577583
}

llvm/lib/Transforms/Vectorize/VPlanSLP.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,8 @@ VPInstruction *VPlanSlp::buildGraph(ArrayRef<VPValue *> Values) {
464464
LLVM_DEBUG(dbgs() << " Adding multinode Ops\n");
465465
// Create dummy VPInstruction, which will we replace later by the
466466
// re-ordered operand.
467-
VPInstruction *Op = new VPInstruction(0, {});
467+
VPInstruction *Op =
468+
new VPInstruction(VPInstruction::Broadcast, {Values[0]});
468469
CombinedOperands.push_back(Op);
469470
MultiNodeOps.emplace_back(Op, Operands);
470471
}

llvm/unittests/Transforms/Vectorize/VPlanTest.cpp

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ namespace {
3535
using VPInstructionTest = VPlanTestBase;
3636

3737
TEST_F(VPInstructionTest, insertBefore) {
38-
VPInstruction *I1 = new VPInstruction(0, {});
39-
VPInstruction *I2 = new VPInstruction(1, {});
40-
VPInstruction *I3 = new VPInstruction(2, {});
38+
VPInstruction *I1 = new VPInstruction(VPInstruction::StepVector, {});
39+
VPInstruction *I2 = new VPInstruction(VPInstruction::VScale, {});
40+
VPInstruction *I3 = new VPInstruction(VPInstruction::StepVector, {});
4141

4242
VPBasicBlock &VPBB1 = *getPlan().createVPBasicBlock("");
4343
VPBB1.appendRecipe(I1);
@@ -50,9 +50,9 @@ TEST_F(VPInstructionTest, insertBefore) {
5050
}
5151

5252
TEST_F(VPInstructionTest, eraseFromParent) {
53-
VPInstruction *I1 = new VPInstruction(0, {});
54-
VPInstruction *I2 = new VPInstruction(1, {});
55-
VPInstruction *I3 = new VPInstruction(2, {});
53+
VPInstruction *I1 = new VPInstruction(VPInstruction::StepVector, {});
54+
VPInstruction *I2 = new VPInstruction(VPInstruction::VScale, {});
55+
VPInstruction *I3 = new VPInstruction(VPInstruction::StepVector, {});
5656

5757
VPBasicBlock &VPBB1 = *getPlan().createVPBasicBlock("");
5858
VPBB1.appendRecipe(I1);
@@ -70,9 +70,9 @@ TEST_F(VPInstructionTest, eraseFromParent) {
7070
}
7171

7272
TEST_F(VPInstructionTest, moveAfter) {
73-
VPInstruction *I1 = new VPInstruction(0, {});
74-
VPInstruction *I2 = new VPInstruction(1, {});
75-
VPInstruction *I3 = new VPInstruction(2, {});
73+
VPInstruction *I1 = new VPInstruction(VPInstruction::StepVector, {});
74+
VPInstruction *I2 = new VPInstruction(VPInstruction::VScale, {});
75+
VPInstruction *I3 = new VPInstruction(VPInstruction::StepVector, {});
7676

7777
VPBasicBlock &VPBB1 = *getPlan().createVPBasicBlock("");
7878
VPBB1.appendRecipe(I1);
@@ -83,8 +83,8 @@ TEST_F(VPInstructionTest, moveAfter) {
8383

8484
CHECK_ITERATOR(VPBB1, I2, I1, I3);
8585

86-
VPInstruction *I4 = new VPInstruction(4, {});
87-
VPInstruction *I5 = new VPInstruction(5, {});
86+
VPInstruction *I4 = new VPInstruction(VPInstruction::VScale, {});
87+
VPInstruction *I5 = new VPInstruction(VPInstruction::StepVector, {});
8888
VPBasicBlock &VPBB2 = *getPlan().createVPBasicBlock("");
8989
VPBB2.appendRecipe(I4);
9090
VPBB2.appendRecipe(I5);
@@ -97,9 +97,9 @@ TEST_F(VPInstructionTest, moveAfter) {
9797
}
9898

9999
TEST_F(VPInstructionTest, moveBefore) {
100-
VPInstruction *I1 = new VPInstruction(0, {});
101-
VPInstruction *I2 = new VPInstruction(1, {});
102-
VPInstruction *I3 = new VPInstruction(2, {});
100+
VPInstruction *I1 = new VPInstruction(VPInstruction::StepVector, {});
101+
VPInstruction *I2 = new VPInstruction(VPInstruction::VScale, {});
102+
VPInstruction *I3 = new VPInstruction(VPInstruction::StepVector, {});
103103

104104
VPBasicBlock &VPBB1 = *getPlan().createVPBasicBlock("");
105105
VPBB1.appendRecipe(I1);
@@ -110,8 +110,8 @@ TEST_F(VPInstructionTest, moveBefore) {
110110

111111
CHECK_ITERATOR(VPBB1, I2, I1, I3);
112112

113-
VPInstruction *I4 = new VPInstruction(4, {});
114-
VPInstruction *I5 = new VPInstruction(5, {});
113+
VPInstruction *I4 = new VPInstruction(VPInstruction::VScale, {});
114+
VPInstruction *I5 = new VPInstruction(VPInstruction::StepVector, {});
115115
VPBasicBlock &VPBB2 = *getPlan().createVPBasicBlock("");
116116
VPBB2.appendRecipe(I4);
117117
VPBB2.appendRecipe(I5);
@@ -136,7 +136,7 @@ TEST_F(VPInstructionTest, setOperand) {
136136
IntegerType *Int32 = IntegerType::get(C, 32);
137137
VPValue *VPV1 = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 1));
138138
VPValue *VPV2 = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 2));
139-
VPInstruction *I1 = new VPInstruction(0, {VPV1, VPV2});
139+
VPInstruction *I1 = new VPInstruction(Instruction::Add, {VPV1, VPV2});
140140
EXPECT_EQ(1u, VPV1->getNumUsers());
141141
EXPECT_EQ(I1, *VPV1->user_begin());
142142
EXPECT_EQ(1u, VPV2->getNumUsers());
@@ -179,7 +179,7 @@ TEST_F(VPInstructionTest, replaceAllUsesWith) {
179179
IntegerType *Int32 = IntegerType::get(C, 32);
180180
VPValue *VPV1 = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 1));
181181
VPValue *VPV2 = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 2));
182-
VPInstruction *I1 = new VPInstruction(0, {VPV1, VPV2});
182+
VPInstruction *I1 = new VPInstruction(Instruction::Add, {VPV1, VPV2});
183183

184184
// Replace all uses of VPV1 with VPV3.
185185
VPValue *VPV3 = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 3));
@@ -210,7 +210,7 @@ TEST_F(VPInstructionTest, replaceAllUsesWith) {
210210
EXPECT_EQ(0u, VPV2->getNumUsers());
211211
EXPECT_EQ(0u, VPV3->getNumUsers());
212212

213-
VPInstruction *I2 = new VPInstruction(0, {VPV1, VPV2});
213+
VPInstruction *I2 = new VPInstruction(Instruction::Add, {VPV1, VPV2});
214214
EXPECT_EQ(3u, VPV1->getNumUsers());
215215
VPV1->replaceAllUsesWith(VPV3);
216216
EXPECT_EQ(3u, VPV3->getNumUsers());
@@ -223,7 +223,7 @@ TEST_F(VPInstructionTest, releaseOperandsAtDeletion) {
223223
IntegerType *Int32 = IntegerType::get(C, 32);
224224
VPValue *VPV1 = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 1));
225225
VPValue *VPV2 = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 1));
226-
VPInstruction *I1 = new VPInstruction(0, {VPV1, VPV2});
226+
VPInstruction *I1 = new VPInstruction(Instruction::Add, {VPV1, VPV2});
227227

228228
EXPECT_EQ(1u, VPV1->getNumUsers());
229229
EXPECT_EQ(I1, *VPV1->user_begin());
@@ -706,7 +706,7 @@ TEST_F(VPBasicBlockTest, reassociateBlocks) {
706706

707707
TEST_F(VPBasicBlockTest, splitAtEnd) {
708708
VPlan &Plan = getPlan();
709-
VPInstruction *VPI = new VPInstruction(0, {});
709+
VPInstruction *VPI = new VPInstruction(VPInstruction::StepVector, {});
710710
VPBasicBlock *VPBB = Plan.createVPBasicBlock("VPBB1", VPI);
711711
VPBlockUtils::connectBlocks(Plan.getEntry(), VPBB);
712712
VPBlockUtils::connectBlocks(VPBB, Plan.getScalarHeader());
@@ -727,7 +727,7 @@ TEST_F(VPBasicBlockTest, print) {
727727

728728
VPInstruction *I1 = new VPInstruction(Instruction::Add, {Val, Val});
729729
VPInstruction *I2 = new VPInstruction(Instruction::Sub, {I1, Val});
730-
VPInstruction *I3 = new VPInstruction(Instruction::Br, {I1, I2});
730+
VPInstruction *I3 = new VPInstruction(Instruction::Store, {I1, I2});
731731

732732
VPBasicBlock *VPBB1 = Plan.createVPBasicBlock("");
733733
VPBB1->appendRecipe(I1);
@@ -736,7 +736,7 @@ TEST_F(VPBasicBlockTest, print) {
736736
VPBB1->setName("bb1");
737737

738738
VPInstruction *I4 = new VPInstruction(Instruction::Mul, {I2, I1});
739-
VPInstruction *I5 = new VPInstruction(Instruction::Br, {I4});
739+
VPInstruction *I5 = new VPInstruction(Instruction::Freeze, {I4});
740740
VPBasicBlock *VPBB2 = Plan.createVPBasicBlock("");
741741
VPBB2->appendRecipe(I4);
742742
VPBB2->appendRecipe(I5);
@@ -750,7 +750,7 @@ TEST_F(VPBasicBlockTest, print) {
750750
raw_string_ostream OS(I3Dump);
751751
VPSlotTracker SlotTracker;
752752
I3->print(OS, "", SlotTracker);
753-
EXPECT_EQ("EMIT br <badref>, <badref>", I3Dump);
753+
EXPECT_EQ("EMIT store <badref>, <badref>", I3Dump);
754754
}
755755

756756
VPBlockUtils::connectBlocks(VPBB2, Plan.getScalarHeader());
@@ -773,14 +773,14 @@ compound=true
773773
"bb1:\l" +
774774
" EMIT vp\<%1\> = add ir\<1\>, ir\<1\>\l" +
775775
" EMIT vp\<%2\> = sub vp\<%1\>, ir\<1\>\l" +
776-
" EMIT br vp\<%1\>, vp\<%2\>\l" +
776+
" EMIT store vp\<%1\>, vp\<%2\>\l" +
777777
"Successor(s): bb2\l"
778778
]
779779
N1 -> N2 [ label=""]
780780
N2 [label =
781781
"bb2:\l" +
782782
" EMIT vp\<%4\> = mul vp\<%2\>, vp\<%1\>\l" +
783-
" EMIT br vp\<%4\>\l" +
783+
" EMIT vp\<%5\> = freeze vp\<%4\>\l" +
784784
"Successor(s): ir-bb\<scalar.header\>\l"
785785
]
786786
N2 -> N3 [ label=""]
@@ -795,7 +795,7 @@ compound=true
795795
const char *ExpectedBlock1Str = R"(bb1:
796796
EMIT vp<%1> = add ir<1>, ir<1>
797797
EMIT vp<%2> = sub vp<%1>, ir<1>
798-
EMIT br vp<%1>, vp<%2>
798+
EMIT store vp<%1>, vp<%2>
799799
Successor(s): bb2
800800
)";
801801
std::string Block1Dump;
@@ -806,7 +806,7 @@ Successor(s): bb2
806806
// Ensure that numbering is good when dumping the second block in isolation.
807807
const char *ExpectedBlock2Str = R"(bb2:
808808
EMIT vp<%4> = mul vp<%2>, vp<%1>
809-
EMIT br vp<%4>
809+
EMIT vp<%5> = freeze vp<%4>
810810
Successor(s): ir-bb<scalar.header>
811811
)";
812812
std::string Block2Dump;
@@ -819,7 +819,7 @@ Successor(s): ir-bb<scalar.header>
819819
raw_string_ostream OS(I3Dump);
820820
VPSlotTracker SlotTracker(&Plan);
821821
I3->print(OS, "", SlotTracker);
822-
EXPECT_EQ("EMIT br vp<%1>, vp<%2>", I3Dump);
822+
EXPECT_EQ("EMIT store vp<%1>, vp<%2>", I3Dump);
823823
}
824824

825825
{
@@ -832,9 +832,11 @@ Successor(s): ir-bb<scalar.header>
832832

833833
TEST_F(VPBasicBlockTest, printPlanWithVFsAndUFs) {
834834
VPlan &Plan = getPlan();
835+
IntegerType *Int32 = IntegerType::get(C, 32);
836+
VPValue *Val = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
835837
VPBasicBlock *VPBB0 = Plan.getEntry();
836838

837-
VPInstruction *I1 = new VPInstruction(Instruction::Add, {});
839+
VPInstruction *I1 = new VPInstruction(Instruction::Add, {Val, Val});
838840
VPBasicBlock *VPBB1 = Plan.createVPBasicBlock("");
839841
VPBB1->appendRecipe(I1);
840842
VPBB1->setName("bb1");
@@ -856,7 +858,7 @@ Live-in ir<1024> = original trip-count
856858
Successor(s): bb1
857859
858860
bb1:
859-
EMIT vp<%1> = add
861+
EMIT vp<%1> = add ir<1>, ir<1>
860862
Successor(s): ir-bb<scalar.header>
861863
862864
ir-bb<scalar.header>:
@@ -879,7 +881,7 @@ Live-in ir<1024> = original trip-count
879881
Successor(s): bb1
880882
881883
bb1:
882-
EMIT vp<%1> = add
884+
EMIT vp<%1> = add ir<1>, ir<1>
883885
Successor(s): ir-bb<scalar.header>
884886
885887
ir-bb<scalar.header>:
@@ -902,7 +904,7 @@ Live-in ir<1024> = original trip-count
902904
Successor(s): bb1
903905
904906
bb1:
905-
EMIT vp<%1> = add
907+
EMIT vp<%1> = add ir<1>, ir<1>
906908
Successor(s): ir-bb<scalar.header>
907909
908910
ir-bb<scalar.header>:
@@ -1736,15 +1738,15 @@ TEST(VPDoubleValueDefTest, traverseUseLists) {
17361738
// directions.
17371739

17381740
// Create a new VPDef which defines 2 values and has 2 operands.
1739-
VPInstruction Op0(20, {});
1740-
VPInstruction Op1(30, {});
1741+
VPInstruction Op0(VPInstruction::StepVector, {});
1742+
VPInstruction Op1(VPInstruction::VScale, {});
17411743
VPDoubleValueDef DoubleValueDef({&Op0, &Op1});
17421744

17431745
// Create a new users of the defined values.
1744-
VPInstruction I1(
1745-
1, {DoubleValueDef.getVPValue(0), DoubleValueDef.getVPValue(1)});
1746-
VPInstruction I2(2, {DoubleValueDef.getVPValue(0)});
1747-
VPInstruction I3(3, {DoubleValueDef.getVPValue(1)});
1746+
VPInstruction I1(Instruction::Add, {DoubleValueDef.getVPValue(0),
1747+
DoubleValueDef.getVPValue(1)});
1748+
VPInstruction I2(Instruction::Freeze, {DoubleValueDef.getVPValue(0)});
1749+
VPInstruction I3(Instruction::Freeze, {DoubleValueDef.getVPValue(1)});
17481750

17491751
// Check operands of the VPDef (traversing upwards).
17501752
SmallVector<VPValue *, 4> DoubleOperands(DoubleValueDef.op_begin(),

0 commit comments

Comments
 (0)