Details
- Reviewers
sscalpone jdoerfert DavidTruby jeanPerier - Group Reviewers
Restricted Project - Commits
- rG2ebf4b6e4c35: [flang] Fix setting mxcsr on MSVC
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
I wonder if something like this patch should be applied more broadly or even in general. I'm seeing the same issue (lack of __mxcsr in fenv_t)
on Solaris/x86. When looking around, I found that that non-standard member does exist in glibc, macOS, and FreeBSD, so they could continue
to use the existing code.
However, AFAICS <xmmintrin.h> is available with all compilers that can be used to build llvm: clang, gcc, and msvc, so one could just remove
the references to __mxcsr and use the _mm_getcsr/_mm_setcsr code instead.
Thoughts?
Yes, _mm_setcsr seems portable across x86_64 systems. It's fine. Is there an already-existing llvm API that is similar? (I don't know.)
This change doesn't preserve the meaning of currentFenv_. I don't know if currentFenv_ (or originalFenv_) are still useful.
Thanks @sscalpone for the review. Looks like originalFenv_ is still used for restoring the original state. Shall I change the type of originalFenv_ to be unsigned int on x86_64? (Or maybe a union?)
From what I understand originalFenv_ is used for changing and restoring the __mxcsr value (or its equivalents on aarch64).
Looks like originalFenv_ is still used for restoring the original state. Shall I change the type of originalFenv_ to be unsigned int on x86_64? (Or maybe a union?)
From what I understand originalFenv_ is used for changing and restoring the __mxcsr value (or its equivalents on aarch64).
In host.cpp, originalFenv_ is more than just the __mxcsr, it also backs-up the whole fp environment (original rounding mode, exceptions that were raised,...) before calling the run-time to fold. Interrupts are also disabled between the related feholdexcept / fesetenv (we do not want the compiler to crash if the Fortran code being folded is wrong and triggers a division by zero or such), so it should be kept.
currentFenv_ however was only about manipulating the __mxcsr (or __fpcr /...), so you can remove it where you do not need it anymore.
I just tried a 2-stage build on amd64-pc-solaris2.11, which failed:
FAILED: tools/flang/unittests/Evaluate/CMakeFiles/FortranEvaluateTesting.dir/fp-testing.cpp.o [...] In file included from /vol/llvm/src/llvm-project/local/flang/unittests/Evaluate/fp-testing.cpp:1: /vol/llvm/src/llvm-project/local/flang/unittests/Evaluate/fp-testing.h:22:10: error: private field 'currentFenv_' is not used [-Werror,-Wunused-private-field] fenv_t currentFenv_; ^ 1 error generated.
Given that this fixes the flang build on at least Windows and Solaris/x86, it would be good if someone could review this.
FWIW, I`ve successfully built and tested with this patch on amd64-pc-solaris2.11
It's been two months since the last reminder without any response. Could someone please review this patch? The current code is unportable and just happens to work on a few select x86 targets. It would be a shame to release LLVM 11 with the flang build broken on at least Windows and Solaris/x86.
@isuruf, do you intend to commit your patch any time soon? It would be good to have it in-tree before LLVM 11 branches.
The one from April wasn't run at all, but only reports some obscure internal error. There were generic problems with the pre-merge infrastructure at that time IIRC.
Last night, I tried to restart the check, but it's still stuck in the first step (creating a branch in the repo to apply the patch to) after 10 hours.
In that form, the pre-merge checks are worse than useless IMO.
I'd suggest you go ahead and commit the patch. Should there be any issues despite your and my testing, the buildbots will let us know quickly enough.