[PATCH] D129155: [InstCombine][SimplifyLibCalls] convert sqrt libcalls with "nnan" to sqrt intrinsics
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 5 11:00:56 PDT 2022
spatel created this revision.
spatel added reviewers: fhahn, efriedma, nikic.
Herald added subscribers: jsji, pengfei, hiraditya, mcrosier.
Herald added a project: All.
spatel requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
If a sqrt call has "nnan", that implies that the input argument is never negative because sqrt of {negative number} --> NAN.
If the argument is never negative, then we can assume that errno is not written, so the call can be translated to the LLVM intrinsic.
This affects codegen for targets like x86 that have a sqrt instruction, but we still have to conservatively assume that a libcall may be needed to set errno as shown in issue #52620 <https://github.com/llvm/llvm-project/issues/52620>.
This patch won't solve that example - we will need to extend this to use `CannotBeOrderedLessThanZero` or similar, enhance that analysis for new operators, and deal with `llvm.assume` too.
https://reviews.llvm.org/D129155
Files:
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/test/Transforms/InstCombine/pow-4.ll
llvm/test/Transforms/InstCombine/pow-sqrt.ll
llvm/test/Transforms/InstCombine/sqrt.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129155.442353.patch
Type: text/x-patch
Size: 6814 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220705/c2efd18c/attachment.bin>
More information about the llvm-commits
mailing list