[PATCH] D28797: [LangRef] Make @llvm.sqrt(x) return undef, rather than have UB, for negative x.
Hal Finkel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 17 12:00:54 PST 2017
hfinkel added a comment.
In https://reviews.llvm.org/D28797#648535, @efriedma wrote:
> > Nothing in LLVM takes advantage of this undefined behavior, as far as we can tell, and the fact that llvm.sqrt has UB dates from its initial addition to the LangRef.
>
> This is false: we take advantage of this to lower @llvm.sqrt() to libm sqrt() on platforms which don't have a native sqrt instruction, and that can have side-effects. See also https://reviews.llvm.org/D28335 .
We do, but this seems somewhat accidental. Most of the libm intrinsics have this problem, and sqrt is the only one for which we have this undefined behavior.
https://reviews.llvm.org/D28797
More information about the llvm-commits
mailing list