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 r12-7816] tree-optimization/105053 - fix reduction chain epilogue generation
Date: Fri, 25 Mar 2022 14:26:41 +0000 (GMT)	[thread overview]
Message-ID: <20220325142641.CF0E1383F862@sourceware.org> (raw)

https://gcc.gnu.org/g:fe705dce2e1e3e4e5e0c69d7f9adaf7f2777cdc8

commit r12-7816-gfe705dce2e1e3e4e5e0c69d7f9adaf7f2777cdc8
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Mar 25 14:31:25 2022 +0100

    tree-optimization/105053 - fix reduction chain epilogue generation
    
    When we optimize permutations in a reduction chain we have to
    be careful to select the correct live-out stmt, otherwise the
    reduction result will be unused and the retained scalar code will
    execute only the number of vector iterations.
    
    2022-03-25  Richard Biener  <rguenther@suse.de>
    
            PR tree-optimization/105053
            * tree-vect-loop.cc (vect_create_epilog_for_reduction): Pick
            the correct live-out stmt for a reduction chain.
    
            * g++.dg/vect/pr105053.cc: New testcase.

Diff:
---
 gcc/testsuite/g++.dg/vect/pr105053.cc | 25 +++++++++++++++++++++++++
 gcc/tree-vect-loop.cc                 | 14 +++++++++++---
 2 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/g++.dg/vect/pr105053.cc b/gcc/testsuite/g++.dg/vect/pr105053.cc
new file mode 100644
index 00000000000..6deef8458fc
--- /dev/null
+++ b/gcc/testsuite/g++.dg/vect/pr105053.cc
@@ -0,0 +1,25 @@
+// { dg-require-effective-target c++11 }
+// { dg-require-effective-target int32plus }
+
+#include <vector>
+#include <tuple>
+#include <algorithm>
+
+int main()
+{
+  const int n = 4;
+  std::vector<std::tuple<int,int,double>> vec
+      = { { 1597201307, 1817606674, 0. },
+            { 1380347796, 1721941769, 0.},
+            {837975613, 1032707773, 0.},
+            {1173654292, 2020064272, 0.} } ;
+  int sup1 = 0;
+  for(int i=0;i<n;++i)
+    sup1=std::max(sup1,std::max(std::get<0>(vec[i]),std::get<1>(vec[i])));
+  int sup2 = 0;
+  for(int i=0;i<n;++i)
+    sup2=std::max(std::max(sup2,std::get<0>(vec[i])),std::get<1>(vec[i]));
+  if (sup1 != sup2)
+    std::abort ();
+  return 0;
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 7a74633e0b4..d7bc34636bd 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -5271,9 +5271,17 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo,
     /* All statements produce live-out values.  */
     live_out_stmts = SLP_TREE_SCALAR_STMTS (slp_node);
   else if (slp_node)
-    /* The last statement in the reduction chain produces the live-out
-       value.  */
-    single_live_out_stmt[0] = SLP_TREE_SCALAR_STMTS (slp_node)[group_size - 1];
+    {
+      /* The last statement in the reduction chain produces the live-out
+	 value.  Note SLP optimization can shuffle scalar stmts to
+	 optimize permutations so we have to search for the last stmt.  */
+      for (k = 0; k < group_size; ++k)
+	if (!REDUC_GROUP_NEXT_ELEMENT (SLP_TREE_SCALAR_STMTS (slp_node)[k]))
+	  {
+	    single_live_out_stmt[0] = SLP_TREE_SCALAR_STMTS (slp_node)[k];
+	    break;
+	  }
+    }
 
   unsigned vec_num;
   int ncopies;


                 reply	other threads:[~2022-03-25 14:26 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=20220325142641.CF0E1383F862@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: link
Be 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).