summaryrefslogtreecommitdiffstats
path: root/llvm/docs
diff options
context:
space:
mode:
authorJustin Lebar <jlebar@google.com>2017-01-27 00:58:03 +0000
committerJustin Lebar <jlebar@google.com>2017-01-27 00:58:03 +0000
commitcb9b41dd767ceaa40b8d76b06658b96f299492a0 (patch)
tree2c5ec0c6ef22eacb35c02558a7d91a546b27634b /llvm/docs
parenta95ff3892495d1b4cfe6cc3e5d3f014acefb7c76 (diff)
downloadbcm5719-llvm-cb9b41dd767ceaa40b8d76b06658b96f299492a0.tar.gz
bcm5719-llvm-cb9b41dd767ceaa40b8d76b06658b96f299492a0.zip
[LangRef] Make @llvm.sqrt(x) return undef, rather than have UB, for negative x.
Summary: Some frontends emit a speculate-and-select idiom for sqrt, wherein they compute sqrt(x), check if x is negative, and select NaN if it is: %cmp = fcmp olt double %a, -0.000000e+00 %sqrt = call double @llvm.sqrt.f64(double %a) %ret = select i1 %cmp, double 0x7FF8000000000000, double %sqrt This is technically UB as the LangRef is written today if %a is ever less than -0. But emitting code that's compliant with the current definition of sqrt would require a branch, which would then prevent us from matching this idiom in SelectionDAG (which we do today -- ISD::FSQRT has defined behavior on negative inputs), because SelectionDAG looks at one BB at a time. 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. Reviewers: arsenm, mehdi_amini, hfinkel Subscribers: wdng, llvm-commits Differential Revision: https://reviews.llvm.org/D28797 llvm-svn: 293242
Diffstat (limited to 'llvm/docs')
-rw-r--r--llvm/docs/LangRef.rst7
1 files changed, 2 insertions, 5 deletions
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 4d51614672c..550e86b0502 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -10076,11 +10076,8 @@ Overview:
"""""""""
The '``llvm.sqrt``' intrinsics return the sqrt of the specified operand,
-returning the same value as the libm '``sqrt``' functions would. Unlike
-``sqrt`` in libm, however, ``llvm.sqrt`` has undefined behavior for
-negative numbers other than -0.0 (which allows for better optimization,
-because there is no need to worry about errno being set).
-``llvm.sqrt(-0.0)`` is defined to return -0.0 like IEEE sqrt.
+returning the same value as the libm '``sqrt``' functions would, but without
+trapping or setting ``errno``.
Arguments:
""""""""""
OpenPOWER on IntegriCloud