[llvm-branch-commits] [llvm] InstCombine: Handle rounding intrinsics in SimplifyDemandedFPClass (PR #174842)
Yingwei Zheng via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Jan 8 07:21:05 PST 2026
================
@@ -2548,6 +2548,72 @@ Value *InstCombinerImpl::SimplifyDemandedUseFPClass(Value *V,
return getFPClassConstant(VTy, ValidResults, /*IsCanonicalizing=*/true);
}
+ case Intrinsic::trunc:
+ case Intrinsic::floor:
+ case Intrinsic::ceil:
+ case Intrinsic::rint:
+ case Intrinsic::nearbyint:
+ case Intrinsic::round:
+ case Intrinsic::roundeven: {
+ FPClassTest DemandedSrcMask = DemandedMask;
+
+ // Zero results imply valid subnormal sources.
+ if (DemandedMask & fcNegZero)
+ DemandedSrcMask |= fcNegSubnormal;
+
+ if (DemandedMask & fcPosZero)
+ DemandedSrcMask |= fcPosSubnormal;
+
+ KnownFPClass KnownSrc;
+ if (SimplifyDemandedFPClass(CI, 0, DemandedSrcMask, KnownSrc, Depth + 1))
+ return I;
+
+ // Note: Possibly dropping snan quiet.
+ if (KnownSrc.isKnownAlways(fcInf | fcNan))
+ return CI->getArgOperand(0);
+
+ // Propagate nnan-ness to source to simplify source checks.
+ if ((DemandedMask & fcNan) == fcNone)
+ KnownSrc.knownNot(fcNan);
+
+ bool IsRoundNearest =
+ IID == Intrinsic::round || IID == Intrinsic::roundeven ||
+ IID == Intrinsic::nearbyint || IID == Intrinsic::rint;
+
+ // Ignore denormals-as-zero, as canonicalization is not mandated.
+ if ((IID == Intrinsic::trunc || IID == Intrinsic::floor ||
+ IsRoundNearest) &&
+ (KnownSrc.isKnownAlways(fcPosZero | fcPosSubnormal)))
+ return ConstantFP::getZero(VTy);
+
+ if ((IID == Intrinsic::trunc || IsRoundNearest) &&
+ KnownSrc.isKnownAlways(fcNegZero | fcNegSubnormal))
+ return ConstantFP::getZero(VTy, true);
+
+ if (IID == Intrinsic::floor && KnownSrc.isKnownAlways(fcNegSubnormal))
+ return ConstantFP::get(VTy, -1.0);
+
+ if (IID == Intrinsic::ceil && KnownSrc.isKnownAlways(fcPosSubnormal))
+ return ConstantFP::get(VTy, 1.0);
+
+ Known = KnownFPClass::roundToIntegral(KnownSrc, IID == Intrinsic::trunc,
+ VTy->isMultiUnitFPType());
----------------
dtcxzyw wrote:
getScalarType
https://github.com/llvm/llvm-project/pull/174842
More information about the llvm-branch-commits
mailing list