public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Henderson <rth@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: richard.guenther@gmail.com
Subject: [PATCH v2 10/13] Avoid CSE of MEMs in different address spaces
Date: Tue, 20 Oct 2015 21:28:00 -0000	[thread overview]
Message-ID: <1445376433-14658-11-git-send-email-rth@redhat.com> (raw)
In-Reply-To: <1445376433-14658-1-git-send-email-rth@redhat.com>

---
 gcc/cselib.c                                 | 22 +++++++++++++---------
 gcc/fold-const.c                             | 14 +++++++-------
 gcc/testsuite/gcc.target/i386/addr-space-2.c | 11 +++++++++++
 3 files changed, 31 insertions(+), 16 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/addr-space-2.c

diff --git a/gcc/cselib.c b/gcc/cselib.c
index 4264394..857e52a 100644
--- a/gcc/cselib.c
+++ b/gcc/cselib.c
@@ -1337,15 +1337,15 @@ new_cselib_val (unsigned int hash, machine_mode mode, rtx x)
 static void
 add_mem_for_addr (cselib_val *addr_elt, cselib_val *mem_elt, rtx x)
 {
-  struct elt_loc_list *l;
-
   addr_elt = canonical_cselib_val (addr_elt);
   mem_elt = canonical_cselib_val (mem_elt);
 
   /* Avoid duplicates.  */
-  for (l = mem_elt->locs; l; l = l->next)
+  addr_space_t as = MEM_ADDR_SPACE (x);
+  for (elt_loc_list *l = mem_elt->locs; l; l = l->next)
     if (MEM_P (l->loc)
-	&& CSELIB_VAL_PTR (XEXP (l->loc, 0)) == addr_elt)
+	&& CSELIB_VAL_PTR (XEXP (l->loc, 0)) == addr_elt
+        && MEM_ADDR_SPACE (l->loc) == as)
       {
 	promote_debug_loc (l);
 	return;
@@ -1372,7 +1372,6 @@ cselib_lookup_mem (rtx x, int create)
   cselib_val **slot;
   cselib_val *addr;
   cselib_val *mem_elt;
-  struct elt_list *l;
 
   if (MEM_VOLATILE_P (x) || mode == BLKmode
       || !cselib_record_memory
@@ -1387,14 +1386,19 @@ cselib_lookup_mem (rtx x, int create)
   addr = cselib_lookup (XEXP (x, 0), addr_mode, create, mode);
   if (! addr)
     return 0;
-
   addr = canonical_cselib_val (addr);
+
   /* Find a value that describes a value of our mode at that address.  */
-  for (l = addr->addr_list; l; l = l->next)
+  addr_space_t as = MEM_ADDR_SPACE (x);
+  for (elt_list *l = addr->addr_list; l; l = l->next)
     if (GET_MODE (l->elt->val_rtx) == mode)
       {
-	promote_debug_loc (l->elt->locs);
-	return l->elt;
+	for (elt_loc_list *l2 = l->elt->locs; l2; l2 = l2->next)
+	  if (MEM_P (l2->loc) && MEM_ADDR_SPACE (l2->loc) == as)
+	    {
+	      promote_debug_loc (l->elt->locs);
+	      return l->elt;
+	    }
       }
 
   if (! create)
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index eb7edca..6da4010 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -2718,6 +2718,13 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
   if (!TREE_TYPE (arg0) || !TREE_TYPE (arg1))
     return 0;
 
+  /* We cannot consider pointers to different address space equal.  */
+  if (POINTER_TYPE_P (TREE_TYPE (arg0))
+      && POINTER_TYPE_P (TREE_TYPE (arg1))
+      && (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (arg0)))
+	  != TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (arg1)))))
+    return 0;
+
   /* Check equality of integer constants before bailing out due to
      precision differences.  */
   if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST)
@@ -2741,13 +2748,6 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
 			     != POINTER_TYPE_P (TREE_TYPE (arg1)))
 	return 0;
 
