[llvm] [TLI] Return LibFunc from TargetLibraryInfo::getLibFunc (PR #217561)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 20 02:39:39 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-compiler-rt-sanitizer
@llvm/pr-subscribers-pgo
@llvm/pr-subscribers-backend-webassembly
Author: Kito Cheng (kito-cheng)
<details>
<summary>Changes</summary>
getLibFunc returned a bool and wrote the result to a LibFunc output argument, which is only set when the lookup succeeds. Callers that ignored the result read an uninitialized LibFunc, and a few in-tree callers did exactly that.
Return the LibFunc instead, and NotLibFunc when the name is not a known library function, so there is no way to get an uninitialized value out of it.
Assisted-by: Opus
---
Patch is 53.15 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/217561.diff
42 Files Affected:
- (modified) llvm/include/llvm/Analysis/TargetLibraryInfo.h (+28-22)
- (modified) llvm/lib/Analysis/BranchProbabilityInfo.cpp (+1-1)
- (modified) llvm/lib/Analysis/ConstantFolding.cpp (+12-11)
- (modified) llvm/lib/Analysis/InlineCost.cpp (+5-2)
- (modified) llvm/lib/Analysis/LazyCallGraph.cpp (+1-3)
- (modified) llvm/lib/Analysis/MemoryBuiltins.cpp (+14-9)
- (modified) llvm/lib/Analysis/MemoryLocation.cpp (+2-2)
- (modified) llvm/lib/Analysis/TargetLibraryInfo.cpp (+17-20)
- (modified) llvm/lib/Analysis/TargetTransformInfo.cpp (+2-3)
- (modified) llvm/lib/Analysis/ValueTracking.cpp (+5-3)
- (modified) llvm/lib/CodeGen/CodeGenPrepare.cpp (+2-3)
- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (+4-3)
- (modified) llvm/lib/LTO/LTO.cpp (+1-2)
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyMemIntrinsicResults.cpp (+1-2)
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyPeephole.cpp (+1-2)
- (modified) llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp (+2-3)
- (modified) llvm/lib/Transforms/IPO/Attributor.cpp (+2-2)
- (modified) llvm/lib/Transforms/IPO/GlobalOpt.cpp (+1-2)
- (modified) llvm/lib/Transforms/IPO/ModuleInliner.cpp (+1-3)
- (modified) llvm/lib/Transforms/InstCombine/InstructionCombining.cpp (+4-6)
- (modified) llvm/lib/Transforms/Instrumentation/AllocToken.cpp (+2-2)
- (modified) llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp (+2-2)
- (modified) llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp (+2-2)
- (modified) llvm/lib/Transforms/Instrumentation/MemProfUse.cpp (+2-2)
- (modified) llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp (+2-2)
- (modified) llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp (+5-6)
- (modified) llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp (+9-22)
- (modified) llvm/lib/Transforms/Instrumentation/ValueProfilePlugins.inc (+2-3)
- (modified) llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp (+4-6)
- (modified) llvm/lib/Transforms/Scalar/ExpandMemCmp.cpp (+2-3)
- (modified) llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp (+5-3)
- (modified) llvm/lib/Transforms/Utils/BuildLibCalls.cpp (+7-13)
- (modified) llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp (+5-5)
- (modified) llvm/lib/Transforms/Utils/Local.cpp (+2-8)
- (modified) llvm/lib/Transforms/Utils/MemoryOpRemark.cpp (+4-4)
- (modified) llvm/lib/Transforms/Utils/MetaRenamer.cpp (+1-2)
- (modified) llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp (+22-27)
- (modified) llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp (+2-3)
- (modified) llvm/test/Analysis/BranchProbabilityInfo/libfunc_call.ll (+7-6)
- (modified) llvm/tools/llubi/lib/Interpreter.cpp (+2-3)
- (modified) llvm/tools/opt/optdriver.cpp (+2-3)
- (modified) llvm/unittests/Analysis/TargetLibraryInfoTest.cpp (+3-4)
``````````diff
diff --git a/llvm/include/llvm/Analysis/TargetLibraryInfo.h b/llvm/include/llvm/Analysis/TargetLibraryInfo.h
index cd61b925ee5d7..8b44190247e95 100644
--- a/llvm/include/llvm/Analysis/TargetLibraryInfo.h
+++ b/llvm/include/llvm/Analysis/TargetLibraryInfo.h
@@ -100,6 +100,8 @@ class TargetLibraryInfoImpl {
AvailableArray[F/4] |= State << 2*(F&3);
}
AvailabilityState getState(LibFunc F) const {
+ if (F == NotLibFunc)
+ return Unavailable;
return static_cast<AvailabilityState>((AvailableArray[F/4] >> 2*(F&3)) & 3);
}
@@ -127,22 +129,24 @@ class TargetLibraryInfoImpl {
/// Searches for a particular function name.
///
- /// If it is one of the known library functions, return true and set F to the
- /// corresponding value.
- LLVM_ABI bool getLibFunc(StringRef funcName, LibFunc &F) const;
+ /// Returns the corresponding LibFunc if it is one of the known library
+ /// functions, and NotLibFunc otherwise.
+ LLVM_ABI LibFunc getLibFunc(StringRef funcName) const;
/// Searches for a particular function name, also checking that its type is
/// valid for the library function matching that name.
///
- /// If it is one of the known library functions, return true and set F to the
- /// corresponding value.
+ /// Returns the corresponding LibFunc if it is one of the known library
+ /// functions, and NotLibFunc otherwise.
///
/// FDecl is assumed to have a parent Module when using this function.
- LLVM_ABI bool getLibFunc(const Function &FDecl, LibFunc &F) const;
+ LLVM_ABI LibFunc getLibFunc(const Function &FDecl) const;
/// Searches for a function name using an Instruction \p Opcode.
/// Currently, only the frem instruction is supported.
- LLVM_ABI bool getLibFunc(unsigned int Opcode, Type *Ty, LibFunc &F) const;
+ ///
+ /// Returns NotLibFunc if there is no matching library function.
+ LLVM_ABI LibFunc getLibFunc(unsigned int Opcode, Type *Ty) const;
/// Forces a function to be marked as unavailable.
void setUnavailable(LibFunc F) {
@@ -286,7 +290,6 @@ class TargetLibraryInfo {
disableAllFunctions();
else {
// Disable individual libc/libm calls in TargetLibraryInfo.
- LibFunc LF;
AttributeSet FnAttrs = (*F)->getAttributes().getFnAttrs();
for (const Attribute &Attr : FnAttrs) {
if (!Attr.isStringAttribute())
@@ -294,7 +297,7 @@ class TargetLibraryInfo {
auto AttrStr = Attr.getKindAsString();
if (!AttrStr.consume_front("no-builtin-"))
continue;
- if (getLibFunc(AttrStr, LF))
+ if (LibFunc LF = getLibFunc(AttrStr); LF != NotLibFunc)
setUnavailable(LF);
}
}
@@ -328,27 +331,30 @@ class TargetLibraryInfo {
/// Searches for a particular function name.
///
- /// If it is one of the known library functions, return true and set F to the
- /// corresponding value.
- bool getLibFunc(StringRef funcName, LibFunc &F) const {
- return Impl->getLibFunc(funcName, F);
+ /// Returns the corresponding LibFunc if it is one of the known library
+ /// functions, and NotLibFunc otherwise.
+ LibFunc getLibFunc(StringRef funcName) const {
+ return Impl->getLibFunc(funcName);
}
- bool getLibFunc(const Function &FDecl, LibFunc &F) const {
- return Impl->getLibFunc(FDecl, F);
+ LibFunc getLibFunc(const Function &FDecl) const {
+ return Impl->getLibFunc(FDecl);
}
- /// If a callbase does not have the 'nobuiltin' attribute, return if the
- /// called function is a known library function and set F to that function.
- bool getLibFunc(const CallBase &CB, LibFunc &F) const {
- return !CB.isNoBuiltin() && CB.getCalledFunction() &&
- getLibFunc(*(CB.getCalledFunction()), F);
+ /// If a callbase does not have the 'nobuiltin' attribute, return the library
+ /// function the callee is, and NotLibFunc otherwise.
+ LibFunc getLibFunc(const CallBase &CB) const {
+ if (CB.isNoBuiltin() || !CB.getCalledFunction())
+ return NotLibFunc;
+ return getLibFunc(*CB.getCalledFunction());
}
/// Searches for a function name using an Instruction \p Opcode.
/// Currently, only the frem instruction is supported.
- bool getLibFunc(unsigned int Opcode, Type *Ty, LibFunc &F) const {
- return Impl->getLibFunc(Opcode, Ty, F);
+ ///
+ /// Returns NotLibFunc if there is no matching library function.
+ LibFunc getLibFunc(unsigned int Opcode, Type *Ty) const {
+ return Impl->getLibFunc(Opcode, Ty);
}
/// Disables all builtins.
diff --git a/llvm/lib/Analysis/BranchProbabilityInfo.cpp b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
index c0abc9ec84e12..5577d27889942 100644
--- a/llvm/lib/Analysis/BranchProbabilityInfo.cpp
+++ b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
@@ -892,7 +892,7 @@ bool BPIConstruction::calcZeroHeuristics(const BasicBlock *BB,
if (TLI)
if (CallInst *Call = dyn_cast<CallInst>(CI->getOperand(0)))
if (Function *CalledFn = Call->getCalledFunction())
- TLI->getLibFunc(*CalledFn, Func);
+ Func = TLI->getLibFunc(*CalledFn);
bool Likely;
if (Func == LibFunc_strcasecmp ||
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index c7347aebbd2e3..c08265be71f33 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -2645,9 +2645,8 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
return GetConstantFoldFPValue128(Result, Ty);
}
- LibFunc Fp128Func = NotLibFunc;
- if (TLI && TLI->getLibFunc(Name, Fp128Func) && TLI->has(Fp128Func) &&
- Fp128Func == LibFunc_logl)
+ if (TLI && TLI->getLibFunc(Name) == LibFunc_logl &&
+ TLI->has(LibFunc_logl))
return ConstantFoldFP128(logf128, Op->getValueAPF(), Ty);
}
#endif
@@ -3021,8 +3020,8 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
if (!TLI)
return nullptr;
- LibFunc Func = NotLibFunc;
- if (!TLI->getLibFunc(Name, Func))
+ LibFunc Func = TLI->getLibFunc(Name);
+ if (Func == NotLibFunc)
return nullptr;
switch (Func) {
@@ -3368,8 +3367,8 @@ static Constant *ConstantFoldLibCall2(StringRef Name, Type *Ty,
if (!TLI)
return nullptr;
- LibFunc Func = NotLibFunc;
- if (!TLI->getLibFunc(Name, Func))
+ LibFunc Func = TLI->getLibFunc(Name);
+ if (Func == NotLibFunc)
return nullptr;
const auto *Op1 = dyn_cast<ConstantFP>(Operands[0]);
@@ -4742,8 +4741,7 @@ Constant *llvm::ConstantFoldCall(const CallBase *Call, Function *F,
if (IID == Intrinsic::not_intrinsic) {
if (!TLI)
return nullptr;
- LibFunc LibF;
- if (!TLI->getLibFunc(*F, LibF))
+ if (TLI->getLibFunc(*F) == NotLibFunc)
return nullptr;
}
@@ -4782,8 +4780,11 @@ bool llvm::isMathLibCallNoop(const CallBase *Call,
if (!F)
return false;
- LibFunc Func;
- if (!TLI || !TLI->getLibFunc(*F, Func))
+ if (!TLI)
+ return false;
+
+ LibFunc Func = TLI->getLibFunc(*F);
+ if (Func == NotLibFunc)
return false;
if (Call->arg_size() == 1) {
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index 94b1fc6ff7c07..de6c2456f0d57 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -2437,8 +2437,11 @@ bool CallAnalyzer::simplifyCallSite(Function *F, CallBase &Call) {
bool CallAnalyzer::isLoweredToCall(Function *F, CallBase &Call) {
const TargetLibraryInfo *TLI = GetTLI ? &GetTLI(*F) : nullptr;
- LibFunc LF;
- if (!TLI || !TLI->getLibFunc(*F, LF) || !TLI->has(LF))
+ if (!TLI)
+ return TTI.isLoweredToCall(F);
+
+ LibFunc LF = TLI->getLibFunc(*F);
+ if (!TLI->has(LF))
return TTI.isLoweredToCall(F);
switch (LF) {
diff --git a/llvm/lib/Analysis/LazyCallGraph.cpp b/llvm/lib/Analysis/LazyCallGraph.cpp
index 1911936cd1fcc..0410e2fc5dd70 100644
--- a/llvm/lib/Analysis/LazyCallGraph.cpp
+++ b/llvm/lib/Analysis/LazyCallGraph.cpp
@@ -142,12 +142,10 @@ LLVM_DUMP_METHOD void LazyCallGraph::Node::dump() const {
#endif
static bool isKnownLibFunction(Function &F, TargetLibraryInfo &TLI) {
- LibFunc LF;
-
// Either this is a normal library function or a "vectorizable"
// function. Not using the VFDatabase here because this query
// is related only to libraries handled via the TLI.
- return TLI.getLibFunc(F, LF) ||
+ return TLI.getLibFunc(F) != NotLibFunc ||
TLI.isKnownVectorFunctionInLibrary(F.getName());
}
diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp
index 0364a8bff9e53..aea1fec55b5bc 100644
--- a/llvm/lib/Analysis/MemoryBuiltins.cpp
+++ b/llvm/lib/Analysis/MemoryBuiltins.cpp
@@ -180,8 +180,11 @@ getAllocationDataForFunction(const Function *Callee, AllocType AllocTy,
return std::nullopt;
// Make sure that the function is available.
- LibFunc TLIFn;
- if (!TLI || !TLI->getLibFunc(*Callee, TLIFn) || !TLI->has(TLIFn))
+ if (!TLI)
+ return std::nullopt;
+
+ LibFunc TLIFn = TLI->getLibFunc(*Callee);
+ if (!TLI->has(TLIFn))
return std::nullopt;
const auto *Iter = find_if(AllocationFnData,
@@ -492,8 +495,8 @@ getFreeFunctionDataForFunction(const Function *Callee, const LibFunc TLIFn) {
std::optional<StringRef>
llvm::getAllocationFamily(const Value *I, const TargetLibraryInfo *TLI) {
if (const Function *Callee = getCalledFunction(I)) {
- LibFunc TLIFn;
- if (TLI && TLI->getLibFunc(*Callee, TLIFn) && TLI->has(TLIFn)) {
+ LibFunc TLIFn = TLI ? TLI->getLibFunc(*Callee) : NotLibFunc;
+ if (TLIFn != NotLibFunc && TLI->has(TLIFn)) {
// Callee is some known library function.
const auto AllocData =
getAllocationDataForFunction(Callee, AnyAlloc, TLI);
@@ -537,8 +540,8 @@ bool llvm::isLibFreeFunction(const Function *F, const LibFunc TLIFn) {
Value *llvm::getFreedOperand(const CallBase *CB, const TargetLibraryInfo *TLI) {
if (const Function *Callee = getCalledFunction(CB)) {
- LibFunc TLIFn;
- if (TLI && TLI->getLibFunc(*Callee, TLIFn) && TLI->has(TLIFn) &&
+ LibFunc TLIFn = TLI ? TLI->getLibFunc(*Callee) : NotLibFunc;
+ if (TLIFn != NotLibFunc && TLI->has(TLIFn) &&
isLibFreeFunction(Callee, TLIFn)) {
// All currently supported free functions free the first argument.
return CB->getArgOperand(0);
@@ -1098,9 +1101,11 @@ OffsetSpan ObjectSizeOffsetVisitor::findLoadOffsetRange(
if (!Callee)
return Unknown();
- LibFunc TLIFn;
- if (!TLI || !TLI->getLibFunc(*CB->getCalledFunction(), TLIFn) ||
- !TLI->has(TLIFn))
+ if (!TLI)
+ return Unknown();
+
+ LibFunc TLIFn = TLI->getLibFunc(*CB->getCalledFunction());
+ if (!TLI->has(TLIFn))
return Unknown();
// TODO: There's probably more interesting case to support here.
diff --git a/llvm/lib/Analysis/MemoryLocation.cpp b/llvm/lib/Analysis/MemoryLocation.cpp
index edca3871ad593..715ae20bbaa3d 100644
--- a/llvm/lib/Analysis/MemoryLocation.cpp
+++ b/llvm/lib/Analysis/MemoryLocation.cpp
@@ -327,8 +327,8 @@ MemoryLocation MemoryLocation::getForArgument(const CallBase *Call,
// for memcpy/memset. This is particularly important because the
// LoopIdiomRecognizer likes to turn loops into calls to memset_pattern16
// whenever possible.
- LibFunc F;
- if (TLI && TLI->getLibFunc(*Call, F) && TLI->has(F)) {
+ LibFunc F = TLI ? TLI->getLibFunc(*Call) : NotLibFunc;
+ if (F != NotLibFunc && TLI->has(F)) {
switch (F) {
case LibFunc_strcpy:
case LibFunc_strcat:
diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp
index 763c04b9b06f7..efde1ba49f9bc 100644
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -972,19 +972,17 @@ buildIndexMap(const llvm::StringTable &StandardNames) {
return Indices;
}
-bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName, LibFunc &F) const {
+LibFunc TargetLibraryInfoImpl::getLibFunc(StringRef funcName) const {
funcName = sanitizeFunctionName(funcName);
if (funcName.empty())
- return false;
+ return NotLibFunc;
static const DenseMap<StringRef, LibFunc> Indices =
buildIndexMap(StandardNamesStrTable);
- if (auto Loc = Indices.find(funcName); Loc != Indices.end()) {
- F = Loc->second;
- return true;
- }
- return false;
+ if (auto Loc = Indices.find(funcName); Loc != Indices.end())
+ return Loc->second;
+ return NotLibFunc;
}
// Return true if ArgTy matches Ty.
@@ -1188,35 +1186,34 @@ bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
return Idx == NumParams + 1 && !FTy.isFunctionVarArg();
}
-bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl,
- LibFunc &F) const {
+LibFunc TargetLibraryInfoImpl::getLibFunc(const Function &FDecl) const {
// Intrinsics don't overlap w/libcalls; if our module has a large number of
// intrinsics, this ends up being an interesting compile time win since we
// avoid string normalization and comparison.
- if (FDecl.isIntrinsic()) return false;
+ if (FDecl.isIntrinsic())
+ return NotLibFunc;
const Module *M = FDecl.getParent();
assert(M && "Expecting FDecl to be connected to a Module.");
if (FDecl.LibFuncCache == Function::UnknownLibFunc)
- if (!getLibFunc(FDecl.getName(), FDecl.LibFuncCache))
- FDecl.LibFuncCache = NotLibFunc;
+ FDecl.LibFuncCache = getLibFunc(FDecl.getName());
if (FDecl.LibFuncCache == NotLibFunc)
- return false;
+ return NotLibFunc;
+
+ if (!isValidProtoForLibFunc(*FDecl.getFunctionType(), FDecl.LibFuncCache, *M))
+ return NotLibFunc;
- F = FDecl.LibFuncCache;
- return isValidProtoForLibFunc(*FDecl.getFunctionType(), F, *M);
+ return FDecl.LibFuncCache;
}
-bool TargetLibraryInfoImpl::getLibFunc(unsigned int Opcode, Type *Ty,
- LibFunc &F) const {
+LibFunc TargetLibraryInfoImpl::getLibFunc(unsigned int Opcode, Type *Ty) const {
// Must be a frem instruction with float or double arguments.
if (Opcode != Instruction::FRem || (!Ty->isDoubleTy() && !Ty->isFloatTy()))
- return false;
+ return NotLibFunc;
- F = Ty->isDoubleTy() ? LibFunc_fmod : LibFunc_fmodf;
- return true;
+ return Ty->isDoubleTy() ? LibFunc_fmod : LibFunc_fmodf;
}
void TargetLibraryInfoImpl::disableAllFunctions() {
diff --git a/llvm/lib/Analysis/TargetTransformInfo.cpp b/llvm/lib/Analysis/TargetTransformInfo.cpp
index 42afdf67a5f93..a0ecb16cfb97b 100644
--- a/llvm/lib/Analysis/TargetTransformInfo.cpp
+++ b/llvm/lib/Analysis/TargetTransformInfo.cpp
@@ -1020,9 +1020,8 @@ InstructionCost TargetTransformInfo::getArithmeticInstrCost(
// ReplaceWithVecLib pass.
if (TLibInfo && Opcode == Instruction::FRem) {
VectorType *VecTy = dyn_cast<VectorType>(Ty);
- LibFunc Func;
- if (VecTy &&
- TLibInfo->getLibFunc(Instruction::FRem, Ty->getScalarType(), Func) &&
+ LibFunc Func = TLibInfo->getLibFunc(Instruction::FRem, Ty->getScalarType());
+ if (VecTy && Func != NotLibFunc &&
TLibInfo->isFunctionVectorizable(TLibInfo->getName(Func),
VecTy->getElementCount()))
return getCallInstrCost(nullptr, VecTy, {VecTy, VecTy}, CostKind);
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 55f6696fe4914..3fd1cb8a0a4d4 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -4681,9 +4681,11 @@ Intrinsic::ID llvm::getIntrinsicForCallSite(const CallBase &CB,
// We are going to infer semantics of a library function based on mapping it
// to an LLVM intrinsic. Check that the library function is available from
// this callbase and in this environment.
- LibFunc Func;
- if (F->hasLocalLinkage() || !TLI || !TLI->getLibFunc(CB, Func) ||
- !CB.onlyReadsMemory())
+ if (F->hasLocalLinkage() || !TLI || !CB.onlyReadsMemory())
+ return Intrinsic::not_intrinsic;
+
+ LibFunc Func = TLI->getLibFunc(CB);
+ if (Func == NotLibFunc)
return Intrinsic::not_intrinsic;
switch (Func) {
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 7b739df127120..53b7a81537975 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -2920,10 +2920,9 @@ static bool isIntrinsicOrLFToBeTailCalled(const TargetLibraryInfo *TLInfo,
return false;
}
- LibFunc LF;
Function *Callee = CI->getCalledFunction();
- if (Callee && TLInfo && TLInfo->getLibFunc(*Callee, LF))
- switch (LF) {
+ if (Callee && TLInfo)
+ switch (TLInfo->getLibFunc(*Callee)) {
case LibFunc_strcpy:
case LibFunc_strncpy:
case LibFunc_strcat:
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index b3e22ff50d4bd..b2605ef54a9ea 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -9807,9 +9807,10 @@ void SelectionDAGBuilder::visitCall(const CallInst &I) {
// some reason.
// This code should not handle libcalls that are already canonicalized to
// intrinsics by the middle-end.
- LibFunc Func;
- if (!I.isNoBuiltin() && !F->hasLocalLinkage() && F->hasName() &&
- LibInfo->getLibFunc(*F, Func) && LibInfo->hasOptimizedCodeGen(Func)) {
+ LibFunc Func = !I.isNoBuiltin() && !F->hasLocalLinkage() && F->hasName()
+ ? LibInfo->getLibFunc(*F)
+ : NotLibFunc;
+ if (LibInfo->hasOptimizedCodeGen(Func)) {
switch (Func) {
default: break;
case LibFunc_bcmp:
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index c8c5b0880819a..a8705e3d925a5 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -661,8 +661,7 @@ Expected<std::unique_ptr<InputFile>> InputFile::create(MemoryBufferRef Object) {
bool InputFile::Symbol::isLibcall(
const TargetLibraryInfo &TLI,
const RTLIB::RuntimeLibcallsInfo &Libcalls) const {
- LibFunc F;
- if (TLI.getLibFunc(IRName, F) && TLI.has(F))
+ if (TLI.has(TLI.getLibFunc(IRName)))
return true;
return Libcalls.getSupportedLibcallImpl(IRName) != RTLIB::Unsupported;
}
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyMemIntrinsicResults.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyMemIntrinsicResults.cpp
index 51da637000f25..6011450403d8c 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyMemIntrinsicResults.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyMemIntrinsicResults.cpp
@@ -184,8 +184,7 @@ bool WebAssemblyMemIntrinsicResultsImpl::optimizeCall(
if (!CallReturnsInput)
return false;
- LibFunc Func;
- if (!LibInfo->getLibFunc(Name, Func))
+ if (LibInfo->getLibFunc(Name) == NotLibFunc)
return false;
Register FromReg = MI.getOperand(2).getReg();
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyPeephole.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyPeephole.cpp
index 992283e9cc3d6..d51891cb6b100 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyPeephole.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyPeephole.cpp
@@ -152,8 +152,7 @@ static bool peephole(MachineFunction &MF, TargetLibraryInfo &LibInfo,
if (Op1.isSymbol()) {
StringRef Name(Op1.getSymbolName());
if (Name == MemcpyName || Name == MemmoveName || Name == MemsetName) {
- LibFunc Func;
- if (LibInfo.getLibFunc(Name, Func)) {
+ if (LibInfo.getLibFunc(Name) != NotLibFunc) {
const auto &Op2 = MI.getOperand(2);
if (!Op2.isReg())
report_fatal_error("Peephole: call to builtin function with "
diff --git a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
index 056092fcc6bbd..f72ff61f028db 100644
--- a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
+++ b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
@@ -2110,9 +2110,8 @@ static bool foldLibCalls(Instruction &I, TargetTransformInfo &TTI,
if (!CalledFunc)
return false;
- LibFunc LF;
- if (!TLI.getLibFunc(*CalledFunc, LF) ||
- !isLibFuncEmittable(CI->getModule(), &TLI, LF))
+ LibFunc LF = TLI.getLibFunc(*CalledFunc);
+ if (!isLibFuncEmittable(CI->getModule(), &TLI, LF))
return false;
...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/217561
More information about the llvm-commits
mailing list