Skip to content

Commit db2cfbb

Browse files
committed
Move isDeInterleaveMaskOfFactor to ShuffleVectorInst
1 parent fcca24a commit db2cfbb

File tree

4 files changed

+40
-50
lines changed

4 files changed

+40
-50
lines changed

llvm/include/llvm/IR/Instructions.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2631,6 +2631,16 @@ class ShuffleVectorInst : public Instruction {
26312631
return isInterleaveMask(Mask, Factor, NumInputElts, StartIndexes);
26322632
}
26332633

2634+
/// Check if the mask is a DE-interleave mask of the given factor
2635+
/// \p Factor like:
2636+
/// <Index, Index+Factor, ..., Index+(NumElts-1)*Factor>
2637+
static bool isDeInterleaveMaskOfFactor(ArrayRef<int> Mask, unsigned Factor,
2638+
unsigned &Index);
2639+
static bool isDeInterleaveMaskOfFactor(ArrayRef<int> Mask, unsigned Factor) {
2640+
unsigned Unused;
2641+
return isDeInterleaveMaskOfFactor(Mask, Factor, Unused);
2642+
}
2643+
26342644
/// Checks if the shuffle is a bit rotation of the first operand across
26352645
/// multiple subelements, e.g:
26362646
///

llvm/lib/CodeGen/InterleavedAccessPass.cpp

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -200,28 +200,6 @@ FunctionPass *llvm::createInterleavedAccessPass() {
200200
return new InterleavedAccess();
201201
}
202202

203-
/// Check if the mask is a DE-interleave mask of the given factor
204-
/// \p Factor like:
205-
/// <Index, Index+Factor, ..., Index+(NumElts-1)*Factor>
206-
static bool isDeInterleaveMaskOfFactor(ArrayRef<int> Mask, unsigned Factor,
207-
unsigned &Index) {
208-
// Check all potential start indices from 0 to (Factor - 1).
209-
for (Index = 0; Index < Factor; Index++) {
210-
unsigned i = 0;
211-
212-
// Check that elements are in ascending order by Factor. Ignore undef
213-
// elements.
214-
for (; i < Mask.size(); i++)
215-
if (Mask[i] >= 0 && static_cast<unsigned>(Mask[i]) != Index + i * Factor)
216-
break;
217-
218-
if (i == Mask.size())
219-
return true;
220-
}
221-
222-
return false;
223-
}
224-
225203
/// Check if the mask is a DE-interleave mask for an interleaved load.
226204
///
227205
/// E.g. DE-interleave masks (Factor = 2) could be:
@@ -238,7 +216,7 @@ static bool isDeInterleaveMask(ArrayRef<int> Mask, unsigned &Factor,
238216
// Make sure we don't produce a load wider than the input load.
239217
if (Mask.size() * Factor > NumLoadElements)
240218
return false;
241-
if (isDeInterleaveMaskOfFactor(Mask, Factor, Index))
219+
if (ShuffleVectorInst::isDeInterleaveMaskOfFactor(Mask, Factor, Index))
242220
return true;
243221
}
244222