-      /* We cannot consider pointers to different address space equal.  */
-      if (POINTER_TYPE_P (TREE_TYPE (arg0))
-			  && POINTER_TYPE_P (TREE_TYPE (arg1))
-	  && (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (arg0)))
-	      != TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (arg1)))))
-	return 0;
-
       /* If both types don't have the same precision, then it is not safe
 	 to strip NOPs.  */
       if (element_precision (TREE_TYPE (arg0))
diff --git a/gcc/testsuite/gcc.target/i386/addr-space-2.c b/gcc/testsuite/gcc.target/i386/addr-space-2.c
new file mode 100644
index 0000000..d5c24b6
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/addr-space-2.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O" } */
+/* { dg-final { scan-assembler "fs:16" } } */
+/* { dg-final { scan-assembler "gs:16" } } */
+
+int test(void)
+{
+  int __seg_fs *f = (int __seg_fs *)16;
+  int __seg_gs *g = (int __seg_gs *)16;
+  return *f + *g;
+}
-- 
2.4.3

  parent reply	other threads:[~2015-10-20 21:28 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-20 21:27 [PATCH v2 00/13] Address space support for x86 Richard Henderson
2015-10-20 21:28 ` [PATCH v2 06/13] i386: Replace ix86_address_seg with addr_space_t Richard Henderson
2015-10-20 21:28 ` [PATCH v2 02/13] Relax ADDR_SPACE_GENERIC_P checks for default address space hooks Richard Henderson
2015-10-21 14:02   ` Jeff Law
2015-10-21 20:50     ` Richard Henderson
2015-10-20 21:28 ` [PATCH v2 05/13] i386: Add address spaces for fs/gs segments Richard Henderson
2015-10-20 21:28 ` [PATCH v2 01/13] Change default of non-overlapping address space conversion Richard Henderson
2015-10-21 14:03   ` Jeff Law
2015-10-20 21:28 ` [PATCH v2 04/13] i386: Disallow address spaces with string insns Richard Henderson
2015-10-20 21:28 ` Richard Henderson [this message]
2015-10-21 13:49   ` [PATCH v2 10/13] Avoid CSE of MEMs in different address spaces Jeff Law
2015-10-21 17:12     ` Richard Henderson
2015-10-22  7:48       ` Richard Biener
2015-10-20 21:28 ` [PATCH v2 07/13] i386: Add address space for tls Richard Henderson
2015-10-20 21:28 ` [PATCH v2 08/13] Add TARGET_ADDR_SPACE_ZERO_ADDRESS_VALID Richard Henderson
2015-10-21 13:59   ` Jeff Law
2015-10-21 20:51     ` Richard Henderson
2015-10-21 21:29       ` Jeff Law
2015-10-22  3:27   ` Sandra Loosemore
2015-10-22  7:59     ` Richard Biener
2015-10-23 17:08       ` Sandra Loosemore
2015-10-22 19:17     ` Richard Henderson
2015-10-20 21:28 ` [PATCH v2 09/13] Fix PR 66768 Richard Henderson
2015-10-21 13:56   ` Jeff Law
2015-10-21 17:55     ` Richard Henderson
2015-10-20 21:28 ` [PATCH v2 12/13] Document the x86 address spaces Richard Henderson
2015-10-22  4:59   ` Sandra Loosemore
2015-10-22 20:30     ` Richard Henderson
2015-10-23 17:16       ` Sandra Loosemore
2015-10-20 21:28 ` [PATCH v2 11/13] Test case for conversion from __seg_tls:0 Richard Henderson
2015-11-09 14:46   ` Richard Biener
2015-11-09 17:55     ` Thomas Schwinge
2015-10-20 21:28 ` [PATCH v2 13/13] Add hook for modifying debug info for address spaces Richard Henderson
2015-10-21 13:55   ` Jeff Law
2015-10-21 14:57   ` H.J. Lu
2015-10-21 17:23     ` Richard Henderson
2015-10-21 17:25       ` H.J. Lu
2015-10-21 17:51         ` Richard Henderson
2015-10-21 18:36           ` H.J. Lu
2015-10-21 16:22   ` Ulrich Weigand
2015-10-21 19:13     ` Richard Henderson
2015-10-22 14:19       ` Ulrich Weigand
2015-10-20 21:34 ` [PATCH v2 03/13] i386: Handle address spaces in movabs patterns Richard Henderson

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=1445376433-14658-11-git-send-email-rth@redhat.com \
    --to=rth@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.guenther@gmail.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).