diff mbox

0004-Set-pseudos-only-once.patch

Message ID 4C18F46C.6090809@codesourcery.com
State New
Headers show

Commit Message

Maxim Kuvyrkov June 16, 2010, 3:57 p.m. UTC
IRA and reload has special relationship with pseudos that are set only 
once.  When such pseudos initialized with constants or instances that 
can be considered constant across the function, reload can rematerialize 
them instead of spilling or apply other optimizations.

This patch makes sure that we don't unnecessarily set same pseudo more 
than once.

OK to apply?

Thank you,

Comments

Jeff Law June 21, 2010, 5:55 p.m. UTC | #1
On 06/16/10 09:57, Maxim Kuvyrkov wrote:
> IRA and reload has special relationship with pseudos that are set only 
> once.  When such pseudos initialized with constants or instances that 
> can be considered constant across the function, reload can 
> rematerialize them instead of spilling or apply other optimizations.
>
> This patch makes sure that we don't unnecessarily set same pseudo more 
> than once.
>
> OK to apply?
OK.  THanks,
Jeff
Maxim Kuvyrkov June 22, 2010, 12:08 p.m. UTC | #2
On 6/21/10 9:55 PM, Jeff Law wrote:
> On 06/16/10 09:57, Maxim Kuvyrkov wrote:
>> IRA and reload has special relationship with pseudos that are set only
>> once. When such pseudos initialized with constants or instances that
>> can be considered constant across the function, reload can
>> rematerialize them instead of spilling or apply other optimizations.
>>
>> This patch makes sure that we don't unnecessarily set same pseudo more
>> than once.
>>
>> OK to apply?
> OK. THanks,

Thank you for reviewing this and other patches.

There is similar code in gcse.c:pre_delete():

		/* Create a pseudo-reg to store the result of reaching
		   expressions into.  Get the mode for the new pseudo from
		   the mode of the original destination pseudo.  */
		if (expr->reaching_reg == NULL)
		  expr->reaching_reg = gen_reg_rtx_and_attrs (SET_DEST (set));

		gcse_emit_move_after (expr->reaching_reg, SET_DEST (set), insn);
		delete_insn (insn);
		occr->deleted_p = 1;
		changed = 1;
		gcse_subst_count++;

 From quick look at PRE, it seem that creating a new pseudo for PRE is 
also correct.  Do you know off-hand if this indeed is the case?

Thanks,
Jeff Law June 23, 2010, 9:35 p.m. UTC | #3
On 06/22/10 06:08, Maxim Kuvyrkov wrote:
> On 6/21/10 9:55 PM, Jeff Law wrote:
>> On 06/16/10 09:57, Maxim Kuvyrkov wrote:
>>> IRA and reload has special relationship with pseudos that are set only
>>> once. When such pseudos initialized with constants or instances that
>>> can be considered constant across the function, reload can
>>> rematerialize them instead of spilling or apply other optimizations.
>>>
>>> This patch makes sure that we don't unnecessarily set same pseudo more
>>> than once.
>>>
>>> OK to apply?
>> OK. THanks,
>
> Thank you for reviewing this and other patches.
>
> There is similar code in gcse.c:pre_delete():
>
>         /* Create a pseudo-reg to store the result of reaching
>            expressions into.  Get the mode for the new pseudo from
>            the mode of the original destination pseudo.  */
>         if (expr->reaching_reg == NULL)
>           expr->reaching_reg = gen_reg_rtx_and_attrs (SET_DEST (set));
>
>         gcse_emit_move_after (expr->reaching_reg, SET_DEST (set), insn);
>         delete_insn (insn);
>         occr->deleted_p = 1;
>         changed = 1;
>         gcse_subst_count++;
>
> From quick look at PRE, it seem that creating a new pseudo for PRE is 
> also correct.  Do you know off-hand if this indeed is the case?
Creating a new pseudo for PRE would be good; however, it's not 
immediately clear to me if creating a new pseudo is safe given the way 
deletion & insertion work for our implementation of PRE.

jeff
diff mbox

Patch

diff --git a/gcc/gcse.c b/gcc/gcse.c
index 74986a4..45cab70 100644
--- a/gcc/gcse.c
+++ b/gcc/gcse.c
@@ -4437,8 +4437,13 @@  hoist_code (void)
 
 		      /* Create a pseudo-reg to store the result of reaching
 			 expressions into.  Get the mode for the new pseudo
-			 from the mode of the original destination pseudo.  */
-		      if (expr->reaching_reg == NULL)
+			 from the mode of the original destination pseudo.
+
+			 It is important to use new pseudos whenever we
+			 emit a set for it in insert_insn_end_basic below.
+			 This will allow reload to use equivalence for
+			 registers that are set only once.  */
+		      if (!insn_inserted_p)
 			expr->reaching_reg
 			  = gen_reg_rtx_and_attrs (SET_DEST (set));