Apply the InstCombine fptrunc sqrt optimization to llvm.sqrt
authorHal Finkel <hfinkel@anl.gov>
Sat, 16 Nov 2013 21:29:08 +0000 (21:29 +0000)
committerHal Finkel <hfinkel@anl.gov>
Sat, 16 Nov 2013 21:29:08 +0000 (21:29 +0000)
commit64fa501b1081b5d5c25e5e9639075abb0cb724d9
treea190f3ea48a03753cd6f44e382cf97464e79b63b
parente6e811277f045ee3d61cd62622d71005c47eb48d
Apply the InstCombine fptrunc sqrt optimization to llvm.sqrt

InstCombine, in visitFPTrunc, applies the following optimization to sqrt calls:

  (fptrunc (sqrt (fpext x))) -> (sqrtf x)

but does not apply the same optimization to llvm.sqrt. This is a problem
because, to enable vectorization, Clang generates llvm.sqrt instead of sqrt in
fast-math mode, and because this optimization is being applied to sqrt and not
applied to llvm.sqrt, sometimes the fast-math code is slower.

This change makes InstCombine apply this optimization to llvm.sqrt as well.

This fixes the specific problem in PR17758, although the same underlying issue
(optimizations applied to libcalls are not applied to intrinsics) exists for
other optimizations in SimplifyLibCalls.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194935 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineCasts.cpp
test/Transforms/InstCombine/double-float-shrink-1.ll