[llvm] InstCombine: Handle canonicalize in SimplifyDemandedFPClass (PR #173189)
Serge Pavlov via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 23 10:45:07 PST 2025
================
@@ -87,6 +87,54 @@ void KnownFPClass::propagateDenormal(const KnownFPClass &Src,
}
}
+void KnownFPClass::canonicalize(DenormalMode DenormMode) {
+ KnownFPClass KnownSrc = *this;
+ *this = KnownFPClass();
+
+ // This is essentially a stronger form of
+ // propagateCanonicalizingSrc. Other "canonicalizing" operations don't
+ // actually have an IR canonicalization guarantee.
+
+ // Canonicalize may flush denormals to zero, so we have to consider the
+ // denormal mode to preserve known-not-0 knowledge.
+ KnownFPClasses = KnownSrc.KnownFPClasses | fcZero | fcQNan;
+
+ // Stronger version of propagateNaN
+ // Canonicalize is guaranteed to quiet signaling nans.
+ if (KnownSrc.isKnownNeverNaN())
+ knownNot(fcNan);
+ else
+ knownNot(fcSNan);
+
+ // FIXME: Missing check of IEEE like types.
+
+ // If the parent function flushes denormals, the canonical output cannot be a
+ // denormal.
+ if (DenormMode == DenormalMode::getIEEE()) {
+ if (KnownSrc.isKnownNever(fcPosZero))
+ knownNot(fcPosZero);
+ if (KnownSrc.isKnownNever(fcNegZero))
+ knownNot(fcNegZero);
+ return;
+ }
+
+ if (DenormMode.inputsAreZero() || DenormMode.outputsAreZero())
----------------
spavloff wrote:
IIUC this function canonicalize FP class of the result of some operation. Output denormal mode is OK here, but how the input mode is used here? If a subnormal operand of an instruction is replaced with zero, it is visible only to the operation.
https://github.com/llvm/llvm-project/pull/173189
More information about the llvm-commits
mailing list