[llvm] ValueTracking: Use computeKnownBits for ldexp integer handling (PR #179234)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 2 05:49:03 PST 2026
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/179234
Switch to using computeKnownBits instead of computeConstantRange
in computeKnownFPClass's ldexp handling. This is preparation to
move the handling into KnownFPClass. Since KnownFPClass is in Support,
it can make use of KnownBits as the input argument. ConstantRange is in IR,
so it cannot be used from Support.
>From 90dcda010dd1d859d0d5196622379ef96d8c16e7 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Mon, 2 Feb 2026 13:03:39 +0100
Subject: [PATCH] ValueTracking: Use computeKnownBits for ldexp integer
handling
Switch to using computeKnownBits instead of computeConstantRange
in computeKnownFPClass's ldexp handling. This is preparation to
move the handling into KnownFPClass. Since KnownFPClass is in Support,
it can make use of KnownBits as the input argument. ConstantRange is in IR,
so it cannot be used from Support.
---
llvm/lib/Analysis/ValueTracking.cpp | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index b0d640e33cc28..87062e7e92a76 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -5409,27 +5409,25 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
II->getType()->getScalarType()->getFltSemantics();
unsigned Precision = APFloat::semanticsPrecision(Flt);
const Value *ExpArg = II->getArgOperand(1);
- ConstantRange ExpRange = computeConstantRange(
- ExpArg, true, Q.IIQ.UseInstrInfo, Q.AC, Q.CxtI, Q.DT, Depth + 1);
+ KnownBits ExpBits = computeKnownBits(ExpArg, DemandedElts, Q, Depth + 1);
const int MantissaBits = Precision - 1;
- if (ExpRange.getSignedMin().sge(static_cast<int64_t>(MantissaBits)))
+ if (ExpBits.getSignedMinValue().sge(static_cast<int64_t>(MantissaBits)))
Known.knownNot(fcSubnormal);
const Function *F = II->getFunction();
- const APInt *ConstVal = ExpRange.getSingleElement();
const fltSemantics &FltSem =
II->getType()->getScalarType()->getFltSemantics();
- if (ConstVal && ConstVal->isZero()) {
+ if (ExpBits.isConstant() && ExpBits.getConstant().isZero()) {
// ldexp(x, 0) -> x, so propagate everything.
Known.propagateCanonicalizingSrc(KnownSrc, F->getDenormalMode(FltSem));
- } else if (ExpRange.isAllNegative()) {
+ } else if (ExpBits.isNegative()) {
// If we know the power is <= 0, can't introduce inf
if (KnownSrc.isKnownNeverPosInfinity())
Known.knownNot(fcPosInf);
if (KnownSrc.isKnownNeverNegInfinity())
Known.knownNot(fcNegInf);
- } else if (ExpRange.isAllNonNegative()) {
+ } else if (ExpBits.isNonNegative()) {
// If we know the power is >= 0, can't introduce subnormal or zero
if (KnownSrc.isKnownNeverPosSubnormal())
Known.knownNot(fcPosSubnormal);
More information about the llvm-commits
mailing list