public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Uros Bizjak <ubizjak@gmail.com>, Jeff Law <law@redhat.com>
Cc: Ilya Enkovich <enkovich.gnu@gmail.com>,
	       Vladimir Makarov <vmakarov@redhat.com>,
	       gcc-patches <gcc-patches@gcc.gnu.org>,
	       Evgeny Stupachenko <evstupac@gmail.com>,
	       Richard Biener <richard.guenther@gmail.com>,
	       Uros Bizjak <ubizjak@gmail.com>,
	Petr Machata <pmachata@redhat.com>
Subject: [PATCH] Improve i?86 address delegitimization after 32-bit pic changes (PR target/63542)
Date: Tue, 21 Oct 2014 16:05:00 -0000	[thread overview]
Message-ID: <20141021160336.GZ10376@tucnak.redhat.com> (raw)
In-Reply-To: <20140929110856.GD17454@tucnak.redhat.com>

On Mon, Sep 29, 2014 at 01:08:56PM +0200, Jakub Jelinek wrote:
> I wonder if during/after reload we just couldn't look at
> ORIGINAL_REGNO of hard regs if ix86_use_pseudo_pic_reg.  Or is that
> the other case, where you don't have any PIC register replacement around,
> and want to subtract something?  Perhaps in that case we could just
> subtract the value of _GLOBAL_OFFSET_TABLE_ symbol if we have nothing better
> around.

Here is a patch that implements both of these ideas.

The number of lines like:
note: non-delegitimized UNSPEC UNSPEC_GOT (0) found in variable location
note: non-delegitimized UNSPEC UNSPEC_GOTOFF (1) found in variable location
during i686-linux bootstrap (not including regtest) went down from
14165 to 19.

The patch trusts that a hard reg with ORIGINAL_REGNO containing the pic
pseudo contains the _GLOBAL_OFFSET_TABLE_ value of the current shared
library (or binary), I think that is reasonable assumption.
And for ELF for the UNSPEC_GOTOFF it worse case can subtract
_GLOBAL_OFFSET_TABLE_ symbol if it doesn't know what register to subtract.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2014-10-21  Jakub Jelinek  <jakub@redhat.com>

	PR target/63542
	* config/i386/i386.c (ix86_pic_register_p): Also return
	true if x is a hard register with ORIGINAL_REGNO equal to
	pic_offset_table_rtx pseudo REGNO.
	(ix86_delegitimize_address): For ix86_use_pseudo_pic_reg ()
	after reload, subtract GOT_SYMBOL_NAME symbol if possible.

	* gcc.target/i386/pr63542-1.c: New test.
	* gcc.target/i386/pr63542-2.c: New test.

--- gcc/config/i386/i386.c.jj	2014-10-21 11:51:30.000000000 +0200
+++ gcc/config/i386/i386.c	2014-10-21 13:06:55.621292368 +0200
@@ -14281,10 +14281,20 @@ 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 (!REG_P (x))
+    return false;
   else if (pic_offset_table_rtx)
-    return REG_P (x) && REGNO (x) == REGNO (pic_offset_table_rtx);
+    {
+      if (REGNO (x) == REGNO (pic_offset_table_rtx))
+	return true;
+      if (HARD_REGISTER_P (x)
+	  && !HARD_REGISTER_P (pic_offset_table_rtx)
+	  && ORIGINAL_REGNO (x) == REGNO (pic_offset_table_rtx))
+	return true;
+      return false;
+    }
   else
