@@ -403,6 +403,9 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) {
403403 " use of undefined value '@" +
404404 Twine (ForwardRefValIDs.begin ()->first ) + " '" );
405405
406+ for (auto [CI, FMF] : FCmpIntrinsicFMFs)
407+ CI->setFastMathFlags (FMF);
408+
406409 if (AllowIncompleteIR && !ForwardRefMDNodes.empty ())
407410 dropUnknownMetadataReferences ();
408411
@@ -8446,12 +8449,26 @@ bool LLParser::parseCall(Instruction *&Inst, PerFunctionState &PFS,
84468449 CI->setTailCallKind (TCK);
84478450 CI->setCallingConv (CC);
84488451 if (FMF.any ()) {
8452+ bool IsFCmpIntrinsic = false ;
84498453 if (!isa<FPMathOperator>(CI)) {
8450- CI->deleteValue ();
8451- return error (CallLoc, " fast-math-flags specified for call without "
8452- " floating-point scalar or vector return type" );
8454+ auto FCmpName = StringRef (CalleeID.StrVal );
8455+ if (FCmpName.starts_with (" llvm." ) &&
8456+ CalleeID.Kind == ValID::t_GlobalName) {
8457+ unsigned IID = Intrinsic::lookupIntrinsicID (FCmpName);
8458+ IsFCmpIntrinsic = IID == Intrinsic::vp_fcmp ||
8459+ IID == Intrinsic::experimental_constrained_fcmp ||
8460+ IID == Intrinsic::experimental_constrained_fcmps;
8461+ }
8462+ if (!IsFCmpIntrinsic) {
8463+ CI->deleteValue ();
8464+ return error (CallLoc, " fast-math-flags specified for call without "
8465+ " floating-point scalar or vector return type "
8466+ " or callee is not fcmp intrinsic" );
8467+ }
8468+ FCmpIntrinsicFMFs[CI] = FMF;
84538469 }
8454- CI->setFastMathFlags (FMF);
8470+ if (!IsFCmpIntrinsic)
8471+ CI->setFastMathFlags (FMF);
84558472 }
84568473
84578474 if (CalleeID.Kind == ValID::t_GlobalName &&
0 commit comments