public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-9261] tree-optimization/103237 - avoid vectorizing unhandled double reductions Date: Mon, 22 Nov 2021 08:00:53 +0000 (GMT) [thread overview] Message-ID: <20211122080053.B51B83858424@sourceware.org> (raw) https://gcc.gnu.org/g:fb1bc2c0865f2b15a219e11270b5c5fca565e169 commit r11-9261-gfb1bc2c0865f2b15a219e11270b5c5fca565e169 Author: Richard Biener <rguenther@suse.de> Date: Mon Nov 15 11:37:56 2021 +0100 tree-optimization/103237 - avoid vectorizing unhandled double reductions Double reductions which have multiple LC PHIs in the inner loop are not handled correctly during transformation since those PHIs are not properly classified as reduction. The following disables vectorizing them. 2021-11-15 Richard Biener <rguenther@suse.de> PR tree-optimization/103237 * tree-vect-loop.c (vect_is_simple_reduction): Fail for double reductions with multiple inner loop LC PHI nodes. * gcc.dg/torture/pr103237.c: New testcase. (cherry picked from commit 220bd61874cf114667b44f9ded76ed0639eb278b) Diff: --- gcc/testsuite/gcc.dg/torture/pr103237.c | 24 ++++++++++++++++++++++++ gcc/tree-vect-loop.c | 11 +++++++++++ 2 files changed, 35 insertions(+) diff --git a/gcc/testsuite/gcc.dg/torture/pr103237.c b/gcc/testsuite/gcc.dg/torture/pr103237.c new file mode 100644 index 00000000000..f2399f9586e --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr103237.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ +/* { dg-additional-options "-ftree-vectorize" } */ + +int g1; +unsigned int g2 = -1U; +static void __attribute__((noipa)) +func_1() +{ + int *l_1 = &g1; + for (int g3a = 0; g3a != 4; g3a++) + for (int l_2 = 0; l_2 <= 3; l_2++) + { + unsigned int *l_3 = &g2; + *l_1 = *l_3 ^= 1; + } +} +int +main() +{ + func_1(); + if (g1 != -1) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c index 4990504db43..e871df9d1a0 100644 --- a/gcc/tree-vect-loop.c +++ b/gcc/tree-vect-loop.c @@ -3638,6 +3638,17 @@ vect_is_simple_reduction (loop_vec_info loop_info, stmt_vec_info phi_info, return def_stmt_info; } + /* When the inner loop of a double reduction ends up with more than + one loop-closed PHI we have failed to classify alternate such + PHIs as double reduction, leading to wrong code. See PR103237. */ + if (inner_loop_of_double_reduc && lcphis.length () != 1) + { + if (dump_enabled_p ()) + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, + "unhandle double reduction\n"); + return NULL; + } + /* If this isn't a nested cycle or if the nested cycle reduction value is used ouside of the inner loop we cannot handle uses of the reduction value. */
reply other threads:[~2021-11-22 8:00 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20211122080053.B51B83858424@sourceware.org \ --to=rguenth@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).