OSDN Git Service

Improve sqrt estimate algorithm (fast-math)
authorSanjay Patel <spatel@rotateright.com>
Thu, 9 Oct 2014 21:26:35 +0000 (21:26 +0000)
committerSanjay Patel <spatel@rotateright.com>
Thu, 9 Oct 2014 21:26:35 +0000 (21:26 +0000)
commita4554c28976480cda89d72313cc717140d11ce6c
treec2e73e3ad30881ca9733a6d2f400bac96fe0698e
parentc3d3f63e748a5c8eba0da5dc7ea54007dba07f37
Improve sqrt estimate algorithm (fast-math)

This patch changes the fast-math implementation for calculating sqrt(x) from:
y = 1 / (1 / sqrt(x))
to:
y = x * (1 / sqrt(x))

This has 2 benefits: less code / faster code and one less estimate instruction
that may lose precision.

The only target that will be affected (until http://reviews.llvm.org/D5658 is approved)
is PPC. The difference in codegen for PPC is 2 less flops for a single-precision sqrtf
or vector sqrtf and 4 less flops for a double-precision sqrt.
We also eliminate a constant load and extra register usage.

Differential Revision: http://reviews.llvm.org/D5682

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219445 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
test/CodeGen/PowerPC/recipest.ll