[PATCH] D28797: [LangRef] Make @llvm.sqrt(x) return undef, rather than have UB, for negative x.

Mehdi AMINI via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 17 11:55:32 PST 2017


mehdi_amini 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 .


What about NaN? A NaN input is legal according to LangRef AFAICT, and errno would still be set. That would lead me to think that lowering unconditionally to libm sqrt() isn't correct.


https://reviews.llvm.org/D28797





More information about the llvm-commits mailing list