This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: REQ_EQUAL and mems hoisted out of loops
On Thu, Mar 27, 2003 at 03:49:08PM -0800, Richard Henderson wrote:
> On Wed, Mar 26, 2003 at 07:19:33PM +1030, Alan Modra wrote:
> > (load_mems): Remove invalid REG_EQUAL notes after hoisting.
>
> I think this is the wrong spot to handle this.
> Do it in replace_loop_mems instead.
Yeah, that's neater.
* loop.c: Include tree.h.
(find_mem_in_note_1, find_mem_in_note): New functions.
(replace_loop_mems): Add "written" param. Remove invalid REG_EQUAL
notes after hoisting.
(load_mems): Adjust replace_loop_mems call.
* Makefile.in (loop.o): Add TREE_H to deps.
Currently regtesting.
Index: gcc/loop.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/loop.c,v
retrieving revision 1.449
diff -u -p -r1.449 loop.c
--- gcc/loop.c 27 Mar 2003 18:53:35 -0000 1.449
+++ gcc/loop.c 28 Mar 2003 01:47:03 -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,10 +329,12 @@ 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 *));
-static void replace_loop_mems PARAMS ((rtx, rtx, rtx));
+static void replace_loop_mems PARAMS ((rtx, rtx, rtx, int));
static int replace_loop_reg PARAMS ((rtx *, void *));
static void replace_loop_regs PARAMS ((rtx insn, rtx, rtx));
static void note_reg_stored PARAMS ((rtx, rtx, void *));
@@ -10033,7 +10036,7 @@ load_mems (loop)
else
/* Replace the memory reference with the shadow register. */
replace_loop_mems (p, loop_info->mems[i].mem,
- loop_info->mems[i].reg);
+ loop_info->mems[i].reg, written);
}
if (GET_CODE (p) == CODE_LABEL
@@ -10398,6 +10401,29 @@ try_swap_copy_prop (loop, replacement, r
}
}
+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 (¬e, find_mem_in_note_1, ¬e))
+ return note;
+ return NULL_RTX;
+}
+
/* Replace MEM with its associated pseudo register. This function is
called from load_mems via for_each_rtx. DATA is actually a pointer
to a structure describing the instruction currently being scanned
@@ -10440,10 +10466,11 @@ replace_loop_mem (mem, data)
}
static void
-replace_loop_mems (insn, mem, reg)
+replace_loop_mems (insn, mem, reg, written)
rtx insn;
rtx mem;
rtx reg;
+ int written;
{
loop_replace_args args;
@@ -10452,6 +10479,27 @@ replace_loop_mems (insn, mem, reg)
args.replacement = reg;
for_each_rtx (&insn, replace_loop_mem, &args);
+
+ /* If we hoist a mem write out of the loop, then REG_EQUAL
+ notes referring to the mem are no longer valid. */
+ if (written)
+ {
+ rtx note, sub;
+ rtx *link;
+
+ for (link = ®_NOTES (insn); (note = *link); link = &XEXP (note, 1))
+ {
+ if (REG_NOTE_KIND (note) == REG_EQUAL
+ && (sub = find_mem_in_note (note))
+ && alias_sets_conflict_p (MEM_ALIAS_SET (mem),
+ MEM_ALIAS_SET (sub)))
+ {
+ /* Remove the note. */
+ validate_change (NULL_RTX, link, XEXP (note, 1), 1);
+ break;
+ }
+ }
+ }
}
/* Replace one register with another. Called through for_each_rtx; PX points
Index: gcc/Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.1026
diff -u -p -r1.1026 Makefile.in
--- gcc/Makefile.in 23 Mar 2003 20:13:50 -0000 1.1026
+++ gcc/Makefile.in 28 Mar 2003 01:50:59 -0000
@@ -1616,7 +1616,8 @@ profile.o : profile.c $(CONFIG_H) $(SYST
flags.h insn-config.h output.h $(REGS_H) $(EXPR_H) function.h \
gcov-io.h gcov-iov.h toplev.h $(GGC_H) hard-reg-set.h $(BASIC_BLOCK_H) \
$(TARGET_H) langhooks.h profile.h libfuncs.h gt-profile.h $(HASHTAB_H)
-loop.o : loop.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) flags.h $(LOOP_H) \
+loop.o : loop.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) \
+ $(TREE_H) flags.h $(LOOP_H) \
insn-config.h $(REGS_H) hard-reg-set.h $(RECOG_H) $(EXPR_H) \
real.h $(PREDICT_H) $(BASIC_BLOCK_H) function.h cfgloop.h \
toplev.h varray.h except.h cselib.h $(OPTABS_H) $(TM_P_H)
--
Alan Modra
IBM OzLabs - Linux Technology Centre