]> granicus.if.org Git - llvm/commit
[ConstantFolding] Constant-fold llvm.sqrt(x) like other intrinsics.
authorJustin Lebar <jlebar@google.com>
Sat, 21 Jan 2017 00:59:57 +0000 (00:59 +0000)
committerJustin Lebar <jlebar@google.com>
Sat, 21 Jan 2017 00:59:57 +0000 (00:59 +0000)
commit12044b3dd7855fd39334ac5321645b27c6c7b49e
treef0bdced63b683dcaa54e832f78dcb541dea4d19b
parent858476981f21a5e8b19789d8158b7653e3bba404
[ConstantFolding] Constant-fold llvm.sqrt(x) like other intrinsics.

Summary:
Currently we return undef, but we're in the process of changing the
LangRef so that llvm.sqrt behaves like the other math intrinsics,
matching the return value of the standard libcall but not setting errno.

This change is legal even without the LangRef change because currently
calling llvm.sqrt(x) where x is negative is spec'ed to be UB.  But in
practice it's also safe because we're simply constant-folding fewer
inputs: Inputs >= -0 get constant-folded as before, but inputs < -0 now
aren't constant-folded, because ConstantFoldFP aborts if the host math
function raises an fp exception.

Reviewers: hfinkel, efriedma, sanjoy

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D28929

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292692 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Analysis/ConstantFolding.cpp
test/Transforms/InstCombine/constant-fold-math.ll