]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/125088 - some TLC to the new vect_bb_slp_scalar_cost
authorRichard Biener <rguenther@suse.de>
Thu, 30 Apr 2026 06:39:52 +0000 (08:39 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 30 Apr 2026 10:44:13 +0000 (12:44 +0200)
This realizes that orig_stmt_info == stmt and refactors control flow
around cost recording to avoid the do { } while (false); loop which
had continue stmts confusing coverity.

PR tree-optimization/125088
* tree-vect-slp.cc (vect_bb_slp_scalar_cost): Refactor and
simplify.
* tree-vect-stmts.cc (vect_nop_conversion_p): Exclude
copies with memory accesses.

gcc/tree-vect-slp.cc
gcc/tree-vect-stmts.cc

index 00bb891fccb252a2db3aa8170b4d7f2ab99c22dc..17b8dc5b9dc2eef1da0551afd2164d152a4ed1a7 100644 (file)
@@ -9454,15 +9454,21 @@ vect_bb_slp_scalar_cost (bb_vec_info vinfo,
 
       gcc_assert (!gimple_visited_p (stmt->stmt));
 
-      gcc_assert (vect_orig_stmt (stmt) == stmt);
-      stmt_vec_info orig_stmt_info = stmt;
-
-      do
+      if (vect_nop_conversion_p (stmt))
+       ;
+      /* For single-argument PHIs assume coalescing which means zero
+        cost for the scalar and the vector PHIs.  This avoids
+        artificially favoring the vector path (but may pessimize it
+        in some cases).  */
+      else if (is_a <gphi *> (stmt->stmt)
+              && gimple_phi_num_args (as_a <gphi *> (stmt->stmt)) == 1)
+       ;
+      else
        {
          vect_cost_for_stmt kind;
-         if (STMT_VINFO_DATA_REF (orig_stmt_info))
+         if (STMT_VINFO_DATA_REF (stmt))
            {
-             data_reference_p dr = STMT_VINFO_DATA_REF (orig_stmt_info);
+             data_reference_p dr = STMT_VINFO_DATA_REF (stmt);
              tree base = get_base_address (DR_REF (dr));
              /* When the scalar access is to a non-global not
                 address-taken decl that is not BLKmode assume we can
@@ -9472,27 +9478,17 @@ vect_bb_slp_scalar_cost (bb_vec_info vinfo,
                  && !TREE_ADDRESSABLE (base)
                  && DECL_MODE (base) != BLKmode)
                kind = scalar_stmt;
-             else if (DR_IS_READ (STMT_VINFO_DATA_REF (orig_stmt_info)))
+             else if (DR_IS_READ (STMT_VINFO_DATA_REF (stmt)))
                kind = scalar_load;
              else
                kind = scalar_store;
            }
-         else if (vect_nop_conversion_p (orig_stmt_info))
-           continue;
-         /* For single-argument PHIs assume coalescing which means zero
-            cost for the scalar and the vector PHIs.  This avoids
-            artificially favoring the vector path (but may pessimize it
-            in some cases).  */
-         else if (is_a <gphi *> (orig_stmt_info->stmt)
-                  && gimple_phi_num_args
-                  (as_a <gphi *> (orig_stmt_info->stmt)) == 1)
-           continue;
          else
            kind = scalar_stmt;
+         /* Cost each scalar stmt only once.  */
          gimple_set_visited (stmt->stmt, true);
-         record_stmt_cost (cost_vec, 1, kind, orig_stmt_info,
-                           NULL_TREE, 0, vect_body);
-       } while (false);
+         record_stmt_cost (cost_vec, 1, kind, stmt, NULL_TREE, 0, vect_body);
+       }
 
       /* Now walk relevant parts of the SSA use-def graph.  */
       slp_oprnds child_ops (stmt);
index 9328cb820f890ddeef5f933ee1cfbeef8227e342..32691f47eb7f3e006aee1d05300a09065924d0b6 100644 (file)
@@ -5935,7 +5935,7 @@ bool
 vect_nop_conversion_p (stmt_vec_info stmt_info)
 {
   gassign *stmt = dyn_cast <gassign *> (stmt_info->stmt);
-  if (!stmt)
+  if (!stmt || STMT_VINFO_DATA_REF (stmt_info))
     return false;
 
   tree lhs = gimple_assign_lhs (stmt);