https://gcc.gnu.org/g:446aac86a4bbdf38868c64410cb0e7823299f98a

commit r16-2748-g446aac86a4bbdf38868c64410cb0e7823299f98a
Author: Richard Biener <rguent...@suse.de>
Date:   Mon Aug 4 13:29:16 2025 +0200

    Fail early when SLP instance build fails
    
    The following makes us fail earlier when parts of the SLP build fails.
    Currently we rely on hybrid stmt detection later to discover not all
    stmts are covered by SLP, but this code should go away.  I've also
    seen a case of a missed gcond SLP build that went undetected.  So
    the following makes us fail during vect_analyze_slp if any of the
    SLP instances we expect to discover fails.
    
            * tree-vect-slp.cc (vect_analyze_slp): When analyzing a loop
            and slp instance discovery fails, immediately fail the whole
            process.

Diff:
---
 gcc/tree-vect-slp.cc | 88 +++++++++++++++++++++++++++++++++-------------------
 1 file changed, 56 insertions(+), 32 deletions(-)

diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index ca14a2deed2b..3f3a509ff301 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -4888,9 +4888,11 @@ vect_analyze_slp (vec_info *vinfo, unsigned 
max_tree_size,
 
   /* Find SLP sequences starting from groups of grouped stores.  */
   FOR_EACH_VEC_ELT (vinfo->grouped_stores, i, first_element)
-    vect_analyze_slp_instance (vinfo, bst_map, first_element,
-                              slp_inst_kind_store, max_tree_size, &limit,
-                              force_single_lane);
+    if (! vect_analyze_slp_instance (vinfo, bst_map, first_element,
+                                    slp_inst_kind_store, max_tree_size, &limit,
+                                    force_single_lane)
+       && loop_vinfo)
+      return opt_result::failure_at (vect_location, "SLP build failed.\n");
 
   /* For loops also start SLP discovery from non-grouped stores.  */
   if (loop_vinfo)
@@ -4908,9 +4910,12 @@ vect_analyze_slp (vec_info *vinfo, unsigned 
max_tree_size,
            vec<tree> remain = vNULL;
            stmts.create (1);
            stmts.quick_push (stmt_info);
-           vect_build_slp_instance (vinfo, slp_inst_kind_store,
-                                    stmts, roots, remain, max_tree_size,
-                                    &limit, bst_map, NULL, force_single_lane);
+           if (! vect_build_slp_instance (vinfo, slp_inst_kind_store,
+                                          stmts, roots, remain, max_tree_size,
+                                          &limit, bst_map, NULL,
+                                          force_single_lane))
+             return opt_result::failure_at (vect_location,
+                                            "SLP build failed.\n");
          }
     }
 
@@ -5002,12 +5007,14 @@ vect_analyze_slp (vec_info *vinfo, unsigned 
max_tree_size,
                      vec<tree> remain = vNULL;
                      stmts.create (1);
                      stmts.quick_push (next_info);
-                     vect_build_slp_instance (vinfo,
-                                              slp_inst_kind_reduc_group,
-                                              stmts, roots, remain,
-                                              max_tree_size, &limit,
-                                              bst_map, NULL,
-                                              force_single_lane);
+                     if (! vect_build_slp_instance (vinfo,
+                                                    slp_inst_kind_reduc_group,
+                                                    stmts, roots, remain,
+                                                    max_tree_size, &limit,
+                                                    bst_map, NULL,
+                                                    force_single_lane))
+                       return opt_result::failure_at (vect_location,
+                                                      "SLP build failed.\n");
                    }
                }
            }
