[llvm] [IR] Add getFMFFromFnAttribute() to derive fast-math flags from function attributes. nfc (PR #162628)
Mel Chen via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 9 03:09:14 PDT 2025
https://github.com/Mel-Chen created https://github.com/llvm/llvm-project/pull/162628
None
>From 397178e3f0573fba810a180ae8c1a6899d017994 Mon Sep 17 00:00:00 2001
From: Mel Chen <mel.chen at sifive.com>
Date: Thu, 9 Oct 2025 01:12:00 -0700
Subject: [PATCH] [Function] Add getFMFFromFnAttribute() to derive
FastMathFlags from function attributes. nfc
---
llvm/include/llvm/IR/Function.h | 3 +++
llvm/lib/Analysis/IVDescriptors.cpp | 6 +-----
llvm/lib/IR/Function.cpp | 8 ++++++++
3 files changed, 12 insertions(+), 5 deletions(-)
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 {
More information about the llvm-commits
mailing list