Skip to content

[ARM][MVE] Add shuffle costs for LDn and STn instructions. #145304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,37 @@ InstructionCost ARMTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,

if (!Mask.empty()) {
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(SrcTy);
// Check for LD2/LD4 instructions, which are represented in llvm IR as
// deinterleaving-shuffle(load). The shuffle cost could potentially be
// free, but we model it with a cost of LT.first so that LD2/LD4 have a
// higher cost than just the load.
if (Args.size() >= 1 && isa<LoadInst>(Args[0]) &&
(LT.second.getScalarSizeInBits() == 8 ||
LT.second.getScalarSizeInBits() == 16 ||
LT.second.getScalarSizeInBits() == 32) &&
LT.second.getSizeInBits() == 128 &&
(ShuffleVectorInst::isDeInterleaveMaskOfFactor(Mask, 2) ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check MaxSupportedInterleaveFactor() >= 2 here? (So -mve-max-interleave-factor=1 will work as expected)

(TLI->getMaxSupportedInterleaveFactor() == 4 &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be >= 4, I think.

ShuffleVectorInst::isDeInterleaveMaskOfFactor(Mask, 4))))
return ST->getMVEVectorCostFactor(TTI::TCK_RecipThroughput) *
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be using the CostKind passed in as an argument? (Though I notice elsewhere in the function it's ignoring the argument and just using RecipThroughput)

std::max<InstructionCost>(1, LT.first / 4);

// Check for ST2/ST4 instructions, which are represented in llvm IR as
// store(interleaving-shuffle). The shuffle cost could potentially be
// free, but we model it with a cost of LT.first so that ST2/ST4 have a
// higher cost than just the store.
if (CxtI && CxtI->hasOneUse() && isa<StoreInst>(*CxtI->user_begin()) &&
(LT.second.getScalarSizeInBits() == 8 ||
LT.second.getScalarSizeInBits() == 16 ||
LT.second.getScalarSizeInBits() == 32) &&
LT.second.getSizeInBits() == 128 &&
(ShuffleVectorInst::isInterleaveMask(
Mask, 2, SrcTy->getElementCount().getKnownMinValue() * 2) ||
(TLI->getMaxSupportedInterleaveFactor() == 4 &&
ShuffleVectorInst::isInterleaveMask(
Mask, 4, SrcTy->getElementCount().getKnownMinValue() * 2))))
return ST->getMVEVectorCostFactor(TTI::TCK_RecipThroughput) * LT.first;

if (LT.second.isVector() &&
Mask.size() <= LT.second.getVectorNumElements() &&
(isVREVMask(Mask, LT.second, 16) || isVREVMask(Mask, LT.second, 32) ||
Expand Down
Loading
Loading