[llvm-branch-commits] [llvm] ValueTracking: Avoid calling computeKnownFPClass on matched constant (PR #173248)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Dec 22 04:12:43 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Matt Arsenault (arsenm)
<details>
<summary>Changes</summary>
The fmul case already tries to match a literal value, we don't
need to match it twice.
---
Full diff: https://github.com/llvm/llvm-project/pull/173248.diff
3 Files Affected:
- (modified) llvm/include/llvm/Support/KnownFPClass.h (+4)
- (modified) llvm/lib/Analysis/ValueTracking.cpp (+6-4)
- (modified) llvm/lib/Support/KnownFPClass.cpp (+4)
``````````diff
diff --git a/llvm/include/llvm/Support/KnownFPClass.h b/llvm/include/llvm/Support/KnownFPClass.h
index b3c18bcf6b34b..a34e5eb7a1698 100644
--- a/llvm/include/llvm/Support/KnownFPClass.h
+++ b/llvm/include/llvm/Support/KnownFPClass.h
@@ -19,6 +19,7 @@
#include <optional>
namespace llvm {
+class APFloat;
struct KnownFPClass {
/// Floating-point classes the value could be one of.
@@ -28,6 +29,9 @@ struct KnownFPClass {
/// definitely set or false if the sign bit is definitely unset.
std::optional<bool> SignBit;
+ KnownFPClass() = default;
+ KnownFPClass(const APFloat &C);
+
bool operator==(KnownFPClass Other) const {
return KnownFPClasses == Other.KnownFPClasses && SignBit == Other.SignBit;
}
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index c4ad71f668506..d657883634df2 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -4920,8 +4920,7 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
assert(Depth <= MaxAnalysisRecursionDepth && "Limit Search Depth");
if (auto *CFP = dyn_cast<ConstantFP>(V)) {
- Known.KnownFPClasses = CFP->getValueAPF().classify();
- Known.SignBit = CFP->isNegative();
+ Known = KnownFPClass(CFP->getValueAPF());
return;
}
@@ -5723,8 +5722,6 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
Known.knownNot(fcNegative);
KnownFPClass KnownLHS, KnownRHS;
- computeKnownFPClass(Op->getOperand(1), DemandedElts, fcAllFlags, KnownRHS,
- Q, Depth + 1);
const APFloat *CRHS;
if (match(Op->getOperand(1), m_APFloat(CRHS))) {
@@ -5741,6 +5738,11 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
int MinKnownExponent = ilogb(*CRHS);
if (MinKnownExponent >= MantissaBits)
Known.knownNot(fcSubnormal);
+
+ KnownRHS = KnownFPClass(*CRHS);
+ } else {
+ computeKnownFPClass(Op->getOperand(1), DemandedElts, fcAllFlags, KnownRHS,
+ Q, Depth + 1);
}
computeKnownFPClass(Op->getOperand(0), DemandedElts, fcAllFlags, KnownLHS,
diff --git a/llvm/lib/Support/KnownFPClass.cpp b/llvm/lib/Support/KnownFPClass.cpp
index 43fb2e7108d2b..88de3a57ba415 100644
--- a/llvm/lib/Support/KnownFPClass.cpp
+++ b/llvm/lib/Support/KnownFPClass.cpp
@@ -12,10 +12,14 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/KnownFPClass.h"
+#include "llvm/ADT/APFloat.h"
#include "llvm/Support/ErrorHandling.h"
using namespace llvm;
+KnownFPClass::KnownFPClass(const APFloat &C)
+ : KnownFPClasses(C.classify()), SignBit(C.isNegative()) {}
+
/// Return true if it's possible to assume IEEE treatment of input denormals in
/// \p F for \p Val.
static bool inputDenormalIsIEEE(DenormalMode Mode) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/173248
More information about the llvm-branch-commits
mailing list