[llvm] [InstCombine] Fix 0.0 / x -> 0 folds when the divisor may be zero (PR #202482)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 15 04:00:37 PDT 2026


================
@@ -2731,12 +2731,22 @@ Value *InstCombinerImpl::SimplifyDemandedUseFPClass(Instruction *I,
         SimplifyDemandedFPClass(I, 1, RHSDemandedMask, KnownRHS, SQ, Depth + 1))
       return I;
 
+    bool ResultNotNan = (DemandedMask & fcNan) == fcNone;
+    bool ResultNotInf = (DemandedMask & fcInf) == fcNone;
+
+    // Replacing 0/x with a zero is only valid when the divisor can't be
+    // (logical) zero, since 0/0 is NaN -- unless NaN results aren't demanded. A
+    // subnormal divisor can flush to zero under a flushing denormal mode.
+    bool DivisorNonZeroOrNanOK =
----------------
arsenm wrote:

This name reads strangely to me. Maybe 's/DivisorNonZeroOrNanOK/CanIgnoreZeroByZeroNan/'?

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


More information about the llvm-commits mailing list