aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2023-03-29 08:33:30 +0200
committerJakub Jelinek <jakub@redhat.com>2023-03-29 08:37:48 +0200
commit8dd57939c20b5e218404a838f514429f8e414dea (patch)
tree8d0bcdff7ce8588399da07ad56a6d6d1793b0095
parentc9954996cd647daf0ba03e34dd279b97982f671f (diff)
downloadgcc-8dd57939c20b5e218404a838f514429f8e414dea.zip
gcc-8dd57939c20b5e218404a838f514429f8e414dea.tar.gz
gcc-8dd57939c20b5e218404a838f514429f8e414dea.tar.bz2
tree-ssa-math-opts: Move PROP_gimple_opt_math from sincos pass to powcabs [PR109301]
The following testcase ICEs since the sincos and vect pass order has been swapped. It is not valid to replace vector sqrt (sqrt (x)) with pow (x, 0.25) because build_real on vector type is invalid (could be handled by using build_uniform_cst and adjusting type passed to build_real) but more importantly because nothing checks if we can actually do vector pow. While we have pow_optab, apparently no target defines it, so it doesn't seem to be worth bothering with for now and the patch just punts on non-scalar sqrts. I think the other simplifications next to it are fine, as they mostly use CBRT which doesn't even have internal function (so is a builtin only and therefore always scalar), or have already pow in the IL (which doesn't have optab and shouldn't be thus vector either). It is true that with <bits/math-vector.h> we do vectorize some calls to pow or cbrt (but don't handle others strangely), but those aren't using internal functions but simd clones and so match.pd doesn't know anything about those (at least for now). The following patch fixes it by mostly restoring the state before r13-1763 where canonicalize_math_p () was true only until the end of the pass which transformed pow or pow-like calls before vectorization (formerly sincos pass, now it is powcabs pass). powcabs is a pass in the spot sincos was happening before, so the only change was defer the sin+cos simplification into cexpi to a later new pass (except for the name moving with it) and none of the canonicalize_math_p () guarded simplification in match.pd seem to rely on those sin+cos -> cexpi simplifications and canonicalize_math_p is the only user of this property. 2023-03-29 Jakub Jelinek <jakub@redhat.com> Richard Biener <rguenther@suse.de> PR tree-optimization/109301 * tree-ssa-math-opts.cc (pass_data_cse_sincos): Change properties_provided from PROP_gimple_opt_math to 0. (pass_data_expand_powcabs): Change properties_provided from 0 to PROP_gimple_opt_math. * gcc.dg/pr109301.c: New test.
-rw-r--r--gcc/testsuite/gcc.dg/pr109301.c13
-rw-r--r--gcc/tree-ssa-math-opts.cc4
2 files changed, 15 insertions, 2 deletions
diff --git a/gcc/testsuite/gcc.dg/pr109301.c b/gcc/testsuite/gcc.dg/pr109301.c
new file mode 100644
index 0000000..ab26ea6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr109301.c
@@ -0,0 +1,13 @@
+/* PR tree-optimization/109301 */
+/* { dg-do compile } */
+/* { dg-options "-O3 -ffast-math" } */
+
+double x[256];
+
+void
+foo (void)
+{
+ for (int i = 0; i < 256; ++i)
+ for (int j = 0; j < 8; ++j)
+ x[i] = __builtin_pow (x[i], 0.5);
+}
diff --git a/gcc/tree-ssa-math-opts.cc b/gcc/tree-ssa-math-opts.cc
index 26ed91d..15eed3e 100644
--- a/gcc/tree-ssa-math-opts.cc
+++ b/gcc/tree-ssa-math-opts.cc
@@ -2237,7 +2237,7 @@ const pass_data pass_data_cse_sincos =
OPTGROUP_NONE, /* optinfo_flags */
TV_TREE_SINCOS, /* tv_id */
PROP_ssa, /* properties_required */
- PROP_gimple_opt_math, /* properties_provided */
+ 0, /* properties_provided */
0, /* properties_destroyed */
0, /* todo_flags_start */
TODO_update_ssa, /* todo_flags_finish */
@@ -2331,7 +2331,7 @@ const pass_data pass_data_expand_powcabs =
OPTGROUP_NONE, /* optinfo_flags */
TV_TREE_POWCABS, /* tv_id */
PROP_ssa, /* properties_required */
- 0, /* properties_provided */
+ PROP_gimple_opt_math, /* properties_provided */
0, /* properties_destroyed */
0, /* todo_flags_start */
TODO_update_ssa, /* todo_flags_finish */