]> git.ipfire.org Git - thirdparty/gcc.git/commit
Match: Fold pow calls to ldexp when possible [PR57492]
authorSoumya AR <soumyaa@nvidia.com>
Wed, 13 Nov 2024 10:11:15 +0000 (15:41 +0530)
committerSoumya AR <soumyaa@nvidia.com>
Wed, 13 Nov 2024 10:12:16 +0000 (15:42 +0530)
commit5a674367c6da870184f3bdb7ec110b96aa91bb2b
tree3ee3e8897e1258031017435899025a44ed9237f7
parentf42f8dcf495e0a17df95a71c6a91093532cb9f3b
Match: Fold pow calls to ldexp when possible [PR57492]

This patch transforms the following POW calls to equivalent LDEXP calls, as
discussed in PR57492:

powi (powof2, i) -> ldexp (1.0, i * log2 (powof2))

powof2 * ldexp (x, i) -> ldexp (x, i + log2 (powof2))

a * ldexp(1., i) -> ldexp (a, i)

This is especially helpful for SVE architectures as LDEXP calls can be
implemented using the FSCALE instruction, as seen in the following patch:
https://gcc.gnu.org/g:9b2915d95d855333d4d8f66b71a75f653ee0d076

SPEC2017 was run with this patch, while there are no noticeable improvements,
there are no non-noise regressions either.

The patch was bootstrapped and regtested on aarch64-linux-gnu, no regression.

Signed-off-by: Soumya AR <soumyaa@nvidia.com>
gcc/ChangeLog:
PR target/57492
* match.pd: Added patterns to fold calls to pow to ldexp and optimize
specific ldexp calls.

gcc/testsuite/ChangeLog:
PR target/57492
* gcc.dg/tree-ssa/ldexp.c: New test.
* gcc.dg/tree-ssa/pow-to-ldexp.c: New test.
gcc/match.pd
gcc/testsuite/gcc.dg/tree-ssa/ldexp.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pow-to-ldexp.c [new file with mode: 0644]