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]

PATCH: detect dead memory stores with auto increments


Hello,

I had a problem with the program below:

typedef struct {
    int   amp1:11;
    int       :5;
    int   amp2:11;
    int       :5;
} amp;

void
cor(amp *a, int n, int cor1, int cor2, int min, int max)
{
	int	i;
	int	new;

	for (i = 0 ; i < n ; i++) {
		new = a[i].amp1 + cor1;
		new = (new < min) ? min : new;
		new = (new > max) ? max : new;
		a[i].amp1 = new;
		new = a[i].amp2 + cor2;
		new = (new < min) ? min : new;
		new = (new > max) ? max : new;
		a[i].amp2 = new;
	}
}

The store to a[i].amp1 was not removed because the sore to a[i].amp2 was
changed into an auto increment. To solve this I changed flow to handle
this. If a post increment/decrement or modify is used and any previous
memory store refers to the same memory location we can delete this store.
I tested this on the c4x. It passes the torture tests.

	Herman.

2000-08-07 Herman A.J. ten Brugge <Haj.Ten.Brugge@net.HCC.nl>

	* flow.c (insn_dead_p): Detect dead memory stores with auto increments.


--- flow.c.org	Mon Aug  7 19:43:30 2000
+++ flow.c	Mon Aug  7 20:26:19 2000
@@ -3923,8 +3923,22 @@ insn_dead_p (pbi, x, call_ok, notes)
 	  temp = pbi->mem_set_list;
 	  while (temp)
 	    {
-	      if (rtx_equal_p (XEXP (temp, 0), r))
+	      rtx mem = XEXP (temp, 0);
+
+	      if (rtx_equal_p (mem, r))
 		return 1;
+#ifdef AUTO_INC_DEC
+	      /* Check if memory reference matches an auto increment. Only
+		 post increment/decrement or modify are valid.  */
+      	      if (GET_MODE (mem) == GET_MODE (r)
+		  && MEM_IN_STRUCT_P (mem) == MEM_IN_STRUCT_P (r)
+	          && (GET_CODE (XEXP (mem, 0)) == POST_DEC
+	              || GET_CODE (XEXP (mem, 0)) == POST_INC
+	              || GET_CODE (XEXP (mem, 0)) == POST_MODIFY)
+		  && GET_MODE (XEXP (mem, 0)) == GET_MODE (r)
+		  && rtx_equal_p (XEXP (XEXP (mem, 0), 0), XEXP (r, 0)))
+		return 1;
+#endif
 	      temp = XEXP (temp, 1);
 	    }
 	}

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