diff mbox series

Improve x86 address delegitimization (PR debug/89006)

Message ID 20190124192808.GR30353@tucnak
State New
Headers show
Series Improve x86 address delegitimization (PR debug/89006) | expand

Commit Message

Jakub Jelinek Jan. 24, 2019, 7:28 p.m. UTC
Hi!

As the following testcase shows, during var-tracking we can end trying to
delegitimize e.g. (plus:SI (unspec:SI ... UNSPEC_SET_GOT)
(const:SI (unspec:SI (symbol_ref:SI ...) UNSPEC_GOTOFF)).  The code is
prepared to handle PIC register + UNSPEC_GOTOFF, delegitimizing that
to the underlying SYMBOL_REF, but we can end up with the UNSPEC_SET_GOT
instead of the %ebx etc. register, because in the RTL that register
is initialized to that UNSPEC_SET_GOT.

The following patch handles it like the pic register; the
ix86_pic_register_p function is used only in the delegitimization hook.

Bootstrapped/regtested on x86_64-linux and i686-linux, the patch removed
all 170 non-delegitimized UNSPEC messages from x86_64-linux bootstrap and
142 out of 144 non-delegitimized UNSPEC messages from i686-linux bootstrap,
ok for trunk?

2019-01-24  Jakub Jelinek  <jakub@redhat.com>

	PR debug/89006
	* config/i386/i386.c (ix86_pic_register_p): Return true for
	UNSPEC_SET_GOT too.

	* g++.dg/debug/pr89006.C: New test.


	Jakub

Comments

Uros Bizjak Jan. 24, 2019, 8:13 p.m. UTC | #1
On Thu, Jan 24, 2019 at 8:28 PM Jakub Jelinek <jakub@redhat.com> wrote:
>
> Hi!
>
> As the following testcase shows, during var-tracking we can end trying to
> delegitimize e.g. (plus:SI (unspec:SI ... UNSPEC_SET_GOT)
> (const:SI (unspec:SI (symbol_ref:SI ...) UNSPEC_GOTOFF)).  The code is
> prepared to handle PIC register + UNSPEC_GOTOFF, delegitimizing that
> to the underlying SYMBOL_REF, but we can end up with the UNSPEC_SET_GOT
> instead of the %ebx etc. register, because in the RTL that register
> is initialized to that UNSPEC_SET_GOT.
>
> The following patch handles it like the pic register; the
> ix86_pic_register_p function is used only in the delegitimization hook.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, the patch removed
> all 170 non-delegitimized UNSPEC messages from x86_64-linux bootstrap and
> 142 out of 144 non-delegitimized UNSPEC messages from i686-linux bootstrap,
> ok for trunk?
>
> 2019-01-24  Jakub Jelinek  <jakub@redhat.com>
>
>         PR debug/89006
>         * config/i386/i386.c (ix86_pic_register_p): Return true for
>         UNSPEC_SET_GOT too.
>
>         * g++.dg/debug/pr89006.C: New test.

LGTM.

Thanks,
Uros.

> --- gcc/config/i386/i386.c.jj   2019-01-22 23:26:46.668212957 +0100
> +++ gcc/config/i386/i386.c      2019-01-24 11:51:40.050801078 +0100
> @@ -16972,6 +16972,8 @@ ix86_pic_register_p (rtx x)
>    if (GET_CODE (x) == VALUE && CSELIB_VAL_PTR (x))
>      return (pic_offset_table_rtx
>             && rtx_equal_for_cselib_p (x, pic_offset_table_rtx));
> +  else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_SET_GOT)
> +    return true;
>    else if (!REG_P (x))
>      return false;
>    else if (pic_offset_table_rtx)
> --- gcc/testsuite/g++.dg/debug/pr89006.C.jj     2019-01-24 12:18:59.119838677 +0100
> +++ gcc/testsuite/g++.dg/debug/pr89006.C        2019-01-24 12:16:56.642859109 +0100
> @@ -0,0 +1,20 @@
> +// PR debug/89006
> +// { dg-do compile }
> +// { dg-options "-O2 -g -w" }
> +// { dg-additional-options "-fPIC" { target fpic } }
> +// { dg-bogus "non-delegitimized UNSPEC UNSPEC_SET_GOT" "" { target { i?86-*-* x86_64-*-* } } 0 }
> +
> +struct A { A (bool); };
> +
> +static void
> +foo (const char *x)
> +{
> +  new A (x);
> +}
> +
> +void
> +bar ()
> +{
> +  foo ("foo");
> +  foo ("bar");
> +}
>
>         Jakub
diff mbox series

Patch

--- gcc/config/i386/i386.c.jj	2019-01-22 23:26:46.668212957 +0100
+++ gcc/config/i386/i386.c	2019-01-24 11:51:40.050801078 +0100
@@ -16972,6 +16972,8 @@  ix86_pic_register_p (rtx x)
   if (GET_CODE (x) == VALUE && CSELIB_VAL_PTR (x))
     return (pic_offset_table_rtx
 	    && rtx_equal_for_cselib_p (x, pic_offset_table_rtx));
+  else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_SET_GOT)
+    return true;
   else if (!REG_P (x))
     return false;
   else if (pic_offset_table_rtx)
--- gcc/testsuite/g++.dg/debug/pr89006.C.jj	2019-01-24 12:18:59.119838677 +0100
+++ gcc/testsuite/g++.dg/debug/pr89006.C	2019-01-24 12:16:56.642859109 +0100
@@ -0,0 +1,20 @@ 
+// PR debug/89006
+// { dg-do compile }
+// { dg-options "-O2 -g -w" }
+// { dg-additional-options "-fPIC" { target fpic } }
+// { dg-bogus "non-delegitimized UNSPEC UNSPEC_SET_GOT" "" { target { i?86-*-* x86_64-*-* } } 0 }
+
+struct A { A (bool); };
+
+static void
+foo (const char *x)
+{
+  new A (x);
+}
+
+void
+bar ()
+{
+  foo ("foo");
+  foo ("bar");
+}