public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Qing Zhao <qing.zhao@oracle.com>
To: Richard Biener <richard.guenther@gmail.com>,
	Jakub Jelinek <jakub@redhat.com>
Cc: gcc-patches Nick Alcock via <gcc-patches@gcc.gnu.org>,
	"Kewen. Lin" <linkw@linux.ibm.com>,
	"H.J. Lu" <hjl.tools@gmail.com>,
	andrew Pinski <pinskia@gmail.com>
Subject: Re: Values of WIDE_INT_MAX_ELTS in gcc11 and gcc12 are different
Date: Mon, 8 Nov 2021 23:47:33 +0000	[thread overview]
Message-ID: <64E9CE8D-1305-45E6-9B54-3E18311E2CF9@oracle.com> (raw)
In-Reply-To: <CAFiYyc2-ZZvRpZ-fVNT+O4xVuKdXO4zCEL=3TDvz_KkYq-jrUQ@mail.gmail.com>

Hi, I tried both the following patches:

Patch1:

[opc@qinzhao-ol8u3-x86 gcc]$ git diff 
diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c
index 0cba95411a6..ca49d2b4514 100644
--- a/gcc/internal-fn.c
+++ b/gcc/internal-fn.c
@@ -3073,12 +3073,14 @@ expand_DEFERRED_INIT (internal_fn, gcall *stmt)
       /* If this variable is in a register use expand_assignment.
         For boolean scalars force zero-init.  */
       tree init;
