Skip to content

[X86][NFCI] Add IsStore parameter to hasConditionalLoadStoreForType #132153

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 1 commit into from
Mar 20, 2025
Merged
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
8 changes: 4 additions & 4 deletions llvm/include/llvm/Analysis/TargetTransformInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ class TargetTransformInfo {

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

/// \return the target-provided register class ID for the provided type,
/// accounting for type promotion and other type-legalization techniques that
Expand Down Expand Up @@ -2107,7 +2107,7 @@ class TargetTransformInfo::Concept {
virtual bool preferToKeepConstantsAttached(const Instruction &Inst,
const Function &Fn) const = 0;
virtual unsigned getNumberOfRegisters(unsigned ClassID) const = 0;
virtual bool hasConditionalLoadStoreForType(Type *Ty = nullptr) const = 0;
virtual bool hasConditionalLoadStoreForType(Type *Ty, bool IsStore) const = 0;
virtual unsigned getRegisterClassForType(bool Vector,
Type *Ty = nullptr) const = 0;
virtual const char *getRegisterClassName(unsigned ClassID) const = 0;
Expand Down Expand Up @@ -2770,8 +2770,8 @@ class TargetTransformInfo::Model final : public TargetTransformInfo::Concept {
unsigned getNumberOfRegisters(unsigned ClassID) const override {
return Impl.getNumberOfRegisters(ClassID);
}
bool hasConditionalLoadStoreForType(Type *Ty = nullptr) const override {
return Impl.hasConditionalLoadStoreForType(Ty);
bool hasConditionalLoadStoreForType(Type *Ty, bool IsStore) const override {
return Impl.hasConditionalLoadStoreForType(Ty, IsStore);
}
unsigned getRegisterClassForType(bool Vector,
Type *Ty = nullptr) const override {
Expand Down
6 changes: 4 additions & 2 deletions llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -504,11 +504,13 @@ class TargetTransformInfoImplBase {
}

unsigned getNumberOfRegisters(unsigned ClassID) const { return 8; }
bool hasConditionalLoadStoreForType(Type *Ty) const { return false; }
bool hasConditionalLoadStoreForType(Type *Ty, bool IsStore) const {
return false;
}

unsigned getRegisterClassForType(bool Vector, Type *Ty = nullptr) const {
return Vector ? 1 : 0;
};
}

const char *getRegisterClassName(unsigned ClassID) const {
switch (ClassID) {
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Analysis/TargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,9 @@ unsigned TargetTransformInfo::getNumberOfRegisters(unsigned ClassID) const {
return TTIImpl->getNumberOfRegisters(ClassID);
}

bool TargetTransformInfo::hasConditionalLoadStoreForType(Type *Ty) const {
return TTIImpl->hasConditionalLoadStoreForType(Ty);
bool TargetTransformInfo::hasConditionalLoadStoreForType(Type *Ty,
bool IsStore) const {
return TTIImpl->hasConditionalLoadStoreForType(Ty, IsStore);
}

unsigned TargetTransformInfo::getRegisterClassForType(bool Vector,
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4790,8 +4790,8 @@ void SelectionDAGBuilder::visitMaskedStore(const CallInst &I,
const auto &TTI =
TLI.getTargetMachine().getTargetTransformInfo(*I.getFunction());
SDValue StoreNode =
!IsCompressing &&
TTI.hasConditionalLoadStoreForType(I.getArgOperand(0)->getType())
!IsCompressing && TTI.hasConditionalLoadStoreForType(
I.getArgOperand(0)->getType(), /*IsStore=*/true)
? TLI.visitMaskedStore(DAG, sdl, getMemoryRoot(), MMO, Ptr, Src0,
Mask)
: DAG.getMaskedStore(getMemoryRoot(), sdl, Src0, Ptr, Offset, Mask,
Expand Down Expand Up @@ -4976,8 +4976,8 @@ void SelectionDAGBuilder::visitMaskedLoad(const CallInst &I, bool IsExpanding) {
// variables.
SDValue Load;
SDValue Res;
if (!IsExpanding &&
TTI.hasConditionalLoadStoreForType(Src0Operand->getType()))
if (!IsExpanding && TTI.hasConditionalLoadStoreForType(Src0Operand->getType(),
/*IsStore=*/false))
Res = TLI.visitMaskedLoad(DAG, sdl, InChain, MMO, Load, Ptr, Src0, Mask);
else
Res = Load =
Expand Down
34 changes: 24 additions & 10 deletions llvm/lib/Target/X86/X86TargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ unsigned X86TTIImpl::getNumberOfRegisters(unsigned ClassID) const {
return 8;
}

bool X86TTIImpl::hasConditionalLoadStoreForType(Type *Ty) const {
bool X86TTIImpl::hasConditionalLoadStoreForType(Type *Ty, bool IsStore) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

Confused about this, the variable IsStored is not used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not used by X86, but as a general interface, maybe used by some future target. See #132032.

if (!ST->hasCF())
return false;
if (!Ty)
Expand Down Expand Up @@ -6229,13 +6229,7 @@ bool X86TTIImpl::canMacroFuseCmp() {
return ST->hasMacroFusion() || ST->hasBranchFusion();
}

bool X86TTIImpl::isLegalMaskedLoad(Type *DataTy, Align Alignment) {
Type *ScalarTy = DataTy->getScalarType();

// The backend can't handle a single element vector w/o CFCMOV.
if (isa<VectorType>(DataTy) && cast<FixedVectorType>(DataTy)->getNumElements() == 1)
return ST->hasCF() && hasConditionalLoadStoreForType(ScalarTy);

static bool isLegalMaskedLoadStore(Type *ScalarTy, const X86Subtarget *ST) {
if (!ST->hasAVX())
return false;

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

bool X86TTIImpl::isLegalMaskedStore(Type *DataType, Align Alignment) {
return isLegalMaskedLoad(DataType, Alignment);
bool X86TTIImpl::isLegalMaskedLoad(Type *DataTy, Align Alignment) {
Type *ScalarTy = DataTy->getScalarType();

// The backend can't handle a single element vector w/o CFCMOV.
if (isa<VectorType>(DataTy) &&
cast<FixedVectorType>(DataTy)->getNumElements() == 1)
return ST->hasCF() &&
hasConditionalLoadStoreForType(ScalarTy, /*IsStore=*/false);

return isLegalMaskedLoadStore(ScalarTy, ST);
}

bool X86TTIImpl::isLegalMaskedStore(Type *DataTy, Align Alignment) {
Type *ScalarTy = DataTy->getScalarType();

// The backend can't handle a single element vector w/o CFCMOV.
if (isa<VectorType>(DataTy) &&
cast<FixedVectorType>(DataTy)->getNumElements() == 1)
return ST->hasCF() &&
hasConditionalLoadStoreForType(ScalarTy, /*IsStore=*/true);

return isLegalMaskedLoadStore(ScalarTy, ST);
}

bool X86TTIImpl::isLegalNTLoad(Type *DataType, Align Alignment) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/X86/X86TargetTransformInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class X86TTIImpl : public BasicTTIImplBase<X86TTIImpl> {
/// @{

unsigned getNumberOfRegisters(unsigned ClassID) const;
bool hasConditionalLoadStoreForType(Type *Ty = nullptr) const;
bool hasConditionalLoadStoreForType(Type *Ty, bool IsStore) const;
TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const;
unsigned getLoadStoreVecRegBitWidth(unsigned AS) const;
unsigned getMaxInterleaveFactor(ElementCount VF);
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1768,19 +1768,21 @@ static void hoistConditionalLoadsStores(
static bool isSafeCheapLoadStore(const Instruction *I,
const TargetTransformInfo &TTI) {
// Not handle volatile or atomic.
bool IsStore = false;
if (auto *L = dyn_cast<LoadInst>(I)) {
if (!L->isSimple())
return false;
} else if (auto *S = dyn_cast<StoreInst>(I)) {
if (!S->isSimple())
return false;
IsStore = true;
} else
return false;

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

Expand Down