]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/116352 - amend previous fix
authorRichard Biener <rguenther@suse.de>
Thu, 8 May 2025 08:56:16 +0000 (10:56 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 8 May 2025 10:59:02 +0000 (12:59 +0200)
The previous fix restricted external vector builds to defs from
the same basic-block.  That turns out too restrictive so we have
to mitigate the original issue in a different way which is
restricting it to the original case where all defs are in the
same basic-block.

PR tree-optimization/116352
* tree-vect-slp.cc (vect_build_slp_tree_2): When compressing
operands from a two-operator node make sure the resulting
operation does not mix defs from different basic-blocks.

gcc/tree-vect-slp.cc

index 80e9c010b1a10bb554dd34043511502543d6e1c6..2774fd23dfa727224f799b777e4129093b4dcb5c 100644 (file)
@@ -2617,13 +2617,14 @@ out:
       if (oprnds_info[0]->def_stmts[0]
          && is_a<gassign *> (oprnds_info[0]->def_stmts[0]->stmt))
        code = gimple_assign_rhs_code (oprnds_info[0]->def_stmts[0]->stmt);
+      basic_block bb = nullptr;
 
       for (unsigned j = 0; j < group_size; ++j)
        {
          FOR_EACH_VEC_ELT (oprnds_info, i, oprnd_info)
            {
              stmt_vec_info stmt_info = oprnd_info->def_stmts[j];
-             if (!stmt_info || !stmt_info->stmt
+             if (!stmt_info
                  || !is_a<gassign *> (stmt_info->stmt)
                  || gimple_assign_rhs_code (stmt_info->stmt) != code
                  || skip_args[i])
@@ -2631,6 +2632,14 @@ out:
                  success = false;
                  break;
                }
+             /* Avoid mixing lanes with defs in different basic-blocks.  */
+             if (!bb)
+               bb = gimple_bb (vect_orig_stmt (stmt_info)->stmt);
+             else if (gimple_bb (vect_orig_stmt (stmt_info)->stmt) != bb)
+               {
+                 success = false;
+                 break;
+               }
 
              bool exists;
              unsigned &stmt_idx