[PATCH] D28797: [LangRef] Make @llvm.sqrt(x) return undef, rather than have UB, for negative x.
Justin Lebar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 17 14:26:41 PST 2017
jlebar added a comment.
> I'm not sure I really like the logic of "all these other intrinsics are broken, therefore we should break llvm.sqrt()", especially since we don't really use most of the intrinsics in question.
My thinking is more along the lines of, "all of these intrinsics, including sqrt, are broken. Therefore we should at least bring the langref more in line with (a) our desired semantics, (b) the semantics that various frontends are currently using, and (c) the semantics of the other ."
The reason that even sqrt is currently broken is -- at least as I understand -- the speculate-and-select IR idiom is lowered to ISD::FSQRT, which is then sometimes legalized into libm_sqrt, which may set errno. It's true that according to the langref as it exists you shouldn't write sqrt speculate-and-select, but as Sanjoy said, we mark sqrt as safe-to-speculate, so, who knows what the optimizer may do.
> If we're going to ignore the problem, at least get rid of the "(which allows for better optimization, because there is no need to worry about errno being set)" bit.
More information about the llvm-commits