@@ -333,8 +311,8 @@ bool InterleavedAccessImpl::lowerInterleavedLoad(
333311
for (auto *Shuffle : Shuffles) {
334312
if (Shuffle->getType() != VecTy)
335313
return false;
336-
if (!isDeInterleaveMaskOfFactor(Shuffle->getShuffleMask(), Factor,
337-
Index))
314+
if (!ShuffleVectorInst::isDeInterleaveMaskOfFactor(
315+
Shuffle->getShuffleMask(), Factor, Index))
338316
return false;
339317

340318
assert(Shuffle->getShuffleMask().size() <= NumLoadElements);
@@ -343,8 +321,8 @@ bool InterleavedAccessImpl::lowerInterleavedLoad(
343321
for (auto *Shuffle : BinOpShuffles) {
344322
if (Shuffle->getType() != VecTy)
345323
return false;
346-
if (!isDeInterleaveMaskOfFactor(Shuffle->getShuffleMask(), Factor,
347-
Index))
324+
if (!ShuffleVectorInst::isDeInterleaveMaskOfFactor(
325+
Shuffle->getShuffleMask(), Factor, Index))
348326
return false;
349327

350328
assert(Shuffle->getShuffleMask().size() <= NumLoadElements);

llvm/lib/IR/Instructions.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2978,6 +2978,29 @@ bool ShuffleVectorInst::isInterleaveMask(
29782978
return true;
29792979
}
29802980

2981+
/// Check if the mask is a DE-interleave mask of the given factor
2982+
/// \p Factor like:
2983+
/// <Index, Index+Factor, ..., Index+(NumElts-1)*Factor>
2984+
bool ShuffleVectorInst::isDeInterleaveMaskOfFactor(ArrayRef<int> Mask,
2985+
unsigned Factor,
2986+
unsigned &Index) {
2987+
// Check all potential start indices from 0 to (Factor - 1).
2988+
for (Index = 0; Index < Factor; Index++) {
2989+
unsigned I = 0;
2990+
2991+
// Check that elements are in ascending order by Factor. Ignore undef
2992+
// elements.
2993+
for (; I < Mask.size(); I++)
2994+
if (Mask[I] >= 0 && static_cast<unsigned>(Mask[I]) != Index + I * Factor)
2995+
break;
2996+
2997+
if (I == Mask.size())
2998+
return true;
2999+
}
3000+
3001+
return false;
3002+
}
3003+
29813004
/// Try to lower a vector shuffle as a bit rotation.
29823005
///
29833006
/// Look for a repeated rotation pattern in each sub group.

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3815,27 +3815,6 @@ InstructionCost AArch64TTIImpl::getSpliceCost(VectorType *Tp, int Index) {
38153815
return LegalizationCost * LT.first;
38163816
}
38173817

3818-
/// Check if the mask is a DE-interleave mask of the given factor
3819-
/// \p Factor like:
3820-
/// <Index, Index+Factor, ..., Index+(NumElts-1)*Factor>
3821-
static bool isDeInterleaveMaskOfFactor(ArrayRef<int> Mask, unsigned Factor) {
3822-
// Check all potential start indices from 0 to (Factor - 1).
3823-
for (unsigned Index = 0; Index < Factor; Index++) {
3824-
unsigned i = 0;
3825-
3826-
// Check that elements are in ascending order by Factor. Ignore undef
3827-
// elements.
3828-
for (; i < Mask.size(); i++)
3829-
if (Mask[i] >= 0 && static_cast<unsigned>(Mask[i]) != Index + i * Factor)
3830-
break;
3831-
3832-
if (i == Mask.size())
3833-
return true;
3834-
}
3835-
3836-
return false;
3837-
}
3838-
38393818
InstructionCost AArch64TTIImpl::getShuffleCost(
38403819
TTI::ShuffleKind Kind, VectorType *Tp, ArrayRef<int> Mask,
38413820
TTI::TargetCostKind CostKind, int Index, VectorType *SubTp,
@@ -3853,8 +3832,8 @@ InstructionCost AArch64TTIImpl::getShuffleCost(
38533832
// but we model it with a cost of LT.first so that LD3/LD4 have a higher
38543833
// cost than just the load.
38553834
if (Args.size() >= 1 && isa<LoadInst>(Args[0]) &&
3856-
(isDeInterleaveMaskOfFactor(Mask, 3) ||
3857-
isDeInterleaveMaskOfFactor(Mask, 4)))
3835+
(ShuffleVectorInst::isDeInterleaveMaskOfFactor(Mask, 3) ||
3836+
ShuffleVectorInst::isDeInterleaveMaskOfFactor(Mask, 4)))
38583837
return std::max<InstructionCost>(1, LT.first / 4);
38593838

38603839
// Check for ST3/ST4 instructions, which are represented in llvm IR as

0 commit comments

Comments
 (0)