[PATCH] D51630: [DAGCombiner] try to convert pow(x, 0.25) to sqrt(sqrt(x))

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 4 07:23:07 PDT 2018


spatel created this revision.
spatel added reviewers: lebedev.ri, efriedma, fhahn, evandro.
Herald added a subscriber: mcrosier.
Herald added a reviewer: javed.absar.

This was proposed as an IR transform in https://reviews.llvm.org/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. I noted the potential enhancements that I imagined with 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).

A follow-on patch can extend this to handle the other pattern that we deferred: pow(x,1.3) --> cbrt. But that requires a bit more work because we don't currently have a FCBRT DAG node defined.


https://reviews.llvm.org/D51630

Files:
  lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  test/CodeGen/AArch64/pow.ll
  test/CodeGen/X86/pow.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51630.163805.patch
Type: text/x-patch
Size: 12653 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180904/112cb9ff/attachment.bin>


More information about the llvm-commits mailing list