aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKolya Panchenko <87679760+nikolaypanchenko@users.noreply.github.com>2024-03-05 17:33:56 -0800
committerGitHub <noreply@github.com>2024-03-05 20:33:56 -0500
commit889d99a50f38150570f6fca903d61ee9770bd932 (patch)
tree67bc12a80193be456da910781a59d08b5d537185
parent8b326d59467b941831942c651c585055b3d512e4 (diff)
downloadllvm-889d99a50f38150570f6fca903d61ee9770bd932.zip
llvm-889d99a50f38150570f6fca903d61ee9770bd932.tar.gz
llvm-889d99a50f38150570f6fca903d61ee9770bd932.tar.bz2
[TTI] Add alignment argument to TTI for compress/expand support (#83516)
Since `llvm.compressstore` and `llvm.expandload` do require memory access, it's essential for some target to check if alignment is good to be able to lower them to target-specific instructions
-rw-r--r--llvm/include/llvm/Analysis/TargetTransformInfo.h16
-rw-r--r--llvm/include/llvm/Analysis/TargetTransformInfoImpl.h8
-rw-r--r--llvm/lib/Analysis/TargetTransformInfo.cpp10
-rw-r--r--llvm/lib/Target/X86/X86TargetTransformInfo.cpp6
-rw-r--r--llvm/lib/Target/X86/X86TargetTransformInfo.h4
-rw-r--r--llvm/lib/Transforms/Scalar/ScalarizeMaskedMemIntrin.cpp8
6 files changed, 31 insertions, 21 deletions
diff --git a/llvm/include/llvm/Analysis/TargetTransformInfo.h b/llvm/include/llvm/Analysis/TargetTransformInfo.h
index 58577a6..4eab357 100644
--- a/llvm/include/llvm/Analysis/TargetTransformInfo.h
+++ b/llvm/include/llvm/Analysis/TargetTransformInfo.h
@@ -777,9 +777,9 @@ public:
bool forceScalarizeMaskedScatter(VectorType *Type, Align Alignment) const;
/// Return true if the target supports masked compress store.
- bool isLegalMaskedCompressStore(Type *DataType) const;
+ bool isLegalMaskedCompressStore(Type *DataType, Align Alignment) const;
/// Return true if the target supports masked expand load.
- bool isLegalMaskedExpandLoad(Type *DataType) const;
+ bool isLegalMaskedExpandLoad(Type *DataType, Align Alignment) const;
/// Return true if the target supports strided load.
bool isLegalStridedLoadStore(Type *DataType, Align Alignment) const;
@@ -1863,8 +1863,8 @@ public:
Align Alignment) = 0;
virtual bool forceScalarizeMaskedScatter(VectorType *DataType,
Align Alignment) = 0;
- virtual bool isLegalMaskedCompressStore(Type *DataType) = 0;
- virtual bool isLegalMaskedExpandLoad(Type *DataType) = 0;
+ virtual bool isLegalMaskedCompressStore(Type *DataType, Align Alignment) = 0;
+ virtual bool isLegalMaskedExpandLoad(Type *DataType, Align Alignment) = 0;
virtual bool isLegalStridedLoadStore(Type *DataType, Align Alignment) = 0;
virtual bool isLegalAltInstr(VectorType *VecTy, unsigned Opcode0,
unsigned Opcode1,
@@ -2358,11 +2358,11 @@ public:
Align Alignment) override {
return Impl.forceScalarizeMaskedScatter(DataType, Alignment);
}
- bool isLegalMaskedCompressStore(Type *DataType) override {
- return Impl.isLegalMaskedCompressStore(DataType);
+ bool isLegalMaskedCompressStore(Type *DataType, Align Alignment) override {
+ return Impl.isLegalMaskedCompressStore(DataType, Alignment);
}
- bool isLegalMaskedExpandLoad(Type *DataType) override {
- return Impl.isLegalMaskedExpandLoad(DataType);
+ bool isLegalMaskedExpandLoad(Type *DataType, Align Alignment) override {
+ return Impl.isLegalMaskedExpandLoad(DataType, Alignment);
}
bool isLegalStridedLoadStore(Type *DataType, Align Alignment) override {
return Impl.isLegalStridedLoadStore(DataType, Alignment);
diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
index 13379cc..95fb13d 100644
--- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
+++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
@@ -295,14 +295,18 @@ public:
return false;
}
- bool isLegalMaskedCompressStore(Type *DataType) const { return false; }
+ bool isLegalMaskedCompressStore(Type *DataType, Align Alignment) const {
+ return false;
+ }
bool isLegalAltInstr(VectorType *VecTy, unsigned Opcode0, unsigned Opcode1,
const SmallBitVector &OpcodeMask) const {
return false;
}
- bool isLegalMaskedExpandLoad(Type *DataType) const { return false; }
+ bool isLegalMaskedExpandLoad(Type *DataType, Align Alignment) const {
+ return false;
+ }
bool isLegalStridedLoadStore(Type *DataType, Align Alignment) const {
return false;
diff --git a/llvm/lib/Analysis/TargetTransformInfo.cpp b/llvm/lib/Analysis/TargetTransformInfo.cpp
index 1f11f0d..15311be 100644
--- a/llvm/lib/Analysis/TargetTransformInfo.cpp
+++ b/llvm/lib/Analysis/TargetTransformInfo.cpp
@@ -492,12 +492,14 @@ bool TargetTransformInfo::forceScalarizeMaskedScatter(VectorType *DataType,
return TTIImpl->forceScalarizeMaskedScatter(DataType, Alignment);
}
-bool TargetTransformInfo::isLegalMaskedCompressStore(Type *DataType) const {
- return TTIImpl->isLegalMaskedCompressStore(DataType);
+bool TargetTransformInfo::isLegalMaskedCompressStore(Type *DataType,
+ Align Alignment) const {
+ return TTIImpl->isLegalMaskedCompressStore(DataType, Alignment);
}
-bool TargetTransformInfo::isLegalMaskedExpandLoad(Type *DataType) const {
- return TTIImpl->isLegalMaskedExpandLoad(DataType);
+bool TargetTransformInfo::isLegalMaskedExpandLoad(Type *DataType,
+ Align Alignment) const {
+ return TTIImpl->isLegalMaskedExpandLoad(DataType, Alignment);
}
bool TargetTransformInfo::isLegalStridedLoadStore(Type *DataType,
diff --git a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp
index 4cca291..d336ab9 100644
--- a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp
+++ b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp
@@ -5938,7 +5938,7 @@ bool X86TTIImpl::isLegalBroadcastLoad(Type *ElementTy,
ElementTy == Type::getDoubleTy(ElementTy->getContext());
}
-bool X86TTIImpl::isLegalMaskedExpandLoad(Type *DataTy) {
+bool X86TTIImpl::isLegalMaskedExpandLoad(Type *DataTy, Align Alignment) {
if (!isa<VectorType>(DataTy))
return false;
@@ -5962,8 +5962,8 @@ bool X86TTIImpl::isLegalMaskedExpandLoad(Type *DataTy) {
((IntWidth == 8 || IntWidth == 16) && ST->hasVBMI2());
}
-bool X86TTIImpl::isLegalMaskedCompressStore(Type *DataTy) {
- return isLegalMaskedExpandLoad(DataTy);
+bool X86TTIImpl::isLegalMaskedCompressStore(Type *DataTy, Align Alignment) {
+ return isLegalMaskedExpandLoad(DataTy, Alignment);
}
bool X86TTIImpl::supportsGather() const {
diff --git a/llvm/lib/Target/X86/X86TargetTransformInfo.h b/llvm/lib/Target/X86/X86TargetTransformInfo.h
index 07a3fff4..1a5e6bc 100644
--- a/llvm/lib/Target/X86/X86TargetTransformInfo.h
+++ b/llvm/lib/Target/X86/X86TargetTransformInfo.h
@@ -269,8 +269,8 @@ public:
bool isLegalMaskedGatherScatter(Type *DataType, Align Alignment);
bool isLegalMaskedGather(Type *DataType, Align Alignment);
bool isLegalMaskedScatter(Type *DataType, Align Alignment);
- bool isLegalMaskedExpandLoad(Type *DataType);
- bool isLegalMaskedCompressStore(Type *DataType);
+ bool isLegalMaskedExpandLoad(Type *DataType, Align Alignment);
+ bool isLegalMaskedCompressStore(Type *DataType, Align Alignment);
bool isLegalAltInstr(VectorType *VecTy, unsigned Opcode0, unsigned Opcode1,
const SmallBitVector &OpcodeMask) const;
bool hasDivRemOp(Type *DataType, bool IsSigned);
diff --git a/llvm/lib/Transforms/Scalar/ScalarizeMaskedMemIntrin.cpp b/llvm/lib/Transforms/Scalar/ScalarizeMaskedMemIntrin.cpp
index f362dc5..a4111fa 100644
--- a/llvm/lib/Transforms/Scalar/ScalarizeMaskedMemIntrin.cpp
+++ b/llvm/lib/Transforms/Scalar/ScalarizeMaskedMemIntrin.cpp
@@ -979,12 +979,16 @@ static bool optimizeCallInst(CallInst *CI, bool &ModifiedDT,
return true;
}
case Intrinsic::masked_expandload:
- if (TTI.isLegalMaskedExpandLoad(CI->getType()))
+ if (TTI.isLegalMaskedExpandLoad(
+ CI->getType(),
+ CI->getAttributes().getParamAttrs(0).getAlignment().valueOrOne()))
return false;
scalarizeMaskedExpandLoad(DL, CI, DTU, ModifiedDT);
return true;
case Intrinsic::masked_compressstore:
- if (TTI.isLegalMaskedCompressStore(CI->getArgOperand(0)->getType()))
+ if (TTI.isLegalMaskedCompressStore(
+ CI->getArgOperand(0)->getType(),
+ CI->getAttributes().getParamAttrs(1).getAlignment().valueOrOne()))
return false;
scalarizeMaskedCompressStore(DL, CI, DTU, ModifiedDT);
return true;