This adds a helper to allow verifying of abnormal coalescing
at pass boundaries.  It helps debugging issues like PR98845
since it's not always obvious where invalid overlapping life
ranges of abnormals were introduced.  The verifier is expensive
so I've added it in a #if 0 block in the usual places we do
IL verification.

Bootstrapped and tested (with the checker enabled) on 
x86_64-unknown-linux-gnu.

OK for trunk?

Thanks,
Richard.

2021-01-27  Richard Biener  <rguent...@suse.de>

        * tree-ssa-coalesce.h (verify_ssa_coalescing): Declare.
        * tree-ssa-coalesce.c (verify_ssa_coalescing): New.
        (create_coalesce_list_for_region): Do not assert we have
        a default def for RESULT_DECLs.
        (coalesce_with_default): Handle not existing default defs.
        * passes.c (execute_function_todo): Call verify_ssa_coalescing,
        commented out.
---
 gcc/passes.c            | 14 +++++++++++---
 gcc/tree-ssa-coalesce.c | 15 ++++++++++++---
 gcc/tree-ssa-coalesce.h |  1 +
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/gcc/passes.c b/gcc/passes.c
index 4fb1be99ce4..3c90dc9db99 100644
--- a/gcc/passes.c
+++ b/gcc/passes.c
@@ -63,6 +63,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "diagnostic-core.h" /* for fnotice */
 #include "stringpool.h"
 #include "attribs.h"
+#include "tree-ssa-coalesce.h"
 
 using namespace gcc;
 
@@ -2044,9 +2045,16 @@ execute_function_todo (function *fn, void *data)
                verify_gimple_in_seq (gimple_body (cfun->decl));
            }
          if (cfun->curr_properties & PROP_ssa)
-           /* IPA passes leave stmts to be fixed up, so make sure to
-              not verify SSA operands whose verifier will choke on that.  */
-           verify_ssa (true, !from_ipa_pass);
+           {
+             /* IPA passes leave stmts to be fixed up, so make sure to
+                not verify SSA operands whose verifier will choke on that.  */
+             verify_ssa (true, !from_ipa_pass);
+#if 0
+             /* If you want to debug a SSA coalescing issue, uncomment.  */
+             if (!from_ipa_pass)
+               verify_ssa_coalescing ();
+#endif
+           }
          /* IPA passes leave basic-blocks unsplit, so make sure to
             not trip on that.  */
          if ((cfun->curr_properties & PROP_cfg)
diff --git a/gcc/tree-ssa-coalesce.c b/gcc/tree-ssa-coalesce.c
index 77ccd6dd618..277136afd45 100644
--- a/gcc/tree-ssa-coalesce.c
+++ b/gcc/tree-ssa-coalesce.c
@@ -1017,7 +1017,7 @@ coalesce_with_default (tree var, coalesce_list *cl, 
bitmap used_in_copy)
     return;
 
   tree ssa = ssa_default_def (cfun, SSA_NAME_VAR (var));
-  if (!has_zero_uses (ssa))
+  if (!ssa || !has_zero_uses (ssa))
     return;
 
   add_cost_one_coalesce (cl, SSA_NAME_VERSION (ssa), SSA_NAME_VERSION (var));
@@ -1124,8 +1124,8 @@ create_coalesce_list_for_region (var_map map, bitmap 
used_in_copy)
                if (!rhs1)
                  break;
                tree lhs = ssa_default_def (cfun, res);
-               gcc_assert (lhs);
-               if (TREE_CODE (rhs1) == SSA_NAME
+               if (lhs
+                   && TREE_CODE (rhs1) == SSA_NAME
                    && gimple_can_coalesce_p (lhs, rhs1))
                  {
                    v1 = SSA_NAME_VERSION (lhs);
@@ -1759,3 +1759,12 @@ coalesce_ssa_name (var_map map)
   ssa_conflicts_delete (graph);
 }
 
+/* Verify that we can coalesce SSA names we must coalesce.  */
+
+DEBUG_FUNCTION void
+verify_ssa_coalescing (void)
+{
+  var_map map = init_var_map (num_ssa_names);
+  coalesce_ssa_name (map);
+  delete_var_map (map);
+}
diff --git a/gcc/tree-ssa-coalesce.h b/gcc/tree-ssa-coalesce.h
index 7e1447bed09..213922433a1 100644
--- a/gcc/tree-ssa-coalesce.h
+++ b/gcc/tree-ssa-coalesce.h
@@ -22,5 +22,6 @@ along with GCC; see the file COPYING3.  If not see
 
 extern void coalesce_ssa_name (var_map);
 extern bool gimple_can_coalesce_p (tree, tree);
+extern void verify_ssa_coalescing (void);
 
 #endif /* GCC_TREE_SSA_COALESCE_H */
-- 
2.26.2

Reply via email to