Skip to content

Commit 6752415

Browse files
authored
[VectorUtils] Simplify the code by new function InterleaveGroup::isFull. nfc (#151112)
1 parent c31cb8b commit 6752415

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

llvm/include/llvm/Analysis/VectorUtils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,9 @@ template <typename InstTy> class InterleaveGroup {
633633
return true;
634634
}
635635

636+
/// Return true if this group is full, i.e. it has no gaps.
637+
bool isFull() const { return getNumMembers() == getFactor(); }
638+
636639
private:
637640
uint32_t Factor; // Interleave Factor.
638641
bool Reverse;

llvm/lib/Analysis/VectorUtils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ Constant *
11231123
llvm::createBitMaskForGaps(IRBuilderBase &Builder, unsigned VF,
11241124
const InterleaveGroup<Instruction> &Group) {
11251125
// All 1's means mask is not needed.
1126-
if (Group.getNumMembers() == Group.getFactor())
1126+
if (Group.isFull())
11271127
return nullptr;
11281128

11291129
// TODO: support reversed access.
@@ -1669,7 +1669,7 @@ void InterleavedAccessInfo::analyzeInterleaving(
16691669
// Case 1: A full group. Can Skip the checks; For full groups, if the wide
16701670
// load would wrap around the address space we would do a memory access at
16711671
// nullptr even without the transformation.
1672-
if (Group->getNumMembers() == Group->getFactor())
1672+
if (Group->isFull())
16731673
continue;
16741674

16751675
// Case 2: If first and last members of the group don't wrap this implies
@@ -1704,7 +1704,7 @@ void InterleavedAccessInfo::analyzeInterleaving(
17041704
// Case 1: A full group. Can Skip the checks; For full groups, if the wide
17051705
// store would wrap around the address space we would do a memory access at
17061706
// nullptr even without the transformation.
1707-
if (Group->getNumMembers() == Group->getFactor())
1707+
if (Group->isFull())
17081708
continue;
17091709

17101710
// Interleave-store-group with gaps is implemented using masked wide store.

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3150,7 +3150,7 @@ bool LoopVectorizationCostModel::interleavedAccessCanBeWidened(
31503150
isa<LoadInst>(I) && Group->requiresScalarEpilogue() &&
31513151
!isScalarEpilogueAllowed();
31523152
bool StoreAccessWithGapsRequiresMasking =
3153-
isa<StoreInst>(I) && (Group->getNumMembers() < Group->getFactor());
3153+
isa<StoreInst>(I) && !Group->isFull();
31543154
if (!PredicatedAccessRequiresMasking &&
31553155
!LoadAccessWithGapsRequiresEpilogMasking &&
31563156
!StoreAccessWithGapsRequiresMasking)
@@ -5372,7 +5372,7 @@ LoopVectorizationCostModel::getInterleaveGroupCost(Instruction *I,
53725372
// Calculate the cost of the whole interleaved group.
53735373
bool UseMaskForGaps =
53745374
(Group->requiresScalarEpilogue() && !isScalarEpilogueAllowed()) ||
5375-
(isa<StoreInst>(I) && (Group->getNumMembers() < Group->getFactor()));
5375+
(isa<StoreInst>(I) && !Group->isFull());
53765376
InstructionCost Cost = TTI.getInterleavedMemoryOpCost(
53775377
InsertPos->getOpcode(), WideVecTy, Group->getFactor(), Indices,
53785378
Group->getAlign(), AS, CostKind, Legal->isMaskRequired(I),

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3209,9 +3209,7 @@ static bool canNarrowLoad(VPWidenRecipe *WideMember0, unsigned OpIdx,
32093209
return !W->getMask() && WideMember0->getOperand(OpIdx) == OpV;
32103210

32113211
if (auto *IR = dyn_cast<VPInterleaveRecipe>(DefR))
3212-
return IR->getInterleaveGroup()->getFactor() ==
3213-
IR->getInterleaveGroup()->getNumMembers() &&
3214-
IR->getVPValue(Idx) == OpV;
3212+
return IR->getInterleaveGroup()->isFull() && IR->getVPValue(Idx) == OpV;
32153213
return false;
32163214
}
32173215

@@ -3328,9 +3326,7 @@ void VPlanTransforms::narrowInterleaveGroups(VPlan &Plan, ElementCount VF,
33283326
if (!DefR)
33293327
return false;
33303328
auto *IR = dyn_cast<VPInterleaveRecipe>(DefR);
3331-
return IR &&
3332-
IR->getInterleaveGroup()->getFactor() ==
3333-
IR->getInterleaveGroup()->getNumMembers() &&
3329+
return IR && IR->getInterleaveGroup()->isFull() &&
33343330
IR->getVPValue(Op.index()) == Op.value();
33353331
})) {
33363332
StoreGroups.push_back(InterleaveR);

0 commit comments

Comments
 (0)