[llvm-branch-commits] [llvm] [ValueTracking][NFC] Prepare computeKnownFPClass before moving it to ValueTrackingFP.cpp (PR #244967)
Eric Ross via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sat Nov 21 15:44:54 PST 2026
https://github.com/ZERICO2005 created https://github.com/llvm/llvm-project/pull/244967
None
>From 82b5356181e4445abd7bb0eb2c9c84c5bf0bffb2 Mon Sep 17 00:00:00 2001
From: zerico <zerico2005 at gmail.com>
Date: Sat, 21 Nov 2026 14:33:18 -0700
Subject: [PATCH] [ValueTracking][NFC] Prepare computeKnownFPClass before
moving it to ValueTrackingFP.cpp
---
llvm/lib/Analysis/ValueTracking.cpp | 26 +++++++-------
llvm/lib/Analysis/ValueTrackingInternal.h | 42 +++++++++++++++++++++++
2 files changed, 55 insertions(+), 13 deletions(-)
create mode 100644 llvm/lib/Analysis/ValueTrackingInternal.h
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index ad1609327e788..517ccf1b05545 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Analysis/ValueTracking.h"
+#include "ValueTrackingInternal.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/FloatingPointMode.h"
@@ -124,9 +125,9 @@ static const Instruction *safeCtxI(const Value *V, const Instruction *CtxI) {
return nullptr;
}
-static bool getShuffleDemandedElts(const ShuffleVectorInst *Shuf,
- const APInt &DemandedElts,
- APInt &DemandedLHS, APInt &DemandedRHS) {
+bool llvm::getShuffleDemandedElts(const ShuffleVectorInst *Shuf,
+ const APInt &DemandedElts, APInt &DemandedLHS,
+ APInt &DemandedRHS) {
if (isa<ScalableVectorType>(Shuf->getType())) {
assert(DemandedElts == APInt(1,1));
DemandedLHS = DemandedRHS = DemandedElts;
@@ -902,9 +903,9 @@ static bool cmpExcludesZero(CmpInst::Predicate Pred, const Value *RHS) {
return true;
}
-static void breakSelfRecursivePHI(const Use *U, const PHINode *PHI,
- Value *&ValOut, Instruction *&CtxIOut,
- const PHINode **PhiOut = nullptr) {
+void llvm::breakSelfRecursivePHI(const Use *U, const PHINode *PHI,
+ Value *&ValOut, Instruction *&CtxIOut,
+ const PHINode **PhiOut) {
ValOut = U->get();
if (ValOut == PHI)
return;
@@ -5212,8 +5213,9 @@ static void computeKnownFPClassFromCond(const Value *V, Value *Cond,
/// frexp(0) = 0, so the tighter max-assuming-nonzero bound is only usable when
/// \p V is known not to be a logical zero (e.g., for fabs(x) < 0.25, the non-0
/// exponent range is [-149, -2], but the 0 edge case is above this range).
-static std::tuple<int, int, int>
-computeKnownExponentRangeFromContext(const Value *V, const SimplifyQuery &Q) {
+std::tuple<int, int, int>
+llvm::computeKnownExponentRangeFromContext(const Value *V,
+ const SimplifyQuery &Q) {
if (!Q.CtxI || !Q.DC || !Q.DT)
return {APFloat::IEK_NaN, APFloat::IEK_Inf, APFloat::IEK_Inf};
@@ -6141,9 +6143,8 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
// The exponent is always a scalar, even when raising a vector to a power.
const Value *Exp = II->getArgOperand(1);
- unsigned BitWidth = Exp->getType()->getIntegerBitWidth();
- KnownBits ExponentKnownBits(BitWidth);
- computeKnownBits(Exp, APInt(1, 1), ExponentKnownBits, Q, Depth + 1);
+ KnownBits ExponentKnownBits =
+ computeKnownBits(Exp, APInt(1, 1), Q, Depth + 1);
FPClassTest InterestedSrcs = fcNone;
if (InterestedClasses & fcNan)
@@ -6775,8 +6776,7 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
}
const Type *EltTy = Ty->getScalarType();
- KnownBits Bits(EltTy->getPrimitiveSizeInBits());
- computeKnownBits(Src, DemandedElts, Bits, Q, Depth + 1);
+ KnownBits Bits = computeKnownBits(Src, DemandedElts, Q, Depth + 1);
Known = KnownFPClass::bitcast(EltTy->getFltSemantics(), Bits);
break;
diff --git a/llvm/lib/Analysis/ValueTrackingInternal.h b/llvm/lib/Analysis/ValueTrackingInternal.h
new file mode 100644
index 0000000000000..74c9147280e82
--- /dev/null
+++ b/llvm/lib/Analysis/ValueTrackingInternal.h
@@ -0,0 +1,42 @@
+//===- ValueTrackingInternal.h - Shared ValueTracking helpers ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Helpers shared between ValueTracking.cpp and ValueTrackingFP.cpp. These are
+// not part of the public ValueTracking interface.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIB_ANALYSIS_VALUETRACKINGINTERNAL_H
+#define LLVM_LIB_ANALYSIS_VALUETRACKINGINTERNAL_H
+
+#include <tuple>
+
+namespace llvm {
+
+class APInt;
+class Instruction;
+class PHINode;
+class ShuffleVectorInst;
+class Use;
+class Value;
+struct SimplifyQuery;
+
+bool getShuffleDemandedElts(const ShuffleVectorInst *Shuf,
+ const APInt &DemandedElts, APInt &DemandedLHS,
+ APInt &DemandedRHS);
+
+void breakSelfRecursivePHI(const Use *U, const PHINode *PHI, Value *&ValOut,
+ Instruction *&CtxIOut,
+ const PHINode **PhiOut = nullptr);
+
+std::tuple<int, int, int>
+computeKnownExponentRangeFromContext(const Value *V, const SimplifyQuery &Q);
+
+} // namespace llvm
+
+#endif // LLVM_LIB_ANALYSIS_VALUETRACKINGINTERNAL_H
More information about the llvm-branch-commits
mailing list