[PATCH] D147971: ValueTracking: Handle non-splat vectors in computeKnownFPClass
Matt Arsenault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 10 14:05:45 PDT 2023
arsenm created this revision.
arsenm added reviewers: bkramer, jcranmer-intel, kpn, cameron.mcinally, sepavloff, nikic, andrew.w.kaylor, scanon.
Herald added subscribers: StephenFan, okura, kuter, hiraditya.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: sstefan1.
Herald added a project: LLVM.
Avoids some regressions when the implementation of isKnownNeverNaN is
replaced with computeKnownFPClass.
https://reviews.llvm.org/D147971
Files:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Transforms/Attributor/nofpclass.ll
Index: llvm/test/Transforms/Attributor/nofpclass.ll
===================================================================
--- llvm/test/Transforms/Attributor/nofpclass.ll
+++ llvm/test/Transforms/Attributor/nofpclass.ll
@@ -85,8 +85,28 @@
ret <2 x double> <double -0.0, double -0.0>
}
+; Test a vector element that's a constant but not ConstantFP.
+define <2 x double> @returned_strange_constant_vector_elt() {
+; CHECK-LABEL: define <2 x double> @returned_strange_constant_vector_elt() {
+; CHECK-NEXT: call void @unknown()
+; CHECK-NEXT: ret <2 x double> <double -0.000000e+00, double bitcast (i64 ptrtoint (ptr @unknown to i64) to double)>
+;
+ call void @unknown()
+ ret <2 x double> <double -0.0, double bitcast (i64 ptrtoint (ptr @unknown to i64) to double)>
+}
+
+; Test a vector element that's an undef/poison
+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>
+;
+ call void @unknown()
+ ret <3 x double> <double -0.0, double poison, double undef>
+}
+
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>
;
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -4357,12 +4357,38 @@
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147971.512256.patch
Type: text/x-patch
Size: 3090 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230410/350d454c/attachment.bin>
More information about the llvm-commits
mailing list