[llvm] [ValueTracking] Fix frexp exponent range for nan/inf inputs (PR #202447)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 9 00:47:41 PDT 2026
================
@@ -10447,21 +10434,23 @@ ConstantRange llvm::computeConstantRange(const Value *V, bool ForSigned,
// It should be possible to implement this for any type, but this logic
// only computes the range assuming standard subnormal handling.
if (APFloat::isIEEELikeFP(FltSem)) {
- KnownFPClass KnownSrc =
- computeKnownFPClass(FrexpSrc, fcSubnormal, SQ, Depth + 1);
-
- // Exponent result is (src == 0) ? 0 : ilogb(src) + 1, and unspecified
- // for inf/nan.
- int MinExp = APFloat::semanticsMinExponent(FltSem) + 1;
-
- // Offset to find the true minimum exponent value for a denormal.
- if (!KnownSrc.isKnownNeverSubnormal())
- MinExp -= (APFloat::semanticsPrecision(FltSem) - 1);
-
- int MaxExp = APFloat::semanticsMaxExponent(FltSem) + 1;
- CR = ConstantRange::getNonEmpty(
- APInt(BitWidth, MinExp, /*isSigned=*/true),
- APInt(BitWidth, MaxExp + 1, /*isSigned=*/true));
+ KnownFPClass KnownSrc = computeKnownFPClass(
+ FrexpSrc, fcSubnormal | fcNan | fcInf, SQ, Depth + 1);
+
+ // The exponent of frexp(NaN) and frexp(Inf) is unspecified. Only
+ // constrain its range when the source can be neither.
+ if (KnownSrc.isKnownNeverNaN() && KnownSrc.isKnownNeverInfinity()) {
----------------
arsenm wrote:
```suggestion
if (KnownSrc.isKnownNeverInfOrNaN()) {
```
https://github.com/llvm/llvm-project/pull/202447
More information about the llvm-commits
mailing list