[llvm] 656b52a - ValueTracking: Handle non-splat vectors in computeKnownFPClass
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 14 14:41:33 PDT 2023
Author: Matt Arsenault
Date: 2023-04-14T17:41:26-04:00
New Revision: 656b52a6c61e15dfbd5969417d66fcaf0e730ce1
URL: https://github.com/llvm/llvm-project/commit/656b52a6c61e15dfbd5969417d66fcaf0e730ce1
DIFF: https://github.com/llvm/llvm-project/commit/656b52a6c61e15dfbd5969417d66fcaf0e730ce1.diff
LOG: ValueTracking: Handle non-splat vectors in computeKnownFPClass
Avoids some regressions when the implementation of isKnownNeverNaN is
replaced with computeKnownFPClass.
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Transforms/Attributor/nofpclass.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index b4ff5940201d..51f88945c532 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -4362,12 +4362,38 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
assert(Depth <= MaxAnalysisRecursionDepth && "Limit Search Depth");
- const APFloat *C;
- if (match(V, m_APFloat(C))) {
- // We know all of the classes for a scalar constant or a splat vector
- // constant!
- Known.KnownFPClasses = C->classify();
- Known.SignBit = C->isNegative();
+ if (auto *CFP = dyn_cast_or_null<ConstantFP>(V)) {
+ Known.KnownFPClasses = CFP->getValueAPF().classify();
+ Known.SignBit = CFP->isNegative();
+ return;
+ }
+
+ // Try to handle fixed width vector constants
+ auto *VFVTy = dyn_cast<FixedVectorType>(V->getType());
+ const Constant *CV = dyn_cast<Constant>(V);
+ if (VFVTy && CV) {
+ Known.KnownFPClasses = fcNone;
+
+ // For vectors, verify that each element is not NaN.
+ unsigned NumElts = VFVTy->getNumElements();
+ for (unsigned i = 0; i != NumElts; ++i) {
+ Constant *Elt = CV->getAggregateElement(i);
+ if (!Elt) {
+ Known = KnownFPClass();
+ return;
+ }
+ if (isa<UndefValue>(Elt))
+ continue;
+ auto *CElt = dyn_cast<ConstantFP>(Elt);
+ if (!CElt) {
+ Known = KnownFPClass();
+ return;
+ }
+
+ KnownFPClass KnownElt{CElt->getValueAPF().classify(), CElt->isNegative()};
+ Known |= KnownElt;
+ }
+
return;
}
diff --git a/llvm/test/Transforms/Attributor/nofpclass.ll b/llvm/test/Transforms/Attributor/nofpclass.ll
index a363933fcfe9..52c9c2e12fdb 100644
--- a/llvm/test/Transforms/Attributor/nofpclass.ll
+++ b/llvm/test/Transforms/Attributor/nofpclass.ll
@@ -97,7 +97,7 @@ define <2 x double> @returned_strange_constant_vector_elt() {
; Test a vector element that's an undef/poison
define <3 x double> @returned_undef_constant_vector_elt() {
-; CHECK-LABEL: define <3 x double> @returned_undef_constant_vector_elt() {
+; CHECK-LABEL: define nofpclass(nan inf pzero sub norm) <3 x double> @returned_undef_constant_vector_elt() {
; CHECK-NEXT: call void @unknown()
; CHECK-NEXT: ret <3 x double> <double -0.000000e+00, double poison, double undef>
;
@@ -106,7 +106,7 @@ define <3 x double> @returned_undef_constant_vector_elt() {
}
define <2 x double> @returned_qnan_zero_vector() {
-; CHECK-LABEL: define noundef <2 x double> @returned_qnan_zero_vector() {
+; CHECK-LABEL: define noundef nofpclass(snan inf nzero sub norm) <2 x double> @returned_qnan_zero_vector() {
; CHECK-NEXT: call void @unknown()
; CHECK-NEXT: ret <2 x double> <double 0x7FF8000000000000, double 0.000000e+00>
;
More information about the llvm-commits
mailing list