OSDN Git Service

fold: sqrt(x * x * y) -> fabs(x) * sqrt(y)
authorSanjay Patel <spatel@rotateright.com>
Thu, 16 Oct 2014 18:48:17 +0000 (18:48 +0000)
committerSanjay Patel <spatel@rotateright.com>
Thu, 16 Oct 2014 18:48:17 +0000 (18:48 +0000)
commitd8214db0868f228026fa6ab1d5ca6c76ab3b5ce0
tree9a0219a80b29a43aa3dc5ea1a88a31edf02d0132
parentc40dab20691fd33f49715104ea7182d3ce14d2b2
fold: sqrt(x * x * y) -> fabs(x) * sqrt(y)

If a square root call has an FP multiplication argument that can be reassociated,
then we can hoist a repeated factor out of the square root call and into a fabs().

In the simplest case, this:

   y = sqrt(x * x);

becomes this:

   y = fabs(x);

This patch relies on an earlier optimization in instcombine or reassociate to put the
multiplication tree into a canonical form, so we don't have to search over
every permutation of the multiplication tree.

Because there are no IR-level FastMathFlags for intrinsics (PR21290), we have to
use function-level attributes to do this optimization. This needs to be fixed
for both the intrinsics and in the backend.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219944 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Transforms/Utils/SimplifyLibCalls.h
lib/Transforms/Utils/SimplifyLibCalls.cpp
test/Transforms/InstCombine/fast-math.ll