diff mbox

PATCH [2/n]: Prepare x32: Convert pointer to TLS symbol if needed

Message ID 20110611154235.GA19926@intel.com
State New
Headers show

Commit Message

H.J. Lu June 11, 2011, 3:42 p.m. UTC
Hi,

Backend may promote pointers to Pmode.  Before we force a TLS symbol
to a pseudo, we may need to convert it to proper mode.  OK for trunk?

Thanks.


H.J.
----
2011-06-11  H.J. Lu  <hongjiu.lu@intel.com>

	* calls.c (precompute_register_parameters): Convert pointer to
	TLS symbol if needed.

Comments

Richard Sandiford June 29, 2011, 8:45 a.m. UTC | #1
"H.J. Lu" <hongjiu.lu@intel.com> writes:
> @@ -706,7 +706,13 @@ precompute_register_parameters (int num_actuals, struct arg_data *args,
>  	   pseudo now.  TLS symbols sometimes need a call to resolve.  */
>  	if (CONSTANT_P (args[i].value)
>  	    && !targetm.legitimate_constant_p (args[i].mode, args[i].value))
> -	  args[i].value = force_reg (args[i].mode, args[i].value);
> +	  {
> +	    if (GET_MODE (args[i].value) != args[i].mode)
> +	      args[i].value = convert_to_mode (args[i].mode,
> +					       args[i].value,
> +					       args[i].unsignedp);
> +	    args[i].value = force_reg (args[i].mode, args[i].value);
> +	  }

But if GET_MODE (args[i].value) != args[i].mode, then the call to
targetm.legitimate_constant_p looks wrong.  The mode passed in the
first argument is supposed to the mode of the second argument.

Is there any reason why this and the following:

	/* If we are to promote the function arg to a wider mode,
	   do it now.  */

	if (args[i].mode != TYPE_MODE (TREE_TYPE (args[i].tree_value)))
	  args[i].value
	    = convert_modes (args[i].mode,
			     TYPE_MODE (TREE_TYPE (args[i].tree_value)),
			     args[i].value, args[i].unsignedp);

need to be done in the current order?  I can't think of any off-hand.
If not, would swapping them also fix the bug?

(I can't review this either way, of course.)

Richard
H.J. Lu June 29, 2011, 2:06 p.m. UTC | #2
On Wed, Jun 29, 2011 at 1:45 AM, Richard Sandiford
<richard.sandiford@linaro.org> wrote:
> "H.J. Lu" <hongjiu.lu@intel.com> writes:
>> @@ -706,7 +706,13 @@ precompute_register_parameters (int num_actuals, struct arg_data *args,
>>          pseudo now.  TLS symbols sometimes need a call to resolve.  */
>>       if (CONSTANT_P (args[i].value)
>>           && !targetm.legitimate_constant_p (args[i].mode, args[i].value))
>> -       args[i].value = force_reg (args[i].mode, args[i].value);
>> +       {
>> +         if (GET_MODE (args[i].value) != args[i].mode)
>> +           args[i].value = convert_to_mode (args[i].mode,
>> +                                            args[i].value,
>> +                                            args[i].unsignedp);
>> +         args[i].value = force_reg (args[i].mode, args[i].value);
>> +       }
>
> But if GET_MODE (args[i].value) != args[i].mode, then the call to
> targetm.legitimate_constant_p looks wrong.  The mode passed in the
> first argument is supposed to the mode of the second argument.
>
> Is there any reason why this and the following:
>
>        /* If we are to promote the function arg to a wider mode,
>           do it now.  */
>
>        if (args[i].mode != TYPE_MODE (TREE_TYPE (args[i].tree_value)))
>          args[i].value
>            = convert_modes (args[i].mode,
>                             TYPE_MODE (TREE_TYPE (args[i].tree_value)),
>                             args[i].value, args[i].unsignedp);
>
> need to be done in the current order?  I can't think of any off-hand.
> If not, would swapping them also fix the bug?
>
> (I can't review this either way, of course.)

It works on the testcase.  I will do a full test.

Thanks.
diff mbox

Patch

diff --git a/gcc/calls.c b/gcc/calls.c
index feb98d2..de98267 100644
--- a/gcc/calls.c
+++ b/gcc/calls.c
@@ -706,7 +706,13 @@  precompute_register_parameters (int num_actuals, struct arg_data *args,
 	   pseudo now.  TLS symbols sometimes need a call to resolve.  */
 	if (CONSTANT_P (args[i].value)
 	    && !targetm.legitimate_constant_p (args[i].mode, args[i].value))
-	  args[i].value = force_reg (args[i].mode, args[i].value);
+	  {
+	    if (GET_MODE (args[i].value) != args[i].mode)
+	      args[i].value = convert_to_mode (args[i].mode,
+					       args[i].value,
+					       args[i].unsignedp);
+	    args[i].value = force_reg (args[i].mode, args[i].value);
+	  }
 
 	/* If we are to promote the function arg to a wider mode,
 	   do it now.  */