[llvm] [IR] Add getFMFFromFnAttribute() to derive fast-math flags from function attributes. nfc (PR #162628)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 9 03:09:53 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
@llvm/pr-subscribers-llvm-analysis
Author: Mel Chen (Mel-Chen)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/162628.diff
3 Files Affected:
- (modified) llvm/include/llvm/IR/Function.h (+3)
- (modified) llvm/lib/Analysis/IVDescriptors.cpp (+1-5)
- (modified) llvm/lib/IR/Function.cpp (+8)
``````````diff
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<Function> {
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 {
``````````
</details>
https://github.com/llvm/llvm-project/pull/162628
More information about the llvm-commits
mailing list