[llvm] [Analysis] Adding convert_from_arbitrary_fp support in computeKnownFPClass. (PR #208585)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 15 02:20:33 PDT 2026
================
@@ -5727,6 +5727,44 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
Known.knownNot(fcNan | fcInf | fcNegative);
break;
}
+ case Intrinsic::convert_from_arbitrary_fp: {
+ auto *MD = cast<MetadataAsValue>(II->getArgOperand(1))->getMetadata();
+ StringRef FormatStr = cast<MDString>(MD)->getString();
+
+ const fltSemantics *SrcSemanticsPtr =
+ APFloat::getArbitraryFPSemantics(FormatStr);
+ // TODO: the unsupported formats should be handle way before this
+ // remove once the verifier is updated.
+ if (!SrcSemanticsPtr)
+ break;
+
+ const fltSemantics SrcSemantics = *SrcSemanticsPtr;
+ const fltSemantics DstSemantics =
+ II->getType()->getScalarType()->getFltSemantics();
+
+ if (!APFloat::semanticsHasNaN(SrcSemantics))
+ Known.knownNot(fcNan);
+ if (!APFloat::semanticsHasInf(SrcSemantics) &&
+ APFloat::isRepresentableBy(SrcSemantics, DstSemantics))
+ Known.knownNot(fcInf);
+
+ if (SrcSemantics.nanEncoding == fltNanEncoding::NegativeZero)
+ Known.knownNot(fcNegZero);
+
+ if (!APFloat::semanticsHasZero(SrcSemantics)) {
+ Known.knownNot(fcZero);
----------------
arsenm wrote:
This probably works in practice. The one possible edge case is if the source value would underflow in the destination format, but I think we'd have to support smaller result types in the IR or larger arbitrary input formats for it to matter
https://github.com/llvm/llvm-project/pull/208585
More information about the llvm-commits
mailing list