6efbd5a
2007-04-21  Alexandre Oliva  <aoliva@redhat.com>
6efbd5a
6efbd5a
	* gcse.c (store_killed_in_insn): Handle PARALLELs.
6efbd5a
	(store_killed_in_pat): New.
6efbd5a
6efbd5a
	* gcc.dg/movsi-sm-1.c: New.
6efbd5a
6efbd5a
--- gcc/gcse.c.jj	2007-02-23 21:29:12.000000000 +0100
6efbd5a
+++ gcc/gcse.c	2007-07-18 20:41:08.000000000 +0200
6efbd5a
@@ -7427,6 +7427,40 @@ find_loads (rtx x, rtx store_pattern, in
6efbd5a
   return ret;
6efbd5a
 }
6efbd5a
 
6efbd5a
+static inline bool
6efbd5a
+store_killed_in_pat (rtx x, rtx pat, int after)
6efbd5a
+{
6efbd5a
+  if (GET_CODE (pat) == SET)
6efbd5a
+    {
6efbd5a
+      rtx dest = SET_DEST (pat);
6efbd5a
+
6efbd5a
+      if (GET_CODE (dest) == SIGN_EXTRACT
6efbd5a
+	  || GET_CODE (dest) == ZERO_EXTRACT)
6efbd5a
+	dest = XEXP (dest, 0);
6efbd5a
+
6efbd5a
+      /* Check for memory stores to aliased objects.  */
6efbd5a
+      if (GET_CODE (dest) == MEM
6efbd5a
+	  && !expr_equiv_p (dest, x))
6efbd5a
+	{
6efbd5a
+	  if (after)
6efbd5a
+	    {
6efbd5a
+	      if (output_dependence (dest, x))
6efbd5a
+		return true;
6efbd5a
+	    }
6efbd5a
+	  else
6efbd5a
+	    {
6efbd5a
+	      if (output_dependence (x, dest))
6efbd5a
+		return true;
6efbd5a
+	    }
6efbd5a
+	}
6efbd5a
+    }
6efbd5a
+
6efbd5a
+  if (find_loads (pat, x, after))
6efbd5a
+    return true;
6efbd5a
+
6efbd5a
+  return false;
6efbd5a
+}
6efbd5a
+
6efbd5a
 /* Check if INSN kills the store pattern X (is aliased with it).
6efbd5a
    AFTER is true if we are checking the case when store X occurs
6efbd5a
    after the insn.  Return true if it it does.  */
6efbd5a
@@ -7434,7 +7468,7 @@ find_loads (rtx x, rtx store_pattern, in
6efbd5a
 static bool
6efbd5a
 store_killed_in_insn (rtx x, rtx x_regs, rtx insn, int after)
6efbd5a
 {
6efbd5a
-  rtx reg, base, note;
6efbd5a
+  rtx reg, base, note, pat;
6efbd5a
 
6efbd5a
   if (!INSN_P (insn))
6efbd5a
     return false;
6efbd5a
@@ -7461,33 +7495,20 @@ store_killed_in_insn (rtx x, rtx x_regs,
6efbd5a
       return false;
6efbd5a
     }
6efbd5a
 
6efbd5a
-  if (GET_CODE (PATTERN (insn)) == SET)
6efbd5a
+  pat = PATTERN (insn);
6efbd5a
+  if (GET_CODE (pat) == SET)
6efbd5a
     {
6efbd5a
-      rtx pat = PATTERN (insn);
6efbd5a
-      rtx dest = SET_DEST (pat);
6efbd5a
-
6efbd5a
-      if (GET_CODE (dest) == SIGN_EXTRACT
6efbd5a
-	  || GET_CODE (dest) == ZERO_EXTRACT)
6efbd5a
-	dest = XEXP (dest, 0);
6efbd5a
-
6efbd5a
-      /* Check for memory stores to aliased objects.  */
6efbd5a
-      if (GET_CODE (dest) == MEM
6efbd5a
-	  && !expr_equiv_p (dest, x))
6efbd5a
-	{
6efbd5a
-	  if (after)
6efbd5a
-	    {
6efbd5a
-	      if (output_dependence (dest, x))
6efbd5a
-		return true;
6efbd5a
-	    }
6efbd5a
-	  else
6efbd5a
-	    {
6efbd5a
-	      if (output_dependence (x, dest))
6efbd5a
-		return true;
6efbd5a
-	    }
6efbd5a
-	}
6efbd5a
-      if (find_loads (SET_SRC (pat), x, after))
6efbd5a
+      if (store_killed_in_pat (x, pat, after))
6efbd5a
 	return true;
6efbd5a
     }
6efbd5a
+  else if (GET_CODE (pat) == PARALLEL)
6efbd5a
+    {
6efbd5a
+      int i;
6efbd5a
+
6efbd5a
+      for (i = 0; i < XVECLEN (pat, 0); i++)
6efbd5a
+	if (store_killed_in_pat (x, XVECEXP (pat, 0, i), after))
6efbd5a
+	  return true;
6efbd5a
+    }
6efbd5a
   else if (find_loads (PATTERN (insn), x, after))
6efbd5a
     return true;
6efbd5a
 
6efbd5a
--- gcc/testsuite/gcc.dg/movsi-sm-1.c.jj	2007-07-18 20:58:08.000000000 +0200
6efbd5a
+++ gcc/testsuite/gcc.dg/movsi-sm-1.c	2007-07-18 21:01:52.000000000 +0200
6efbd5a
@@ -0,0 +1,35 @@
6efbd5a
+/* { dg-do run } */
6efbd5a
+/* { dg-options "-O2" } */
6efbd5a
+/* { dg-options "-O2 -mtune=i386" { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
6efbd5a
+
6efbd5a
+int ret = 1;
6efbd5a
+char buf[128];
6efbd5a
+
6efbd5a
+void
6efbd5a
+__attribute__((noinline))
6efbd5a
+bug (int arg)
6efbd5a
+{
6efbd5a
+  char str[28];
6efbd5a
+
6efbd5a
+  __builtin_memcpy (str, "Bugged!", 8);
6efbd5a
+
6efbd5a
+  if (arg & 0200)
6efbd5a
+    {
6efbd5a
+      __builtin_memcpy (str, "This is what we should get!", 28);
6efbd5a
+      ret = 0;
6efbd5a
+    }
6efbd5a
+
6efbd5a
+  if (arg & 0100)
6efbd5a
+    __builtin_memcpy (str, "Broken!", 8);
6efbd5a
+
6efbd5a
+  __builtin_sprintf (buf, "%s\n", str);
6efbd5a
+}
6efbd5a
+
6efbd5a
+int
6efbd5a
+main ()
6efbd5a
+{
6efbd5a
+  bug (0200);
6efbd5a
+  if (ret)
6efbd5a
+    return ret;
6efbd5a
+  return __builtin_strcmp (buf, "This is what we should get!\n") != 0;
6efbd5a
+}