This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Avoid some more REG_EQUAL ASM_OPERANDS notes
- To: Richard Henderson <rth at redhat dot com>
- Subject: Re: [PATCH] Avoid some more REG_EQUAL ASM_OPERANDS notes
- From: Jakub Jelinek <jakub at redhat dot com>
- Date: Mon, 29 Oct 2001 19:15:34 -0500
- Cc: gcc-patches at gcc dot gnu dot org
- References: <20011029153717.F22496@sunsite.ms.mff.cuni.cz> <20011029091920.B9074@redhat.com>
- Reply-To: Jakub Jelinek <jakub at redhat dot com>
On Mon, Oct 29, 2001 at 09:19:20AM -0800, Richard Henderson wrote:
> On Mon, Oct 29, 2001 at 03:37:17PM +0100, Jakub Jelinek wrote:
> > * gcse.c (try_replace_reg): Don't create REG_EQUAL notes for
> > ASM_OPERANDS.
> >
> > * gcc.dg/20011029-2.c: New test.
>
> Hmm. Conceptually ok.
>
> We should codify what is OK to have in a REG_EQUAL note and centralize
> that knowledge in a function, rather than open-coding in multiple places.
Do you mean something like:
2001-10-30 Jakub Jelinek <jakub@redhat.com>
* emit-rtl.c (set_unique_reg_note): Don't create REG_EQUAL or
REG_EQUIV notes for ASM_OPERANDS. Return the new note (if any).
* rtl.h (set_unique_reg_note): Change return value.
* gcse.c (try_replace_reg): Use set_unique_reg_note.
* cse.c (cse_insn): Likewise.
* expr.c (emit_move_insn): Likewise.
* explow.c (force_reg): Likewise.
* local-alloc (update_equiv_regs): Likewise.
* loop.c (move_moveables, load_mems): Likewise.
* reload (find_reloads): Likewise.
* gcc.dg/20011029-2.c: New test.
--- gcc/gcse.c.jj Mon Oct 29 15:06:34 2001
+++ gcc/gcse.c Tue Oct 30 00:58:46 2001
@@ -3933,8 +3933,7 @@ try_replace_reg (from, to, insn)
/* If we've failed to do replacement, have a single SET, and don't already
have a note, add a REG_EQUAL note to not lose information. */
if (!success && note == 0 && set != 0)
- note = REG_NOTES (insn)
- = gen_rtx_EXPR_LIST (REG_EQUAL, src, REG_NOTES (insn));
+ note = set_unique_reg_note (insn, REG_EQUAL, src);
/* If there is already a NOTE, update the expression in it with our
replacement. */
--- gcc/emit-rtl.c.jj Thu Oct 25 20:35:53 2001
+++ gcc/emit-rtl.c Tue Oct 30 01:15:48 2001
@@ -3960,7 +3960,7 @@ force_next_line_note ()
/* Place a note of KIND on insn INSN with DATUM as the datum. If a
note of this type already exists, remove it first. */
-void
+rtx
set_unique_reg_note (insn, kind, datum)
rtx insn;
enum reg_note kind;
@@ -3968,11 +3968,20 @@ set_unique_reg_note (insn, kind, datum)
{
rtx note = find_reg_note (insn, kind, NULL_RTX);
- /* First remove the note if there already is one. */
+ /* Don't add ASM_OPERAND REG_EQUAL/REG_EQUIV notes.
+ It serves no useful purpose and breaks eliminate_regs. */
+ if ((kind == REG_EQUAL || kind == REG_EQUIV)
+ && GET_CODE (datum) == ASM_OPERANDS)
+ return NULL_RTX;
+
if (note)
- remove_note (insn, note);
+ {
+ XEXP (note, 0) = datum;
+ return note;
+ }
REG_NOTES (insn) = gen_rtx_EXPR_LIST (kind, datum, REG_NOTES (insn));
+ return REG_NOTES (insn);
}
/* Return an indication of which type of insn should have X as a body.
--- gcc/rtl.h.jj Thu Oct 25 20:35:54 2001
+++ gcc/rtl.h Tue Oct 30 01:16:10 2001
@@ -1409,7 +1409,7 @@ extern enum machine_mode choose_hard_reg
unsigned int));
/* In emit-rtl.c */
-extern void set_unique_reg_note PARAMS ((rtx, enum reg_note, rtx));
+extern rtx set_unique_reg_note PARAMS ((rtx, enum reg_note, rtx));
/* Functions in rtlanal.c */
--- gcc/testsuite/gcc.dg/20011029-2.c.jj Mon Oct 29 15:35:40 2001
+++ gcc/testsuite/gcc.dg/20011029-2.c Mon Oct 29 15:38:23 2001
@@ -0,0 +1,23 @@
+/* { dg-do compile { target i?86-*-* } } */
+/* { dg-options "-O2" } */
+
+int foo (int s)
+{
+ for (;;)
+ {
+ int a[32];
+ int y, z;
+ __asm__ __volatile__ ("" : "=c" (y), "=D" (z)
+ : "a" (0), "0" (32), "1" (a) : "memory");
+ if (({ register char r;
+ __asm__ __volatile__ ("" : "=q" (r)
+ : "r" (s % 32), "m" (a[s / 32])
+ : "cc"); r; }))
+ continue;
+ else if (({ register char r;
+ __asm__ __volatile__ ("" : "=q" (r)
+ : "r" (0), "m" (a)
+ : "cc"); r; }))
+ continue;
+ }
+}
--- gcc/cse.c.jj Mon Oct 29 15:05:39 2001
+++ gcc/cse.c Tue Oct 30 00:54:56 2001
@@ -5648,18 +5648,12 @@ cse_insn (insn, libcall_insn)
&& GET_CODE (XEXP (XEXP (src_const, 0), 0)) == LABEL_REF
&& GET_CODE (XEXP (XEXP (src_const, 0), 1)) == LABEL_REF))
{
- tem = find_reg_note (insn, REG_EQUAL, NULL_RTX);
-
/* Make sure that the rtx is not shared with any other insn. */
src_const = copy_rtx (src_const);
/* Record the actual constant value in a REG_EQUAL note, making
a new one if one does not already exist. */
- if (tem)
- XEXP (tem, 0) = src_const;
- else
- REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EQUAL,
- src_const, REG_NOTES (insn));
+ set_unique_reg_note (insn, REG_EQUAL, src_const);
/* If storing a constant value in a register that
previously held the constant value 0,
--- gcc/expr.c.jj Mon Oct 29 15:06:33 2001
+++ gcc/expr.c Tue Oct 30 00:59:55 2001
@@ -2774,8 +2774,7 @@ emit_move_insn (x, y)
last_insn = emit_move_insn_1 (x, y);
if (y_cst && GET_CODE (x) == REG)
- REG_NOTES (last_insn)
- = gen_rtx_EXPR_LIST (REG_EQUAL, y_cst, REG_NOTES (last_insn));
+ set_unique_reg_note (last_insn, REG_EQUAL, y_cst);
return last_insn;
}
--- gcc/explow.c.jj Wed Oct 24 17:33:58 2001
+++ gcc/explow.c Tue Oct 30 01:05:26 2001
@@ -743,14 +743,7 @@ force_reg (mode, x)
if (CONSTANT_P (x)
&& (set = single_set (insn)) != 0
&& SET_DEST (set) == temp)
- {
- rtx note = find_reg_note (insn, REG_EQUAL, NULL_RTX);
-
- if (note)
- XEXP (note, 0) = x;
- else
- REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EQUAL, x, REG_NOTES (insn));
- }
+ set_unique_reg_note (insn, REG_EQUAL, x);
return temp;
}
--- gcc/local-alloc.c.jj Mon Oct 29 15:06:34 2001
+++ gcc/local-alloc.c Tue Oct 30 01:07:52 2001
@@ -927,13 +927,9 @@ update_equiv_regs ()
/* cse sometimes generates function invariants, but doesn't put a
REG_EQUAL note on the insn. Since this note would be redundant,
- there's no point creating it earlier than here. Don't do this
- for ASM_OPERANDS since eliminate_regs doesn't support it and
- it serves no useful purpose. */
- if (! note && ! rtx_varies_p (src, 0)
- && GET_CODE (src) != ASM_OPERANDS)
- REG_NOTES (insn)
- = note = gen_rtx_EXPR_LIST (REG_EQUAL, src, REG_NOTES (insn));
+ there's no point creating it earlier than here. */
+ if (! note && ! rtx_varies_p (src, 0))
+ note = set_unique_reg_note (insn, REG_EQUAL, src);
/* Don't bother considering a REG_EQUAL note containing an EXPR_LIST
since it represents a function call */
--- gcc/loop.c.jj Mon Oct 29 15:06:34 2001
+++ gcc/loop.c Tue Oct 30 01:13:32 2001
@@ -1831,9 +1831,9 @@ move_movables (loop, movables, threshold
i1 = loop_insn_hoist (loop, seq);
if (! find_reg_note (i1, REG_EQUAL, NULL_RTX))
- REG_NOTES (i1)
- = gen_rtx_EXPR_LIST (m->is_equiv ? REG_EQUIV : REG_EQUAL,
- m->set_src, REG_NOTES (i1));
+ set_unique_reg_note (i1,
+ m->is_equiv ? REG_EQUIV : REG_EQUAL,
+ m->set_src);
if (loop_dump_stream)
fprintf (loop_dump_stream, " moved to %d", INSN_UID (i1));
@@ -1991,10 +1991,8 @@ move_movables (loop, movables, threshold
i1 = loop_insn_hoist (loop, seq);
if (! find_reg_note (i1, REG_EQUAL, NULL_RTX))
- REG_NOTES (i1)
- = gen_rtx_EXPR_LIST ((m->is_equiv ? REG_EQUIV
- : REG_EQUAL),
- m->set_src, REG_NOTES (i1));
+ set_unique_reg_note (i1, m->is_equiv ? REG_EQUIV
+ : REG_EQUAL, m->set_src);
}
else
i1 = loop_insn_hoist (loop, PATTERN (p));
@@ -9136,9 +9134,7 @@ load_mems (loop)
}
if (const_equiv)
- REG_NOTES (set) = gen_rtx_EXPR_LIST (REG_EQUAL,
- copy_rtx (const_equiv->loc),
- REG_NOTES (set));
+ set_unique_reg_note (set, REG_EQUAL, copy_rtx (const_equiv->loc));
if (written)
{
--- gcc/reload.c.jj Mon Oct 22 11:07:03 2001
+++ gcc/reload.c Tue Oct 30 01:15:13 2001
@@ -2666,9 +2666,9 @@ find_reloads (insn, replace, ind_levels,
&& GET_CODE (reg) == REG
&& (GET_MODE_SIZE (GET_MODE (reg))
>= GET_MODE_SIZE (GET_MODE (op))))
- REG_NOTES (emit_insn_before (gen_rtx_USE (VOIDmode, reg), insn))
- = gen_rtx_EXPR_LIST (REG_EQUAL,
- reg_equiv_memory_loc[REGNO (reg)], NULL_RTX);
+ set_unique_reg_note (emit_insn_before (gen_rtx_USE (VOIDmode, reg),
+ insn),
+ REG_EQUAL, reg_equiv_memory_loc[REGNO (reg)]);
substed_operand[i] = recog_data.operand[i] = op;
}
Jakub