]> git.ipfire.org Git - thirdparty/gcc.git/commit
match.pd: Fold logarithmic identities.
authorJennifer Schmitz <jschmitz@nvidia.com>
Wed, 25 Sep 2024 10:21:22 +0000 (03:21 -0700)
committerJennifer Schmitz <jschmitz@nvidia.com>
Fri, 11 Oct 2024 14:56:37 +0000 (16:56 +0200)
commit4be7d2d340a013d01a47c43d2feb6826d1b67af0
treecc320817624aa13bd9024e695fb915f5392bc54b
parent00a87ee76f47d0fa5a10ef982101cb3c3b8e9c99
match.pd: Fold logarithmic identities.

This patch implements 4 rules for logarithmic identities in match.pd
under -funsafe-math-optimizations:
1) logN(1.0/a) -> -logN(a). This avoids the division instruction.
2) logN(C/a) -> logN(C) - logN(a), where C is a real constant. Same as 1).
3) logN(a) + logN(b) -> logN(a*b). This reduces the number of calls to
log function.
4) logN(a) - logN(b) -> logN(a/b). Same as 4).
Tests were added for float, double, and long double.

The patch was bootstrapped and regtested on aarch64-linux-gnu and
x86_64-linux-gnu, no regression.
Additionally, SPEC 2017 fprate was run. While the transform does not seem
to be triggered, we also see no non-noise impact on performance.
OK for mainline?

Signed-off-by: Jennifer Schmitz <jschmitz@nvidia.com>
gcc/
PR tree-optimization/116826
PR tree-optimization/86710
* match.pd: Fold logN(1.0/a) -> -logN(a),
logN(C/a) -> logN(C) - logN(a), logN(a) + logN(b) -> logN(a*b),
and logN(a) - logN(b) -> logN(a/b).

gcc/testsuite/
PR tree-optimization/116826
PR tree-optimization/86710
* gcc.dg/tree-ssa/log_ident.c: New test.
gcc/match.pd
gcc/testsuite/gcc.dg/tree-ssa/log_ident.c [new file with mode: 0644]