Skip to content

Conversation

@arsenm
Copy link
Contributor

@arsenm arsenm commented Jan 3, 2026

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

arsenm added 6 commits January 3, 2026 11:15
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.
Copy link
Contributor Author

arsenm commented Jan 3, 2026

@arsenm arsenm marked this pull request as ready for review January 3, 2026 10:27
Copy link
Contributor Author

arsenm commented Jan 3, 2026

Accidentally posted this in the parent initially

@llvmbot
Copy link
Member

llvmbot commented Jan 3, 2026

@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-llvm-analysis

Author: Matt Arsenault (arsenm)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/174272.diff

1 Files Affected:

  • (modified) llvm/lib/Analysis/ValueTracking.cpp (+4-8)
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
@arsenm arsenm enabled auto-merge (squash) January 3, 2026 10:58
@arsenm arsenm merged commit 00fdb29 into main Jan 3, 2026
15 of 16 checks passed
@arsenm arsenm deleted the users/arsenm/valuetracking/avoid-unnecessary-denormal-mode-lookup branch January 3, 2026 10:59
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Jan 6, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants