Skip to content

[SLP]Improved reduction cost/codegen #118293

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

Merged
Merged
Show file tree
Hide file tree
Changes from 6 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
8 changes: 8 additions & 0 deletions llvm/include/llvm/Analysis/TargetTransformInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,10 @@ class TargetTransformInfo {
/// split during legalization. Zero is returned when the answer is unknown.
unsigned getNumberOfParts(Type *Tp) const;

/// \return true if \p Tp represent a type, fully occupying whole register,
/// false otherwise.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Improve the description as it doesn't seem to match the implementation in BasicTTIImpl.h

bool isFullSingleRegisterType(Type *Tp) const;

/// \returns The cost of the address computation. For most targets this can be
/// merged into the instruction indexing mode. Some targets might want to
/// distinguish between address computation for memory operations on vector
Expand Down Expand Up @@ -2238,6 +2242,7 @@ class TargetTransformInfo::Concept {
ArrayRef<Type *> Tys,
TTI::TargetCostKind CostKind) = 0;
virtual unsigned getNumberOfParts(Type *Tp) = 0;
virtual bool isFullSingleRegisterType(Type *Tp) const = 0;
virtual InstructionCost
getAddressComputationCost(Type *Ty, ScalarEvolution *SE, const SCEV *Ptr) = 0;
virtual InstructionCost
Expand Down Expand Up @@ -2987,6 +2992,9 @@ class TargetTransformInfo::Model final : public TargetTransformInfo::Concept {
unsigned getNumberOfParts(Type *Tp) override {
return Impl.getNumberOfParts(Tp);
}
bool isFullSingleRegisterType(Type *Tp) const override {
return Impl.isFullSingleRegisterType(Tp);
}
InstructionCost getAddressComputationCost(Type *Ty, ScalarEvolution *SE,
const SCEV *Ptr) override {
return Impl.getAddressComputationCost(Ty, SE, Ptr);
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@ class TargetTransformInfoImplBase {

// Assume that we have a register of the right size for the type.
unsigned getNumberOfParts(Type *Tp) const { return 1; }
bool isFullSingleRegisterType(Type *Tp) const { return false; }

InstructionCost getAddressComputationCost(Type *Tp, ScalarEvolution *,
const SCEV *) const {
Expand Down
16 changes: 16 additions & 0 deletions llvm/include/llvm/CodeGen/BasicTTIImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2682,6 +2682,22 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
return *LT.first.getValue();
}

bool isFullSingleRegisterType(Type *Tp) const {
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Tp);
if (!LT.first.isValid() || LT.first > 1)
return false;

if (auto *FTp = dyn_cast<FixedVectorType>(Tp);
Tp && LT.second.isFixedLengthVector()) {
// Check if the n x i1 fits fully into largest integer.
if (unsigned VF = LT.second.getVectorNumElements();
LT.second.getVectorElementType() == MVT::i1)
return DL.isLegalInteger(VF) && !DL.isLegalInteger(VF * 2);
return FTp == EVT(LT.second).getTypeForEVT(Tp->getContext());
}
return false;
}

InstructionCost getAddressComputationCost(Type *Ty, ScalarEvolution *,
const SCEV *) {
return 0;
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Analysis/TargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,10 @@ unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
return TTIImpl->getNumberOfParts(Tp);
}

bool TargetTransformInfo::isFullSingleRegisterType(Type *Tp) const {
return TTIImpl->isFullSingleRegisterType(Tp);
}

InstructionCost
TargetTransformInfo::getAddressComputationCost(Type *Tp, ScalarEvolution *SE,
const SCEV *Ptr) const {
Expand Down
Loading
Loading