This is an archive of the discontinued LLVM Phabricator instance.

[flang][msvc] Work around if constexpr (false) evaluation. NFC.
ClosedPublic

Authored by Meinersbur on Sep 15 2020, 4:21 PM.

Details

Summary

MSVC tries to expand templates that are in the false-branch of a if constexpr construct. In this case, the condition checks whether a tuple has at least one element and then is trying to access it using std::get<0>, which fails when the tuple has 0 elements.

The workaround is to extract that case into a separate method.

This patch is part of the series to make flang compilable with MS Visual Studio http://lists.llvm.org/pipermail/flang-dev/2020-July/000448.html.

Diff Detail

Event Timeline

Meinersbur created this revision.Sep 15 2020, 4:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 15 2020, 4:21 PM

Is there any effect on the performance of the parser on large Fortran source files when it's built with non-Microsoft C++ compilers?

The function should be inlined, in which case there is no performance difference.

The function should be inlined, in which case there is no performance difference.

Sure, but have you measured the performance and verified that there's no penalty in gcc & clang builds for this MSVC work-around? I'm worried that we'll get to the end of this MSVC bug work-around process, notice that the Linux builds of f18 have lost performance, and somebody else is going to have to figure out which of these patches needs to be reworked to avoid the penalty. Are you able to measure f18 parsing performance? If not, let me know.

Do you have a suggestion for a large Fortran file that I could measure? I think my measurements would not be accurate enough to show a difference between inlining and non-inlining of this function. If you know how to do it yourself, I would be grateful.

klausler accepted this revision.Sep 16 2020, 10:31 AM

Do you have a suggestion for a large Fortran file that I could measure? I think my measurements would not be accurate enough to show a difference between inlining and non-inlining of this function. If you know how to do it yourself, I would be grateful.

Whether or not the measurements differ more than the margin of error is essentially the problem that I'm worried about. The f18 parser is a stressful case for C++ compilers and inline expansion is not guaranteed. The template being changed here is the one that's used to generate every node in the parse tree, so each cycle matters.

We'll see if we can find some good examples of Fortran source files that are unencumbered and suitable for inclusion in the test base. One nice thing about Fortran is that one may concatenate a lot of source code into a single source file as long as module dependency order is observed, so one can build up very large single source files that can expose parsing performance changes. In the meantime, go ahead with your changes, and I'll keep an eye on performance here and let you know if I notice a drop, and we'll deal with it if it happens via conditional code or something.

This revision is now accepted and ready to land.Sep 16 2020, 10:31 AM
This revision was landed with ongoing or failed builds.Sep 16 2020, 1:01 PM
This revision was automatically updated to reflect the committed changes.