Skip to content

Commit 64555e3

Browse files
authored
[X86][NFCI] Add IsStore parameter to hasConditionalLoadStoreForType (llvm#132153)
Address llvm#132032 (comment)
1 parent 750e716 commit 64555e3

File tree

7 files changed

+43
-24
lines changed

7 files changed

+43
-24
lines changed

llvm/include/llvm/Analysis/TargetTransformInfo.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,7 @@ class TargetTransformInfo {
11621162

11631163
/// \return true if the target supports load/store that enables fault
11641164
/// suppression of memory operands when the source condition is false.
1165-
bool hasConditionalLoadStoreForType(Type *Ty = nullptr) const;
1165+
bool hasConditionalLoadStoreForType(Type *Ty, bool IsStore) const;
11661166

11671167
/// \return the target-provided register class ID for the provided type,
11681168
/// accounting for type promotion and other type-legalization techniques that
@@ -2107,7 +2107,7 @@ class TargetTransformInfo::Concept {
21072107
virtual bool preferToKeepConstantsAttached(const Instruction &Inst,
21082108
const Function &Fn) const = 0;
21092109
virtual unsigned getNumberOfRegisters(unsigned ClassID) const = 0;
2110-
virtual bool hasConditionalLoadStoreForType(Type *Ty = nullptr) const = 0;
2110+
virtual bool hasConditionalLoadStoreForType(Type *Ty, bool IsStore) const = 0;
21112111
virtual unsigned getRegisterClassForType(bool Vector,
21122112
Type *Ty = nullptr) const = 0;
21132113
virtual const char *getRegisterClassName(unsigned ClassID) const = 0;
@@ -2770,8 +2770,8 @@ class TargetTransformInfo::Model final : public TargetTransformInfo::Concept {
27702770
unsigned getNumberOfRegisters(unsigned ClassID) const override {
27712771
return Impl.getNumberOfRegisters(ClassID);
27722772
}
2773-
bool hasConditionalLoadStoreForType(Type *Ty = nullptr) const override {
2774-
return Impl.hasConditionalLoadStoreForType(Ty);
2773+
bool hasConditionalLoadStoreForType(Type *Ty, bool IsStore) const override {
2774+
return Impl.hasConditionalLoadStoreForType(Ty, IsStore);
27752775
}
27762776
unsigned getRegisterClassForType(bool Vector,
27772777
Type *Ty = nullptr) const override {

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -504,11 +504,13 @@ class TargetTransformInfoImplBase {
504504
}
505505

506506
unsigned getNumberOfRegisters(unsigned ClassID) const { return 8; }
507-
bool hasConditionalLoadStoreForType(Type *Ty) const { return false; }
507+
bool hasConditionalLoadStoreForType(Type *Ty, bool IsStore) const {
508+
return false;
509+
}
508510

509511
unsigned getRegisterClassForType(bool Vector, Type *Ty = nullptr) const {
510512
return Vector ? 1 : 0;
511-
};
513+
}
512514

513515
const char *getRegisterClassName(unsigned ClassID) const {
514516
switch (ClassID) {

llvm/lib/Analysis/TargetTransformInfo.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -759,8 +759,9 @@ unsigned TargetTransformInfo::getNumberOfRegisters(unsigned ClassID) const {
759759
return TTIImpl->getNumberOfRegisters(ClassID);
760760
}
761761

762-
bool TargetTransformInfo::hasConditionalLoadStoreForType(Type *Ty) const {
763-
return TTIImpl->hasConditionalLoadStoreForType(Ty);
762+
bool TargetTransformInfo::hasConditionalLoadStoreForType(Type *Ty,
763+
bool IsStore) const {
764+
return TTIImpl->hasConditionalLoadStoreForType(Ty, IsStore);
764765
}
765766

766767
unsigned TargetTransformInfo::getRegisterClassForType(bool Vector,

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -4790,8 +4790,8 @@ void SelectionDAGBuilder::visitMaskedStore(const CallInst &I,
47904790
const auto &TTI =
47914791
TLI.getTargetMachine().getTargetTransformInfo(*I.getFunction());
47924792
SDValue StoreNode =
4793-
!IsCompressing &&
4794-
TTI.hasConditionalLoadStoreForType(I.getArgOperand(0)->getType())
4793+
!IsCompressing && TTI.hasConditionalLoadStoreForType(
4794+
I.getArgOperand(0)->getType(), /*IsStore=*/true)
47954795
? TLI.visitMaskedStore(DAG, sdl, getMemoryRoot(), MMO, Ptr, Src0,
47964796
Mask)
47974797
: DAG.getMaskedStore(getMemoryRoot(), sdl, Src0, Ptr, Offset, Mask,
@@ -4976,8 +4976,8 @@ void SelectionDAGBuilder::visitMaskedLoad(const CallInst &I, bool IsExpanding) {
49764976
// variables.
49774977
SDValue Load;
49784978
SDValue Res;
4979-
if (!IsExpanding &&
4980-
TTI.hasConditionalLoadStoreForType(Src0Operand->getType()))
4979+
if (!IsExpanding && TTI.hasConditionalLoadStoreForType(Src0Operand->getType(),
4980+
/*IsStore=*/false))
49814981
Res = TLI.visitMaskedLoad(DAG, sdl, InChain, MMO, Load, Ptr, Src0, Mask);
49824982
else
49834983
Res = Load =

llvm/lib/Target/X86/X86TargetTransformInfo.cpp

+24-10
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ unsigned X86TTIImpl::getNumberOfRegisters(unsigned ClassID) const {
175175
return 8;
176176
}
177177

178-
bool X86TTIImpl::hasConditionalLoadStoreForType(Type *Ty) const {
178+
bool X86TTIImpl::hasConditionalLoadStoreForType(Type *Ty, bool IsStore) const {
179179
if (!ST->hasCF())
180180
return false;
181181
if (!Ty)
@@ -6229,13 +6229,7 @@ bool X86TTIImpl::canMacroFuseCmp() {
62296229
return ST->hasMacroFusion() || ST->hasBranchFusion();
62306230
}
62316231

6232-
bool X86TTIImpl::isLegalMaskedLoad(Type *DataTy, Align Alignment) {
6233-
Type *ScalarTy = DataTy->getScalarType();
6234-
6235-
// The backend can't handle a single element vector w/o CFCMOV.
6236-
if (isa<VectorType>(DataTy) && cast<FixedVectorType>(DataTy)->getNumElements() == 1)
6237-
return ST->hasCF() && hasConditionalLoadStoreForType(ScalarTy);
6238-
6232+
static bool isLegalMaskedLoadStore(Type *ScalarTy, const X86Subtarget *ST) {
62396233
if (!ST->hasAVX())
62406234
return false;
62416235

@@ -6259,8 +6253,28 @@ bool X86TTIImpl::isLegalMaskedLoad(Type *DataTy, Align Alignment) {
62596253
((IntWidth == 8 || IntWidth == 16) && ST->hasBWI());
62606254
}
62616255

6262-
bool X86TTIImpl::isLegalMaskedStore(Type *DataType, Align Alignment) {
6263-
return isLegalMaskedLoad(DataType, Alignment);
6256+
bool X86TTIImpl::isLegalMaskedLoad(Type *DataTy, Align Alignment) {
6257+
Type *ScalarTy = DataTy->getScalarType();
6258+
6259+
// The backend can't handle a single element vector w/o CFCMOV.
6260+
if (isa<VectorType>(DataTy) &&
6261+
cast<FixedVectorType>(DataTy)->getNumElements() == 1)
6262+
return ST->hasCF() &&
6263+
hasConditionalLoadStoreForType(ScalarTy, /*IsStore=*/false);
6264+
6265+
return isLegalMaskedLoadStore(ScalarTy, ST);
6266+
}
6267+
6268+
bool X86TTIImpl::isLegalMaskedStore(Type *DataTy, Align Alignment) {
6269+
Type *ScalarTy = DataTy->getScalarType();
6270+
6271+
// The backend can't handle a single element vector w/o CFCMOV.
6272+
if (isa<VectorType>(DataTy) &&
6273+
cast<FixedVectorType>(DataTy)->getNumElements() == 1)
6274+
return ST->hasCF() &&
6275+
hasConditionalLoadStoreForType(ScalarTy, /*IsStore=*/true);
6276+
6277+
return isLegalMaskedLoadStore(ScalarTy, ST);
62646278
}
62656279

62666280
bool X86TTIImpl::isLegalNTLoad(Type *DataType, Align Alignment) {

llvm/lib/Target/X86/X86TargetTransformInfo.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class X86TTIImpl : public BasicTTIImplBase<X86TTIImpl> {
132132
/// @{
133133

134134
unsigned getNumberOfRegisters(unsigned ClassID) const;
135-
bool hasConditionalLoadStoreForType(Type *Ty = nullptr) const;
135+
bool hasConditionalLoadStoreForType(Type *Ty, bool IsStore) const;
136136
TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const;
137137
unsigned getLoadStoreVecRegBitWidth(unsigned AS) const;
138138
unsigned getMaxInterleaveFactor(ElementCount VF);

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1768,19 +1768,21 @@ static void hoistConditionalLoadsStores(
17681768
static bool isSafeCheapLoadStore(const Instruction *I,
17691769
const TargetTransformInfo &TTI) {
17701770
// Not handle volatile or atomic.
1771+
bool IsStore = false;
17711772
if (auto *L = dyn_cast<LoadInst>(I)) {
17721773
if (!L->isSimple())
17731774
return false;
17741775
} else if (auto *S = dyn_cast<StoreInst>(I)) {
17751776
if (!S->isSimple())
17761777
return false;
1778+
IsStore = true;
17771779
} else
17781780
return false;
17791781

17801782
// llvm.masked.load/store use i32 for alignment while load/store use i64.
17811783
// That's why we have the alignment limitation.
17821784
// FIXME: Update the prototype of the intrinsics?
1783-
return TTI.hasConditionalLoadStoreForType(getLoadStoreType(I)) &&
1785+
return TTI.hasConditionalLoadStoreForType(getLoadStoreType(I), IsStore) &&
17841786
getLoadStoreAlignment(I) < Value::MaximumAlignment;
17851787
}
17861788

0 commit comments

Comments
 (0)