[llvm] Add remaining patterns for floating-point flag matches (PR #173912)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 29 11:12:31 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
Author: Mikołaj Piróg (mikolaj-pirog)
<details>
<summary>Changes</summary>
As in title. Only `reassoc` pattern was supplied -- for completeness all should be supplied.
---
Full diff: https://github.com/llvm/llvm-project/pull/173912.diff
2 Files Affected:
- (modified) llvm/include/llvm/IR/FMF.h (+4)
- (modified) llvm/include/llvm/IR/PatternMatch.h (+63-5)
``````````diff
diff --git a/llvm/include/llvm/IR/FMF.h b/llvm/include/llvm/IR/FMF.h
index 8bd591250a38a..b397c09a99825 100644
--- a/llvm/include/llvm/IR/FMF.h
+++ b/llvm/include/llvm/IR/FMF.h
@@ -105,6 +105,10 @@ class FastMathFlags {
return Flags != OtherFlags.Flags;
}
+ bool operator==(const FastMathFlags &OtherFlags) const {
+ return Flags == OtherFlags.Flags;
+ }
+
/// Print fast-math flags to \p O.
LLVM_ABI void print(raw_ostream &O) const;
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index 88aef4a368f29..9ce157bbb28e6 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -28,6 +28,7 @@
#ifndef LLVM_IR_PATTERNMATCH_H
#define LLVM_IR_PATTERNMATCH_H
+#include "FMF.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include "llvm/IR/Constant.h"
@@ -81,19 +82,76 @@ template <typename T> inline OneUse_match<T> m_OneUse(const T &SubPattern) {
return SubPattern;
}
-template <typename SubPattern_t> struct AllowReassoc_match {
+template <typename SubPattern_t, int Flag> struct AllowFmf_match {
SubPattern_t SubPattern;
-
- AllowReassoc_match(const SubPattern_t &SP) : SubPattern(SP) {}
+ FastMathFlags FMF;
+
+ AllowFmf_match(const SubPattern_t &SP) : SubPattern(SP) {
+ if (Flag == FastMathFlags::AllowReassoc)
+ FMF.setAllowReassoc();
+ if (Flag == FastMathFlags::AllowReciprocal)
+ FMF.setAllowReciprocal();
+ if (Flag == FastMathFlags::AllowContract)
+ FMF.setAllowContract();
+ if (Flag == FastMathFlags::ApproxFunc)
+ FMF.setApproxFunc();
+ if (Flag == FastMathFlags::NoNaNs)
+ FMF.setNoNaNs();
+ if (Flag == FastMathFlags::NoInfs)
+ FMF.setNoInfs();
+ if (Flag == FastMathFlags::NoSignedZeros)
+ FMF.setNoSignedZeros();
+ }
template <typename OpTy> bool match(OpTy *V) const {
auto *I = dyn_cast<FPMathOperator>(V);
- return I && I->hasAllowReassoc() && SubPattern.match(I);
+ return I && ((I->getFastMathFlags() & FMF) == FMF) && SubPattern.match(I);
}
};
template <typename T>
-inline AllowReassoc_match<T> m_AllowReassoc(const T &SubPattern) {
+inline AllowFmf_match<T, FastMathFlags::AllowReassoc>
+m_AllowReassoc(const T &SubPattern) {
+ return SubPattern;
+}
+
+template <typename T>
+inline AllowFmf_match<T, FastMathFlags::AllowReciprocal>
+m_AllowReciprocal(const T &SubPattern) {
+ return SubPattern;
+}
+
+template <typename T>
+inline AllowFmf_match<T, FastMathFlags::AllowContract>
+m_AllowContract(const T &SubPattern) {
+ return SubPattern;
+}
+
+template <typename T>
+inline AllowFmf_match<T, FastMathFlags::ApproxFunc>
+m_ApproxFunc(const T &SubPattern) {
+ return SubPattern;
+}
+
+template <typename T>
+inline AllowFmf_match<T, FastMathFlags::NoNaNs> m_NoNaNs(const T &SubPattern) {
+ return SubPattern;
+}
+
+template <typename T>
+inline AllowFmf_match<T, FastMathFlags::NoInfs> m_NoInfs(const T &SubPattern) {
+ return SubPattern;
+}
+
+template <typename T>
+inline AllowFmf_match<T, FastMathFlags::NoSignedZeros>
+m_NoSignedZeros(const T &SubPattern) {
+ return SubPattern;
+}
+
+template <typename T>
+inline AllowFmf_match<T, FastMathFlags::AllFlagsMask>
+m_IsFast(const T &SubPattern) {
return SubPattern;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/173912
More information about the llvm-commits
mailing list