@@ -5032,11 +5039,14 @@ vect_analyze_slp (vec_info *vinfo, unsigned 
max_tree_size,
                  vec<tree> remain = vNULL;
                  stmts.create (1);
                  stmts.quick_push (vect_stmt_to_vectorize (stmt_info));
-                 vect_build_slp_instance (vinfo,
-                                          slp_inst_kind_reduc_group,
-                                          stmts, roots, remain,
-                                          max_tree_size, &limit,
-                                          bst_map, NULL, force_single_lane);
+                 if (! vect_build_slp_instance (vinfo,
+                                                slp_inst_kind_reduc_group,
+                                                stmts, roots, remain,
+                                                max_tree_size, &limit,
+                                                bst_map, NULL,
+                                                force_single_lane))
+                   return opt_result::failure_at (vect_location,
+                                                  "SLP build failed.\n");
                }
            }
          saved_stmts.release ();
@@ -5065,11 +5075,14 @@ vect_analyze_slp (vec_info *vinfo, unsigned 
max_tree_size,
                vec<tree> remain = vNULL;
                stmts.create (1);
                stmts.quick_push (vect_stmt_to_vectorize (stmt_info));
-               vect_build_slp_instance (vinfo,
-                                        slp_inst_kind_reduc_group,
-                                        stmts, roots, remain,
-                                        max_tree_size, &limit,
-                                        bst_map, NULL, force_single_lane);
+               if (! vect_build_slp_instance (vinfo,
+                                              slp_inst_kind_reduc_group,
+                                              stmts, roots, remain,
+                                              max_tree_size, &limit,
+                                              bst_map, NULL,
+                                              force_single_lane))
+                 return opt_result::failure_at (vect_location,
+                                                "SLP build failed.\n");
              }
          }
 
@@ -5092,7 +5105,8 @@ vect_analyze_slp (vec_info *vinfo, unsigned max_tree_size,
              || !integer_zerop (args1))
            {
              roots.release ();
-             continue;
+             return opt_result::failure_at (vect_location,
+                                            "SLP build failed.\n");
            }
 
          /* An argument without a loop def will be codegened from vectorizing 
the
@@ -5110,7 +5124,11 @@ vect_analyze_slp (vec_info *vinfo, unsigned 
max_tree_size,
                                         stmts, roots, remain,
                                         max_tree_size, &limit,
                                         bst_map, NULL, force_single_lane))
-           roots.release ();
+           {
+             roots.release ();
+             return opt_result::failure_at (vect_location,
+                                            "SLP build failed.\n");
+           }
        }
 
        /* Find and create slp instances for inductions that have been forced
@@ -5128,10 +5146,13 @@ vect_analyze_slp (vec_info *vinfo, unsigned 
max_tree_size,
              {
                stmts.create (1);
                stmts.quick_push (vect_stmt_to_vectorize (lc_info));
-               vect_build_slp_instance (vinfo, slp_inst_kind_reduc_group,
-                                        stmts, roots, remain,
-                                        max_tree_size, &limit,
-                                        bst_map, NULL, force_single_lane);
+               if (! vect_build_slp_instance (vinfo, slp_inst_kind_reduc_group,
+                                              stmts, roots, remain,
+                                              max_tree_size, &limit,
+                                              bst_map, NULL,
+                                              force_single_lane))
+                 return opt_result::failure_at (vect_location,
+                                                "SLP build failed.\n");
              }
            /* When the latch def is from a different cycle this can only
               be a induction.  Build a simple instance for this.
@@ -5144,10 +5165,13 @@ vect_analyze_slp (vec_info *vinfo, unsigned 
max_tree_size,
              {
                stmts.create (1);
                stmts.quick_push (stmt_info);
-               vect_build_slp_instance (vinfo, slp_inst_kind_reduc_group,
-                                        stmts, roots, remain,
-                                        max_tree_size, &limit,
-                                        bst_map, NULL, force_single_lane);
+               if (! vect_build_slp_instance (vinfo, slp_inst_kind_reduc_group,
+                                              stmts, roots, remain,
+                                              max_tree_size, &limit,
+                                              bst_map, NULL,
+                                              force_single_lane))
+                 return opt_result::failure_at (vect_location,
+                                                "SLP build failed.\n");
              }
          }
     }

Reply via email to