There are cases where you know that a certain floating-point expression will always be non-negative. For example, when computing the length of a vector, one does sqrt(
After about a week, I asked on the matter on GCC Bugzilla & they've provided a solution which is the closest to what I had in mind
float test (float x)
{
float y = x*x;
if (std::isless(y, 0.f))
__builtin_unreachable();
return std::sqrt(y);
}
that compiles to the following assembly:
test(float):
mulss xmm0, xmm0
sqrtss xmm0, xmm0
ret
I'm still not quite sure what exactly happens here, though.