-
Notifications
You must be signed in to change notification settings - Fork 15.6k
ValueTracking: Avoid calling computeKnownFPClass on matched constant #173248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: users/arsenm/valuetracking/improve-fmul-0-handling
Are you sure you want to change the base?
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
@llvm/pr-subscribers-llvm-support @llvm/pr-subscribers-llvm-transforms Author: Matt Arsenault (arsenm) ChangesThe fmul case already tries to match a literal value, we don't Full diff: https://github.com/llvm/llvm-project/pull/173248.diff 3 Files Affected:
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) {
|
🪟 Windows x64 Test Results
✅ The build succeeded and all tests passed. |
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
The fmul case already tries to match a literal value, we don't need to match it twice.
eb5db7e to
ab51313
Compare
578dde3 to
57ea81c
Compare
dtcxzyw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM

The fmul case already tries to match a literal value, we don't
need to match it twice.