[PATCH] D129167: [AggressiveInstCombine] convert sqrt libcalls with "nnan" to sqrt intrinsics

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 5 19:22:05 PDT 2022


spatel created this revision.
spatel added reviewers: efriedma, fhahn, 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.

This is an alternate to D129155 <https://reviews.llvm.org/D129155> that uses TTI.haveFastSqrt() to avoid a potential miscompile for programs with reads of errno. Moving the transform to AggressiveInstCombine provides access to TTI.

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 and the call can be lowered without a libcall, then we can assume that errno accesses are unchanged after lowering, so the call can be translated to the LLVM intrinsic (which is expected to become inline code).

This affects codegen for targets like x86 that have sqrt instructions, but 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> and issue #56383 <https://github.com/llvm/llvm-project/issues/56383>.

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/D129167

Files:
  llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
  llvm/test/Transforms/AggressiveInstCombine/X86/sqrt.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129167.442424.patch
Type: text/x-patch
Size: 5682 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220706/d0e4d2bb/attachment.bin>


More information about the llvm-commits mailing list