Hi!

On 2020-01-31T11:20:14+0000, Andrew Stubbs <a...@codesourcery.com> wrote:
> This is one of those things I don't know why we didn't notice sooner. 

..., and here's another thing I don't know why we didn't notice sooner.
;-P (Category: "don't we all love C++?!")

> [...]
> I also needed a convenient way to create 0.0 vector constants without 
> uglifying the machine description code, so extending gcn_vec_constant 
> seemed like a useful place to do it.

> --- a/gcc/config/gcn/gcn.c
> +++ b/gcc/config/gcn/gcn.c
> @@ -992,9 +992,19 @@ gcn_vec_constant (machine_mode mode, int a)
>      return CONST2_RTX (mode);*/
>  
>    int units = GET_MODE_NUNITS (mode);
> -  rtx tem = gen_int_mode (a, GET_MODE_INNER (mode));
> -  rtvec v = rtvec_alloc (units);
> +  machine_mode innermode = GET_MODE_INNER (mode);
> +
> +  rtx tem;
> +  if (FLOAT_MODE_P (innermode))
> +    {
> +      REAL_VALUE_TYPE rv;
> +      real_from_integer (&rv, NULL, a, SIGNED);
> +      tem = const_double_from_real_value (rv, innermode);
> +    }
> +  else
> +    tem = gen_int_mode (a, innermode);
>  
> +  rtvec v = rtvec_alloc (units);
>    for (int i = 0; i < units; ++i)
>      RTVEC_ELT (v, i) = tem;

That's apparently not the proper way to use 'real_from_integer'.  Its
second argument is a 'format_helper', which is a class defined in
'gcc/real.h', which has a templated constructor that is meant to receive
a mode, so instead of 'NULL', this should pass in 'VOIDmode' (correct?).
Anyway: until recently, this appeared to work (fine?) -- but broke with
Andrew Pinski's recent commit b3f1b9e2aa079f8ec73e3cb48143a16645c49566
"build: Remove INCLUDE_MEMORY [PR117737]":

    [...]
    In file included from ../../source-gcc/gcc/coretypes.h:507:0,
                     from ../../source-gcc/gcc/config/gcn/gcn.cc:24:
    ../../source-gcc/gcc/real.h: In instantiation of 
‘format_helper::format_helper(const T&) [with T = std::nullptr_t]’:
    ../../source-gcc/gcc/config/gcn/gcn.cc:1178:46:   required from here
    ../../source-gcc/gcc/real.h:233:17: error: no match for ‘operator==’ 
(operand types are ‘std::nullptr_t’ and ‘machine_mode’)
       : m_format (m == VOIDmode ? 0 : REAL_MODE_FORMAT (m))
                     ^
    [...]

Andrew P.'s commit doesn't touch 'gcc/config/gcn/gcn.cc'; the only part
relevant here -- per my understanding -- should be:

    --- gcc/system.h
    +++ gcc/system.h
    @@ -224,0 +225 @@ extern int fprintf_unlocked (FILE *, const char *, ...);
    +# include <memory>
    @@ -761,7 +761,0 @@ private:
    -/* Some of the headers included by <memory> can use "abort" within a
    -   namespace, e.g. "_VSTD::abort();", which fails after we use the
    -   preprocessor to redefine "abort" as "fancy_abort" below.  */
    -
    -#ifdef INCLUDE_MEMORY
    -# include <memory>
    -#endif

In other words, (unconditional) '#include <memory>' appears to preclude
ability to convert 'NULL' into a mode?  (Or, I'm off-track, of course...)

Either way: OK to push the attached "GCN: Fix 'real_from_integer' usage"
after testing completes?


Grüße
 Thomas


>From dfc2a5398979738ae25eb0258bbf64b82df621a5 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <tschwi...@baylibre.com>
Date: Thu, 5 Dec 2024 14:28:26 +0100
Subject: [PATCH] GCN: Fix 'real_from_integer' usage
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The recent commit b3f1b9e2aa079f8ec73e3cb48143a16645c49566
"build: Remove INCLUDE_MEMORY [PR117737]" exposed an issue in code added in
2020 GCN back end commit 95607c12363712c39345e1d97f2c1aee8025e188
"Zero-initialise masked load destinations"; compilation now fails:

    [...]
    In file included from ../../source-gcc/gcc/coretypes.h:507:0,
                     from ../../source-gcc/gcc/config/gcn/gcn.cc:24:
    ../../source-gcc/gcc/real.h: In instantiation of ‘format_helper::format_helper(const T&) [with T = std::nullptr_t]’:
    ../../source-gcc/gcc/config/gcn/gcn.cc:1178:46:   required from here
    ../../source-gcc/gcc/real.h:233:17: error: no match for ‘operator==’ (operand types are ‘std::nullptr_t’ and ‘machine_mode’)
       : m_format (m == VOIDmode ? 0 : REAL_MODE_FORMAT (m))
                     ^
    [...]

That's with 'g++ (GCC) 5.5.0', and seen similarly with
'g++ (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0', for example.

	gcc/
	* config/gcn/gcn.cc (gcn_vec_constant): Fix 'real_from_integer'
	usage.
---
 gcc/config/gcn/gcn.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/gcn/gcn.cc b/gcc/config/gcn/gcn.cc
index d078392eeaf1..b60835d8df48 100644
--- a/gcc/config/gcn/gcn.cc
+++ b/gcc/config/gcn/gcn.cc
@@ -1175,7 +1175,7 @@ gcn_vec_constant (machine_mode mode, int a)
   if (FLOAT_MODE_P (innermode))
     {
       REAL_VALUE_TYPE rv;
-      real_from_integer (&rv, NULL, a, SIGNED);
+      real_from_integer (&rv, VOIDmode, a, SIGNED);
       tem = const_double_from_real_value (rv, innermode);
     }
   else
-- 
2.34.1

Reply via email to