This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Avoid unnecesary MEM RTXes


> On Sat, Jan 24, 2004 at 01:34:02AM +0100, Jan Hubicka wrote:
> > I see.  Would be sane to simply notice that and return early in these
> > functions?
> 
> That's what I had been thinking, yes.
I am already testing the attached patch.  Does it look fine?

2004-01-24  Jan Hubicka  <jh@suse.cz>
	* emit-rtl.c (change_address, adjust_address_1, offset_address,
	widen_memory_access):  Return early when there is nothing to change.
Index: emit-rtl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/emit-rtl.c,v
retrieving revision 1.368
diff -c -3 -p -r1.368 emit-rtl.c
*** emit-rtl.c	23 Jan 2004 22:05:18 -0000	1.368
--- emit-rtl.c	24 Jan 2004 00:54:04 -0000
*************** change_address (rtx memref, enum machine
*** 1872,1877 ****
--- 1880,1889 ----
    rtx new = change_address_1 (memref, mode, addr, 1);
    enum machine_mode mmode = GET_MODE (new);
  
+   /* If there are no changes, just return the original memory reference.  */
+   if (new == memref)
+     return new;
+ 
    MEM_ATTRS (new)
      = get_mem_attrs (MEM_ALIAS_SET (memref), 0, 0,
  		     mmode == BLKmode ? 0 : GEN_INT (GET_MODE_SIZE (mmode)),
*************** adjust_address_1 (rtx memref, enum machi
*** 1898,1903 ****
--- 1910,1920 ----
    rtx size = 0;
    unsigned int memalign = MEM_ALIGN (memref);
  
+   /* If there are no changes, just return the original memory reference.  */
+   if (mode == GET_MODE (memref) && !offset
+       && (!validate || memory_address_p (mode, addr)))
+     return memref;
+ 
    /* ??? Prefer to create garbage instead of creating shared rtl.
       This may happen even if offset is nonzero -- consider
       (plus (plus reg reg) const_int) -- so do this always.  */
*************** offset_address (rtx memref, rtx offset, 
*** 1988,1993 ****
--- 2005,2014 ----
    update_temp_slot_address (XEXP (memref, 0), new);
    new = change_address_1 (memref, VOIDmode, new, 1);
  
+   /* If there are no changes, just return the original memory reference.  */
+   if (new == memref)
+     return new;
+ 
    /* Update the alignment to reflect the offset.  Reset the offset, which
       we don't know.  */
    MEM_ATTRS (new)
*************** widen_memory_access (rtx memref, enum ma
*** 2031,2036 ****
--- 2052,2061 ----
    tree expr = MEM_EXPR (new);
    rtx memoffset = MEM_OFFSET (new);
    unsigned int size = GET_MODE_SIZE (mode);
+ 
+   /* If there are no changes, just return the original memory reference.  */
+   if (new == memref)
+     return new;
  
    /* If we don't know what offset we were at within the expression, then
       we can't know if we've overstepped the bounds.  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]