@@ -403,6 +403,11 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) {
403403 " use of undefined value '@" +
404404 Twine (ForwardRefValIDs.begin ()->first ) + " '" );
405405
406+ // Fix fast-math flags for fcmp intrinsic calls.
407+ for (auto [CI, FMF] : FCmpIntrinsicFMFs)
408+ CI->setFastMathFlags (FMF);
409+ FCmpIntrinsicFMFs.clear ();
410+
406411 if (AllowIncompleteIR && !ForwardRefMDNodes.empty ())
407412 dropUnknownMetadataReferences ();
408413
@@ -8446,12 +8451,26 @@ bool LLParser::parseCall(Instruction *&Inst, PerFunctionState &PFS,
84468451 CI->setTailCallKind (TCK);
84478452 CI->setCallingConv (CC);
84488453 if (FMF.any ()) {
8454+ bool IsFCmpIntrinsic = false ;
84498455 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" );
8456+ auto FCmpName = StringRef (CalleeID.StrVal );
8457+ if (FCmpName.starts_with (" llvm." ) &&
8458+ CalleeID.Kind == ValID::t_GlobalName) {
8459+ unsigned IID = Intrinsic::lookupIntrinsicID (FCmpName);
8460+ IsFCmpIntrinsic = IID == Intrinsic::vp_fcmp ||
8461+ IID == Intrinsic::experimental_constrained_fcmp ||
8462+ IID == Intrinsic::experimental_constrained_fcmps;
8463+ }
8464+ if (!IsFCmpIntrinsic) {
8465+ CI->deleteValue ();
8466+ return error (CallLoc, " fast-math-flags specified for call without "
8467+ " floating-point scalar or vector return type "
8468+ " or callee is not fcmp intrinsic" );
8469+ }
8470+ FCmpIntrinsicFMFs[CI] = FMF;
84538471 }
8454- CI->setFastMathFlags (FMF);
8472+ if (!IsFCmpIntrinsic)
8473+ CI->setFastMathFlags (FMF);
84558474 }
84568475
84578476 if (CalleeID.Kind == ValID::t_GlobalName &&
0 commit comments