Skip to content
Closed
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
9 changes: 9 additions & 0 deletions llvm/include/llvm/Analysis/TargetTransformInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,9 @@ class TargetTransformInfo {
bool isLegalMaskedScatter(Type *DataType, Align Alignment) const;
/// Return true if the target supports masked gather.
bool isLegalMaskedGather(Type *DataType, Align Alignment) const;
/// Return true if the target supports vectorization of histograms.
bool isLegalForHistogramVectorization(const LoadInst *LI,
const StoreInst *SI) const;
/// Return true if the target forces scalarizing of llvm.masked.gather
/// intrinsics.
bool forceScalarizeMaskedGather(VectorType *Type, Align Alignment) const;
Expand Down Expand Up @@ -2028,6 +2031,8 @@ class TargetTransformInfo::Concept {
ElementCount NumElements) const = 0;
virtual bool isLegalMaskedScatter(Type *DataType, Align Alignment) = 0;
virtual bool isLegalMaskedGather(Type *DataType, Align Alignment) = 0;
virtual bool isLegalForHistogramVectorization(const LoadInst *LI,
const StoreInst *SI) = 0;
virtual bool forceScalarizeMaskedGather(VectorType *DataType,
Align Alignment) = 0;
virtual bool forceScalarizeMaskedScatter(VectorType *DataType,
Expand Down Expand Up @@ -2589,6 +2594,10 @@ class TargetTransformInfo::Model final : public TargetTransformInfo::Concept {
bool isLegalMaskedGather(Type *DataType, Align Alignment) override {
return Impl.isLegalMaskedGather(DataType, Alignment);
}
bool isLegalForHistogramVectorization(const LoadInst *LI,
const StoreInst *SI) override {
return Impl.isLegalForHistogramVectorization(LI, SI);
}
bool forceScalarizeMaskedGather(VectorType *DataType,
Align Alignment) override {
return Impl.forceScalarizeMaskedGather(DataType, Alignment);
Expand Down
16 changes: 16 additions & 0 deletions llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,22 @@ class TargetTransformInfoImplBase {
return false;
}

bool isLegalForHistogramVectorization(const LoadInst *LI,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm wondering if you could add the load and store to the parameters in IntrinsicCostAttributes when asking for the cost of a histogram intrinsic, and return Invalid if the target doesn't support it instead of introducing a new method.

I guess this is a fast way of rejecting something in a different address space though, without going through the rest of the analysis.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When investigating your approach, I realized that IntrinsicCostAttributes already contains the GEP pointer, which includes the address space information. By adjusting the cost (or simply marking it as invalid), I can control which histogram operations I'd like to support.
Thank you for the feedback!
I'll go ahead and close the PR.

const StoreInst *SI) const {
// TODO: Currently, when a target wants to use histogram intrinsics, it adds
// the
// `-enable-histogram-loop-vectorization` flag to Clang.
//
// Once the histogram option is enabled by default, we will need to update
// the default hook to return `false`, and each target that wants automatic
// histogram vectorization will need to override it to return `true`.
//
// Additionally, we will need to deprecate the
// `-enable-histogram-loop-vectorization` flag, as it will no longer be
// necessary.
return true;
}

bool forceScalarizeMaskedGather(VectorType *DataType, Align Alignment) const {
return false;
}
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/Analysis/TargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,11 @@ bool TargetTransformInfo::isLegalMaskedGather(Type *DataType,
return TTIImpl->isLegalMaskedGather(DataType, Alignment);
}

bool TargetTransformInfo::isLegalForHistogramVectorization(
const LoadInst *LI, const StoreInst *SI) const {
return TTIImpl->isLegalForHistogramVectorization(LI, SI);
}

bool TargetTransformInfo::isLegalAltInstr(
VectorType *VecTy, unsigned Opcode0, unsigned Opcode1,
const SmallBitVector &OpcodeMask) const {
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,9 @@ bool LoopVectorizationLegality::canVectorizeIndirectUnsafeDependences() {
if (!LI || !SI)
return false;

if (!TTI->isLegalForHistogramVectorization(LI, SI))
return false;

LLVM_DEBUG(dbgs() << "LV: Checking for a histogram on: " << *SI << "\n");
return findHistogram(LI, SI, TheLoop, LAI->getPSE(), Histograms);
}
Expand Down