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: REQ_EQUAL and mems hoisted out of loops


On Tue, Mar 25, 2003 at 10:42:16PM +1030, Alan Modra wrote:
> Oops, reg 145 has changed in the meantime at insn 41.  From what I can
> tell, the REG_EQUAL notes in combination with the fact that the store
> to "y" has been moved out of the loop by loop optimization, is the cause
> of cse confusion.
> 
> So it seems a possible fix would be to delete all REG_EQUAL notes
> that mention any mem hoisted out of a loop.  Before I try to do that,
> I thought I'd solicit comments on the approach.  Reasonable?

This cures the failures.  Bootstrapped, regression tested powerpc-linux
and powerpc64-linux on 3.3 branch.  Currently testing on mainline.

	* loop.c: Include tree.h.
	(find_mem_in_note_1, find_mem_in_note): New functions.
	(load_mems): Remove invalid REG_EQUAL notes after hoisting.

OK?

Index: gcc/loop.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/loop.c,v
retrieving revision 1.448
diff -u -p -r1.448 loop.c
--- gcc/loop.c	15 Mar 2003 22:51:33 -0000	1.448
+++ gcc/loop.c	26 Mar 2003 08:40:23 -0000
@@ -39,6 +39,7 @@ Software Foundation, 59 Temple Place - S
 #include "coretypes.h"
 #include "tm.h"
 #include "rtl.h"
+#include "tree.h"
 #include "tm_p.h"
 #include "function.h"
 #include "expr.h"
@@ -328,6 +329,8 @@ static void update_reg_last_use PARAMS (
 static rtx next_insn_in_loop PARAMS ((const struct loop *, rtx));
 static void loop_regs_scan PARAMS ((const struct loop *, int));
 static int count_insns_in_loop PARAMS ((const struct loop *));
+static int find_mem_in_note_1 PARAMS ((rtx *, void *));
+static rtx find_mem_in_note PARAMS ((rtx));
 static void load_mems PARAMS ((const struct loop *));
 static int insert_loop_mem PARAMS ((rtx *, void *));
 static int replace_loop_mem PARAMS ((rtx *, void *));
@@ -9800,6 +9803,29 @@ count_insns_in_loop (loop)
   return count;
 }
 
+static int
+find_mem_in_note_1 (x, data)
+     rtx *x;
+     void *data;
+{
+  if (*x != NULL_RTX && GET_CODE (*x) == MEM)
+    {
+      rtx *res = (rtx *) data;
+      *res = *x;
+      return 1;
+    }
+  return 0;
+}
+
+static rtx
+find_mem_in_note (note)
+     rtx note;
+{
+  if (note && for_each_rtx (&note, find_mem_in_note_1, &note))
+    return note;
+  return NULL_RTX;
+}
+  
 /* Move MEMs into registers for the duration of the loop.  */
 
 static void
@@ -10130,6 +10156,25 @@ load_mems (loop)
 	       try_swap_copy_prop (loop, reg, j);
 	     });
 	  CLEAR_REG_SET (&store_copies);
+
+	  /* If we hoist a mem write out of the loop, then REG_EQUAL
+	     notes referring to the mem are no longer valid.  */
+	  if (written)
+	    {
+	      for (p = next_insn_in_loop (loop, loop->scan_start);
+		   p != NULL_RTX;
+		   p = next_insn_in_loop (loop, p))
+		{
+		  rtx note, sub;
+
+		  if (INSN_P (p)
+		      && (note = find_reg_note (p, REG_EQUAL, NULL_RTX))
+		      && (sub = find_mem_in_note (note))
+		      && alias_sets_conflict_p (MEM_ALIAS_SET (mem),
+						MEM_ALIAS_SET (sub)))
+		    remove_note (p, note);
+		}
+	    }
 	}
     }
 

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


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