diff mbox

-fuse-caller-save - Collect register usage information

Message ID 53A30A69.7060905@mentor.com
State New
Headers show

Commit Message

Tom de Vries June 19, 2014, 4:06 p.m. UTC
On 19-06-14 07:13, Richard Henderson wrote:
> On 05/19/2014 07:30 AM, Tom de Vries wrote:
>> +  for (insn = get_insns (); insn != NULL_RTX; insn = next_insn (insn))
>> +    {
>> +      HARD_REG_SET insn_used_regs;
>> +
>> +      if (!NONDEBUG_INSN_P (insn))
>> +	continue;
>> +
>> +      find_all_hard_reg_sets (insn, &insn_used_regs, false);
>> +
>> +      if (CALL_P (insn)
>> +	  && !get_call_reg_set_usage (insn, &insn_used_regs, call_used_reg_set))
>> +	{
>> +	  CLEAR_HARD_REG_SET (node->function_used_regs);
>> +	  return;
>> +	}
>> +
>> +      IOR_HARD_REG_SET (node->function_used_regs, insn_used_regs);
>> +    }

<SNIP>

> Let's suppose that we've got a rather large function, with only local calls for
> which we can acquire usage.  Let's suppose that even one of those callees
> further calls something else, such that insn_used_regs == call_used_reg_set.
>
> We fill node->function_used_regs immediately, but keep scanning the rest of the
> large function.
>
>
>> +
>> +  /* Be conservative - mark fixed and global registers as used.  */
>> +  IOR_HARD_REG_SET (node->function_used_regs, fixed_reg_set);
>> +  for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
>> +    if (global_regs[i])
>> +      SET_HARD_REG_BIT (node->function_used_regs, i);
>> +
>> +#ifdef STACK_REGS
>> +  /* Handle STACK_REGS conservatively, since the df-framework does not
>> +     provide accurate information for them.  */
>> +
>> +  for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
>> +    SET_HARD_REG_BIT (node->function_used_regs, i);
>> +#endif
>> +
>> +  node->function_used_regs_valid = 1;
>
> Wouldn't it be better to compare the collected function_used_regs; if it
> contains all of call_used_reg_set, decline to set function_used_regs_valid.
> That way, we'll early exit from the above loop whenever we see that we can't
> improve over the default call-clobber set.
>

Richard,

Agreed.  Attached patch implements this (on top of the minor rewrite of 
https://gcc.gnu.org/ml/gcc-patches/2014-06/msg01535.html ).

> Although perhaps function_used_regs_valid is no longer the best name in that
> case...
>

I think the name is still ok.  The field function_used_regs_valid just states 
that the function_used_regs field is valid and can be used.


OK for trunk if bootstrap and reg-test on x86_64 is ok ?

Thanks,
- Tom

Comments

Richard Henderson June 19, 2014, 4:26 p.m. UTC | #1
On 06/19/2014 09:06 AM, Tom de Vries wrote:
> 
> 2014-06-19  Tom de Vries  <tom@codesourcery.com>
> 
> 	* final.c (collect_fn_hard_reg_usage): Don't save function_used_regs if
> 	it contains all call_used_regs.

Ok.


r~
Jan Hubicka June 19, 2014, 7:36 p.m. UTC | #2
> On 06/19/2014 09:06 AM, Tom de Vries wrote:
> > 
> > 2014-06-19  Tom de Vries  <tom@codesourcery.com>
> > 
> > 	* final.c (collect_fn_hard_reg_usage): Don't save function_used_regs if
> > 	it contains all call_used_regs.
> 
> Ok.

When we now have way to represent different reg usages for functions, what would be best
way to make local functions to default into saving some SSE registers on x86/x86-64?

Honza
Richard Henderson June 19, 2014, 7:45 p.m. UTC | #3
On 06/19/2014 12:36 PM, Jan Hubicka wrote:
>> On 06/19/2014 09:06 AM, Tom de Vries wrote:
>>>
>>> 2014-06-19  Tom de Vries  <tom@codesourcery.com>
>>>
>>> 	* final.c (collect_fn_hard_reg_usage): Don't save function_used_regs if
>>> 	it contains all call_used_regs.
>>
>> Ok.
> 
> When we now have way to represent different reg usages for functions, what would be best
> way to make local functions to default into saving some SSE registers on x86/x86-64?

I wouldn't do that at all.  Leave all sse registers call-clobbered.  This way
you don't need to have different entry points (or one possibly less efficient
entry point) when a function is used both locally and globally.

What I would investigate is how to use this hard reg usage data in the register
allocator.  If we know that the callee only uses xmm0-xmm4, then we can keep
xmm5-xmm15 live across the call.


r~
diff mbox

Patch

2014-06-19  Tom de Vries  <tom@codesourcery.com>

	* final.c (collect_fn_hard_reg_usage): Don't save function_used_regs if
	it contains all call_used_regs.

diff --git a/gcc/final.c b/gcc/final.c
index e39930d..e67e84b 100644
--- a/gcc/final.c
+++ b/gcc/final.c
@@ -4795,6 +4795,11 @@  collect_fn_hard_reg_usage (void)
     SET_HARD_REG_BIT (function_used_regs, i);
 #endif
 
+  /* The information we have gathered is only interesting if it exposes a
+     register from the call_used_regs that is not used in this function.  */
+  if (hard_reg_set_subset_p (call_used_reg_set, function_used_regs))
+    return;
+
   node = cgraph_rtl_info (current_function_decl);
   gcc_assert (node != NULL);
 
-- 
1.9.1