[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)
commitdbf52837fea5b9588f69632d5e067fa3e323de97
tree609aca6333e43ff014770bcce3a60d0287350c80
parent3daf3e707234309889a5c8b484c66ac2be0f7a45
[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

llvm-svn: 341481
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/AArch64/pow.ll
llvm/test/CodeGen/ARM/pow.ll [new file with mode: 0644]
llvm/test/CodeGen/X86/pow.ll