[PATCH] D39204: [CodeGen] __builtin_sqrt should map to the compiler's intrinsic sqrt function

Eli Friedman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 23 14:53:29 PDT 2017


efriedma added a comment.

The gcc documentation says "GCC includes built-in versions of many of the functions in the standard C library. These functions come in two forms: one whose names start with the `__builtin_` prefix, and the other without. Both forms have the same type (including prototype), the same address (when their address is taken), and the same meaning as the C library functions".  And gcc specifically preserves the stated semantics.  Given that, I'm not sure it makes sense for us to try to redefine `__builtin_sqrt()` just because it's convenient.

Note that this reasoning only applies if the user hasn't specified any fast-math flags; under -ffinite-math-only, we can assume the result isn't a NaN, and therefore we can use `llvm.sqrt.*`. (The definition of `llvm.sqrt.*` changed in https://reviews.llvm.org/D28797; I don't think we ever updated clang to take advantage of this).

If we really need a name for the never-sets-errno sqrt, we should probably use a different name, e.g. `__builtin_ieee_sqrt()`.


https://reviews.llvm.org/D39204





More information about the cfe-commits mailing list