public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] alias: Fix -fcompare-debug issues caused by compare_base_symbol_refs [PR105415]
@ 2022-04-29  9:05 Jakub Jelinek
  2022-04-29  9:32 ` Richard Biener
  0 siblings, 1 reply; 12+ messages in thread
From: Jakub Jelinek @ 2022-04-29  9:05 UTC (permalink / raw)
  To: Richard Biener, Jeff Law; +Cc: gcc-patches

Hi!

The following testcase fails -fcompare-debug on aarch64-linux.  The problem
is that for the n variable we create a varpool node, then remove it again
because the var isn't really used, but it keeps being referenced in debug
stmts/insns with -g.  Later during sched1 pass we ask whether the n var
can be modified through some store to an anchored variable and with -g
we create a new varpool node for it again just so that we can find its
ultimate alias target.  Even later on we create some cgraph node for the
loop parallelization, but as there has been an extra varpool node creation
in between, we get higher node->order with -g than without.

I think we just shouldn't create varpool nodes during RTL optimizations,
either the vars exist and we have varpool nodes for those, or they are some
late created variables which will have itself as ultimate alias target
(in debugging dumps I've done on powerpc64le-linux for this, 828576 out of
828580 cases where symtab_node::get (x_decl) returned NULL here it was
some DECL_IN_CONSTANT_POOL decl so certainly
symtab_node::get_create (x_decl)->ultimate_alias_target ()->decl == x_decl
), or as in this case it is a var referenced only in debug insns and we'd
better not to create varpool node for it, just:
gcc.dg/pr105415.c foo n
gcc.dg/pr105415.c foo n
gcc.dg/torture/pr41555.c main g_47
gcc.dg/torture/pr41555.c main g_47
).
So the following patch calls just get instead of get_create and assumes
that if we'd create a new varpool node, it would have itself as its
ultimate_alias_target that late and it would be a definition unless
DECL_EXTERNAL.

Bootstrapped/regtested on aarch64-linux and powerpc64le-linux, ok for trunk?

2022-04-29  Jakub Jelinek  <jakub@redhat.com>

	PR debug/105415
	* alias.cc (compare_base_symbol_refs): Avoid creating new symtab
	nodes, if it doesn't exist, punt if DECL_EXTERNAL, otherwise use
	x_decl instead of x_node->decl.

	* gcc.dg/pr105415.c: New test.

--- gcc/alias.cc.jj	2022-02-21 16:51:50.261232505 +0100
+++ gcc/alias.cc	2022-04-28 11:57:18.940425126 +0200
@@ -2219,12 +2219,19 @@ compare_base_symbol_refs (const_rtx x_ba
 	  || (!TREE_STATIC (x_decl) && !TREE_PUBLIC (x_decl)))
 	return 0;
 
-      symtab_node *x_node = symtab_node::get_create (x_decl)
-			    ->ultimate_alias_target ();
-      /* External variable cannot be in section anchor.  */
-      if (!x_node->definition)
+      symtab_node *x_node = symtab_node::get (x_decl);
+      tree x_decl2 = x_decl;
+      if (x_node != NULL)
+	{
+	  x_node = x_node->ultimate_alias_target ();
+	  /* External variable cannot be in section anchor.  */
+	  if (!x_node->definition)
+	    return 0;
+	  x_decl2 = x_node->decl;
+	}
+      else if (DECL_EXTERNAL (x_decl))
 	return 0;
-      x_base = XEXP (DECL_RTL (x_node->decl), 0);
+      x_base = XEXP (DECL_RTL (x_decl2), 0);
       /* If not in anchor, we can disambiguate.  */
       if (!SYMBOL_REF_HAS_BLOCK_INFO_P (x_base))
 	return 0;
--- gcc/testsuite/gcc.dg/pr105415.c.jj	2022-04-28 12:26:13.174302870 +0200
+++ gcc/testsuite/gcc.dg/pr105415.c	2022-04-28 12:25:36.770809149 +0200
@@ -0,0 +1,26 @@
+/* PR debug/105415 */
+/* { dg-do compile } */
+/* { dg-require-effective-target pthread } */
+/* { dg-options "-O2 -ftree-parallelize-loops=2 -fcompare-debug" } */
+
+int m;
+static int n;
+
+void
+foo (void)
+{
+  int s = 0;
+
+  while (m < 1)
+    {
+      s += n;
+      ++m;
+    }
+}
+
+void
+bar (int *arr, int i)
+{
+  while (i < 1)
+    arr[i++] = 1;
+}

	Jakub


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2022-05-02  8:42 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-29  9:05 [PATCH] alias: Fix -fcompare-debug issues caused by compare_base_symbol_refs [PR105415] Jakub Jelinek
2022-04-29  9:32 ` Richard Biener
2022-04-29  9:38   ` Jakub Jelinek
2022-04-29  9:52     ` Richard Biener
2022-04-29 10:38       ` Jakub Jelinek
2022-04-29 10:58         ` Richard Biener
2022-04-29 11:11           ` Jakub Jelinek
2022-04-29 11:22             ` Jakub Jelinek
2022-04-29 11:23               ` Richard Biener
2022-05-02  8:34                 ` Jakub Jelinek
2022-05-02  8:42                   ` Richard Biener
2022-04-29 11:22             ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).