OSDN Git Service

[DAGCombiner] try to convert pow(x, 0.25) to sqrt(sqrt(x))
authorSanjay Patel <spatel@rotateright.com>
Wed, 5 Sep 2018 17:01:56 +0000 (17:01 +0000)
committerSanjay Patel <spatel@rotateright.com>
Wed, 5 Sep 2018 17:01:56 +0000 (17:01 +0000)
commit39f79ecf00ea66888786e9325036dde02af1944b
tree67170af17c895e960f957297e9ba2549b613d16d
parent3fcb1c02a5d44f867e058194e581a7f80ac09967
[DAGCombiner] try to convert pow(x, 0.25) to sqrt(sqrt(x))

This was proposed as an IR transform in D49306, but it was not clearly justifiable as a canonicalization.
Here, we only do the transform when the target tells us that sqrt can be lowered with inline code.

This is the basic case. Some potential enhancements are in the TODO comments:

1. Generalize the transform for other exponents (allow more than 2 sqrt calcs if that's really cheaper).
2. If we have less fast-math-flags, generate code to avoid -0.0 and/or INF.
3. Allow the transform when optimizing/minimizing size (might require a target hook to get that right).

Note that by default, x86 converts single-precision sqrt calcs into sqrt reciprocal estimate with
refinement. That codegen is controlled by CPU attributes and can be manually overridden. We have plenty
of test coverage for that already, so I didn't bother to include extra testing for that here. AArch uses
its full-precision ops in all cases (not sure if that's the intended behavior or not, but that should
also be covered by existing tests).

Differential Revision: https://reviews.llvm.org/D51630

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@341481 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
test/CodeGen/AArch64/pow.ll
test/CodeGen/ARM/pow.ll [new file with mode: 0644]
test/CodeGen/X86/pow.ll