[llvm] ValueTracking: Use computeKnownBits for ldexp integer handling (PR #179234)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 2 06:47:38 PST 2026
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/179234
>From 4d0ca8f1723e69eb1171eeead7c4753d5a792e1c 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 +++++-------
llvm/test/Transforms/Attributor/nofpclass-ldexp.ll | 4 ++--
2 files changed, 7 insertions(+), 9 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);
diff --git a/llvm/test/Transforms/Attributor/nofpclass-ldexp.ll b/llvm/test/Transforms/Attributor/nofpclass-ldexp.ll
index b9156319b0a91..5743aa71b3912 100644
--- a/llvm/test/Transforms/Attributor/nofpclass-ldexp.ll
+++ b/llvm/test/Transforms/Attributor/nofpclass-ldexp.ll
@@ -702,10 +702,10 @@ define <2 x float> @ret_ldexp_v2f32_known_pos_exp_noinf(<2 x float> nofpclass(in
}
define <2 x float> @ret_ldexp_v2f32_known_neg_exp_noinf(<2 x float> nofpclass(inf) %arg0, <2 x i32> %arg1) #0 {
-; CHECK-LABEL: define <2 x float> @ret_ldexp_v2f32_known_neg_exp_noinf
+; CHECK-LABEL: define nofpclass(inf) <2 x float> @ret_ldexp_v2f32_known_neg_exp_noinf
; CHECK-SAME: (<2 x float> nofpclass(inf) [[ARG0:%.*]], <2 x i32> [[ARG1:%.*]]) #[[ATTR1]] {
; CHECK-NEXT: [[OR_ARG1:%.*]] = or <2 x i32> [[ARG1]], <i32 -16, i32 -32>
-; CHECK-NEXT: [[CALL:%.*]] = call <2 x float> @llvm.ldexp.v2f32.v2i32(<2 x float> nofpclass(inf) [[ARG0]], <2 x i32> [[OR_ARG1]]) #[[ATTR10]]
+; CHECK-NEXT: [[CALL:%.*]] = call nofpclass(inf) <2 x float> @llvm.ldexp.v2f32.v2i32(<2 x float> nofpclass(inf) [[ARG0]], <2 x i32> [[OR_ARG1]]) #[[ATTR10]]
; CHECK-NEXT: ret <2 x float> [[CALL]]
;
%or.arg1 = or <2 x i32> %arg1, <i32 -16, i32 -32>
More information about the llvm-commits
mailing list