In this BZ we're getting a debug compare failure.  Thanks to a nice hint from
Jakub it was pretty easy to track it back to the register renaming pass which 
was
making different renaming decisions based on the existence of DEBUG_INSNs.


The culprit is check_new_reg_p which potentially changes its return value in the
presence of a DEBUG_INSN in the use chain which in turn potentially changes the
renaming decisions made.

This patch arranges to always ignore DEBUG_INSNs in the chain within
check_new_reg_p and the decisions we get there are consistent.

I've bootstrapped and regression tested on x86_64, i686, ppc64le, ppc64.  It's
also tested without regressions on a variety of *-elf targets and built a bunch
of *-linux-gnu cross toolchains along the way as well.

Committed to the trunk.

Jeff
commit baf3b9b2e5259558ef86bd62398e2ccecd7a4a4c
Author: Jeff Law <l...@redhat.com>
Date:   Sat Apr 18 09:39:18 2020 -0600

    Don't let DEBUG_INSNSs change register renaming decisions
    
            PR debug/94439
            * regrename.c (check_new_reg_p): Ignore DEBUG_INSNs when walking
            the chain.
    
            PR debug/94439
            * gcc.dg/torture/pr94439.c: New test.

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index aa0902274e5..1edb5f2d70b 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2020-04-18  Jeff Law  <l...@redhat.com>
+
+       PR debug/94439
+       * regrename.c (check_new_reg_p): Ignore DEBUG_INSNs when walking
+       the chain.
+
 2020-04-18  Iain Buclaw  <ibuc...@gdcproject.org>
 
        * doc/sourcebuild.texi (Effective-Target Keywords, Environment
diff --git a/gcc/regrename.c b/gcc/regrename.c
index 663935b7ec1..669a6ead705 100644
--- a/gcc/regrename.c
+++ b/gcc/regrename.c
@@ -348,11 +348,17 @@ check_new_reg_p (int reg ATTRIBUTE_UNUSED, int new_reg,
   /* See whether it accepts all modes that occur in
      definition and uses.  */
   for (tmp = this_head->first; tmp; tmp = tmp->next_use)
-    if ((!targetm.hard_regno_mode_ok (new_reg, GET_MODE (*tmp->loc))
-        && ! DEBUG_INSN_P (tmp->insn))
-       || call_clobbered_in_chain_p (this_head, GET_MODE (*tmp->loc),
-                                     new_reg))
-      return false;
+    {
+      /* Completely ignore DEBUG_INSNs, otherwise we can get
+        -fcompare-debug failures.  */
+      if (DEBUG_INSN_P (tmp->insn))
+       continue;
+
+      if (!targetm.hard_regno_mode_ok (new_reg, GET_MODE (*tmp->loc))
+         || call_clobbered_in_chain_p (this_head, GET_MODE (*tmp->loc),
+                                       new_reg))
+       return false;
+    }
 
   return true;
 }
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index db691564bba..c2b5ddfa5cc 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-04-18  Jeff Law  <l...@redhat.com>
+
+       PR debug/94439
+       * gcc.dg/torture/pr94439.c: New test.
+
 2020-04-18  Iain Buclaw  <ibuc...@gdcproject.org>
 
        * gdc.dg/link.d: Use d_runtime_has_std_library effective target.
diff --git a/gcc/testsuite/gcc.dg/torture/pr94439.c 
b/gcc/testsuite/gcc.dg/torture/pr94439.c
new file mode 100644
index 00000000000..a461b2f8c18
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr94439.c
@@ -0,0 +1,55 @@
+/* { dg-do compile { target i?86-*-* x86_64-*-* } } */
+/* { dg-additional-options "-flive-patching=inline-clone -funroll-loops 
-fno-tree-forwprop -fno-expensive-optimizations -mstack-arg-probe 
-fcompare-debug" } */
+/* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */
+
+extern void exit (int);
+extern void abort (void);
+
+#define COMPARE_BODY(A, B, TYPE, COPYSIGN)                             \
+  do {                                                                 \
+    TYPE s1 = COPYSIGN ((TYPE) 1.0, A);                                        
\
+    TYPE s2 = COPYSIGN ((TYPE) 1.0, B);                                        
\
+    if (s1 != s2)                                                      \
+      abort ();                                                                
\
+    if ((__builtin_isnan (A) != 0) != (__builtin_isnan (B) != 0))      \
+      abort ();                                                                
\
+    if ((A != B) != (__builtin_isnan (A) != 0))                                
\
+      abort ();                                                                
\
+  } while (0)
+
+void
+comparel (long double a, long double b)
+{
+  COMPARE_BODY (a, b, long double, __builtin_copysignl);
+}
+
+void
+comparecl (_Complex long double a, long double r, long double i)
+{
+  comparel (__real__ a, r);
+  comparel (__imag__ a, i);
+}
+
+#define VERIFY(A, B, TYPE, COMPARE)                    \
+  do {                                                 \
+    TYPE a = A;                                                \
+    TYPE b = B;                                                \
+    _Complex TYPE cr = __builtin_complex (a, b);       \
+    static _Complex TYPE cs = __builtin_complex (A, B);        \
+    COMPARE (cr, A, B);                                        \
+    COMPARE (cs, A, B);                                        \
+  } while (0)
+
+#define ALL_CHECKS(PZ, NZ, NAN, INF, TYPE, COMPARE)    \
+  do {                                                 \
+    VERIFY (NAN, NZ, TYPE, COMPARE);                   \
+    VERIFY (INF, NZ, TYPE, COMPARE);                   \
+    VERIFY (INF, NAN, TYPE, COMPARE);                  \
+    VERIFY (INF, INF, TYPE, COMPARE);                  \
+  } while (0)
+
+void
+check_long_double (void)
+{
+  ALL_CHECKS (0.0l, -0.0l, __builtin_nanl(""), __builtin_infl(), long double, 
comparecl);
+}

Reply via email to