]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix overly restrictive live-lane extraction replacement
authorRichard Biener <rguenther@suse.de>
Thu, 5 Mar 2026 10:39:38 +0000 (11:39 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 5 Mar 2026 13:34:15 +0000 (14:34 +0100)
The following fixes a regression introduced by r11-5542 which
restricts replacing uses of live original defs of now vectorized
stmts to when that does not require new loop-closed PHIs to be
inserted.  That restriction keeps the original scalar definition
live which is sub-optimal and also not reflected in costing.

The particular case the following fixes can be seen in
gcc.dg/vect/bb-slp-57.c is the case where we are replacing an
existing loop closed PHI argument.

PR tree-optimization/98064
* tree-vect-loop.cc (vectorizable_live_operation): Do
not restrict replacing uses in a LC PHI.

* gcc.dg/vect/bb-slp-57.c: Verify we do not keep original
stmts live.

gcc/testsuite/gcc.dg/vect/bb-slp-57.c
gcc/tree-vect-loop.cc

index 6f13507fd67e13babd21163c34b89582928d7234..6633a3092ad7d2f8aaf22f6dd2ef8b68219e81f7 100644 (file)
@@ -36,3 +36,4 @@ void l()
 
 /* { dg-final { scan-tree-dump-times "transform load" 1 "slp1" { target { { x86_64-*-* i?86-*-* } && lp64 } } } } */
 /* { dg-final { scan-tree-dump "optimized: basic block" "slp1" { target { { x86_64-*-* i?86-*-* } && lp64 } } } } */
+/* { dg-final { scan-tree-dump-not "missed: Using original scalar computation" "slp1" } } */
index 670a03ea06b35bd6f63c4386c766577a92086544..4818a8e88a19354d231a6862fdf1d5ece922d6a8 100644 (file)
@@ -10441,26 +10441,35 @@ vectorizable_live_operation (vec_info *vinfo, stmt_vec_info stmt_info,
                                   "def\n");
                continue;
              }
-           /* ???  It can also happen that we end up pulling a def into
-              a loop where replacing out-of-loop uses would require
-              a new LC SSA PHI node.  Retain the original scalar in
-              those cases as well.  PR98064.  */
-           if (TREE_CODE (new_tree) == SSA_NAME
-               && !SSA_NAME_IS_DEFAULT_DEF (new_tree)
-               && (gimple_bb (use_stmt)->loop_father
-                   != gimple_bb (vec_stmt)->loop_father)
-               && !flow_loop_nested_p (gimple_bb (vec_stmt)->loop_father,
-                                       gimple_bb (use_stmt)->loop_father))
+           FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
              {
-               if (dump_enabled_p ())
-                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
-                                  "Using original scalar computation for "
-                                  "live lane because there is an out-of-loop "
-                                  "definition for it\n");
-               continue;
+               /* ???  It can also happen that we end up pulling a def into
+                  a loop where replacing out-of-loop uses would require
+                  a new LC SSA PHI node.  Retain the original scalar in
+                  those cases as well.  PR98064.  */
+               edge e;
+               if (TREE_CODE (new_tree) == SSA_NAME
+                   && !SSA_NAME_IS_DEFAULT_DEF (new_tree)
+                   && (gimple_bb (use_stmt)->loop_father
+                       != gimple_bb (vec_stmt)->loop_father)
+                   /* But a replacemend in a LC PHI is OK.  This happens
+                      in gcc.dg/vect/bb-slp-57.c for example.  */
+                   && (gimple_code (use_stmt) != GIMPLE_PHI
+                       || (((e = phi_arg_edge_from_use (use_p)), true)
+                           && !loop_exit_edge_p
+                                 (gimple_bb (vec_stmt)->loop_father, e)))
+                   && !flow_loop_nested_p (gimple_bb (vec_stmt)->loop_father,
+                                           gimple_bb (use_stmt)->loop_father))
+                 {
+                   if (dump_enabled_p ())
+                     dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+                                      "Using original scalar computation for "
+                                      "live lane because there is an "
+                                      "out-of-loop definition for it\n");
+                   continue;
+                 }
+               SET_USE (use_p, new_tree);
              }
-           FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
-             SET_USE (use_p, new_tree);
            update_stmt (use_stmt);
          }
     }