public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PING] Fix PR46399 - missing mode promotion for libcall args
@ 2011-04-13 10:54 Andreas Krebbel
  2011-04-13 13:31 ` Ian Lance Taylor
  0 siblings, 1 reply; 11+ messages in thread
From: Andreas Krebbel @ 2011-04-13 10:54 UTC (permalink / raw)
  To: gcc-patches; +Cc: ian, rguenther

This fixes a wrong code generation bug for sw DFP:

http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00141.html

Bye,

-Andreas-

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PING] Fix PR46399 - missing mode promotion for libcall args
  2011-04-13 10:54 [PING] Fix PR46399 - missing mode promotion for libcall args Andreas Krebbel
@ 2011-04-13 13:31 ` Ian Lance Taylor
  2011-04-13 13:59   ` Andreas Krebbel
  0 siblings, 1 reply; 11+ messages in thread
From: Ian Lance Taylor @ 2011-04-13 13:31 UTC (permalink / raw)
  To: Andreas Krebbel; +Cc: gcc-patches, rguenther

"Andreas Krebbel" <krebbel@linux.vnet.ibm.com> writes:

> This fixes a wrong code generation bug for sw DFP:
>
> http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00141.html

Why do we need a new target hook just for libcalls?  Why not just use
the existing TARGET_PROMOTE_FUNCTION_MODE hook?  We could say that for a
libcall functype is passed as NULL.  Only the SH cares about the
function type at all, and it is already prepared to handle NULL.

Ian

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PING] Fix PR46399 - missing mode promotion for libcall args
  2011-04-13 13:31 ` Ian Lance Taylor
@ 2011-04-13 13:59   ` Andreas Krebbel
  2011-04-13 14:53     ` Ian Lance Taylor
  0 siblings, 1 reply; 11+ messages in thread
From: Andreas Krebbel @ 2011-04-13 13:59 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-patches, rguenther

On 04/13/2011 03:31 PM, Ian Lance Taylor wrote:
> "Andreas Krebbel" <krebbel@linux.vnet.ibm.com> writes:
> 
>> This fixes a wrong code generation bug for sw DFP:
>>
>> http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00141.html
> 
> Why do we need a new target hook just for libcalls?  Why not just use
> the existing TARGET_PROMOTE_FUNCTION_MODE hook?  We could say that for a
> libcall functype is passed as NULL.  Only the SH cares about the
> function type at all, and it is already prepared to handle NULL.

But in order to preserve current behaviour all targets defining the hook then would have
to be modified not to do any promotions if funtype is NULL.  As I understand it a target
usually does not want the normal promotions for libcalls since libcalls follow their own ABI.

-Andreas-

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PING] Fix PR46399 - missing mode promotion for libcall args
  2011-04-13 13:59   ` Andreas Krebbel
@ 2011-04-13 14:53     ` Ian Lance Taylor
  2011-04-18  9:23       ` Andreas Krebbel
  0 siblings, 1 reply; 11+ messages in thread
From: Ian Lance Taylor @ 2011-04-13 14:53 UTC (permalink / raw)
  To: Andreas Krebbel; +Cc: gcc-patches, rguenther

Andreas Krebbel <krebbel@linux.vnet.ibm.com> writes:

> On 04/13/2011 03:31 PM, Ian Lance Taylor wrote:
>> "Andreas Krebbel" <krebbel@linux.vnet.ibm.com> writes:
>> 
>>> This fixes a wrong code generation bug for sw DFP:
>>>
>>> http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00141.html
>> 
>> Why do we need a new target hook just for libcalls?  Why not just use
>> the existing TARGET_PROMOTE_FUNCTION_MODE hook?  We could say that for a
>> libcall functype is passed as NULL.  Only the SH cares about the
>> function type at all, and it is already prepared to handle NULL.
>
> But in order to preserve current behaviour all targets defining the hook then would have
> to be modified not to do any promotions if funtype is NULL.  As I understand it a target
> usually does not want the normal promotions for libcalls since libcalls follow their own ABI.

In the good old days libcalls followed their own ABI, but that is no
longer really true.  E.g., you are talking about functions in
libdecnumber, which are written in C, and follow the ordinary C ABI.  In
general gcc has been moving away from libcall-specific code and moving
toward treating libcalls and ordinary functions the same.

If there are cases where promoting is different between ordinary
libcalls and functions, those cases are most likely bugs.  The only
cases where it would not be a bug would be targets which provide libgcc
functions written in assembler.  So look at those to see if any
behaviour would change.

Ian

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PING] Fix PR46399 - missing mode promotion for libcall args
  2011-04-13 14:53     ` Ian Lance Taylor
@ 2011-04-18  9:23       ` Andreas Krebbel
  2011-04-25 19:46         ` Ian Lance Taylor
  2011-05-04 13:45         ` Richard Guenther
  0 siblings, 2 replies; 11+ messages in thread
From: Andreas Krebbel @ 2011-04-18  9:23 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-patches

Hi,

the attached patch uses the existing promote_function_mode hook.  For
a libcall neither TYPE nor FNTYPE is available so I had to change a
few related function in order to deal with that.

The patch also fixes the s390 DFP problems.

Bye,

-Andreas-


2011-04-18  Andreas Krebbel  <Andreas.Krebbel@de.ibm.com>

	* calls.c (emit_library_call_value_1): Invoke
	promote_function_mode hook on libcall arguments.
	* explow.c (promote_function_mode, promote_mode): Handle TYPE
	argument being NULL.
	* targhooks.c (default_promote_function_mode): Lisewise.
	* config/s390/s390.c (s390_promote_function_mode): Likewise.
	* config/sparc/sparc.c (sparc_promote_function_mode): Likewise.

	* doc/tm.texi: Document that TYPE argument might be NULL.


Index: gcc/calls.c
===================================================================
*** gcc/calls.c.orig
--- gcc/calls.c
*************** emit_library_call_value_1 (int retval, r
*** 3484,3489 ****
--- 3484,3490 ----
      {
        rtx val = va_arg (p, rtx);
        enum machine_mode mode = (enum machine_mode) va_arg (p, int);
+       int unsigned_p = 0;
  
        /* We cannot convert the arg value to the mode the library wants here;
  	 must do it earlier where we know the signedness of the arg.  */
*************** emit_library_call_value_1 (int retval, r
*** 3531,3539 ****
  	  val = force_operand (XEXP (slot, 0), NULL_RTX);
  	}
  
!       argvec[count].value = val;
        argvec[count].mode = mode;
! 
        argvec[count].reg = targetm.calls.function_arg (&args_so_far, mode,
  						      NULL_TREE, true);
  
--- 3532,3540 ----
  	  val = force_operand (XEXP (slot, 0), NULL_RTX);
  	}
  
!       mode = promote_function_mode (NULL_TREE, mode, &unsigned_p, NULL_TREE, 0);
        argvec[count].mode = mode;
!       argvec[count].value = convert_modes (mode, GET_MODE (val), val, 0);
        argvec[count].reg = targetm.calls.function_arg (&args_so_far, mode,
  						      NULL_TREE, true);
  
Index: gcc/config/s390/s390.c
===================================================================
*** gcc/config/s390/s390.c.orig
--- gcc/config/s390/s390.c
*************** s390_promote_function_mode (const_tree t
*** 8742,8748 ****
    if (INTEGRAL_MODE_P (mode)
        && GET_MODE_SIZE (mode) < UNITS_PER_LONG)
      {
!       if (POINTER_TYPE_P (type))
  	*punsignedp = POINTERS_EXTEND_UNSIGNED;
        return Pmode;
      }
--- 8742,8748 ----
    if (INTEGRAL_MODE_P (mode)
        && GET_MODE_SIZE (mode) < UNITS_PER_LONG)
      {
!       if (type != NULL_TREE && POINTER_TYPE_P (type))
  	*punsignedp = POINTERS_EXTEND_UNSIGNED;
        return Pmode;
      }
Index: gcc/explow.c
===================================================================
*** gcc/explow.c.orig
--- gcc/explow.c
*************** enum machine_mode
*** 771,776 ****
--- 771,787 ----
  promote_function_mode (const_tree type, enum machine_mode mode, int *punsignedp,
  		       const_tree funtype, int for_return)
  {
+   /* Called without a type node for a libcall.  */
+   if (type == NULL_TREE)
+     {
+       if (INTEGRAL_MODE_P (mode))
+ 	return targetm.calls.promote_function_mode (NULL_TREE, mode,
+ 						    punsignedp, funtype,
+ 						    for_return);
+       else
+ 	return mode;
+     }
+ 
    switch (TREE_CODE (type))
      {
      case INTEGER_TYPE:   case ENUMERAL_TYPE:   case BOOLEAN_TYPE:
*************** enum machine_mode
*** 791,796 ****
--- 802,813 ----
  promote_mode (const_tree type ATTRIBUTE_UNUSED, enum machine_mode mode,
  	      int *punsignedp ATTRIBUTE_UNUSED)
  {
+   /* For libcalls this is invoked without TYPE from the backends
+      TARGET_PROMOTE_FUNCTION_MODE hooks.  Don't do anything in that
+      case.  */
+   if (type == NULL_TREE)
+     return mode;
+ 
    /* FIXME: this is the same logic that was there until GCC 4.4, but we
       probably want to test POINTERS_EXTEND_UNSIGNED even if PROMOTE_MODE
       is not defined.  The affected targets are M32C, S390, SPARC.  */
Index: gcc/config/sparc/sparc.c
===================================================================
*** gcc/config/sparc/sparc.c.orig
--- gcc/config/sparc/sparc.c
*************** init_cumulative_args (struct sparc_args 
*** 4965,4977 ****
  /* Handle promotion of pointer and integer arguments.  */
  
  static enum machine_mode
! sparc_promote_function_mode (const_tree type ATTRIBUTE_UNUSED,
                               enum machine_mode mode,
!                              int *punsignedp ATTRIBUTE_UNUSED,
                               const_tree fntype ATTRIBUTE_UNUSED,
                               int for_return ATTRIBUTE_UNUSED)
  {
!   if (POINTER_TYPE_P (type))
      {
        *punsignedp = POINTERS_EXTEND_UNSIGNED;
        return Pmode;
--- 4965,4977 ----
  /* Handle promotion of pointer and integer arguments.  */
  
  static enum machine_mode
! sparc_promote_function_mode (const_tree type,
                               enum machine_mode mode,
!                              int *punsignedp,
                               const_tree fntype ATTRIBUTE_UNUSED,
                               int for_return ATTRIBUTE_UNUSED)
  {
!   if (type != NULL_TREE && POINTER_TYPE_P (type))
      {
        *punsignedp = POINTERS_EXTEND_UNSIGNED;
        return Pmode;
Index: gcc/doc/tm.texi.in
===================================================================
*** gcc/doc/tm.texi.in.orig
--- gcc/doc/tm.texi.in
*************** which an incoming parameter is copied, o
*** 952,957 ****
--- 952,959 ----
  then the hook should return the same mode as @code{promote_mode}, though
  the signedness may be different.
  
+ @var{type} can be omitted when promoting function arguments of libcalls.
+ 
  The default is to not promote arguments and return values.  You can
  also define the hook to @code{default_promote_function_mode_always_promote}
  if you would like to apply the same rules given by @code{PROMOTE_MODE}.
Index: gcc/doc/tm.texi
===================================================================
*** gcc/doc/tm.texi.orig
--- gcc/doc/tm.texi
*************** which an incoming parameter is copied, o
*** 962,967 ****
--- 962,969 ----
  then the hook should return the same mode as @code{promote_mode}, though
  the signedness may be different.
  
+ @var{type} can be omitted when promoting function arguments of libcalls.
+ 
  The default is to not promote arguments and return values.  You can
  also define the hook to @code{default_promote_function_mode_always_promote}
  if you would like to apply the same rules given by @code{PROMOTE_MODE}.
Index: gcc/targhooks.c
===================================================================
*** gcc/targhooks.c.orig
--- gcc/targhooks.c
*************** default_promote_function_mode (const_tre
*** 124,130 ****
  			       const_tree funtype ATTRIBUTE_UNUSED,
  			       int for_return ATTRIBUTE_UNUSED)
  {
!   if (for_return == 2)
      return promote_mode (type, mode, punsignedp);
    return mode;
  }
--- 124,130 ----
  			       const_tree funtype ATTRIBUTE_UNUSED,
  			       int for_return ATTRIBUTE_UNUSED)
  {
!   if (type != NULL_TREE && for_return == 2)
      return promote_mode (type, mode, punsignedp);
    return mode;
  }

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PING] Fix PR46399 - missing mode promotion for libcall args
  2011-04-18  9:23       ` Andreas Krebbel
@ 2011-04-25 19:46         ` Ian Lance Taylor
  2011-05-04 13:45         ` Richard Guenther
  1 sibling, 0 replies; 11+ messages in thread
From: Ian Lance Taylor @ 2011-04-25 19:46 UTC (permalink / raw)
  To: Andreas Krebbel; +Cc: gcc-patches

"Andreas Krebbel" <krebbel@linux.vnet.ibm.com> writes:

> 2011-04-18  Andreas Krebbel  <Andreas.Krebbel@de.ibm.com>
>
> 	* calls.c (emit_library_call_value_1): Invoke
> 	promote_function_mode hook on libcall arguments.
> 	* explow.c (promote_function_mode, promote_mode): Handle TYPE
> 	argument being NULL.
> 	* targhooks.c (default_promote_function_mode): Lisewise.
> 	* config/s390/s390.c (s390_promote_function_mode): Likewise.
> 	* config/sparc/sparc.c (sparc_promote_function_mode): Likewise.
>
> 	* doc/tm.texi: Document that TYPE argument might be NULL.

>
>
> Index: gcc/calls.c
> ===================================================================
> *** gcc/calls.c.orig
> --- gcc/calls.c
> *************** emit_library_call_value_1 (int retval, r
> *** 3484,3489 ****
> --- 3484,3490 ----
>       {
>         rtx val = va_arg (p, rtx);
>         enum machine_mode mode = (enum machine_mode) va_arg (p, int);
> +       int unsigned_p = 0;
>   
>         /* We cannot convert the arg value to the mode the library wants here;
>   	 must do it earlier where we know the signedness of the arg.  */
> *************** emit_library_call_value_1 (int retval, r
> *** 3531,3539 ****
>   	  val = force_operand (XEXP (slot, 0), NULL_RTX);
>   	}
>   
> !       argvec[count].value = val;
>         argvec[count].mode = mode;
> ! 
>         argvec[count].reg = targetm.calls.function_arg (&args_so_far, mode,
>   						      NULL_TREE, true);
>   
> --- 3532,3540 ----
>   	  val = force_operand (XEXP (slot, 0), NULL_RTX);
>   	}
>   
> !       mode = promote_function_mode (NULL_TREE, mode, &unsigned_p, NULL_TREE, 0);
>         argvec[count].mode = mode;
> !       argvec[count].value = convert_modes (mode, GET_MODE (val), val, 0);
>         argvec[count].reg = targetm.calls.function_arg (&args_so_far, mode,
>   						      NULL_TREE, true);


It seems to me that you should pass unsigned_p to convert_modes.


> Index: gcc/doc/tm.texi.in
> ===================================================================
> *** gcc/doc/tm.texi.in.orig
> --- gcc/doc/tm.texi.in
> *************** which an incoming parameter is copied, o
> *** 952,957 ****
> --- 952,959 ----
>   then the hook should return the same mode as @code{promote_mode}, though
>   the signedness may be different.
>   
> + @var{type} can be omitted when promoting function arguments of libcalls.
> + 
>   The default is to not promote arguments and return values.  You can
>   also define the hook to @code{default_promote_function_mode_always_promote}
>   if you would like to apply the same rules given by @code{PROMOTE_MODE}.

I think it would be clearer if you s/omitted/NULL/.

The patch is OK with those changes.

Thanks.

Ian

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PING] Fix PR46399 - missing mode promotion for libcall args
  2011-05-04 13:45         ` Richard Guenther
@ 2011-05-04 13:45           ` Kai Tietz
  2011-05-04 13:58             ` Richard Guenther
  0 siblings, 1 reply; 11+ messages in thread
From: Kai Tietz @ 2011-05-04 13:45 UTC (permalink / raw)
  To: Richard Guenther; +Cc: Andreas Krebbel, Ian Lance Taylor, gcc-patches

2011/5/4 Richard Guenther <richard.guenther@gmail.com>:
> On Mon, Apr 18, 2011 at 10:17 AM, Andreas Krebbel
> <krebbel@linux.vnet.ibm.com> wrote:
>> Hi,
>>
>> the attached patch uses the existing promote_function_mode hook.  For
>> a libcall neither TYPE nor FNTYPE is available so I had to change a
>> few related function in order to deal with that.
>>
>> The patch also fixes the s390 DFP problems.
>>
>> Bye,
>>
>> -Andreas-
>>
>>
>> 2011-04-18  Andreas Krebbel  <Andreas.Krebbel@de.ibm.com>
>>
>>        * calls.c (emit_library_call_value_1): Invoke
>>        promote_function_mode hook on libcall arguments.
>>        * explow.c (promote_function_mode, promote_mode): Handle TYPE
>>        argument being NULL.
>>        * targhooks.c (default_promote_function_mode): Lisewise.
>>        * config/s390/s390.c (s390_promote_function_mode): Likewise.
>>        * config/sparc/sparc.c (sparc_promote_function_mode): Likewise.
>>
>>        * doc/tm.texi: Document that TYPE argument might be NULL.
>>
>>
>> Index: gcc/calls.c
>> ===================================================================
>> *** gcc/calls.c.orig
>> --- gcc/calls.c
>> *************** emit_library_call_value_1 (int retval, r
>> *** 3484,3489 ****
>> --- 3484,3490 ----
>>      {
>>        rtx val = va_arg (p, rtx);
>>        enum machine_mode mode = (enum machine_mode) va_arg (p, int);
>> +       int unsigned_p = 0;
>>
>>        /* We cannot convert the arg value to the mode the library wants here;
>>         must do it earlier where we know the signedness of the arg.  */
>> *************** emit_library_call_value_1 (int retval, r
>> *** 3531,3539 ****
>>          val = force_operand (XEXP (slot, 0), NULL_RTX);
>>        }
>>
>> !       argvec[count].value = val;
>>        argvec[count].mode = mode;
>> !
>>        argvec[count].reg = targetm.calls.function_arg (&args_so_far, mode,
>>                                                      NULL_TREE, true);
>>
>> --- 3532,3540 ----
>>          val = force_operand (XEXP (slot, 0), NULL_RTX);
>>        }
>>
>> !       mode = promote_function_mode (NULL_TREE, mode, &unsigned_p, NULL_TREE, 0);
>>        argvec[count].mode = mode;
>> !       argvec[count].value = convert_modes (mode, GET_MODE (val), val, 0);
>>        argvec[count].reg = targetm.calls.function_arg (&args_so_far, mode,
>>                                                      NULL_TREE, true);
>>
>> Index: gcc/config/s390/s390.c
>> ===================================================================
>> *** gcc/config/s390/s390.c.orig
>> --- gcc/config/s390/s390.c
>> *************** s390_promote_function_mode (const_tree t
>> *** 8742,8748 ****
>>    if (INTEGRAL_MODE_P (mode)
>>        && GET_MODE_SIZE (mode) < UNITS_PER_LONG)
>>      {
>> !       if (POINTER_TYPE_P (type))
>>        *punsignedp = POINTERS_EXTEND_UNSIGNED;
>>        return Pmode;
>>      }
>> --- 8742,8748 ----
>>    if (INTEGRAL_MODE_P (mode)
>>        && GET_MODE_SIZE (mode) < UNITS_PER_LONG)
>>      {
>> !       if (type != NULL_TREE && POINTER_TYPE_P (type))
>>        *punsignedp = POINTERS_EXTEND_UNSIGNED;
>>        return Pmode;
>>      }
>> Index: gcc/explow.c
>> ===================================================================
>> *** gcc/explow.c.orig
>> --- gcc/explow.c
>> *************** enum machine_mode
>> *** 771,776 ****
>> --- 771,787 ----
>>  promote_function_mode (const_tree type, enum machine_mode mode, int *punsignedp,
>>                       const_tree funtype, int for_return)
>>  {
>> +   /* Called without a type node for a libcall.  */
>> +   if (type == NULL_TREE)
>> +     {
>> +       if (INTEGRAL_MODE_P (mode))
>> +       return targetm.calls.promote_function_mode (NULL_TREE, mode,
>> +                                                   punsignedp, funtype,
>> +                                                   for_return);
>> +       else
>> +       return mode;
>> +     }
>> +
>>    switch (TREE_CODE (type))
>>      {
>>      case INTEGER_TYPE:   case ENUMERAL_TYPE:   case BOOLEAN_TYPE:
>> *************** enum machine_mode
>> *** 791,796 ****
>> --- 802,813 ----
>>  promote_mode (const_tree type ATTRIBUTE_UNUSED, enum machine_mode mode,
>>              int *punsignedp ATTRIBUTE_UNUSED)
>>  {
>> +   /* For libcalls this is invoked without TYPE from the backends
>> +      TARGET_PROMOTE_FUNCTION_MODE hooks.  Don't do anything in that
>> +      case.  */
>> +   if (type == NULL_TREE)
>> +     return mode;
>> +
>
> This broke bootstrap
>
> /space/rguenther/src/svn/trunk/gcc/explow.c: In function 'promote_mode':
> /space/rguenther/src/svn/trunk/gcc/explow.c:815:3: error: ISO C90
> forbids mixed declarations and code [-Werror=edantic]
> cc1: all warnings being treated as errors
>
>
>>    /* FIXME: this is the same logic that was there until GCC 4.4, but we
>>       probably want to test POINTERS_EXTEND_UNSIGNED even if PROMOTE_MODE
>>       is not defined.  The affected targets are M32C, S390, SPARC.  */
>> Index: gcc/config/sparc/sparc.c
>> ===================================================================
>> *** gcc/config/sparc/sparc.c.orig
>> --- gcc/config/sparc/sparc.c
>> *************** init_cumulative_args (struct sparc_args
>> *** 4965,4977 ****
>>  /* Handle promotion of pointer and integer arguments.  */
>>
>>  static enum machine_mode
>> ! sparc_promote_function_mode (const_tree type ATTRIBUTE_UNUSED,
>>                               enum machine_mode mode,
>> !                              int *punsignedp ATTRIBUTE_UNUSED,
>>                               const_tree fntype ATTRIBUTE_UNUSED,
>>                               int for_return ATTRIBUTE_UNUSED)
>>  {
>> !   if (POINTER_TYPE_P (type))
>>      {
>>        *punsignedp = POINTERS_EXTEND_UNSIGNED;
>>        return Pmode;
>> --- 4965,4977 ----
>>  /* Handle promotion of pointer and integer arguments.  */
>>
>>  static enum machine_mode
>> ! sparc_promote_function_mode (const_tree type,
>>                               enum machine_mode mode,
>> !                              int *punsignedp,
>>                               const_tree fntype ATTRIBUTE_UNUSED,
>>                               int for_return ATTRIBUTE_UNUSED)
>>  {
>> !   if (type != NULL_TREE && POINTER_TYPE_P (type))
>>      {
>>        *punsignedp = POINTERS_EXTEND_UNSIGNED;
>>        return Pmode;
>> Index: gcc/doc/tm.texi.in
>> ===================================================================
>> *** gcc/doc/tm.texi.in.orig
>> --- gcc/doc/tm.texi.in
>> *************** which an incoming parameter is copied, o
>> *** 952,957 ****
>> --- 952,959 ----
>>  then the hook should return the same mode as @code{promote_mode}, though
>>  the signedness may be different.
>>
>> + @var{type} can be omitted when promoting function arguments of libcalls.
>> +
>>  The default is to not promote arguments and return values.  You can
>>  also define the hook to @code{default_promote_function_mode_always_promote}
>>  if you would like to apply the same rules given by @code{PROMOTE_MODE}.
>> Index: gcc/doc/tm.texi
>> ===================================================================
>> *** gcc/doc/tm.texi.orig
>> --- gcc/doc/tm.texi
>> *************** which an incoming parameter is copied, o
>> *** 962,967 ****
>> --- 962,969 ----
>>  then the hook should return the same mode as @code{promote_mode}, though
>>  the signedness may be different.
>>
>> + @var{type} can be omitted when promoting function arguments of libcalls.
>> +
>>  The default is to not promote arguments and return values.  You can
>>  also define the hook to @code{default_promote_function_mode_always_promote}
>>  if you would like to apply the same rules given by @code{PROMOTE_MODE}.
>> Index: gcc/targhooks.c
>> ===================================================================
>> *** gcc/targhooks.c.orig
>> --- gcc/targhooks.c
>> *************** default_promote_function_mode (const_tre
>> *** 124,130 ****
>>                               const_tree funtype ATTRIBUTE_UNUSED,
>>                               int for_return ATTRIBUTE_UNUSED)
>>  {
>> !   if (for_return == 2)
>>      return promote_mode (type, mode, punsignedp);
>>    return mode;
>>  }
>> --- 124,130 ----
>>                               const_tree funtype ATTRIBUTE_UNUSED,
>>                               int for_return ATTRIBUTE_UNUSED)
>>  {
>> !   if (type != NULL_TREE && for_return == 2)
>>      return promote_mode (type, mode, punsignedp);
>>    return mode;
>>  }
>>
>


Yes, following patch fix that:

Index: explow.c
===================================================================
--- explow.c    (revision 173374)
+++ explow.c    (working copy)
@@ -802,6 +802,10 @@
 promote_mode (const_tree type ATTRIBUTE_UNUSED, enum machine_mode mode,
              int *punsignedp ATTRIBUTE_UNUSED)
 {
+#ifdef PROMOTE_MODE
+  const enum tree_code code;
+  int unsignedp;
+#endif
   /* For libcalls this is invoked without TYPE from the backends
      TARGET_PROMOTE_FUNCTION_MODE hooks.  Don't do anything in that
      case.  */
@@ -812,8 +816,8 @@
      probably want to test POINTERS_EXTEND_UNSIGNED even if PROMOTE_MODE
      is not defined.  The affected targets are M32C, S390, SPARC.  */
 #ifdef PROMOTE_MODE
-  const enum tree_code code = TREE_CODE (type);
-  int unsignedp = *punsignedp;
+  code = TREE_CODE (type);
+  unsignedp = *punsignedp;

   switch (code)
     {

Ok for apply?

Regards,
Kai

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PING] Fix PR46399 - missing mode promotion for libcall args
  2011-04-18  9:23       ` Andreas Krebbel
  2011-04-25 19:46         ` Ian Lance Taylor
@ 2011-05-04 13:45         ` Richard Guenther
  2011-05-04 13:45           ` Kai Tietz
  1 sibling, 1 reply; 11+ messages in thread
From: Richard Guenther @ 2011-05-04 13:45 UTC (permalink / raw)
  To: Andreas Krebbel; +Cc: Ian Lance Taylor, gcc-patches

On Mon, Apr 18, 2011 at 10:17 AM, Andreas Krebbel
<krebbel@linux.vnet.ibm.com> wrote:
> Hi,
>
> the attached patch uses the existing promote_function_mode hook.  For
> a libcall neither TYPE nor FNTYPE is available so I had to change a
> few related function in order to deal with that.
>
> The patch also fixes the s390 DFP problems.
>
> Bye,
>
> -Andreas-
>
>
> 2011-04-18  Andreas Krebbel  <Andreas.Krebbel@de.ibm.com>
>
>        * calls.c (emit_library_call_value_1): Invoke
>        promote_function_mode hook on libcall arguments.
>        * explow.c (promote_function_mode, promote_mode): Handle TYPE
>        argument being NULL.
>        * targhooks.c (default_promote_function_mode): Lisewise.
>        * config/s390/s390.c (s390_promote_function_mode): Likewise.
>        * config/sparc/sparc.c (sparc_promote_function_mode): Likewise.
>
>        * doc/tm.texi: Document that TYPE argument might be NULL.
>
>
> Index: gcc/calls.c
> ===================================================================
> *** gcc/calls.c.orig
> --- gcc/calls.c
> *************** emit_library_call_value_1 (int retval, r
> *** 3484,3489 ****
> --- 3484,3490 ----
>      {
>        rtx val = va_arg (p, rtx);
>        enum machine_mode mode = (enum machine_mode) va_arg (p, int);
> +       int unsigned_p = 0;
>
>        /* We cannot convert the arg value to the mode the library wants here;
>         must do it earlier where we know the signedness of the arg.  */
> *************** emit_library_call_value_1 (int retval, r
> *** 3531,3539 ****
>          val = force_operand (XEXP (slot, 0), NULL_RTX);
>        }
>
> !       argvec[count].value = val;
>        argvec[count].mode = mode;
> !
>        argvec[count].reg = targetm.calls.function_arg (&args_so_far, mode,
>                                                      NULL_TREE, true);
>
> --- 3532,3540 ----
>          val = force_operand (XEXP (slot, 0), NULL_RTX);
>        }
>
> !       mode = promote_function_mode (NULL_TREE, mode, &unsigned_p, NULL_TREE, 0);
>        argvec[count].mode = mode;
> !       argvec[count].value = convert_modes (mode, GET_MODE (val), val, 0);
>        argvec[count].reg = targetm.calls.function_arg (&args_so_far, mode,
>                                                      NULL_TREE, true);
>
> Index: gcc/config/s390/s390.c
> ===================================================================
> *** gcc/config/s390/s390.c.orig
> --- gcc/config/s390/s390.c
> *************** s390_promote_function_mode (const_tree t
> *** 8742,8748 ****
>    if (INTEGRAL_MODE_P (mode)
>        && GET_MODE_SIZE (mode) < UNITS_PER_LONG)
>      {
> !       if (POINTER_TYPE_P (type))
>        *punsignedp = POINTERS_EXTEND_UNSIGNED;
>        return Pmode;
>      }
> --- 8742,8748 ----
>    if (INTEGRAL_MODE_P (mode)
>        && GET_MODE_SIZE (mode) < UNITS_PER_LONG)
>      {
> !       if (type != NULL_TREE && POINTER_TYPE_P (type))
>        *punsignedp = POINTERS_EXTEND_UNSIGNED;
>        return Pmode;
>      }
> Index: gcc/explow.c
> ===================================================================
> *** gcc/explow.c.orig
> --- gcc/explow.c
> *************** enum machine_mode
> *** 771,776 ****
> --- 771,787 ----
>  promote_function_mode (const_tree type, enum machine_mode mode, int *punsignedp,
>                       const_tree funtype, int for_return)
>  {
> +   /* Called without a type node for a libcall.  */
> +   if (type == NULL_TREE)
> +     {
> +       if (INTEGRAL_MODE_P (mode))
> +       return targetm.calls.promote_function_mode (NULL_TREE, mode,
> +                                                   punsignedp, funtype,
> +                                                   for_return);
> +       else
> +       return mode;
> +     }
> +
>    switch (TREE_CODE (type))
>      {
>      case INTEGER_TYPE:   case ENUMERAL_TYPE:   case BOOLEAN_TYPE:
> *************** enum machine_mode
> *** 791,796 ****
> --- 802,813 ----
>  promote_mode (const_tree type ATTRIBUTE_UNUSED, enum machine_mode mode,
>              int *punsignedp ATTRIBUTE_UNUSED)
>  {
> +   /* For libcalls this is invoked without TYPE from the backends
> +      TARGET_PROMOTE_FUNCTION_MODE hooks.  Don't do anything in that
> +      case.  */
> +   if (type == NULL_TREE)
> +     return mode;
> +

This broke bootstrap

/space/rguenther/src/svn/trunk/gcc/explow.c: In function 'promote_mode':
/space/rguenther/src/svn/trunk/gcc/explow.c:815:3: error: ISO C90
forbids mixed declarations and code [-Werror=edantic]
cc1: all warnings being treated as errors


>    /* FIXME: this is the same logic that was there until GCC 4.4, but we
>       probably want to test POINTERS_EXTEND_UNSIGNED even if PROMOTE_MODE
>       is not defined.  The affected targets are M32C, S390, SPARC.  */
> Index: gcc/config/sparc/sparc.c
> ===================================================================
> *** gcc/config/sparc/sparc.c.orig
> --- gcc/config/sparc/sparc.c
> *************** init_cumulative_args (struct sparc_args
> *** 4965,4977 ****
>  /* Handle promotion of pointer and integer arguments.  */
>
>  static enum machine_mode
> ! sparc_promote_function_mode (const_tree type ATTRIBUTE_UNUSED,
>                               enum machine_mode mode,
> !                              int *punsignedp ATTRIBUTE_UNUSED,
>                               const_tree fntype ATTRIBUTE_UNUSED,
>                               int for_return ATTRIBUTE_UNUSED)
>  {
> !   if (POINTER_TYPE_P (type))
>      {
>        *punsignedp = POINTERS_EXTEND_UNSIGNED;
>        return Pmode;
> --- 4965,4977 ----
>  /* Handle promotion of pointer and integer arguments.  */
>
>  static enum machine_mode
> ! sparc_promote_function_mode (const_tree type,
>                               enum machine_mode mode,
> !                              int *punsignedp,
>                               const_tree fntype ATTRIBUTE_UNUSED,
>                               int for_return ATTRIBUTE_UNUSED)
>  {
> !   if (type != NULL_TREE && POINTER_TYPE_P (type))
>      {
>        *punsignedp = POINTERS_EXTEND_UNSIGNED;
>        return Pmode;
> Index: gcc/doc/tm.texi.in
> ===================================================================
> *** gcc/doc/tm.texi.in.orig
> --- gcc/doc/tm.texi.in
> *************** which an incoming parameter is copied, o
> *** 952,957 ****
> --- 952,959 ----
>  then the hook should return the same mode as @code{promote_mode}, though
>  the signedness may be different.
>
> + @var{type} can be omitted when promoting function arguments of libcalls.
> +
>  The default is to not promote arguments and return values.  You can
>  also define the hook to @code{default_promote_function_mode_always_promote}
>  if you would like to apply the same rules given by @code{PROMOTE_MODE}.
> Index: gcc/doc/tm.texi
> ===================================================================
> *** gcc/doc/tm.texi.orig
> --- gcc/doc/tm.texi
> *************** which an incoming parameter is copied, o
> *** 962,967 ****
> --- 962,969 ----
>  then the hook should return the same mode as @code{promote_mode}, though
>  the signedness may be different.
>
> + @var{type} can be omitted when promoting function arguments of libcalls.
> +
>  The default is to not promote arguments and return values.  You can
>  also define the hook to @code{default_promote_function_mode_always_promote}
>  if you would like to apply the same rules given by @code{PROMOTE_MODE}.
> Index: gcc/targhooks.c
> ===================================================================
> *** gcc/targhooks.c.orig
> --- gcc/targhooks.c
> *************** default_promote_function_mode (const_tre
> *** 124,130 ****
>                               const_tree funtype ATTRIBUTE_UNUSED,
>                               int for_return ATTRIBUTE_UNUSED)
>  {
> !   if (for_return == 2)
>      return promote_mode (type, mode, punsignedp);
>    return mode;
>  }
> --- 124,130 ----
>                               const_tree funtype ATTRIBUTE_UNUSED,
>                               int for_return ATTRIBUTE_UNUSED)
>  {
> !   if (type != NULL_TREE && for_return == 2)
>      return promote_mode (type, mode, punsignedp);
>    return mode;
>  }
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PING] Fix PR46399 - missing mode promotion for libcall args
  2011-05-04 13:45           ` Kai Tietz
@ 2011-05-04 13:58             ` Richard Guenther
  2011-05-06 16:20               ` NightStrike
  0 siblings, 1 reply; 11+ messages in thread
From: Richard Guenther @ 2011-05-04 13:58 UTC (permalink / raw)
  To: Kai Tietz; +Cc: Andreas Krebbel, Ian Lance Taylor, gcc-patches

On Wed, May 4, 2011 at 3:45 PM, Kai Tietz <ktietz70@googlemail.com> wrote:
> 2011/5/4 Richard Guenther <richard.guenther@gmail.com>:
>> On Mon, Apr 18, 2011 at 10:17 AM, Andreas Krebbel
>> <krebbel@linux.vnet.ibm.com> wrote:
>>> Hi,
>>>
>>> the attached patch uses the existing promote_function_mode hook.  For
>>> a libcall neither TYPE nor FNTYPE is available so I had to change a
>>> few related function in order to deal with that.
>>>
>>> The patch also fixes the s390 DFP problems.
>>>
>>> Bye,
>>>
>>> -Andreas-
>>>
>>>
>>> 2011-04-18  Andreas Krebbel  <Andreas.Krebbel@de.ibm.com>
>>>
>>>        * calls.c (emit_library_call_value_1): Invoke
>>>        promote_function_mode hook on libcall arguments.
>>>        * explow.c (promote_function_mode, promote_mode): Handle TYPE
>>>        argument being NULL.
>>>        * targhooks.c (default_promote_function_mode): Lisewise.
>>>        * config/s390/s390.c (s390_promote_function_mode): Likewise.
>>>        * config/sparc/sparc.c (sparc_promote_function_mode): Likewise.
>>>
>>>        * doc/tm.texi: Document that TYPE argument might be NULL.
>>>
>>>
>>> Index: gcc/calls.c
>>> ===================================================================
>>> *** gcc/calls.c.orig
>>> --- gcc/calls.c
>>> *************** emit_library_call_value_1 (int retval, r
>>> *** 3484,3489 ****
>>> --- 3484,3490 ----
>>>      {
>>>        rtx val = va_arg (p, rtx);
>>>        enum machine_mode mode = (enum machine_mode) va_arg (p, int);
>>> +       int unsigned_p = 0;
>>>
>>>        /* We cannot convert the arg value to the mode the library wants here;
>>>         must do it earlier where we know the signedness of the arg.  */
>>> *************** emit_library_call_value_1 (int retval, r
>>> *** 3531,3539 ****
>>>          val = force_operand (XEXP (slot, 0), NULL_RTX);
>>>        }
>>>
>>> !       argvec[count].value = val;
>>>        argvec[count].mode = mode;
>>> !
>>>        argvec[count].reg = targetm.calls.function_arg (&args_so_far, mode,
>>>                                                      NULL_TREE, true);
>>>
>>> --- 3532,3540 ----
>>>          val = force_operand (XEXP (slot, 0), NULL_RTX);
>>>        }
>>>
>>> !       mode = promote_function_mode (NULL_TREE, mode, &unsigned_p, NULL_TREE, 0);
>>>        argvec[count].mode = mode;
>>> !       argvec[count].value = convert_modes (mode, GET_MODE (val), val, 0);
>>>        argvec[count].reg = targetm.calls.function_arg (&args_so_far, mode,
>>>                                                      NULL_TREE, true);
>>>
>>> Index: gcc/config/s390/s390.c
>>> ===================================================================
>>> *** gcc/config/s390/s390.c.orig
>>> --- gcc/config/s390/s390.c
>>> *************** s390_promote_function_mode (const_tree t
>>> *** 8742,8748 ****
>>>    if (INTEGRAL_MODE_P (mode)
>>>        && GET_MODE_SIZE (mode) < UNITS_PER_LONG)
>>>      {
>>> !       if (POINTER_TYPE_P (type))
>>>        *punsignedp = POINTERS_EXTEND_UNSIGNED;
>>>        return Pmode;
>>>      }
>>> --- 8742,8748 ----
>>>    if (INTEGRAL_MODE_P (mode)
>>>        && GET_MODE_SIZE (mode) < UNITS_PER_LONG)
>>>      {
>>> !       if (type != NULL_TREE && POINTER_TYPE_P (type))
>>>        *punsignedp = POINTERS_EXTEND_UNSIGNED;
>>>        return Pmode;
>>>      }
>>> Index: gcc/explow.c
>>> ===================================================================
>>> *** gcc/explow.c.orig
>>> --- gcc/explow.c
>>> *************** enum machine_mode
>>> *** 771,776 ****
>>> --- 771,787 ----
>>>  promote_function_mode (const_tree type, enum machine_mode mode, int *punsignedp,
>>>                       const_tree funtype, int for_return)
>>>  {
>>> +   /* Called without a type node for a libcall.  */
>>> +   if (type == NULL_TREE)
>>> +     {
>>> +       if (INTEGRAL_MODE_P (mode))
>>> +       return targetm.calls.promote_function_mode (NULL_TREE, mode,
>>> +                                                   punsignedp, funtype,
>>> +                                                   for_return);
>>> +       else
>>> +       return mode;
>>> +     }
>>> +
>>>    switch (TREE_CODE (type))
>>>      {
>>>      case INTEGER_TYPE:   case ENUMERAL_TYPE:   case BOOLEAN_TYPE:
>>> *************** enum machine_mode
>>> *** 791,796 ****
>>> --- 802,813 ----
>>>  promote_mode (const_tree type ATTRIBUTE_UNUSED, enum machine_mode mode,
>>>              int *punsignedp ATTRIBUTE_UNUSED)
>>>  {
>>> +   /* For libcalls this is invoked without TYPE from the backends
>>> +      TARGET_PROMOTE_FUNCTION_MODE hooks.  Don't do anything in that
>>> +      case.  */
>>> +   if (type == NULL_TREE)
>>> +     return mode;
>>> +
>>
>> This broke bootstrap
>>
>> /space/rguenther/src/svn/trunk/gcc/explow.c: In function 'promote_mode':
>> /space/rguenther/src/svn/trunk/gcc/explow.c:815:3: error: ISO C90
>> forbids mixed declarations and code [-Werror=edantic]
>> cc1: all warnings being treated as errors
>>
>>
>>>    /* FIXME: this is the same logic that was there until GCC 4.4, but we
>>>       probably want to test POINTERS_EXTEND_UNSIGNED even if PROMOTE_MODE
>>>       is not defined.  The affected targets are M32C, S390, SPARC.  */
>>> Index: gcc/config/sparc/sparc.c
>>> ===================================================================
>>> *** gcc/config/sparc/sparc.c.orig
>>> --- gcc/config/sparc/sparc.c
>>> *************** init_cumulative_args (struct sparc_args
>>> *** 4965,4977 ****
>>>  /* Handle promotion of pointer and integer arguments.  */
>>>
>>>  static enum machine_mode
>>> ! sparc_promote_function_mode (const_tree type ATTRIBUTE_UNUSED,
>>>                               enum machine_mode mode,
>>> !                              int *punsignedp ATTRIBUTE_UNUSED,
>>>                               const_tree fntype ATTRIBUTE_UNUSED,
>>>                               int for_return ATTRIBUTE_UNUSED)
>>>  {
>>> !   if (POINTER_TYPE_P (type))
>>>      {
>>>        *punsignedp = POINTERS_EXTEND_UNSIGNED;
>>>        return Pmode;
>>> --- 4965,4977 ----
>>>  /* Handle promotion of pointer and integer arguments.  */
>>>
>>>  static enum machine_mode
>>> ! sparc_promote_function_mode (const_tree type,
>>>                               enum machine_mode mode,
>>> !                              int *punsignedp,
>>>                               const_tree fntype ATTRIBUTE_UNUSED,
>>>                               int for_return ATTRIBUTE_UNUSED)
>>>  {
>>> !   if (type != NULL_TREE && POINTER_TYPE_P (type))
>>>      {
>>>        *punsignedp = POINTERS_EXTEND_UNSIGNED;
>>>        return Pmode;
>>> Index: gcc/doc/tm.texi.in
>>> ===================================================================
>>> *** gcc/doc/tm.texi.in.orig
>>> --- gcc/doc/tm.texi.in
>>> *************** which an incoming parameter is copied, o
>>> *** 952,957 ****
>>> --- 952,959 ----
>>>  then the hook should return the same mode as @code{promote_mode}, though
>>>  the signedness may be different.
>>>
>>> + @var{type} can be omitted when promoting function arguments of libcalls.
>>> +
>>>  The default is to not promote arguments and return values.  You can
>>>  also define the hook to @code{default_promote_function_mode_always_promote}
>>>  if you would like to apply the same rules given by @code{PROMOTE_MODE}.
>>> Index: gcc/doc/tm.texi
>>> ===================================================================
>>> *** gcc/doc/tm.texi.orig
>>> --- gcc/doc/tm.texi
>>> *************** which an incoming parameter is copied, o
>>> *** 962,967 ****
>>> --- 962,969 ----
>>>  then the hook should return the same mode as @code{promote_mode}, though
>>>  the signedness may be different.
>>>
>>> + @var{type} can be omitted when promoting function arguments of libcalls.
>>> +
>>>  The default is to not promote arguments and return values.  You can
>>>  also define the hook to @code{default_promote_function_mode_always_promote}
>>>  if you would like to apply the same rules given by @code{PROMOTE_MODE}.
>>> Index: gcc/targhooks.c
>>> ===================================================================
>>> *** gcc/targhooks.c.orig
>>> --- gcc/targhooks.c
>>> *************** default_promote_function_mode (const_tre
>>> *** 124,130 ****
>>>                               const_tree funtype ATTRIBUTE_UNUSED,
>>>                               int for_return ATTRIBUTE_UNUSED)
>>>  {
>>> !   if (for_return == 2)
>>>      return promote_mode (type, mode, punsignedp);
>>>    return mode;
>>>  }
>>> --- 124,130 ----
>>>                               const_tree funtype ATTRIBUTE_UNUSED,
>>>                               int for_return ATTRIBUTE_UNUSED)
>>>  {
>>> !   if (type != NULL_TREE && for_return == 2)
>>>      return promote_mode (type, mode, punsignedp);
>>>    return mode;
>>>  }
>>>
>>
>
>
> Yes, following patch fix that:
>
> Index: explow.c
> ===================================================================
> --- explow.c    (revision 173374)
> +++ explow.c    (working copy)
> @@ -802,6 +802,10 @@
>  promote_mode (const_tree type ATTRIBUTE_UNUSED, enum machine_mode mode,
>              int *punsignedp ATTRIBUTE_UNUSED)
>  {
> +#ifdef PROMOTE_MODE
> +  const enum tree_code code;
> +  int unsignedp;
> +#endif
>   /* For libcalls this is invoked without TYPE from the backends
>      TARGET_PROMOTE_FUNCTION_MODE hooks.  Don't do anything in that
>      case.  */
> @@ -812,8 +816,8 @@
>      probably want to test POINTERS_EXTEND_UNSIGNED even if PROMOTE_MODE
>      is not defined.  The affected targets are M32C, S390, SPARC.  */
>  #ifdef PROMOTE_MODE
> -  const enum tree_code code = TREE_CODE (type);
> -  int unsignedp = *punsignedp;
> +  code = TREE_CODE (type);
> +  unsignedp = *punsignedp;
>
>   switch (code)
>     {
>
> Ok for apply?

It doesn't work ;)

I'm in stage3 and will commit a fix once it passed.

Richard.

> Regards,
> Kai
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PING] Fix PR46399 - missing mode promotion for libcall args
  2011-05-04 13:58             ` Richard Guenther
@ 2011-05-06 16:20               ` NightStrike
  0 siblings, 0 replies; 11+ messages in thread
From: NightStrike @ 2011-05-06 16:20 UTC (permalink / raw)
  To: Richard Guenther
  Cc: Kai Tietz, Andreas Krebbel, Ian Lance Taylor, gcc-patches

On Wed, May 4, 2011 at 9:45 AM, Richard Guenther
<richard.guenther@gmail.com> wrote:
> On Wed, May 4, 2011 at 3:45 PM, Kai Tietz <ktietz70@googlemail.com> wrote:
>> 2011/5/4 Richard Guenther <richard.guenther@gmail.com>:
>>> On Mon, Apr 18, 2011 at 10:17 AM, Andreas Krebbel
>>> <krebbel@linux.vnet.ibm.com> wrote:
>>>> Hi,
>>>>
>>>> the attached patch uses the existing promote_function_mode hook.  For
>>>> a libcall neither TYPE nor FNTYPE is available so I had to change a
>>>> few related function in order to deal with that.
>>>>
>>>> The patch also fixes the s390 DFP problems.
>>>>
>>>> Bye,
>>>>
>>>> -Andreas-
>>>>
>>>>
>>>> 2011-04-18  Andreas Krebbel  <Andreas.Krebbel@de.ibm.com>
>>>>
>>>>        * calls.c (emit_library_call_value_1): Invoke
>>>>        promote_function_mode hook on libcall arguments.
>>>>        * explow.c (promote_function_mode, promote_mode): Handle TYPE
>>>>        argument being NULL.
>>>>        * targhooks.c (default_promote_function_mode): Lisewise.
>>>>        * config/s390/s390.c (s390_promote_function_mode): Likewise.
>>>>        * config/sparc/sparc.c (sparc_promote_function_mode): Likewise.
>>>>
>>>>        * doc/tm.texi: Document that TYPE argument might be NULL.
>>>>
>>>>
>>>> Index: gcc/calls.c
>>>> ===================================================================
>>>> *** gcc/calls.c.orig
>>>> --- gcc/calls.c
>>>> *************** emit_library_call_value_1 (int retval, r
>>>> *** 3484,3489 ****
>>>> --- 3484,3490 ----
>>>>      {
>>>>        rtx val = va_arg (p, rtx);
>>>>        enum machine_mode mode = (enum machine_mode) va_arg (p, int);
>>>> +       int unsigned_p = 0;
>>>>
>>>>        /* We cannot convert the arg value to the mode the library wants here;
>>>>         must do it earlier where we know the signedness of the arg.  */
>>>> *************** emit_library_call_value_1 (int retval, r
>>>> *** 3531,3539 ****
>>>>          val = force_operand (XEXP (slot, 0), NULL_RTX);
>>>>        }
>>>>
>>>> !       argvec[count].value = val;
>>>>        argvec[count].mode = mode;
>>>> !
>>>>        argvec[count].reg = targetm.calls.function_arg (&args_so_far, mode,
>>>>                                                      NULL_TREE, true);
>>>>
>>>> --- 3532,3540 ----
>>>>          val = force_operand (XEXP (slot, 0), NULL_RTX);
>>>>        }
>>>>
>>>> !       mode = promote_function_mode (NULL_TREE, mode, &unsigned_p, NULL_TREE, 0);
>>>>        argvec[count].mode = mode;
>>>> !       argvec[count].value = convert_modes (mode, GET_MODE (val), val, 0);
>>>>        argvec[count].reg = targetm.calls.function_arg (&args_so_far, mode,
>>>>                                                      NULL_TREE, true);
>>>>
>>>> Index: gcc/config/s390/s390.c
>>>> ===================================================================
>>>> *** gcc/config/s390/s390.c.orig
>>>> --- gcc/config/s390/s390.c
>>>> *************** s390_promote_function_mode (const_tree t
>>>> *** 8742,8748 ****
>>>>    if (INTEGRAL_MODE_P (mode)
>>>>        && GET_MODE_SIZE (mode) < UNITS_PER_LONG)
>>>>      {
>>>> !       if (POINTER_TYPE_P (type))
>>>>        *punsignedp = POINTERS_EXTEND_UNSIGNED;
>>>>        return Pmode;
>>>>      }
>>>> --- 8742,8748 ----
>>>>    if (INTEGRAL_MODE_P (mode)
>>>>        && GET_MODE_SIZE (mode) < UNITS_PER_LONG)
>>>>      {
>>>> !       if (type != NULL_TREE && POINTER_TYPE_P (type))
>>>>        *punsignedp = POINTERS_EXTEND_UNSIGNED;
>>>>        return Pmode;
>>>>      }
>>>> Index: gcc/explow.c
>>>> ===================================================================
>>>> *** gcc/explow.c.orig
>>>> --- gcc/explow.c
>>>> *************** enum machine_mode
>>>> *** 771,776 ****
>>>> --- 771,787 ----
>>>>  promote_function_mode (const_tree type, enum machine_mode mode, int *punsignedp,
>>>>                       const_tree funtype, int for_return)
>>>>  {
>>>> +   /* Called without a type node for a libcall.  */
>>>> +   if (type == NULL_TREE)
>>>> +     {
>>>> +       if (INTEGRAL_MODE_P (mode))
>>>> +       return targetm.calls.promote_function_mode (NULL_TREE, mode,
>>>> +                                                   punsignedp, funtype,
>>>> +                                                   for_return);
>>>> +       else
>>>> +       return mode;
>>>> +     }
>>>> +
>>>>    switch (TREE_CODE (type))
>>>>      {
>>>>      case INTEGER_TYPE:   case ENUMERAL_TYPE:   case BOOLEAN_TYPE:
>>>> *************** enum machine_mode
>>>> *** 791,796 ****
>>>> --- 802,813 ----
>>>>  promote_mode (const_tree type ATTRIBUTE_UNUSED, enum machine_mode mode,
>>>>              int *punsignedp ATTRIBUTE_UNUSED)
>>>>  {
>>>> +   /* For libcalls this is invoked without TYPE from the backends
>>>> +      TARGET_PROMOTE_FUNCTION_MODE hooks.  Don't do anything in that
>>>> +      case.  */
>>>> +   if (type == NULL_TREE)
>>>> +     return mode;
>>>> +
>>>
>>> This broke bootstrap
>>>
>>> /space/rguenther/src/svn/trunk/gcc/explow.c: In function 'promote_mode':
>>> /space/rguenther/src/svn/trunk/gcc/explow.c:815:3: error: ISO C90
>>> forbids mixed declarations and code [-Werror=edantic]
>>> cc1: all warnings being treated as errors
>>>
>>>
>>>>    /* FIXME: this is the same logic that was there until GCC 4.4, but we
>>>>       probably want to test POINTERS_EXTEND_UNSIGNED even if PROMOTE_MODE
>>>>       is not defined.  The affected targets are M32C, S390, SPARC.  */
>>>> Index: gcc/config/sparc/sparc.c
>>>> ===================================================================
>>>> *** gcc/config/sparc/sparc.c.orig
>>>> --- gcc/config/sparc/sparc.c
>>>> *************** init_cumulative_args (struct sparc_args
>>>> *** 4965,4977 ****
>>>>  /* Handle promotion of pointer and integer arguments.  */
>>>>
>>>>  static enum machine_mode
>>>> ! sparc_promote_function_mode (const_tree type ATTRIBUTE_UNUSED,
>>>>                               enum machine_mode mode,
>>>> !                              int *punsignedp ATTRIBUTE_UNUSED,
>>>>                               const_tree fntype ATTRIBUTE_UNUSED,
>>>>                               int for_return ATTRIBUTE_UNUSED)
>>>>  {
>>>> !   if (POINTER_TYPE_P (type))
>>>>      {
>>>>        *punsignedp = POINTERS_EXTEND_UNSIGNED;
>>>>        return Pmode;
>>>> --- 4965,4977 ----
>>>>  /* Handle promotion of pointer and integer arguments.  */
>>>>
>>>>  static enum machine_mode
>>>> ! sparc_promote_function_mode (const_tree type,
>>>>                               enum machine_mode mode,
>>>> !                              int *punsignedp,
>>>>                               const_tree fntype ATTRIBUTE_UNUSED,
>>>>                               int for_return ATTRIBUTE_UNUSED)
>>>>  {
>>>> !   if (type != NULL_TREE && POINTER_TYPE_P (type))
>>>>      {
>>>>        *punsignedp = POINTERS_EXTEND_UNSIGNED;
>>>>        return Pmode;
>>>> Index: gcc/doc/tm.texi.in
>>>> ===================================================================
>>>> *** gcc/doc/tm.texi.in.orig
>>>> --- gcc/doc/tm.texi.in
>>>> *************** which an incoming parameter is copied, o
>>>> *** 952,957 ****
>>>> --- 952,959 ----
>>>>  then the hook should return the same mode as @code{promote_mode}, though
>>>>  the signedness may be different.
>>>>
>>>> + @var{type} can be omitted when promoting function arguments of libcalls.
>>>> +
>>>>  The default is to not promote arguments and return values.  You can
>>>>  also define the hook to @code{default_promote_function_mode_always_promote}
>>>>  if you would like to apply the same rules given by @code{PROMOTE_MODE}.
>>>> Index: gcc/doc/tm.texi
>>>> ===================================================================
>>>> *** gcc/doc/tm.texi.orig
>>>> --- gcc/doc/tm.texi
>>>> *************** which an incoming parameter is copied, o
>>>> *** 962,967 ****
>>>> --- 962,969 ----
>>>>  then the hook should return the same mode as @code{promote_mode}, though
>>>>  the signedness may be different.
>>>>
>>>> + @var{type} can be omitted when promoting function arguments of libcalls.
>>>> +
>>>>  The default is to not promote arguments and return values.  You can
>>>>  also define the hook to @code{default_promote_function_mode_always_promote}
>>>>  if you would like to apply the same rules given by @code{PROMOTE_MODE}.
>>>> Index: gcc/targhooks.c
>>>> ===================================================================
>>>> *** gcc/targhooks.c.orig
>>>> --- gcc/targhooks.c
>>>> *************** default_promote_function_mode (const_tre
>>>> *** 124,130 ****
>>>>                               const_tree funtype ATTRIBUTE_UNUSED,
>>>>                               int for_return ATTRIBUTE_UNUSED)
>>>>  {
>>>> !   if (for_return == 2)
>>>>      return promote_mode (type, mode, punsignedp);
>>>>    return mode;
>>>>  }
>>>> --- 124,130 ----
>>>>                               const_tree funtype ATTRIBUTE_UNUSED,
>>>>                               int for_return ATTRIBUTE_UNUSED)
>>>>  {
>>>> !   if (type != NULL_TREE && for_return == 2)
>>>>      return promote_mode (type, mode, punsignedp);
>>>>    return mode;
>>>>  }
>>>>
>>>
>>
>>
>> Yes, following patch fix that:
>>
>> Index: explow.c
>> ===================================================================
>> --- explow.c    (revision 173374)
>> +++ explow.c    (working copy)
>> @@ -802,6 +802,10 @@
>>  promote_mode (const_tree type ATTRIBUTE_UNUSED, enum machine_mode mode,
>>              int *punsignedp ATTRIBUTE_UNUSED)
>>  {
>> +#ifdef PROMOTE_MODE
>> +  const enum tree_code code;
>> +  int unsignedp;
>> +#endif
>>   /* For libcalls this is invoked without TYPE from the backends
>>      TARGET_PROMOTE_FUNCTION_MODE hooks.  Don't do anything in that
>>      case.  */
>> @@ -812,8 +816,8 @@
>>      probably want to test POINTERS_EXTEND_UNSIGNED even if PROMOTE_MODE
>>      is not defined.  The affected targets are M32C, S390, SPARC.  */
>>  #ifdef PROMOTE_MODE
>> -  const enum tree_code code = TREE_CODE (type);
>> -  int unsignedp = *punsignedp;
>> +  code = TREE_CODE (type);
>> +  unsignedp = *punsignedp;
>>
>>   switch (code)
>>     {
>>
>> Ok for apply?
>
> It doesn't work ;)
>
> I'm in stage3 and will commit a fix once it passed.
>
> Richard.
>
>> Regards,
>> Kai
>>
>

Did you commit a fix yet?  PR46399 is still unconfirmed.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PING] Fix PR46399 - missing mode promotion for libcall args
@ 2011-03-28 13:14 Andreas Krebbel
  0 siblings, 0 replies; 11+ messages in thread
From: Andreas Krebbel @ 2011-03-28 13:14 UTC (permalink / raw)
  To: gcc-patches

This fixes a wrong code generation bug for sw DFP:

http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00141.html

Bye,

-Andreas-

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-05-06 16:05 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-13 10:54 [PING] Fix PR46399 - missing mode promotion for libcall args Andreas Krebbel
2011-04-13 13:31 ` Ian Lance Taylor
2011-04-13 13:59   ` Andreas Krebbel
2011-04-13 14:53     ` Ian Lance Taylor
2011-04-18  9:23       ` Andreas Krebbel
2011-04-25 19:46         ` Ian Lance Taylor
2011-05-04 13:45         ` Richard Guenther
2011-05-04 13:45           ` Kai Tietz
2011-05-04 13:58             ` Richard Guenther
2011-05-06 16:20               ` NightStrike
  -- strict thread matches above, loose matches on Subject: below --
2011-03-28 13:14 Andreas Krebbel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).