-    return REG_P (x) && REGNO (x) == PIC_OFFSET_TABLE_REGNUM;
+    return REGNO (x) == PIC_OFFSET_TABLE_REGNUM;
 }
 
 /* Helper function for ix86_delegitimize_address.
@@ -14457,15 +14467,20 @@ ix86_delegitimize_address (rtx x)
 	 leal (%ebx, %ecx, 4), %ecx
 	 ...
 	 movl foo@GOTOFF(%ecx), %edx
-	 in which case we return (%ecx - %ebx) + foo.
-
-	 Note that when pseudo_pic_reg is used we can generate it only
-	 before reload_completed.  */
+	 in which case we return (%ecx - %ebx) + foo
+	 or (%ecx - _GLOBAL_OFFSET_TABLE_) + foo if pseudo_pic_reg
+	 and reload has completed.  */
       if (pic_offset_table_rtx
 	  && (!reload_completed || !ix86_use_pseudo_pic_reg ()))
         result = gen_rtx_PLUS (Pmode, gen_rtx_MINUS (Pmode, copy_rtx (addend),
 						     pic_offset_table_rtx),
 			       result);
+      else if (pic_offset_table_rtx && !TARGET_MACHO && !TARGET_VXWORKS_RTP)
+	{
+	  rtx tmp = gen_rtx_SYMBOL_REF (Pmode, GOT_SYMBOL_NAME);
+	  tmp = gen_rtx_MINUS (Pmode, copy_rtx (addend), tmp);
+	  result = gen_rtx_PLUS (Pmode, tmp, result);
+	}
       else
 	return orig_x;
     }
