Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::isfinite poor codegen with Microsoft STL + Clang #4609

Closed
johnstiles-google opened this issue Apr 20, 2024 · 6 comments · Fixed by #4612
Closed

std::isfinite poor codegen with Microsoft STL + Clang #4609

johnstiles-google opened this issue Apr 20, 2024 · 6 comments · Fixed by #4612
Labels
fixed Something works now, yay! performance Must go faster

Comments

@johnstiles-google
Copy link

I work on Skia. I recently attempted to replace our hand-rolled implementation of std::isfinite with the standard library version, trusting that a modern compiler's implementation would be equally efficient.

In practice, this led to a significant, measurable regression in our path-rendering code in clang-cl builds (which mixes Microsoft's STL with the Clang compiler).

I believe the discrepancy comes from https://github.com/microsoft/STL/blob/main/stl/inc/cmath . There does not appear to be support for clang's __builtin_isfinite. Other Clang builtins are supported, however—there are special codepaths for __builtin_ceilf, __builtin_floorf, __builtin_copysignf, and others. However, isfinite has no Clang builtin support, and ends up calling into fpclassifyd for each value, which is extremely expensive relative to the handful of instructions that a native isfinite needs.

I've filed this with our LLVM team (buganizer) but they said they could not control it from their end.

@johnstiles-google johnstiles-google changed the title std::isfinite poor codegen with Clang std::isfinite poor codegen with Microsoft STL + Clang Apr 20, 2024
@frederick-vs-ja
Copy link
Contributor

frederick-vs-ja commented Apr 20, 2024

I've filed this with our LLVM team (buganizer) but they said they could not control it from their end.

On MSVC STL, std::isfinite (at least for FP types) is ultimately provided MS UCRT, so the MSVC STL team and contributors cannot control it either.

As shown in #4537, we can fix this when <cmath> is included. But the issue still exists if only <math.h> is included.

@johnstiles-google
Copy link
Author

That's fine. We're happy to #include <cmath> and use the namespaced std::isfinite.

@StephanTLavavej StephanTLavavej added the performance Must go faster label Apr 20, 2024
@StephanTLavavej
Copy link
Member

I can work on a fix.

@johnstiles-google
Copy link
Author

johnstiles-google commented Apr 20, 2024 via email

hubot pushed a commit to google/skia that referenced this issue Apr 22, 2024
Chrome and Flutter usage of SkScalarIsFinite has been cleaned
up in earlier CLs.

`SkIsFinite` continues to exist as private API in
SkFloatingPoint.h, in order to avoid regressions in clang-cl.
MSVC STL is working on a performance update for their
std::isfinite at microsoft/STL#4609.

Bug: b/335895731
Bug: b/335901087
Change-Id: Ia9efdf567a2fe9b8653a0dd608ff0804a187d3aa
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/844258
Reviewed-by: Brian Osman <[email protected]>
Auto-Submit: John Stiles <[email protected]>
Commit-Queue: Brian Osman <[email protected]>
@StephanTLavavej StephanTLavavej added the fixed Something works now, yay! label Apr 26, 2024
@StephanTLavavej
Copy link
Member

This fix is expected to ship in VS 2022 17.11 Preview 2. Thanks again for the report!

@johnstiles-google
Copy link
Author

johnstiles-google commented Apr 27, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed Something works now, yay! performance Must go faster
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants