[llvm] [SelectionDAG] Use `KnownFPClass` to infer `isKnownNeverZeroFloat` (PR #190621)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 6 08:45:19 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-selectiondag
Author: zGoldthorpe
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/190621.diff
2 Files Affected:
- (modified) llvm/include/llvm/CodeGen/SelectionDAG.h (+8-3)
- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (+9-6)
``````````diff
diff --git a/llvm/include/llvm/CodeGen/SelectionDAG.h b/llvm/include/llvm/CodeGen/SelectionDAG.h
index c1012c940ed5b..e0778e5730eb8 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAG.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAG.h
@@ -2442,9 +2442,14 @@ class SelectionDAG {
return isKnownNeverNaN(Op, true, Depth);
}
- /// Test whether the given floating point SDValue is known to never be
- /// positive or negative zero.
- LLVM_ABI bool isKnownNeverZeroFloat(SDValue Op) const;
+ /// Test whether the given SDValue (or all elements of it, if it is a vector)
+ /// is known to never be positive or negative zero in \p DemandedElts.
+ LLVM_ABI bool isKnownNeverZeroFloat(SDValue Op, const APInt &DemandedElts,
+ unsigned Depth = 0) const;
+
+ /// Test whether the given floating point SDValue (or all elements of it, if
+ /// it is a vector) is known to never be positive or negative zero.
+ LLVM_ABI bool isKnownNeverZeroFloat(SDValue Op, unsigned Depth = 0) const;
/// Test whether the given SDValue is known to contain non-zero value(s).
LLVM_ABI bool isKnownNeverZero(SDValue Op, unsigned Depth = 0) const;
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 137922aa62557..4c89195a0e17d 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -6317,13 +6317,16 @@ bool SelectionDAG::isKnownNeverNaN(SDValue Op, const APInt &DemandedElts,
return Known.isKnownNever(NanMask);
}
-bool SelectionDAG::isKnownNeverZeroFloat(SDValue Op) const {
- assert(Op.getValueType().isFloatingPoint() &&
- "Floating point type expected");
+bool SelectionDAG::isKnownNeverZeroFloat(SDValue Op, unsigned Depth) const {
+ APInt DemandedElts = getDemandAllEltsMask(Op);
+ return isKnownNeverZeroFloat(Op, DemandedElts, Depth);
+}
- // If the value is a constant, we can obviously see if it is a zero or not.
- return ISD::matchUnaryFpPredicate(
- Op, [](ConstantFPSDNode *C) { return !C->isZero(); });
+bool SelectionDAG::isKnownNeverZeroFloat(SDValue Op, const APInt &DemandedElts,
+ unsigned Depth) const {
+ assert(!DemandedElts.isZero() && "No demanded elements");
+ KnownFPClass Known = computeKnownFPClass(Op, DemandedElts, fcZero, Depth);
+ return Known.isKnownNeverZero();
}
bool SelectionDAG::isKnownNeverZero(SDValue Op, unsigned Depth) const {
``````````
</details>
https://github.com/llvm/llvm-project/pull/190621
More information about the llvm-commits
mailing list