https://gcc.gnu.org/g:567547a89763b583e8b829b81f1db9053c246b96

commit r12-10906-g567547a89763b583e8b829b81f1db9053c246b96
Author: Richard Biener <rguent...@suse.de>
Date:   Sun Oct 13 15:12:44 2024 +0200

    tree-optimization/116290 - fix compare-debug issue in ldist
    
    Loop distribution does different analysis with -g0/-g due to counting
    a debug stmt starting a BB against a limit which will everntually
    lead to different IVOPTs choices.  I've fixed a possible IVOPTs
    issue on the way even though it doesn't make a difference here.
    
            PR tree-optimization/116290
            * tree-loop-distribution.cc (determine_reduction_stmt_1): PHIs
            have no debug variants.  Start with first non-debug real stmt.
            * tree-ssa-loop-ivopts.cc (find_givs_in_bb): Do not analyze
            debug stmts.
    
            * gcc.dg/pr116290.c: New testcase.
    
    (cherry picked from commit 566740013b3445162b8c4bc2205e4e568d014968)

Diff:
---
 gcc/testsuite/gcc.dg/pr116290.c | 18 ++++++++++++++++++
 gcc/tree-loop-distribution.cc   |  6 +++---
 gcc/tree-ssa-loop-ivopts.cc     |  3 ++-
 3 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/pr116290.c b/gcc/testsuite/gcc.dg/pr116290.c
new file mode 100644
index 000000000000..97b946bda893
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr116290.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-g -O2 -fcompare-debug" } */
+
+char *camel_message_info_class_intern_init_part;
+void g_once_init_enter();
+void camel_message_info_class_intern_init() {
+  int ii;
+  char *label;
+  for (; camel_message_info_class_intern_init_part[ii]; ii++)
+    if (camel_message_info_class_intern_init_part) {
+      if (label && *label)
+        g_once_init_enter();
+      label = &camel_message_info_class_intern_init_part[ii + 1];
+      camel_message_info_class_intern_init_part[ii] = ' ';
+    }
+  if (label)
+    g_once_init_enter();
+}
diff --git a/gcc/tree-loop-distribution.cc b/gcc/tree-loop-distribution.cc
index 1b7d2a1ea7d2..449b9ffd4389 100644
--- a/gcc/tree-loop-distribution.cc
+++ b/gcc/tree-loop-distribution.cc
@@ -3492,7 +3492,7 @@ determine_reduction_stmt_1 (const loop_p loop, const 
basic_block *bbs)
       basic_block bb = bbs[i];
 
       for (gphi_iterator bsi = gsi_start_phis (bb); !gsi_end_p (bsi);
-          gsi_next_nondebug (&bsi))
+          gsi_next (&bsi))
        {
          gphi *phi = bsi.phi ();
          if (virtual_operand_p (gimple_phi_result (phi)))
@@ -3505,8 +3505,8 @@ determine_reduction_stmt_1 (const loop_p loop, const 
basic_block *bbs)
            }
        }
 
-      for (gimple_stmt_iterator bsi = gsi_start_bb (bb); !gsi_end_p (bsi);
-          gsi_next_nondebug (&bsi), ++ninsns)
+      for (gimple_stmt_iterator bsi = gsi_start_nondebug_bb (bb);
+          !gsi_end_p (bsi); gsi_next_nondebug (&bsi), ++ninsns)
        {
          /* Bail out early for loops which are unlikely to match.  */
          if (ninsns > 16)
diff --git a/gcc/tree-ssa-loop-ivopts.cc b/gcc/tree-ssa-loop-ivopts.cc
index eb4d8388906f..597c4b0e8a67 100644
--- a/gcc/tree-ssa-loop-ivopts.cc
+++ b/gcc/tree-ssa-loop-ivopts.cc
@@ -1458,7 +1458,8 @@ find_givs_in_bb (struct ivopts_data *data, basic_block bb)
   gimple_stmt_iterator bsi;
 
   for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi))
-    find_givs_in_stmt (data, gsi_stmt (bsi));
+    if (!is_gimple_debug (gsi_stmt (bsi)))
+      find_givs_in_stmt (data, gsi_stmt (bsi));
 }
 
 /* Finds general ivs.  */

Reply via email to