Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions llvm/lib/Target/ARM/ARMAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,19 @@ static bool checkDenormalAttributeConsistency(const Module &M,
});
}

// Returns true if all functions have different denormal modes.
static bool checkDenormalAttributeInconsistency(const Module &M) {
auto F = M.functions().begin();
auto E = M.functions().end();
if (F == E)
return false;
DenormalMode Value = F->getDenormalModeRaw();
++F;
return std::any_of(F, E, [&](const Function &F) {
return !F.isDeclaration() && F.getDenormalModeRaw() != Value;
});
}

void ARMAsmPrinter::emitAttributes() {
MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();
ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
Expand Down Expand Up @@ -695,7 +708,9 @@ void ARMAsmPrinter::emitAttributes() {
DenormalMode::getPositiveZero()))
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
ARMBuildAttrs::PositiveZero);
else if (!TM.Options.UnsafeFPMath)
else if (checkDenormalAttributeInconsistency(*MMI->getModule()) ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is working very well, either before this patch or after it. Nothing we do will be perfect and the existing functions are already broken (I think they did better before 0ab5b5b).

I would have expected -ffast-math to set denormal attributes, if it makes use of crtfastmath.o. But that is not what happens at the moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can frontend emit some hints for this when targeting ARM?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might be a sensible approach. We would need to make sure it worked well with LTO and whatnot. Lets try this first and see if anyone has problems with it. If so we can give the alternative a try. Thanks for your work on getting this done.

checkDenormalAttributeConsistency(
*MMI->getModule(), "denormal-fp-math", DenormalMode::getIEEE()))
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
ARMBuildAttrs::IEEEDenormals);
else {
Expand Down Expand Up @@ -730,7 +745,7 @@ void ARMAsmPrinter::emitAttributes() {
TM.Options.NoTrappingFPMath)
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions,
ARMBuildAttrs::Not_Allowed);
else if (!TM.Options.UnsafeFPMath) {
else {
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions, ARMBuildAttrs::Allowed);

// If the user has permitted this code to choose the IEEE 754
Expand Down
Loading