Patchwork 0004-Set-pseudos-only-once.patch

login
register
mail settings
Submitter Maxim Kuvyrkov
Date June 16, 2010, 3:57 p.m.
Message ID <4C18F46C.6090809@codesourcery.com>
Download mbox | patch
Permalink /patch/55905/
State New
Headers show

Comments

Maxim Kuvyrkov - June 16, 2010, 3:57 p.m.
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,
Jeff Law - June 21, 2010, 5:55 p.m.
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.
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.
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

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));