================
@@ -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
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to