This is an archive of the discontinued LLVM Phabricator instance.

[libc] Automatically add -mfma flag for architectures supporting FMA.
ClosedPublic

Authored by lntue on Apr 12 2022, 8:50 AM.

Details

Summary

Detect if the architecture supports FMA instructions and if
the targets depend on fma.

Diff Detail

Event Timeline

lntue created this revision.Apr 12 2022, 8:50 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 12 2022, 8:50 AM
lntue requested review of this revision.Apr 12 2022, 8:50 AM
michaelrj added inline comments.Apr 12 2022, 12:26 PM
libc/cmake/modules/LLVMLibCObjectRules.cmake
39

would it be possible to make this a more generic option than just FMA? Perhaps there's a way to use generator expressions?

lntue updated this revision to Diff 427958.May 8 2022, 3:21 PM

Remove debugging messages.

lntue marked an inline comment as done.May 9 2022, 8:45 AM
lntue added inline comments.
libc/cmake/modules/LLVMLibCObjectRules.cmake
39

A more general option is now added with https://reviews.llvm.org/D125174.

lntue updated this revision to Diff 429930.May 16 2022, 9:08 PM
lntue marked an inline comment as done.

Only apply FMA_OPT flags for x86-64 targets with FMA instructions.

gchatelet added inline comments.Jun 1 2022, 4:33 AM
libc/cmake/modules/LLVMLibCObjectRules.cmake
21

It would make sense to factor the two conditions inside the fma variable.

libc/test/src/math/CMakeLists.txt
1207–1208

I'm not sure I understand the semantic here. Does that mean that the test requires FMA?
If so does it? It would make sense to test it with and without FMA.

Maybe I missed something.

lntue added inline comments.Jun 1 2022, 6:09 AM
libc/test/src/math/CMakeLists.txt
1207–1208

Yes, for this patch, this test does require FMA. That is because without FMA instructions, the current expm1f implementation is not correctly rounded for all float inputs (1 extra exceptional value). This will be fixed in the followup patch: https://reviews.llvm.org/D123440

lntue updated this revision to Diff 433374.Jun 1 2022, 6:31 AM

Refactor the condition for adding fma compile flags.

lntue marked an inline comment as done.Jun 1 2022, 6:32 AM
gchatelet accepted this revision.Jun 2 2022, 1:30 PM
gchatelet added inline comments.
libc/cmake/modules/LLVMLibCFlagRules.cmake
135

"Skip FMA_OPT flag for target that don't support fma"

libc/test/src/math/CMakeLists.txt
1207–1208

Do you mind adding a comment ?

This revision is now accepted and ready to land.Jun 2 2022, 1:30 PM
lntue updated this revision to Diff 433948.Jun 2 2022, 9:52 PM

Address comments.

lntue marked 2 inline comments as done.Jun 2 2022, 9:52 PM