@@ -632,6 +632,19 @@ static bool checkDenormalAttributeConsistency(const Module &M, StringRef Attr,
632632 });
633633}
634634
635+ // Returns true if all functions have different denormal modes.
636+ static bool checkDenormalAttributeInconsistency (const Module &M) {
637+ auto F = M.functions ().begin ();
638+ auto E = M.functions ().end ();
639+ if (F == E)
640+ return false ;
641+ DenormalMode Value = F->getDenormalModeRaw ();
642+ ++F;
643+ return std::any_of (F, E, [&](const Function &F) {
644+ return !F.isDeclaration () && F.getDenormalModeRaw () != Value;
645+ });
646+ }
647+
635648void ARMAsmPrinter::emitAttributes () {
636649 MCTargetStreamer &TS = *OutStreamer->getTargetStreamer ();
637650 ARMTargetStreamer &ATS = static_cast <ARMTargetStreamer &>(TS);
@@ -698,7 +711,9 @@ void ARMAsmPrinter::emitAttributes() {
698711 DenormalMode::getPositiveZero ()))
699712 ATS.emitAttribute (ARMBuildAttrs::ABI_FP_denormal,
700713 ARMBuildAttrs::PositiveZero);
701- else if (!TM.Options .UnsafeFPMath )
714+ else if (checkDenormalAttributeInconsistency (*MMI->getModule ()) ||
715+ checkDenormalAttributeConsistency (
716+ *MMI->getModule (), " denormal-fp-math" , DenormalMode::getIEEE ()))
702717 ATS.emitAttribute (ARMBuildAttrs::ABI_FP_denormal,
703718 ARMBuildAttrs::IEEEDenormals);
704719 else {
@@ -733,7 +748,7 @@ void ARMAsmPrinter::emitAttributes() {
733748 TM.Options .NoTrappingFPMath )
734749 ATS.emitAttribute (ARMBuildAttrs::ABI_FP_exceptions,
735750 ARMBuildAttrs::Not_Allowed);
736- else if (!TM. Options . UnsafeFPMath ) {
751+ else {
737752 ATS.emitAttribute (ARMBuildAttrs::ABI_FP_exceptions, ARMBuildAttrs::Allowed);
738753
739754 // If the user has permitted this code to choose the IEEE 754
0 commit comments