Patchwork [2/8] Add adjust_bitfield_address_size

login
register
mail settings
Submitter Richard Sandiford
Date Nov. 3, 2012, 11:14 a.m.
Message ID <87boffey5n.fsf@talisman.home>
Download mbox | patch
Permalink /patch/196820/
State New
Headers show

Comments

Richard Sandiford - Nov. 3, 2012, 11:14 a.m.
As mentioned in the covering note, the new memory optabs take a BLKmode
reference to the bitfield.  That requires a new adjust_bitfield_address
interface that takes the size of the reference as a parameter.

Tested as described in the covering note.  OK to install?

Richard


gcc/
	* expr.h (adjust_address_1): Add a size parameter.
	(adjust_address, adjust_address_nv, adjust_bitfield_address)
	(adjust_bitfield_address_nv): Adjust accordingly.
	(adjust_bitfield_address_size): Define.
	* emit-rtl.c (adjust_address_1): Add a size parameter.
	Use it to set the size if MODE has no size.  Check whether
	the size matches before returning the original memref.
	Require the size to be known for adjust_object.
	(adjust_automodify_address_1, widen_memory_access): Update calls
	to adjust_address_1.
Eric Botcazou - Nov. 10, 2012, 3:51 p.m.
> Tested as described in the covering note.  OK to install?
> 
> Richard
> 
> 
> gcc/
> 	* expr.h (adjust_address_1): Add a size parameter.
> 	(adjust_address, adjust_address_nv, adjust_bitfield_address)
> 	(adjust_bitfield_address_nv): Adjust accordingly.
> 	(adjust_bitfield_address_size): Define.
> 	* emit-rtl.c (adjust_address_1): Add a size parameter.
> 	Use it to set the size if MODE has no size.  Check whether
> 	the size matches before returning the original memref.
> 	Require the size to be known for adjust_object.
> 	(adjust_automodify_address_1, widen_memory_access): Update calls
> 	to adjust_address_1.

No objections by me.

Patch

