public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Sandiford <richard.sandiford@linaro.org>
To: gcc-patches@gcc.gnu.org
Subject: Make more use of byte_lowpart_offset
Date: Wed, 23 Aug 2017 10:58:00 -0000	[thread overview]
Message-ID: <87shgitv0m.fsf@linaro.org> (raw)

This patch uses byte_lowpart_offset in places that open-coded the
calculation.

Tested on aarch64-linux-gnu and x86_64-linux-gnu, and by making sure
that there were no differences in testsuite assembly output for one
target per CPU.  OK to install?

Richard


2017-08-23  Richard Sandiford  <richard.sandiford@linaro.org>
	    Alan Hayward  <alan.hayward@arm.com>
	    David Sherwood  <david.sherwood@arm.com>

gcc/
	* caller-save.c (replace_reg_with_saved_mem): Use byte_lowpart_offset.
	* combine.c (gen_lowpart_for_combine): Likewise.
	* dwarf2out.c (rtl_for_decl_location): Likewise.
	* final.c (alter_subreg): Likewise.
	* rtlhooks.c (gen_lowpart_general): Likewise.
	(gen_lowpart_if_possible): Likewise.

Index: gcc/caller-save.c
===================================================================
--- gcc/caller-save.c	2017-08-23 10:44:56.292488492 +0100
+++ gcc/caller-save.c	2017-08-23 10:47:17.536760752 +0100
@@ -1129,17 +1129,7 @@ replace_reg_with_saved_mem (rtx *loc,
 	{
 	  /* This is gen_lowpart_if_possible(), but without validating
 	     the newly-formed address.  */
-	  int offset = 0;
-
-	  if (WORDS_BIG_ENDIAN)
-	    offset = (MAX (GET_MODE_SIZE (GET_MODE (mem)), UNITS_PER_WORD)
-		      - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
-	  if (BYTES_BIG_ENDIAN)
-	    /* Adjust the address so that the address-after-the-data is
-	       unchanged.  */
-	    offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))
-		       - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (mem))));
-
+	  HOST_WIDE_INT offset = byte_lowpart_offset (mode, GET_MODE (mem));
 	  mem = adjust_address_nv (mem, mode, offset);
 	}
     }
Index: gcc/combine.c
===================================================================
--- gcc/combine.c	2017-08-23 10:45:34.493718192 +0100
+++ gcc/combine.c	2017-08-23 10:47:17.537756580 +0100
@@ -11458,8 +11458,6 @@ gen_lowpart_for_combine (machine_mode om
 
   if (MEM_P (x))
     {
-      int offset = 0;
-
       /* Refuse to work on a volatile memory ref or one with a mode-dependent
 	 address.  */
       if (MEM_VOLATILE_P (x)
@@ -11472,14 +11470,7 @@ gen_lowpart_for_combine (machine_mode om
       if (paradoxical_subreg_p (omode, imode))
 	return gen_rtx_SUBREG (omode, x, 0);
 
-      if (WORDS_BIG_ENDIAN)
-	offset = MAX (isize, UNITS_PER_WORD) - MAX (osize, UNITS_PER_WORD);
-
-      /* Adjust the address so that the address-after-the-data is
-	 unchanged.  */
-      if (BYTES_BIG_ENDIAN)
-	offset -= MIN (UNITS_PER_WORD, osize) - MIN (UNITS_PER_WORD, isize);
-
+      HOST_WIDE_INT offset = byte_lowpart_offset (omode, imode);
       return adjust_address_nv (x, omode, offset);
     }
 
Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c	2017-08-22 10:15:11.279742253 +0100
+++ gcc/dwarf2out.c	2017-08-23 10:47:17.539748235 +0100
@@ -19064,12 +19064,11 @@ rtl_for_decl_location (tree decl)
   else if (VAR_P (decl)
 	   && rtl
 	   && MEM_P (rtl)
-	   && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
-	   && BYTES_BIG_ENDIAN)
+	   && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl)))
     {
       machine_mode addr_mode = get_address_mode (rtl);
-      int rsize = GET_MODE_SIZE (GET_MODE (rtl));
-      int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
+      HOST_WIDE_INT offset = byte_lowpart_offset (TYPE_MODE (TREE_TYPE (decl)),
+						  GET_MODE (rtl));
 
       /* If a variable is declared "register" yet is smaller than
 	 a register, then if we store the variable to memory, it
@@ -19077,10 +19076,9 @@ rtl_for_decl_location (tree decl)
 	 fact we are not.  We need to adjust the offset of the
 	 storage location to reflect the actual value's bytes,
 	 else gdb will not be able to display it.  */
-      if (rsize > dsize)
+      if (offset != 0)
 	rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
-			   plus_constant (addr_mode, XEXP (rtl, 0),
-					  rsize - dsize));
+			   plus_constant (addr_mode, XEXP (rtl, 0), offset));
     }
 
   /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
