https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/173248

>From 57ea81cd9cbfa369402f54c6288908ec31e6cfe5 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <[email protected]>
Date: Mon, 22 Dec 2025 12:29:29 +0100
Subject: [PATCH] ValueTracking: Avoid calling computeKnownFPClass on matched
 constant

The fmul case already tries to match a literal value, we don't
need to match it twice.
---
 llvm/include/llvm/Support/KnownFPClass.h |  4 ++++
 llvm/lib/Analysis/ValueTracking.cpp      | 10 ++++++----
 llvm/lib/Support/KnownFPClass.cpp        |  4 ++++
 3 files changed, 14 insertions(+), 4 deletions(-)

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) {

_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to