+      scalar_int_mode var_mode;
       if (TREE_CODE (TREE_TYPE (lhs)) != BOOLEAN_TYPE
          && tree_fits_uhwi_p (var_size)
          && (init_type == AUTO_INIT_PATTERN
              || !is_gimple_reg_type (var_type))
          && int_mode_for_size (tree_to_uhwi (var_size) * BITS_PER_UNIT,
-                               0).exists ())
+                               0).exists (&var_mode)
+         && targetm.scalar_mode_supported_p (var_mode))
        {
          unsigned HOST_WIDE_INT total_bytes = tree_to_uhwi (var_size);
          unsigned char *buf = (unsigned char *) xmalloc (total_bytes);

AND

Patch2:
diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c
index 0cba95411a6..7f129655926 100644
--- a/gcc/internal-fn.c
+++ b/gcc/internal-fn.c
@@ -3073,12 +3073,14 @@ expand_DEFERRED_INIT (internal_fn, gcall *stmt)
       /* If this variable is in a register use expand_assignment.
         For boolean scalars force zero-init.  */
       tree init;
+      scalar_int_mode var_mode;
       if (TREE_CODE (TREE_TYPE (lhs)) != BOOLEAN_TYPE
          && tree_fits_uhwi_p (var_size)
          && (init_type == AUTO_INIT_PATTERN
              || !is_gimple_reg_type (var_type))
          && int_mode_for_size (tree_to_uhwi (var_size) * BITS_PER_UNIT,
-                               0).exists ())
+                               0).exists (&var_mode)
+         && have_insn_for (SET, var_mode))
        {
          unsigned HOST_WIDE_INT total_bytes = tree_to_uhwi (var_size);
          unsigned char *buf = (unsigned char *) xmalloc (total_bytes);

Have the same effect:

1. Resolved the ICE in gcc11;
2. For _Complex long double variables, both return FALSE, as a result, for PATTERN initialization of _Complex long double variables, now they are initialization with ZEROs instead of FEs.

Let me know you opinion on this, If the above 2 is okay, then I might pick the above Patch 1 for the final patch to this issue.

Thanks.

Qing

> On Nov 8, 2021, at 2:41 AM, Richard Biener <richard.guenther@gmail.com> wrote:
> 
> On Sat, Nov 6, 2021 at 10:56 AM Jakub Jelinek <jakub@redhat.com> wrote:
>> 
>> On Fri, Nov 05, 2021 at 05:37:25PM +0000, Qing Zhao wrote:
>>>> On Nov 5, 2021, at 11:17 AM, Jakub Jelinek <jakub@redhat.com> wrote:
>>>> 
>>>> On Fri, Nov 05, 2021 at 04:11:36PM +0000, Qing Zhao wrote:
>>>>> 3076       if (TREE_CODE (TREE_TYPE (lhs)) != BOOLEAN_TYPE
>>>>> 3077           && tree_fits_uhwi_p (var_size)
>>>>> 3078           && (init_type == AUTO_INIT_PATTERN
>>>>> 3079               || !is_gimple_reg_type (var_type))
>>>>> 3080           && int_mode_for_size (tree_to_uhwi (var_size) * BITS_PER_UNIT,
>>>>> 3081                                 0).exists ())
>>>>> 3082         {
>>>>> 3083           unsigned HOST_WIDE_INT total_bytes = tree_to_uhwi (var_size);
>>>>> 3084           unsigned char *buf = (unsigned char *) xmalloc (total_bytes);
>>>>> 3085           memset (buf, (init_type == AUTO_INIT_PATTERN
>>>>> 3086                         ? INIT_PATTERN_VALUE : 0), total_bytes);
>>>>> 3087           tree itype = build_nonstandard_integer_type
>>>>> 3088                          (total_bytes * BITS_PER_UNIT, 1);
>>>>> 
>>>>> The exact failing point is at function “set_min_and_max_values_for_integral_type”:
>>>>> 
>>>>> 2851   gcc_assert (precision <= WIDE_INT_MAX_PRECISION);
>>>>> 
>>>>> For _Complex long double,  “precision” is 256.
>>>>> In GCC11, “WIDE_INT_MAX_PRECISION” is 192,  in GCC12, it’s 512.
>>>>> As a result, the above assertion failed on GCC11.
>>>>> 
>>>>> I am wondering what’s the best fix for this issue in gcc11?
>>>> 
>>>> Even for gcc 12 the above is wrong, you can't blindly assume that
>>>> build_nonstandard_integer_type will work for arbitrary precisions,
>>>> and even if it works that it will actually work.
>>>> The fact that such a mode exist is one thing, but
>>>> targetm.scalar_mode_supported_p should be tested for whether the mode
>>>> is actually supported.
>>> 
>>> You mean “int_mode_for_size().exists()” is not enough to make sure
>>> “build_nonstandard_integer_type” to be valid?  We should add
>>> “targetm.scalar_mode_supported_p” too ?
>> 
>> Yeah.  The former says whether the backend has that mode at all.
>> But some modes may be there only in some specific patterns but
>> without support for mov, add, etc.  Only for
>> targetm.scalar_mode_supported_p modes the backend guarantees that
>> one can use them e.g. in mode attribute and can expect expansion
>> to expand everything with that mode that is needed in some way.
>> E.g. only if targetm.scalar_mode_supported_p (TImode) the FEs
>> support __int128_t type, etc.
> 
> The memcpy folding code now checks
> 
>              scalar_int_mode mode;
>              if (int_mode_for_size (ilen * 8, 0).exists (&mode)
>                  && GET_MODE_SIZE (mode) * BITS_PER_UNIT == ilen * 8
>                  && have_insn_for (SET, mode)
> 
> thus specifically only have_insn_for (SET, mode), which I guess is
> good enough for this case as well?
> 
>>        Jakub


  reply	other threads:[~2021-11-08 23:47 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-04 20:37 Qing Zhao
2021-11-05  1:34 ` Kewen.Lin
2021-11-05  6:05 ` Andrew Pinski
2021-11-05  6:53   ` Jakub Jelinek
2021-11-05 10:01     ` Richard Biener
2021-11-05 12:25       ` H.J. Lu
2021-11-05 16:11       ` Qing Zhao
2021-11-05 16:17         ` Jakub Jelinek
2021-11-05 17:37           ` Qing Zhao
2021-11-06  9:56             ` Jakub Jelinek
2021-11-08  8:41               ` Richard Biener
2021-11-08 23:47                 ` Qing Zhao [this message]
2021-11-09  7:13                   ` Richard Biener
2021-11-09  9:10                     ` Jakub Jelinek
2021-11-09 10:44                       ` Richard Biener
2021-11-09 17:19                         ` Qing Zhao
2021-11-10  8:37                           ` Richard Biener
2021-11-10 18:02                             ` Qing Zhao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=64E9CE8D-1305-45E6-9B54-3E18311E2CF9@oracle.com \
    --to=qing.zhao@oracle.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hjl.tools@gmail.com \
    --cc=jakub@redhat.com \
    --cc=linkw@linux.ibm.com \
    --cc=pinskia@gmail.com \
    --cc=richard.guenther@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).