reassoc: Reassociate integral multiplies [PR95867]
authorJakub Jelinek <jakub@redhat.com>
Mon, 11 Jan 2021 09:35:10 +0000 (10:35 +0100)
committerJakub Jelinek <jakub@redhat.com>
Mon, 11 Jan 2021 09:36:24 +0000 (10:36 +0100)
commit9a6c37e6ae520534993ef76dd45d016c8c86db21
treed0035483cb49261a3fcdf2b3122adb700f585f7d
parent9febe9e4be7812519258ea3ed4f38bbc1a61624b
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.
gcc/testsuite/gcc.dg/tree-ssa/pr95867.c [new file with mode: 0644]
gcc/tree-ssa-math-opts.c
gcc/tree-ssa-math-opts.h [new file with mode: 0644]
gcc/tree-ssa-reassoc.c