public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-8880] middle-end: don't cache restart_loop in vectorizable_live_operations [PR113808]
@ 2024-02-08 10:44 Tamar Christina
  0 siblings, 0 replies; only message in thread
From: Tamar Christina @ 2024-02-08 10:44 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:3f69db1812106cb5bab203e17a60300ac51cdc68

commit r14-8880-g3f69db1812106cb5bab203e17a60300ac51cdc68
Author: Tamar Christina <tamar.christina@arm.com>
Date:   Thu Feb 8 10:43:13 2024 +0000

    middle-end: don't cache restart_loop in vectorizable_live_operations [PR113808]
    
    There's a bug in vectorizable_live_operation that restart_loop is defined
    outside the loop.
    
    This variable is supposed to indicate whether we are doing a first or last
    index reduction.  The problem is that by defining it outside the loop it becomes
    dependent on the order we visit the USE/DEFs.
    
    In the given example, the loop isn't PEELED, but we visit the early exit uses
    first.  This then sets the boolean to true and it can't get to false again.
    
    So when we visit the main exit we still treat it as an early exit for that
    SSA name.
    
    This cleans it up and renames the variables to something that's hopefully
    clearer to their intention.
    
    gcc/ChangeLog:
    
            PR tree-optimization/113808
            * tree-vect-loop.cc (vectorizable_live_operation): Don't cache the
            value cross iterations.
    
    gcc/testsuite/ChangeLog:
    
            PR tree-optimization/113808
            * gfortran.dg/vect/vect-early-break_1-PR113808.f90: New test.

Diff:
---
 .../vect/vect-early-break_1-PR113808.f90            | 21 +++++++++++++++++++++
 gcc/tree-vect-loop.cc                               |  5 ++---
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gfortran.dg/vect/vect-early-break_1-PR113808.f90 b/gcc/testsuite/gfortran.dg/vect/vect-early-break_1-PR113808.f90
new file mode 100644
index 000000000000..5c339fa7a348
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/vect/vect-early-break_1-PR113808.f90
@@ -0,0 +1,21 @@
+! { dg-add-options vect_early_break }
+! { dg-require-effective-target vect_early_break }
+! { dg-require-effective-target vect_long_long }
+! { dg-additional-options "-fopenmp-simd" }
+
+! { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" } }
+
+program main
+  integer :: n, i,k
+  n = 11
+  do i = 1, n,2
+    !$omp simd lastprivate(k)
+    do k = 1, i + 41
+      if (k > 11 + 41 .or. k < 1) error stop
+    end do
+  end do
+  if (k /= 53) then
+    print *, k, 53
+    error stop
+  endif
+end
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 190df9ec7741..eed2268e9bae 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -10950,7 +10950,7 @@ vectorizable_live_operation (vec_info *vinfo, stmt_vec_info stmt_info,
 	 did.  For the live values we want the value at the start of the iteration
 	 rather than at the end.  */
       edge main_e = LOOP_VINFO_IV_EXIT (loop_vinfo);
-      bool restart_loop = LOOP_VINFO_EARLY_BREAKS_VECT_PEELED (loop_vinfo);
+      bool all_exits_as_early_p = LOOP_VINFO_EARLY_BREAKS_VECT_PEELED (loop_vinfo);
       FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, lhs)
 	if (!is_gimple_debug (use_stmt)
 	    && !flow_bb_inside_loop_p (loop, gimple_bb (use_stmt)))
@@ -10966,8 +10966,7 @@ vectorizable_live_operation (vec_info *vinfo, stmt_vec_info stmt_info,
 	      /* For early exit where the exit is not in the BB that leads
 		 to the latch then we're restarting the iteration in the
 		 scalar loop.  So get the first live value.  */
-	      restart_loop = restart_loop || !main_exit_edge;
-	      if (restart_loop
+	      if ((all_exits_as_early_p || !main_exit_edge)
 		  && STMT_VINFO_DEF_TYPE (stmt_info) == vect_induction_def)
 		{
 		  tmp_vec_lhs = vec_lhs0;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-08 10:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-08 10:44 [gcc r14-8880] middle-end: don't cache restart_loop in vectorizable_live_operations [PR113808] Tamar Christina

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).