Hi!

The following testcase fails -fcompare-debug, because it is ifcvt optimized
into umin only with -g0 and not with -g - the function(s) use
prev_nonnote_insn, which without -g finds a real insn the code is looking
for, while with -g finds a DEBUG_INSN.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2021-06-09  Jakub Jelinek  <ja...@redhat.com>

        PR debug/100852
        * ifcvt.c (noce_get_alt_condition, noce_try_abs): Use
        prev_nonnote_nondebug_insn instead of prev_nonnote_insn.

        * g++.dg/opt/pr100852.C: New test.

--- gcc/ifcvt.c.jj      2021-05-04 21:02:24.061801088 +0200
+++ gcc/ifcvt.c 2021-06-08 15:36:53.339411347 +0200
@@ -2398,7 +2398,7 @@ noce_get_alt_condition (struct noce_if_i
       rtx_insn *prev_insn;
 
       /* First, look to see if we put a constant in a register.  */
-      prev_insn = prev_nonnote_insn (if_info->cond_earliest);
+      prev_insn = prev_nonnote_nondebug_insn (if_info->cond_earliest);
       if (prev_insn
          && BLOCK_FOR_INSN (prev_insn)
             == BLOCK_FOR_INSN (if_info->cond_earliest)
@@ -2669,7 +2669,7 @@ noce_try_abs (struct noce_if_info *if_in
   if (REG_P (c))
     {
       rtx set;
-      rtx_insn *insn = prev_nonnote_insn (earliest);
+      rtx_insn *insn = prev_nonnote_nondebug_insn (earliest);
       if (insn
          && BLOCK_FOR_INSN (insn) == BLOCK_FOR_INSN (earliest)
          && (set = single_set (insn))
--- gcc/testsuite/g++.dg/opt/pr100852.C.jj      2021-06-08 15:39:48.089013415 
+0200
+++ gcc/testsuite/g++.dg/opt/pr100852.C 2021-06-08 15:41:12.816850768 +0200
@@ -0,0 +1,25 @@
+// PR debug/100852
+// { dg-do compile }
+// { dg-options "-Og -fif-conversion -fno-tree-ccp -fno-tree-copy-prop 
-fcompare-debug" }
+
+static inline int
+min (unsigned a, int b)
+{
+  return a < b ? a : b;
+}
+
+struct S { S (char); };
+
+static inline S
+foo (unsigned x)
+{
+  int h;
+  h += min (x * 4, h);
+  return h;
+}
+
+void
+bar ()
+{
+  foo (0);
+}

        Jakub

Reply via email to