-
Notifications
You must be signed in to change notification settings - Fork 15.7k
ValueTracking: Avoid unnecessary denormal mode lookup for fadd #174272
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
Merged
arsenm
merged 6 commits into
main
from
users/arsenm/valuetracking/avoid-unnecessary-denormal-mode-lookup
Jan 3, 2026
Merged
ValueTracking: Avoid unnecessary denormal mode lookup for fadd #174272
arsenm
merged 6 commits into
main
from
users/arsenm/valuetracking/avoid-unnecessary-denormal-mode-lookup
Jan 3, 2026
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This already recognized that if both inputs are positive, the result is positive. Extend this to the mirror situation with negative inputs. Also special case fadd x, x. Canonically, fmul x, 2 is fadd x, x. We can tell the sign bit won't change, and 0 will propagate.
The mode was already queried, so don't do it again.
This was referenced Jan 3, 2026
Contributor
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Contributor
Author
|
Accidentally posted this in the parent initially |
Member
|
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-llvm-analysis Author: Matt Arsenault (arsenm) ChangesThe mode was already queried, so don't do it again. Full diff: https://github.com/llvm/llvm-project/pull/174272.diff 1 Files Affected:
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index d7d5daa348412..6b5792227a371 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -4728,12 +4728,6 @@ Intrinsic::ID llvm::getIntrinsicForCallSite(const CallBase &CB,
return Intrinsic::not_intrinsic;
}
-static bool outputDenormalIsIEEEOrPosZero(const Function &F, const Type *Ty) {
- Ty = Ty->getScalarType();
- DenormalMode Mode = F.getDenormalMode(Ty->getFltSemantics());
- return Mode.Output == DenormalMode::IEEE ||
- Mode.Output == DenormalMode::PositiveZero;
-}
/// Given an exploded icmp instruction, return true if the comparison only
/// checks the sign bit. If it only checks the sign bit, set TrueIfSigned if
/// the result of the comparison is true when the input value is signed.
@@ -5671,7 +5665,8 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
if ((KnownLHS.isKnownNeverLogicalNegZero(Mode) ||
KnownRHS.isKnownNeverLogicalNegZero(Mode)) &&
// Make sure output negative denormal can't flush to -0
- outputDenormalIsIEEEOrPosZero(*F, Op->getType()))
+ (Mode.Output == DenormalMode::IEEE ||
+ Mode.Output == DenormalMode::PositiveZero))
Known.knownNot(fcNegZero);
} else {
if (!F)
@@ -5685,7 +5680,8 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
if ((KnownLHS.isKnownNeverLogicalNegZero(Mode) ||
KnownRHS.isKnownNeverLogicalPosZero(Mode)) &&
// Make sure output negative denormal can't flush to -0
- outputDenormalIsIEEEOrPosZero(*F, Op->getType()))
+ (Mode.Output == DenormalMode::IEEE ||
+ Mode.Output == DenormalMode::PositiveZero))
Known.knownNot(fcNegZero);
}
}
|
Base automatically changed from
users/arsenm/valuetracking/special-case-computeknownfpclass-double
to
main
January 3, 2026 10:57
mahesh-attarde
pushed a commit
to mahesh-attarde/llvm-project
that referenced
this pull request
Jan 6, 2026
…174272) The mode was already queried, so don't do it again.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
floating-point
Floating-point math
llvm:analysis
Includes value tracking, cost tables and constant folding
llvm:transforms
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

The mode was already queried, so don't do it again.