Skip to content

Commit cc1a779

Browse files
committed
!fixup address comments, thanks
1 parent 48699d9 commit cc1a779

File tree

5 files changed

+23
-20
lines changed

5 files changed

+23
-20
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -936,9 +936,9 @@ class VPInstruction : public VPRecipeWithIRFlags,
936936
BranchOnCount,
937937
BranchOnCond,
938938
Broadcast,
939-
/// Creates a struct of fixed-width vectors containing all operands. The
940-
/// number of operands
941-
/// matches the number of fields in the struct.
939+
/// Given operands of (the same) struct type, creates a struct of fixed-
940+
/// width vectors each containing a struct field of all operands. The
941+
/// number of operands matches the element count of every vector.
942942
BuildStructVector,
943943
/// Creates a fixed-width vector containing all operands. The number of
944944
/// operands matches the vector element count.

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -610,15 +610,12 @@ Value *VPInstruction::generate(VPTransformState &State) {
610610
}
611611
case VPInstruction::BuildStructVector: {
612612
// For struct types, we need to build a new 'wide' struct type, where each
613-
// element is widened.
613+
// element is widened, i.e. we crate a struct of vectors .
614614
auto *StructTy =
615615
cast<StructType>(State.TypeAnalysis.inferScalarType(getOperand(0)));
616-
auto NumOfElements = ElementCount::getFixed(getNumOperands());
617-
Value *Res = PoisonValue::get(toVectorizedTy(StructTy, NumOfElements));
618-
assert(NumOfElements.getKnownMinValue() == StructTy->getNumElements() &&
619-
"number of operands must match number of elements in StructTy");
616+
Value *Res = PoisonValue::get(toVectorizedTy(StructTy, State.VF));
620617
for (const auto &[Idx, Op] : enumerate(operands())) {
621-
for (unsigned I = 0; I != NumOfElements.getKnownMinValue(); I++) {
618+
for (unsigned I = 0; I != StructTy->getNumElements(); I++) {
622619
Value *ScalarValue = Builder.CreateExtractValue(State.get(Op, true), I);
623620
Value *VectorValue = Builder.CreateExtractValue(Res, I);
624621
VectorValue =
@@ -2688,6 +2685,7 @@ void VPReplicateRecipe::execute(VPTransformState &State) {
26882685
}
26892686
State.set(this, State.packScalarIntoVectorizedValue(this, WideValue,
26902687
*State.Lane));
2688+
}
26912689
}
26922690

26932691
bool VPReplicateRecipe::shouldPack() const {

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,7 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
11481148
BuildVector->getOperand(BuildVector->getNumOperands() - 1));
11491149
return;
11501150
}
1151+
11511152
// Look through ExtractPenultimateElement (BuildVector ....).
11521153
if (match(&R, m_VPInstruction<VPInstruction::ExtractPenultimateElement>(
11531154
m_BuildVector()))) {

llvm/lib/Transforms/Vectorize/VPlanTransforms.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ struct VPlanTransforms {
9999
/// Explicitly unroll \p Plan by \p UF.
100100
static void unrollByUF(VPlan &Plan, unsigned UF, LLVMContext &Ctx);
101101

102-
/// Replace replicating VPReplicateRecipes outside replicate regions in \p
103-
/// Plan with \p VF single-scalar recipes.
104-
/// TODO: Also unroll VPReplicateRegions by VF.
102+
/// Replace each VPReplicateRecipe outside on any replicate region in \p Plan
103+
/// with \p VF single-scalar recipes.
104+
/// TODO: Also replicate VPReplicateRecipes inside replicate regions, thereby
105+
/// dissolving the latter.
105106
static void replicateByVF(VPlan &Plan, ElementCount VF);
106107

107108
/// Optimize \p Plan based on \p BestVF and \p BestUF. This may restrict the

llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -511,22 +511,25 @@ void VPlanTransforms::replicateByVF(VPlan &Plan, ElementCount VF) {
511511
for (unsigned I = 0; I != VF.getKnownMinValue(); ++I)
512512
LaneDefs.push_back(cloneForLane(Plan, Builder, IdxTy, RepR, VPLane(I)));
513513

514+
if (RepR->getNumUsers() == 0) {
515+
RepR->eraseFromParent();
516+
continue;
517+
}
518+
514519
/// Users that only demand the first lane can use the definition for lane
515520
/// 0.
516521
RepR->replaceUsesWithIf(LaneDefs[0], [RepR](VPUser &U, unsigned) {
517522
return U.onlyFirstLaneUsed(RepR);
518523
});
519524

520-
Type *ResTy = RepR->getUnderlyingInstr()->getType();
521525
// If needed, create a Build(Struct)Vector recipe to insert the scalar
522526
// lane values into a vector.
523-
if (!ResTy->isVoidTy()) {
524-
VPValue *VecRes = Builder.createNaryOp(
525-
ResTy->isStructTy() ? VPInstruction::BuildStructVector
526-
: VPInstruction::BuildVector,
527-
LaneDefs);
528-
RepR->replaceAllUsesWith(VecRes);
529-
}
527+
Type *ResTy = RepR->getUnderlyingInstr()->getType();
528+
VPValue *VecRes = Builder.createNaryOp(
529+
ResTy->isStructTy() ? VPInstruction::BuildStructVector
530+
: VPInstruction::BuildVector,
531+
LaneDefs);
532+
RepR->replaceAllUsesWith(VecRes);
530533
RepR->eraseFromParent();
531534
}
532535
}

0 commit comments

Comments
 (0)