This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
PATCH: optimization/5844: Bad code generated for -O2 -mcpu=i586
- From: "H . J . Lu" <hjl at lucon dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 6 Mar 2002 09:53:02 -0800
- Subject: PATCH: optimization/5844: Bad code generated for -O2 -mcpu=i586
- References: <20020305182642.A6139@lucon.org> <20020306000218.A11157@lucon.org>
On Wed, Mar 06, 2002 at 12:02:18AM -0800, H . J . Lu wrote:
> On Tue, Mar 05, 2002 at 06:26:42PM -0800, H . J . Lu wrote:
> > The bug is in copyprop_hardreg_forward. It turns
> >
> > (insn 83 35 84 (set (reg:SI 0 eax)
> > (mem/s:SI (plus:SI (reg/v/f:SI 2 ecx [58])
> > (const_int 4 [0x4])) [4 <variable>.uncaughtExceptions+0 S4 A32])) -1 (nil)
> > (nil))
> >
> > (insn 84 83 85 (parallel[
> > (set (reg:SI 0 eax)
> > (plus:SI (reg:SI 0 eax)
> > (const_int 1 [0x1])))
> > (clobber (reg:CC 17 flags))
> > ] ) -1 (nil)
> > (expr_list:REG_UNUSED (reg:CC 17 flags)
> > (nil)))
> >
> > (insn 85 84 40 (set (mem/s:SI (plus:SI (reg/v/f:SI 2 ecx [58])
> > (const_int 4 [0x4])) [4 <variable>.uncaughtExceptions+0 S4
> > A32])
> > (reg:SI 0 eax)) -1 (nil)
> > (expr_list:REG_DEAD (reg:SI 0 eax)
> > (nil)))
> >
> > into
> >
> > (insn 83 35 84 (set (reg:SI 0 eax)
> > (mem/s:SI (plus:SI (reg:SI 0 eax [58])
> > (const_int 4 [0x4])) [4 <variable>.uncaughtExceptions+0 S4
> > A32])
> > ) 45 {*movsi_1} (nil)
> > (nil))
> >
> > (insn 84 83 85 (parallel[
> > (set (reg:SI 0 eax)
> > (plus:SI (reg:SI 0 eax)
> > (const_int 1 [0x1])))
> > (clobber (reg:CC 17 flags))
> > ] ) 207 {*addsi_1} (nil)
> > (expr_list:REG_UNUSED (reg:CC 17 flags)
> > (nil)))
> >
> > (insn 85 84 40 (set (mem/s:SI (plus:SI (reg:SI 0 eax [58])
> > (const_int 4 [0x4])) [4 <variable>.uncaughtExceptions+0 S4
> > A32])
> > (reg:SI 0 eax)) 45 {*movsi_1} (nil)
> > (expr_list:REG_DEAD (reg:SI 0 eax [58])
> > (nil)))
> >
> >
> > When it sees
> >
> > (insn 83 35 84 (set (reg:SI 0 eax)
> > (mem/s:SI (plus:SI (reg/v/f:SI 2 ecx [58])
> > (const_int 4 [0x4])) [4 <variable>.uncaughtExceptions+0 S4 A32])) -1 (nil)
> > (nil))
> >
> > It believes it can replace ecx with eax since it uses the value data
> > from its predecessor where eax == ecx. Shouldn't it update the value
> > data before passing it to copyprop_hardreg_forward_1?
> >
> >
>
> It is wrong for replace_oldest_value_reg to use the destination of a
> set insn to replace the source of it even if they are the same at that
> insn. After that insn, they won't be the same anymore. This patch
> seems to fix my testcase.
>
>
> H.J.
> ----
> 2002-03-05 H.J. Lu (hjl@gnu.org)
>
> * regrename.c (replace_oldest_value_reg): Don't use the
> destination of a set to replace the register.
>
How about this patch?
H.J.
----
2002-03-06 H.J. Lu (hjl@gnu.org)
* regrename.c (copyprop_hardreg_forward_1): Also kill the
destination register.
--- gcc/regrename.c.i586 Sat Feb 23 13:03:18 2002
+++ gcc/regrename.c Wed Mar 6 09:48:06 2002
@@ -1600,6 +1600,9 @@ copyprop_hardreg_forward_1 (bb, vd)
register in the same class. */
if (REG_P (SET_DEST (set)))
{
+ /* Kill the destination. */
+ kill_value (SET_DEST (set), vd);
+
new = find_oldest_value_reg (REGNO_REG_CLASS (regno), src, vd);
if (new && validate_change (insn, &SET_SRC (set), new, 0))
{