[llvm-branch-commits] [llvm] InstCombine: Handle fdiv in SimplifyDemandedFPClass (PR #175946)
Matt Arsenault via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Jan 14 10:10:10 PST 2026
================
@@ -2331,6 +2331,136 @@ Value *InstCombinerImpl::SimplifyDemandedUseFPClass(Instruction *I,
FPClassTest ValidResults = DemandedMask & Known.KnownFPClasses;
return getFPClassConstant(VTy, ValidResults, /*IsCanonicalizing=*/true);
}
+ case Instruction::FDiv: {
+ Value *X = I->getOperand(0);
+ Value *Y = I->getOperand(1);
+ if (X == Y && isGuaranteedNotToBeUndef(X, SQ.AC, CxtI, SQ.DT, Depth + 1)) {
+ // If the source is 0, inf or nan, the result is a nan
+
+ Value *IsZeroOrNan = Builder.CreateFCmpFMF(
+ FCmpInst::FCMP_UEQ, I->getOperand(0), ConstantFP::getZero(VTy), FMF);
+
+ Value *Fabs =
+ Builder.CreateUnaryIntrinsic(Intrinsic::fabs, I->getOperand(0), FMF);
+ Value *IsInfOrNan = Builder.CreateFCmpFMF(
+ FCmpInst::FCMP_UEQ, Fabs, ConstantFP::getInfinity(VTy), FMF);
+
+ Value *IsInfOrZeroOrNan = Builder.CreateOr(IsInfOrNan, IsZeroOrNan);
----------------
arsenm wrote:
That doesn't have the same behavior. is.fpclass doesn't canonicalize the input, emitting fcmp gets the correct behavior regardless of denormal mode. instcombine will only fold to is.fpclass depending on the mode
https://github.com/llvm/llvm-project/pull/175946
More information about the llvm-branch-commits
mailing list