--- gcc/testsuite/gcc.target/i386/pr63542-1.c.jj	2014-10-21 13:47:25.938470961 +0200
+++ gcc/testsuite/gcc.target/i386/pr63542-1.c	2014-10-21 13:48:26.227333649 +0200
@@ -0,0 +1,21 @@
+/* PR target/63542 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -g -dA" } */
+/* { dg-additional-options "-fpic" { target fpic } } */
+
+float
+foo (long long u)
+{
+  if (!(-(1LL << 53) < u && u < (1LL << 53)))
+    {
+      if ((unsigned long long) u & ((1ULL << 11) - 1))
+	{
+	  u &= ~((1ULL << 11) - 1);
+	  u |= (1ULL << 11);
+	}
+    }
+  double f = (int) (u >> (32));
+  f *= 0x1p32f;
+  f += (unsigned int) u;
+  return (float) f;
+}
--- gcc/testsuite/gcc.target/i386/pr63542-2.c.jj	2014-10-21 13:47:29.084411447 +0200
+++ gcc/testsuite/gcc.target/i386/pr63542-2.c	2014-10-21 13:48:38.779096466 +0200
@@ -0,0 +1,37 @@
+/* PR target/63542 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -g -dA" } */
+/* { dg-additional-options "-fpic" { target fpic } } */
+
+struct B { unsigned long c; unsigned char *d; };
+extern struct A { struct B *e[0x400]; } *f[128];
+extern void (*bar) (char *p, char *q);
+
+char *
+foo (char *p, char *q)
+{
+  struct B *g;
+  char *b, *l;
+  unsigned long s;
+
+  g = f[((unsigned long) p) >> 22]->e[(((unsigned long) p) >> 12) & 0x3ff];
+  s = g->c << 2;
+  int r = ((unsigned long) p) & 0xfff;
+  int m = g->d[r];
+  if (m > 0xfd)
+    {
+      m = (r >> 2) % (s >> 2);
+      if ((((unsigned long) p) & ~(unsigned long) 0xfff) != (((unsigned long) q) & ~(unsigned long) 0xfff))
+	goto fail;
+    }
+  b = (char *) ((unsigned long) p & ~(unsigned long) 3);
+  b -= m << 2;
+  l = b + s;
+
+  if ( q >= l || q < b)
+    goto fail;
+  return p;
+fail:
+  (*bar) (p, q);
+  return p;
+}


	Jakub

  reply	other threads:[~2014-10-21 16:03 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAOvf_xxsQ_oYGqNAVQ1+BW+CuD3mzebZ2xma0jpF=WfyZMCRCA@mail.gmail.com>
     [not found] ` <CAFiYyc1mFtTezkTJORmJJq+yht=qPSwiN7KDn19+bSuSdaqvMQ@mail.gmail.com>
     [not found]   ` <CAOvf_xyeVeg2oB9Xxz8RMEQ6gyfJY5whd9s4ygoAAEaMU9efnA@mail.gmail.com>
     [not found]     ` <20140707114750.GB31640@tucnak.redhat.com>
     [not found]       ` <CAMbmDYZV_fx0jxmKHhLsC2pJ7pDzuu6toEAH72izOdpq6KGyfg@mail.gmail.com>
2014-08-22 12:21         ` Enable EBX for x86 in 32bits PIC code Ilya Enkovich
2014-08-23  1:47           ` Hans-Peter Nilsson
2014-08-25  9:25             ` Ilya Enkovich
2014-08-25 11:24               ` Hans-Peter Nilsson
2014-08-25 11:43                 ` Ilya Enkovich
2014-08-25 15:09           ` Vladimir Makarov
2014-08-26  7:49             ` Ilya Enkovich
2014-08-26  8:57               ` Ilya Enkovich
2014-08-26 15:25                 ` Vladimir Makarov
2014-08-26 21:42                   ` Ilya Enkovich
2014-08-27 20:19                     ` Vladimir Makarov
2014-08-28  8:28                       ` Ilya Enkovich
2014-08-29  6:47                         ` Ilya Enkovich
2014-09-02 14:29                           ` Vladimir Makarov
2014-09-03 20:19                           ` Vladimir Makarov
     [not found]                             ` <0EFAB2BDD0F67E4FB6CCC8B9F87D756969B3A89D@IRSMSX101.ger.corp.intel.com>
2014-09-09 16:43                               ` Vladimir Makarov
2014-09-11 19:57                                 ` Jeff Law
2014-09-23 13:54                             ` Ilya Enkovich
2014-09-23 14:23                               ` Uros Bizjak
2014-09-23 15:59                                 ` Jeff Law
2014-09-23 14:34                               ` Jakub Jelinek
2014-09-23 15:59                                 ` Petr Machata
2014-09-23 16:00                                 ` Jeff Law
2014-09-23 16:03                                   ` Jakub Jelinek
2014-09-23 16:10                                     ` Jeff Law
2014-09-24  6:56                                       ` Ilya Enkovich
2014-09-24 15:27                                         ` Jeff Law
2014-09-24 20:32                                           ` Ilya Enkovich
2014-09-24 21:20                                             ` Jeff Law
2014-09-29 11:09                                               ` Jakub Jelinek
2014-10-21 16:05                                                 ` Jakub Jelinek [this message]
2014-10-22  2:02                                                   ` [PATCH] Improve i?86 address delegitimization after 32-bit pic changes (PR target/63542) Jeff Law
2014-11-24 15:57                                                   ` H.J. Lu
2014-08-27 21:39                     ` Enable EBX for x86 in 32bits PIC code Jeff Law
2014-08-28  8:37                       ` Ilya Enkovich
2014-08-28 12:43                         ` Uros Bizjak
2014-08-28 12:54                           ` Ilya Enkovich
2014-08-28 13:08                             ` Uros Bizjak
2014-08-28 13:29                               ` Ilya Enkovich
2014-08-28 16:25                                 ` Uros Bizjak
2014-08-29 18:56                         ` Jeff Law
2014-08-25 17:30           ` Jeff Law
2014-08-28 13:01           ` Uros Bizjak
2014-08-28 13:13             ` Ilya Enkovich
2014-08-28 18:30             ` Florian Weimer
2014-08-29 18:48             ` Jeff Law
2014-08-28 18:58           ` Uros Bizjak
2014-08-29  6:51             ` Ilya Enkovich
2014-08-29 18:45             ` Jeff Law

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141021160336.GZ10376@tucnak.redhat.com \
    --to=jakub@redhat.com \
    --cc=enkovich.gnu@gmail.com \
    --cc=evstupac@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=law@redhat.com \
    --cc=pmachata@redhat.com \
    --cc=richard.guenther@gmail.com \
    --cc=ubizjak@gmail.com \
    --cc=vmakarov@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).