diff --git a/llvm/include/llvm/IR/Function.h b/llvm/include/llvm/IR/Function.h index d3497716ca844..21e9d5ea9d066 100644 --- a/llvm/include/llvm/IR/Function.h +++ b/llvm/include/llvm/IR/Function.h @@ -470,6 +470,9 @@ class LLVM_ABI Function : public GlobalObject, public ilist_node { return AttributeSets.getFnStackAlignment(); } + /// Derive fast-math flags from the function attributes. + FastMathFlags getFMFFromFnAttribute() const; + /// Returns true if the function has ssp, sspstrong, or sspreq fn attrs. bool hasStackProtectorFnAttr() const; diff --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp index b8c540ce4b99d..9b842d6ab37c5 100644 --- a/llvm/lib/Analysis/IVDescriptors.cpp +++ b/llvm/lib/Analysis/IVDescriptors.cpp @@ -998,11 +998,7 @@ bool RecurrenceDescriptor::isReductionPHI(PHINode *Phi, Loop *TheLoop, ScalarEvolution *SE) { BasicBlock *Header = TheLoop->getHeader(); Function &F = *Header->getParent(); - FastMathFlags FMF; - FMF.setNoNaNs( - F.getFnAttribute("no-nans-fp-math").getValueAsBool()); - FMF.setNoSignedZeros( - F.getFnAttribute("no-signed-zeros-fp-math").getValueAsBool()); + FastMathFlags FMF = F.getFMFFromFnAttribute(); if (AddReductionVar(Phi, RecurKind::Add, TheLoop, FMF, RedDes, DB, AC, DT, SE)) { diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp index fc067459dcba3..d2b41c1c9c2ab 100644 --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -784,6 +784,14 @@ uint64_t Function::getFnAttributeAsParsedInteger(StringRef Name, return Result; } +FastMathFlags Function::getFMFFromFnAttribute() const { + FastMathFlags FuncFMF; + FuncFMF.setNoNaNs(getFnAttribute("no-nans-fp-math").getValueAsBool()); + FuncFMF.setNoSignedZeros( + getFnAttribute("no-signed-zeros-fp-math").getValueAsBool()); + return FuncFMF; +} + /// gets the specified attribute from the list of attributes. Attribute Function::getParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const {