On Tue, Nov 9, 2021 at 12:47 AM Qing Zhao <qing.z...@oracle.com> wrote: > > 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.
I think zero-initialization is OK, but I'd choose Patch2 for consistency with what we do in the memcpy folding. Richard. > Thanks. > > Qing > > > On Nov 8, 2021, at 2:41 AM, Richard Biener <richard.guent...@gmail.com> > > wrote: > > > > On Sat, Nov 6, 2021 at 10:56 AM Jakub Jelinek <ja...@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 <ja...@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 >