[llvm] [KnownFPClass] Correct denormal mode handling for `KnownFPClass::minMaxLike` (PR #220148)

Eric Ross via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 13 10:09:19 PDT 2026


================
@@ -2258,6 +2258,13 @@ simplifyDemandedFPClassMinMax(KnownFPClass &Known, Intrinsic::ID IID,
                               KnownFPClass KnownLHS, KnownFPClass KnownRHS,
                               const Function &F, bool NSZ) {
   bool OrderedZeroSign = !NSZ;
+  Type *EltTy = CI->getType()->getScalarType();
+  DenormalMode Mode = F.getDenormalMode(EltTy->getFltSemantics());
+  // Prevent folding of the operand if a subnormal output/input could flush to
+  // zero.
+  bool CanReturnOperand =
+      Mode == DenormalMode::getIEEE() ||
+      (KnownLHS.isKnownNeverSubnormal() && KnownRHS.isKnownNeverSubnormal());
----------------
ZERICO2005 wrote:

I did it this way because I was not sure if we can fold `min(negative-subnormal, negative-zero)` to `negative-subnormal` if negative subnormals could flush to positive zero (which would then imply that we should instead fold `min(negative-subnormal, negative-zero)` to negative zero)

https://github.com/llvm/llvm-project/pull/220148


More information about the llvm-commits mailing list