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.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

        * tree-vect-slp.cc (vect_analyze_slp): When analyzing a loop
        and slp instance discovery fails, immediately fail the whole
        process.
---
 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 97e1b87b81f..d1d36833217 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -4887,9 +4887,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)
@@ -4907,9 +4909,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");
          }
     }
 
@@ -5001,12 +5006,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");
                    }
                }
            }
@@ -5031,11 +5038,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 ();
@@ -5064,11 +5074,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");
              }
          }
 
@@ -5091,7 +5104,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
@@ -5109,7 +5123,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
@@ -5127,10 +5145,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.
@@ -5143,10 +5164,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");
              }
          }
     }
-- 
2.43.0

Reply via email to