This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Bug in reload_cse_move2add()
- To: Alexandre Oliva <aoliva at redhat dot com>
- Subject: Re: Bug in reload_cse_move2add()
- From: amylaar at cambridge dot redhat dot com
- Date: Thu, 4 Jan 2001 19:37:20 GMT
- Cc: gcc-patches at gcc dot gnu dot org, amylaar at cambridge dot redhat dot com,law at redhat dot com
[Apologies if this appears twice - I've sent a similar message yesterday, but
it seems to have been lost.]
In article <ork88fju0g.fsf@guarana.lsd.ic.unicamp.br> you wrote:
: Here's a patch that arranges for us to record the original offset when
: we copy from a register, so that we can tell by how much it has
: changed when we attempt to optimize away a new copy. I see this
: infrastructure may enable a number of additional optimizations, by
: simply updating reg_offset without touching reg_set_luid when a
: register is inc/decremented and its reg_offset is already a CONST_INT,
: but I'll leave them for a separate patch, some other day (if I had
: posted this yesterday, I'd have said for the next millennium, but it's
: too late now :-)
If you just want to fix the bug, it should be sufficient to update the luid,
like this:
Index: reload1.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/reload1.c,v
retrieving revision 1.248
diff -p -r1.248 reload1.c
*** reload1.c 2001/01/02 00:59:52 1.248
--- reload1.c 2001/01/03 18:54:58
*************** move2add_note_store (dst, set, data)
*** 9149,9159 ****
{
if (REGNO (src0) != regno
|| reg_offset[regno] != const0_rtx)
! {
! reg_base_reg[regno] = REGNO (src0);
! reg_set_luid[regno] = move2add_luid;
! }
reg_offset[regno] = XEXP (src, 1);
break;
}
--- 9149,9157 ----
{
if (REGNO (src0) != regno
|| reg_offset[regno] != const0_rtx)
! reg_base_reg[regno] = REGNO (src0);
+ reg_set_luid[regno] = move2add_luid;
reg_offset[regno] = XEXP (src, 1);
break;
}
OTOH, if you want to optimize these cases better, you can canonocalize the
reg_base_reg / reg_offset entries to refer to the earliest register. This
gives some additional optimization opportunities, and doesn't need an extra
array:
Index: reload1.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/reload1.c,v
retrieving revision 1.248
diff -p -r1.248 reload1.c
*** reload1.c 2001/01/02 00:59:52 1.248
--- reload1.c 2001/01/03 19:43:12
*************** reload_cse_move2add (first)
*** 9011,9017 ****
...
(set (REGX) (plus (REGX) (CONST_INT B-A))) */
else if (GET_CODE (src) == REG
! && reg_base_reg[regno] == (int) REGNO (src)
&& reg_set_luid[regno] > reg_set_luid[REGNO (src)])
{
rtx next = next_nonnote_insn (insn);
--- 9011,9020 ----
...
(set (REGX) (plus (REGX) (CONST_INT B-A))) */
else if (GET_CODE (src) == REG
! && (reg_base_reg[regno] == (int) REGNO (src)
! || (GET_CODE (reg_offset[REGNO (src)]) == CONST_INT
! && (reg_base_reg[regno]
! == reg_base_reg[REGNO (src)]))
&& reg_set_luid[regno] > reg_set_luid[REGNO (src)])
{
rtx next = next_nonnote_insn (insn);
*************** reload_cse_move2add (first)
*** 9026,9034 ****
--- 9029,9041 ----
&& GET_CODE (XEXP (SET_SRC (set), 1)) == CONST_INT)
{
rtx src3 = XEXP (SET_SRC (set), 1);
+ rtx src_offset =
+ (reg_base_reg[regno] == (int) REGNO (src)
+ ? const0_rtx : reg_offset[REGNO (src)])
rtx new_src
= gen_mode_int (GET_MODE (reg),
INTVAL (src3)
+ + INTVAL (src_offset)
- INTVAL (reg_offset[regno]));
int success = 0;
*************** move2add_note_store (dst, set, data)
*** 9147,9160 ****
if (GET_CODE (src0) == REG)
{
! if (REGNO (src0) != regno
! || reg_offset[regno] != const0_rtx)
{
! reg_base_reg[regno] = REGNO (src0);
! reg_set_luid[regno] = move2add_luid;
}
! reg_offset[regno] = XEXP (src, 1);
break;
}
--- 9154,9171 ----
if (GET_CODE (src0) == REG)
{
! int srcno = REGNO (src0);
! rtx offset = XEXP (src, 1);
!
! if (GET_CODE (reg_offset[srcno]) == CONST_INT)
{
! offset = plus_constant (offset, INTVAL (reg_offset[srcno]));
! srcno = reg_base_reg[srcno];
}
! reg_base_reg[regno] = srcno;
! reg_offset[regno] = offset;
! reg_set_luid[regno] = move2add_luid;
break;
}