diff options
author | Jakub Jelinek <jakub@redhat.com> | 2021-01-11 10:35:10 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2021-01-11 10:36:24 +0100 |
commit | 9a6c37e6ae520534993ef76dd45d016c8c86db21 (patch) | |
tree | d0035483cb49261a3fcdf2b3122adb700f585f7d /gcc/tree-ssa-math-opts.c | |
parent | 9febe9e4be7812519258ea3ed4f38bbc1a61624b (diff) | |
download | gcc-9a6c37e6ae520534993ef76dd45d016c8c86db21.zip gcc-9a6c37e6ae520534993ef76dd45d016c8c86db21.tar.gz gcc-9a6c37e6ae520534993ef76dd45d016c8c86db21.tar.bz2 |
reassoc: Reassociate integral multiplies [PR95867]
For floating point multiply, we have nice code in reassoc to reassociate
multiplications to almost optimal sequence of as few multiplications as
possible (or library call), but for integral types we just give up
because there is no __builtin_powi* for those types.
As there is no library routine we could use, instead of adding new internal
call just to hold it temporarily and then lower to multiplications again,
this patch for the integral types calls into the sincos pass routine that
expands it into multiplications right away.
2021-01-11 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/95867
* tree-ssa-math-opts.h: New header.
* tree-ssa-math-opts.c: Include tree-ssa-math-opts.h.
(powi_as_mults): No longer static. Use build_one_cst instead of
build_real. Formatting fix.
* tree-ssa-reassoc.c: Include tree-ssa-math-opts.h.
(attempt_builtin_powi): Handle multiplication reassociation without
powi_fndecl using powi_as_mults.
(reassociate_bb): For integral types don't require
-funsafe-math-optimizations to call attempt_builtin_powi.
* gcc.dg/tree-ssa/pr95867.c: New test.
Diffstat (limited to 'gcc/tree-ssa-math-opts.c')
-rw-r--r-- | gcc/tree-ssa-math-opts.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c index 91ec0f6..74a16b6 100644 --- a/gcc/tree-ssa-math-opts.c +++ b/gcc/tree-ssa-math-opts.c @@ -115,6 +115,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-eh.h" #include "targhooks.h" #include "domwalk.h" +#include "tree-ssa-math-opts.h" /* This structure represents one basic block that either computes a division, or is a common dominator for basic block that compute a @@ -1527,7 +1528,7 @@ powi_as_mults_1 (gimple_stmt_iterator *gsi, location_t loc, tree type, /* Convert ARG0**N to a tree of multiplications of ARG0 with itself. This function needs to be kept in sync with powi_cost above. */ -static tree +tree powi_as_mults (gimple_stmt_iterator *gsi, location_t loc, tree arg0, HOST_WIDE_INT n) { @@ -1536,9 +1537,9 @@ powi_as_mults (gimple_stmt_iterator *gsi, location_t loc, tree target; if (n == 0) - return build_real (type, dconst1); + return build_one_cst (type); - memset (cache, 0, sizeof (cache)); + memset (cache, 0, sizeof (cache)); cache[1] = arg0; result = powi_as_mults_1 (gsi, loc, type, (n < 0) ? -n : n, cache); |