Index: gcc/final.c
===================================================================
--- gcc/final.c	2017-08-22 17:14:30.336881519 +0100
+++ gcc/final.c	2017-08-23 10:47:17.540744062 +0100
@@ -3205,14 +3205,7 @@ alter_subreg (rtx *xp, bool final_p)
       /* For paradoxical subregs on big-endian machines, SUBREG_BYTE
 	 contains 0 instead of the proper offset.  See simplify_subreg.  */
       if (paradoxical_subreg_p (x))
-        {
-          int difference = GET_MODE_SIZE (GET_MODE (y))
-			   - GET_MODE_SIZE (GET_MODE (x));
-          if (WORDS_BIG_ENDIAN)
-            offset += (difference / UNITS_PER_WORD) * UNITS_PER_WORD;
-          if (BYTES_BIG_ENDIAN)
-            offset += difference % UNITS_PER_WORD;
-        }
+	offset = byte_lowpart_offset (GET_MODE (x), GET_MODE (y));
 
       if (final_p)
 	*xp = adjust_address (y, GET_MODE (x), offset);
Index: gcc/rtlhooks.c
===================================================================
--- gcc/rtlhooks.c	2017-07-13 09:25:12.420277223 +0100
+++ gcc/rtlhooks.c	2017-08-23 10:47:17.540744062 +0100
@@ -58,8 +58,6 @@ gen_lowpart_general (machine_mode mode,
     }
   else
     {
-      int offset = 0;
-
       /* The only additional case we can do is MEM.  */
       gcc_assert (MEM_P (x));
 
@@ -70,16 +68,7 @@ gen_lowpart_general (machine_mode mode,
 	  && !reload_completed)
 	return gen_lowpart_general (mode, force_reg (GET_MODE (x), x));
 
-      if (WORDS_BIG_ENDIAN)
-	offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
-		  - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
-
-      if (BYTES_BIG_ENDIAN)
-	/* Adjust the address so that the address-after-the-data
-	   is unchanged.  */
-	offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))
-		   - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
-
+      HOST_WIDE_INT offset = byte_lowpart_offset (mode, GET_MODE (x));
       return adjust_address (x, mode, offset);
     }
 }
@@ -132,19 +121,8 @@ gen_lowpart_if_possible (machine_mode mo
   else if (MEM_P (x))
     {
       /* This is the only other case we handle.  */
-      int offset = 0;
-      rtx new_rtx;
-
-      if (WORDS_BIG_ENDIAN)
-	offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
-		  - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
-      if (BYTES_BIG_ENDIAN)
-	/* Adjust the address so that the address-after-the-data is
-	   unchanged.  */
-	offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))
-		   - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
-
-      new_rtx = adjust_address_nv (x, mode, offset);
+      HOST_WIDE_INT offset = byte_lowpart_offset (mode, GET_MODE (x));
+      rtx new_rtx = adjust_address_nv (x, mode, offset);
       if (! memory_address_addr_space_p (mode, XEXP (new_rtx, 0),
 					 MEM_ADDR_SPACE (x)))
 	return 0;

             reply	other threads:[~2017-08-23 10:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-23 10:58 Richard Sandiford [this message]
2017-10-12 23:02 ` 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=87shgitv0m.fsf@linaro.org \
    --to=richard.sandiford@linaro.org \
    --cc=gcc-patches@gcc.gnu.org \
    /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).