Index: gcc/expr.h
===================================================================
--- gcc/expr.h	2012-11-01 23:06:58.000000000 +0000
+++ gcc/expr.h	2012-11-01 23:12:39.719369067 +0000
@@ -557,22 +557,27 @@  extern rtx change_address (rtx, enum mac
 /* Return a memory reference like MEMREF, but with its mode changed
    to MODE and its address offset by OFFSET bytes.  */
 #define adjust_address(MEMREF, MODE, OFFSET) \
-  adjust_address_1 (MEMREF, MODE, OFFSET, 1, 1, 0)
+  adjust_address_1 (MEMREF, MODE, OFFSET, 1, 1, 0, 0)
 
 /* Likewise, but the reference is not required to be valid.  */
 #define adjust_address_nv(MEMREF, MODE, OFFSET) \
-  adjust_address_1 (MEMREF, MODE, OFFSET, 0, 1, 0)
+  adjust_address_1 (MEMREF, MODE, OFFSET, 0, 1, 0, 0)
 
 /* Return a memory reference like MEMREF, but with its mode changed
    to MODE and its address offset by OFFSET bytes.  Assume that it's
    for a bitfield and conservatively drop the underlying object if we
    cannot be sure to stay within its bounds.  */
 #define adjust_bitfield_address(MEMREF, MODE, OFFSET) \
-  adjust_address_1 (MEMREF, MODE, OFFSET, 1, 1, 1)
+  adjust_address_1 (MEMREF, MODE, OFFSET, 1, 1, 1, 0)
+
+/* As for adjust_bitfield_address, but specify that the width of
+   BLKmode accesses is SIZE bytes.  */
+#define adjust_bitfield_address_size(MEMREF, MODE, OFFSET, SIZE) \
+  adjust_address_1 (MEMREF, MODE, OFFSET, 1, 1, 1, SIZE)
 
 /* Likewise, but the reference is not required to be valid.  */
 #define adjust_bitfield_address_nv(MEMREF, MODE, OFFSET) \
-  adjust_address_1 (MEMREF, MODE, OFFSET, 0, 1, 1)
+  adjust_address_1 (MEMREF, MODE, OFFSET, 0, 1, 1, 0)
 
 /* Return a memory reference like MEMREF, but with its mode changed
    to MODE and its address changed to ADDR, which is assumed to be
@@ -585,7 +590,7 @@  #define adjust_automodify_address_nv(MEM
   adjust_automodify_address_1 (MEMREF, MODE, ADDR, OFFSET, 0)
 
 extern rtx adjust_address_1 (rtx, enum machine_mode, HOST_WIDE_INT, int, int,
-			     int);
+			     int, HOST_WIDE_INT);
 extern rtx adjust_automodify_address_1 (rtx, enum machine_mode, rtx,
 					HOST_WIDE_INT, int);
 
Index: gcc/emit-rtl.c
===================================================================
--- gcc/emit-rtl.c	2012-11-01 23:06:58.000000000 +0000
+++ gcc/emit-rtl.c	2012-11-01 23:15:35.968368637 +0000
@@ -2061,11 +2061,14 @@  change_address (rtx memref, enum machine
    If ADJUST_OBJECT is zero, the underlying object associated with the
    memory reference is left unchanged and the caller is responsible for
    dealing with it.  Otherwise, if the new memory reference is outside
-   the underlying object, even partially, then the object is dropped.  */
+   the underlying object, even partially, then the object is dropped.
+   SIZE, if nonzero, is the size of an access in cases where MODE
+   has no inherent size.  */
 
 rtx
 adjust_address_1 (rtx memref, enum machine_mode mode, HOST_WIDE_INT offset,
-		  int validate, int adjust_address, int adjust_object)
+		  int validate, int adjust_address, int adjust_object,
+		  HOST_WIDE_INT size)
 {
   rtx addr = XEXP (memref, 0);
   rtx new_rtx;
@@ -2076,8 +2079,14 @@  adjust_address_1 (rtx memref, enum machi
 
   attrs = *get_mem_attrs (memref);
 
+  /* Take the size of non-BLKmode accesses from the mode.  */
+  defattrs = mode_mem_attrs[(int) mode];
+  if (defattrs->size_known_p)
+    size = defattrs->size;
+
   /* If there are no changes, just return the original memory reference.  */
   if (mode == GET_MODE (memref) && !offset
+      && (size == 0 || (attrs.size_known_p && attrs.size == size))
       && (!validate || memory_address_addr_space_p (mode, addr,
 						    attrs.addrspace)))
     return memref;
@@ -2150,24 +2159,23 @@  adjust_address_1 (rtx memref, enum machi
       attrs.align = MIN (attrs.align, max_align);
     }
 
-  /* We can compute the size in a number of ways.  */
-  defattrs = mode_mem_attrs[(int) GET_MODE (new_rtx)];
-  if (defattrs->size_known_p)
+  if (size)
     {
       /* Drop the object if the new right end is not within its bounds.  */
-      if (adjust_object && (offset + defattrs->size) > attrs.size)
+      if (adjust_object && (offset + size) > attrs.size)
 	{
 	  attrs.expr = NULL_TREE;
 	  attrs.alias = 0;
 	}
       attrs.size_known_p = true;
-      attrs.size = defattrs->size;
+      attrs.size = size;
     }
   else if (attrs.size_known_p)
     {
+      gcc_assert (!adjust_object);
       attrs.size -= offset;
-      /* ??? The store_by_pieces machinery generates negative sizes.  */
-      gcc_assert (!(adjust_object && attrs.size < 0));
+      /* ??? The store_by_pieces machinery generates negative sizes,
+	 so don't assert for that here.  */
     }
 
   set_mem_attrs (new_rtx, &attrs);
@@ -2185,7 +2193,7 @@  adjust_automodify_address_1 (rtx memref,
 			     HOST_WIDE_INT offset, int validate)
 {
   memref = change_address_1 (memref, VOIDmode, addr, validate);
-  return adjust_address_1 (memref, mode, offset, validate, 0, 0);
+  return adjust_address_1 (memref, mode, offset, validate, 0, 0, 0);
 }
 
 /* Return a memory reference like MEMREF, but whose address is changed by
@@ -2267,7 +2275,7 @@  replace_equiv_address_nv (rtx memref, rt
 rtx
 widen_memory_access (rtx memref, enum machine_mode mode, HOST_WIDE_INT offset)
 {
-  rtx new_rtx = adjust_address_1 (memref, mode, offset, 1, 1, 0);
+  rtx new_rtx = adjust_address_1 (memref, mode, offset, 1, 1, 0, 0);
   struct mem_attrs attrs;
   unsigned int size = GET_MODE_SIZE (mode);