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

Minimal support for __builtin_unreachable and for __builtin_expect #394

Merged
merged 2 commits into from
May 2, 2021

Conversation

xavierleroy
Copy link
Contributor

These two builtins are used by GCC and Clang as optimization hints. They occur frequently in open-source code.

This PR adds minimal support for both builtins. They are not taken into account by optimizations yet.

  • __builtin_unreachable is transported all the way to assembly, where it generates no code. In the future, it could be used during the Linearize pass to remove more unreachable code.
  • __builtin_expect is currently removed during C2C elaboration, so it does not even enter the verified part of CompCert. If we keep it as a "no op" builtin, inefficient code is generated for comparisons on 64-bit platforms. (Because __builtin_expect forces a conversion of its argument to type long.) More work is needed to take full advantage of this builtin.

Not yet used for optimizations.
Not yet used for optimizations.

Actually, __builtin_expect is removed during C2C conversion, otherwise
the conversion to type "long" produces inefficient code on 64-bit platforms.
@xavierleroy
Copy link
Contributor Author

Positive feedback received, merging!

@xavierleroy xavierleroy merged commit 3b448f5 into master May 2, 2021
@xavierleroy xavierleroy deleted the builtin-expect-unreachable branch May 8, 2021 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant