Hi Joseph and Gaius,

on 2024/6/4 02:02, Joseph Myers wrote:
> On Sun, 2 Jun 2024, Kewen Lin wrote:
> 
>> diff --git a/gcc/m2/gm2-gcc/m2type.cc b/gcc/m2/gm2-gcc/m2type.cc
>> index 571923c08ef..d52cbdf0b99 100644
>> --- a/gcc/m2/gm2-gcc/m2type.cc
>> +++ b/gcc/m2/gm2-gcc/m2type.cc
>> @@ -1420,7 +1420,7 @@ build_m2_short_real_node (void)
>>    /* Define `REAL'.  */
>>  
>>    c = make_node (REAL_TYPE);
>> -  TYPE_PRECISION (c) = FLOAT_TYPE_SIZE;
>> +  TYPE_PRECISION (c) = TYPE_PRECISION (float_type_node);
>>    layout_type (c);
>>    return c;
>>  }
>> @@ -1433,7 +1433,7 @@ build_m2_real_node (void)
>>    /* Define `REAL'.  */
>>  
>>    c = make_node (REAL_TYPE);
>> -  TYPE_PRECISION (c) = DOUBLE_TYPE_SIZE;
>> +  TYPE_PRECISION (c) = TYPE_PRECISION (double_type_node);
>>    layout_type (c);
>>    return c;
>>  }
>> @@ -1447,7 +1447,7 @@ build_m2_long_real_node (void)
>>    if (M2Options_GetIBMLongDouble ())
>>      {
>>        longreal = make_node (REAL_TYPE);
>> -      TYPE_PRECISION (longreal) = LONG_DOUBLE_TYPE_SIZE;
>> +      TYPE_PRECISION (longreal) = TYPE_PRECISION (long_double_type_node);
> 
> This looks rather like m2 would still have the same problem the generic 
> code previously had: going via precision when that might not uniquely 
> determine the desired machine mode.  And so making sure to use the right 
> machine mode as done when setting up long_double_type_node etc. would be 
> better than keeping this code copying TYPE_PRECISION and hoping to 
> determine a machine mode from that.  It certainly looks like this code 
> wants to match float, double and long double, rather than possibly getting 
> a different mode with possibly the same TYPE_PRECISION.

Good point, sorry that I just did a replacement without checking the context.
If the above holds (Gaius can confirm or clarify), SET_TYPE_MODE would be
also applied here, that is:

diff --git a/gcc/m2/gm2-gcc/m2type.cc b/gcc/m2/gm2-gcc/m2type.cc
index d52cbdf0b99..5ff02a18876 100644
--- a/gcc/m2/gm2-gcc/m2type.cc
+++ b/gcc/m2/gm2-gcc/m2type.cc
@@ -1421,6 +1421,7 @@ build_m2_short_real_node (void)

   c = make_node (REAL_TYPE);
   TYPE_PRECISION (c) = TYPE_PRECISION (float_type_node);
+  SET_TYPE_MODE (c, TYPE_MODE (float_type_node));
   layout_type (c);
   return c;
 }
@@ -1434,6 +1435,7 @@ build_m2_real_node (void)

   c = make_node (REAL_TYPE);
   TYPE_PRECISION (c) = TYPE_PRECISION (double_type_node);
+  SET_TYPE_MODE (c, TYPE_MODE (double_type_node));
   layout_type (c);
   return c;
 }

I'm not sure and curious why the above builds new nodes for short real and
real but re-use float128_type_node or long_double_type_node for some cases,
some special needs cause the former ones should have separated nodes?

> 
> (I don't know if the M2Options_GetIBMLongDouble call would be needed at 
> all once you use the machine mode for long double in a reliable way, or 
> whether this code could be further simplified.)

long_double_type_node should already take care of ibmlongdouble, IIUC it
would be like:

@@ -1443,13 +1445,7 @@ build_m2_long_real_node (void)
 {
   tree longreal;

-  /* Define `LONGREAL'.  */
-  if (M2Options_GetIBMLongDouble ())
-    {
-      longreal = make_node (REAL_TYPE);
-      TYPE_PRECISION (longreal) = TYPE_PRECISION (long_double_type_node);
-    }
-  else if (M2Options_GetIEEELongDouble ())
+  if (M2Options_GetIEEELongDouble ())
     longreal = float128_type_node;
   else
     longreal = long_double_type_node;

unless there is some special need requiring one different node for
ibmlongdouble, then:

diff --git a/gcc/m2/gm2-gcc/m2type.cc b/gcc/m2/gm2-gcc/m2type.cc
index c808e3e8dbb..5e479e4bbce 100644
--- a/gcc/m2/gm2-gcc/m2type.cc
+++ b/gcc/m2/gm2-gcc/m2type.cc
@@ -1450,6 +1450,7 @@ build_m2_long_real_node (void)
     {
       longreal = make_node (REAL_TYPE);
       TYPE_PRECISION (longreal) = TYPE_PRECISION (long_double_type_node);
+      SET_TYPE_MODE (longreal, TYPE_MODE (long_double_type_node));
     }
   else if (M2Options_GetIEEELongDouble ())
     longreal = float128_type_node;

BR,
Kewen

Reply via email to