tree-optimization/97539 - reset out-of-loop debug uses before peeling
authorRichard Biener <rguenther@suse.de>
Mon, 26 Oct 2020 09:08:38 +0000 (10:08 +0100)
committerRichard Biener <rguenther@suse.de>
Mon, 26 Oct 2020 10:33:50 +0000 (11:33 +0100)
This makes sure to reset out-of-loop debug uses before vectorizer
loop peeling as we cannot make sure to retain the use-def dominance
relationship when there are no LC SSA nodes.

2020-10-26  Richard Biener  <rguenther@suse.de>

PR tree-optimization/97539
* tree-vect-loop-manip.c (vect_do_peeling): Reset out-of-loop
debug uses before peeling.

* gcc.dg/pr97539.c: New testcase.

gcc/testsuite/gcc.dg/pr97539.c [new file with mode: 0644]
gcc/tree-vect-loop-manip.c

diff --git a/gcc/testsuite/gcc.dg/pr97539.c b/gcc/testsuite/gcc.dg/pr97539.c
new file mode 100644 (file)
index 0000000..def55e1
--- /dev/null
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -g" } */
+
+int a, b;
+void c() {
+  char d;
+  for (; b;)
+    for (;;)
+      for (; d <= 7; d += 1) {
+        a = 7;
+        for (; a; a += 1)
+        e:
+          d += d;
+        d ^= 0;
+      }
+  goto e;
+}
index 7cf00e6eed4eedd2458bb62b3c972b5f5ecafcf3..5d00b6fb9569029dac3bbdfe4a265b81b6168e94 100644 (file)
@@ -2545,6 +2545,45 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree niters, tree nitersm1,
   if (!prolog_peeling && !epilog_peeling)
     return NULL;
 
+  /* Before doing any peeling make sure to reset debug binds outside of
+     the loop refering to defs not in LC SSA.  */
+  class loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
+  for (unsigned i = 0; i < loop->num_nodes; ++i)
+    {
+      basic_block bb = LOOP_VINFO_BBS (loop_vinfo)[i];
+      imm_use_iterator ui;
+      gimple *use_stmt;
+      for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
+          gsi_next (&gsi))
+       {
+         FOR_EACH_IMM_USE_STMT (use_stmt, ui, gimple_phi_result (gsi.phi ()))
+           if (gimple_debug_bind_p (use_stmt)
+               && loop != gimple_bb (use_stmt)->loop_father
+               && !flow_loop_nested_p (loop,
+                                       gimple_bb (use_stmt)->loop_father))
+             {
+               gimple_debug_bind_reset_value (use_stmt);
+               update_stmt (use_stmt);
+             }
+       }
+      for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
+          gsi_next (&gsi))
+       {
+         ssa_op_iter op_iter;
+         def_operand_p def_p;
+         FOR_EACH_SSA_DEF_OPERAND (def_p, gsi_stmt (gsi), op_iter, SSA_OP_DEF)
+           FOR_EACH_IMM_USE_STMT (use_stmt, ui, DEF_FROM_PTR (def_p))
+             if (gimple_debug_bind_p (use_stmt)
+                 && loop != gimple_bb (use_stmt)->loop_father
+                 && !flow_loop_nested_p (loop,
+                                         gimple_bb (use_stmt)->loop_father))
+               {
+                 gimple_debug_bind_reset_value (use_stmt);
+                 update_stmt (use_stmt);
+               }
+       }
+    }
+
   prob_vector = profile_probability::guessed_always ().apply_scale (9, 10);
   estimated_vf = vect_vf_for_cost (loop_vinfo);
   if (estimated_vf == 2)
@@ -2552,7 +2591,7 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree niters, tree nitersm1,
   prob_prolog = prob_epilog = profile_probability::guessed_always ()
                        .apply_scale (estimated_vf - 1, estimated_vf);
 
-  class loop *prolog, *epilog = NULL, *loop = LOOP_VINFO_LOOP (loop_vinfo);
+  class loop *prolog, *epilog = NULL;
   class loop *first_loop = loop;
   bool irred_flag = loop_preheader_edge (loop)->flags & EDGE_IRREDUCIBLE_LOOP;