Skip to content

Commit 4b233d8

Browse files
paperchalicemahesh-attarde
authored andcommitted
[ARM] Remove UnsafeFPMath uses (llvm#151275)
Try to remove `UnsafeFPMath` uses in arm backend. These global flags block some improvements like https://discourse.llvm.org/t/rfc-honor-pragmas-with-ffp-contract-fast/80797. Remove them incrementally.
1 parent 401cbfd commit 4b233d8

File tree

2 files changed

+17
-321
lines changed

2 files changed

+17
-321
lines changed

llvm/lib/Target/ARM/ARMAsmPrinter.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
635648
void 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

Comments
 (0)