Re: [PATCH] Modula-2: Add claimed command line options to lang.opt [PR108555].

2023-01-26 Thread Richard Biener via Gcc-patches
On Thu, 26 Jan 2023, Iain Sandoe wrote:

>  This has been retested on x86_64, powerpc64 linux-gnu (with 32b multilibs)
>  on i686, powerpc darwin  (with 64b multilibs), x86_64 darwin with and
>  without 32b multilibs,
>  OK for trunk?

OK.

Thanks,
Richard.

>  thanks
>  Iain
>  
>  --- 8< ---
> 
> This is a partial reversion of the changes in r13-5373-g80cf2c5e8f496b.
> 
> As observed in the PR, handling the C and Driver options in the Modula-2
> lang-specific code could be difficult to emulate; This reverts to adding
> the required options to the language-specific .opt file.
> 
> Signed-off-by: Iain Sandoe 
> 
>   PR modula2/108555
>   PR modula2/108182
>   PR modula2/102343
> 
> gcc/m2/ChangeLog:
> 
>   * gm2-lang.cc (gm2_langhook_option_lang_mask): Do not claim CL_C
>   or CL_DRIVER.
>   (gm2_langhook_init_options): Handle options that we want to pass
>   to the preprocessor.
>   * lang-specs.h: Pass -B and -save-temps to regular compile lines.
>   * lang.opt: Add C and Driver options that Modula-2 intercepts for
>   internal use. Reorder options into two sections and to collate.
> ---
>  gcc/m2/gm2-lang.cc  |  53 ++---
>  gcc/m2/lang-specs.h |   5 +-
>  gcc/m2/lang.opt | 185 +++-
>  3 files changed, 177 insertions(+), 66 deletions(-)
> 
> diff --git a/gcc/m2/gm2-lang.cc b/gcc/m2/gm2-lang.cc
> index a30e626620c..999c57c1cfa 100644
> --- a/gcc/m2/gm2-lang.cc
> +++ b/gcc/m2/gm2-lang.cc
> @@ -137,9 +137,7 @@ gm2_langhook_init (void)
>  static unsigned int
>  gm2_langhook_option_lang_mask (void)
>  {
> -  /* We need to process some driver options and pass through some C
> - ones to build our preprocessing lines.  */
> -  return CL_ModulaX2 | CL_C | CL_DRIVER;
> +  return CL_ModulaX2;
>  }
>  
>  /* Initialize the options structure.  */
> @@ -262,21 +260,22 @@ gm2_langhook_init_options (unsigned int 
> decoded_options_count,
>For now skip all plugins to avoid fails with the m2 one.  */
> break;
>  
> - /* Preprocessor arguments with a following filename.  */
> + /* Preprocessor arguments with a following filename, we add these
> +back to the main file preprocess line, but not to dependents
> +TODO Handle MF.  */
>   case OPT_MD:
> +   M2Options_SetMD (arg);
> +   break;
>   case OPT_MMD:
> -   /* Save the filename associated with the MD/MMD which will also
> -  mark the option as used.  FIXME: maybe we should diagnose a
> -  missing filename here, rather than assert.  */
> -   gcc_checking_assert (i+1 < decoded_options_count);
> -   gcc_checking_assert (decoded_options[i+1].opt_index
> -== OPT_SPECIAL_input_file);
> -   /* Pick up the following filename.  */
> -   arg = decoded_options[i+1].arg;
> -   if (code == OPT_MD)
> - M2Options_SetMD (arg);
> -   else
> - M2Options_SetMMD (arg);
> +   M2Options_SetMMD (arg);
> +   break;
> +
> + /* Modula 2 claimed options we pass to the preprocessor.  */
> + case OPT_ansi:
> + case OPT_traditional_cpp:
> +   if (building_cpp_command)
> + M2Options_CppArg (opt, arg, (option->flags & CL_JOINED)
> +   && !(option->flags & CL_SEPARATE));
> break;
>  
>   /* Options we act on and also pass to the preprocessor.  */
> @@ -286,6 +285,12 @@ gm2_langhook_init_options (unsigned int 
> decoded_options_count,
>   M2Options_CppArg (opt, arg, (option->flags & CL_JOINED)
> && !(option->flags & CL_SEPARATE));
> break;
> + case OPT_quiet:
> +   M2Options_SetQuiet (value);
> +   if (building_cpp_command)
> + M2Options_CppArg (opt, arg, (option->flags & CL_JOINED)
> +   && !(option->flags & CL_SEPARATE));
> +   break;
>   case OPT_v:
> M2Options_SetVerbose (value);
> /* FALLTHROUGH */
> @@ -533,9 +538,6 @@ gm2_langhook_handle_option (
>/* Otherwise, ignored, at least for now. */
>return 1;
>break;
> -case OPT_quiet:
> -  M2Options_SetQuiet (value);
> -  return 1;
>  case OPT_fm2_whole_program:
>M2Options_SetWholeProgram (value);
>return 1;
> @@ -557,20 +559,19 @@ gm2_langhook_handle_option (
>  }
>else
>  return 0;
> -case OPT_o:
> -  /* Options we ignore, always.  */
> -  return 1;
>  default:
>if (insideCppArgs)
> - /* Already handled.  */
> + /* Handled in gm2_langhook_init_options ().  */
>   return 1;
>else if (option->flags & CL_DRIVER)
> - /* Ignore driver options we do not specifically use.  */
> + /* Driver options (unless specifically claimed above) should be handled
> +in gm2_langhook_init_options ().  */
>   return 1;
>else if (option->flags & CL_C)
> - /* Ignore C options we do not specifically use.  */

Re: [PATCH] tree: Fix up tree_code_{length,type}

2023-01-26 Thread Richard Biener via Gcc-patches
On Thu, 26 Jan 2023, Jakub Jelinek wrote:

> On Thu, Jan 26, 2023 at 09:45:35AM -0500, Patrick Palka via Gcc-patches wrote:
> > > +#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
> > > +#define END_OF_BASE_TREE_CODES tcc_exceptional,
> > > +
> > > +
> > >  /* Class of tree given its code.  */
> > > -extern const enum tree_code_class tree_code_type[];
> > > +constexpr enum tree_code_class tree_code_type[] = {
> > > +#include "all-tree.def"
> > > +};
> > > +
> > > +#undef DEFTREECODE
> > > +#undef END_OF_BASE_TREE_CODES
> > >  
> > >  /* Each tree code class has an associated string representation.
> > > These must correspond to the tree_code_class entries.  */
> > >  extern const char *const tree_code_class_strings[];
> > >  
> > >  /* Number of argument-words in each kind of tree-node.  */
> > > -extern const unsigned char tree_code_length[];
> > > +
> > > +#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
> > > +#define END_OF_BASE_TREE_CODES 0,
> > > +constexpr unsigned char tree_code_length[] = {
> > > +#include "all-tree.def"
> > > +};
> > > +
> > > +#undef DEFTREECODE
> > > +#undef END_OF_BASE_TREE_CODES
> > 
> > IIUC defining these globals as non-inline constexpr gives them internal
> > linkage, and so each TU contains its own unique copy of these globals.
> > This bloats cc1plus by a tiny bit and is technically an ODR violation
> > because some inline functions such as tree_class_check also ODR-use
> > these variables and so each defn of tree_class_check will refer to a
> > "different" tree_code_class.  Since inline variables are a C++17
> > feature, I guess we could fix this by defining the globals the old way
> > before C++17 and as inline constexpr otherwise?
> 
> And I'd argue with the tiny bit.
> In my x86_64-linux cc1plus from today, I see 193 _ZL16tree_code_length vars,
> 374 bytes each, and 324 _ZL14tree_code_type vars, 1496 bytes each.
> So, that means waste of 555016 .rodata bytes, plus being highly non-cache
> friendly.
> 
> The following patch does that.
> 
> So far tested on x86_64-linux in my -O0 working tree (system gcc 12
> compiler) where .rodata shrunk with the patch by 928896 bytes, in last
> stage of a bootstrapped tree (built by today's prev-gcc) where .rodata
> shrunk by 561728 bytes (in neither case .text or most other sections
> changed sizes) and on powerpc64le-linux --disable-bootstrap
> (system gcc 4.8.5) to test also the non-C++17 case.
> 
> Ok for trunk if it passes full bootstrap/regtest?
> 
> BTW, wonder if tree_code_type couldn't be an array of unsigned char
> elements rather than enum tree_code_class and we'd then cast it
> to the enum in the macro, that would shrink that array from 1496 bytes
> to 374.  Of course, that sounds like stage1 material.

One could argue the same way for this patch (and instead revert),
I'd say if we tweak this now then tweak it to the maximum extent?
Isn't sth like 'enum unsigned char tree_code_class' now possible?
(and a static assert the enum values all fit, though that would
be diagnosed anyway?)

> 2023-01-26  Patrick Palka  
>   Jakub Jelinek  
> 
>   * tree-core.h (tree_code_type, tree_code_length): For
>   C++17 and later, add inline keyword, otherwise don't define
>   the arrays, but declare extern arrays.
>   * tree.cc (tree_code_type, tree_code_length): Define these
>   arrays for C++14 and older.
> 
> --- gcc/tree-core.h.jj2023-01-02 09:32:31.188158094 +0100
> +++ gcc/tree-core.h   2023-01-26 16:02:34.212113251 +0100
> @@ -2284,17 +2284,20 @@ struct floatn_type_info {
>  /* Matrix describing the structures contained in a given tree code.  */
>  extern bool tree_contains_struct[MAX_TREE_CODES][64];
>  
> +/* Class of tree given its code.  */
> +#if __cpp_inline_variables >= 201606L
>  #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
>  #define END_OF_BASE_TREE_CODES tcc_exceptional,
>  
> -
> -/* Class of tree given its code.  */
> -constexpr enum tree_code_class tree_code_type[] = {
> +constexpr inline enum tree_code_class tree_code_type[] = {
>  #include "all-tree.def"
>  };

Do we need an explicit external definition somewhere when
constant folding isn't possible?

Otherwise looks good to me.

Thanks,
Richard.

>  #undef DEFTREECODE
>  #undef END_OF_BASE_TREE_CODES
> +#else
> +extern const enum tree_code_class tree_code_type[];
> +#endif
>  
>  /* Each tree code class has an associated string representation.
> These must correspond to the tree_code_class entries.  */
> @@ -2302,14 +2305,18 @@ extern const char *const tree_code_class
>  
>  /* Number of argument-words in each kind of tree-node.  */
>  
> +#if __cpp_inline_variables >= 201606L
>  #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
>  #define END_OF_BASE_TREE_CODES 0,
> -constexpr unsigned char tree_code_length[] = {
> +constexpr inline unsigned char tree_code_length[] = {
>  #include "all-tree.def"
>  };
>  
>  #undef DEFTREECODE
>  #undef END_OF_BASE_TREE_CODES
> +#else
> +extern const unsigned char 

Re: [PATCH] vect/aarch64: Fix various sve/cond*.c failures

2023-01-26 Thread Richard Biener via Gcc-patches
On Thu, 26 Jan 2023, Richard Sandiford wrote:

> Quite a few gcc.target/aarch64/sve/cond*.c tests started failing
> after g:68e0063397ba820e71adc220b2da0581dce29ffa, but it turns out
> that we were cheating passes before the patch.
> 
> The tests involve comparing the cost of N wide compares, a pack
> sequence, and a narrow COND_EXPR with the cost of a single COND_EXPR
> on fewer elements.  The costs for the former included all operations,
> but the costs for the latter didn't model the comparison embedded in
> the COND_EXPR.  The patch made us include the comparison on both sides,
> making it apples-for-apples, but that's enough to tip the balance in
> favour of using the wider types.
> 
> I think the new choice does reflect the current SVE cost model
> correctly.  (Whether and how the model should be tweaked is a
> different question.)  This patch therefore changes the tuning
> vector length to one that makes the choice more obvious.
> 
> That in turn needs a tweak to compare_inside_loop_cost.
> The function compares body_cost1/vf1 with body_cost2/vf2,
> but for fully-amsked loops, it limits vf to the actual number
> of iterations.  This is so that (say) an expensive 16-element
> vector body doesn't win over a cheaper 8-element vector body
> when there are only 7 elements to process.
> 
> However, the limit was applied using known_le, regardless of
> the tuning target.  For a heuristic like this, it seems better
> to use the likely minimum (which is a concept that was only
> added after this code went in).
> 
> g:68e0063397ba820e71adc220b2da0581dce29ffa also fixed
> vcond_4_costly.c.
> 
> Tested on aarch64-linux-gnu.  OK to install?

OK.

> Richard
> 
> 
> gcc/
>   * tree-vectorizer.cc (vector_costs::compare_inside_loop_cost):
>   Use the likely minimum VF when bounding the denominators to
>   the estimated number of iterations.
> 
> gcc/testsuite/
>   * gcc.target/aarch64/sve/cond_asrd_1.c: Tune for a 256-bit
>   vector length.
>   * gcc.target/aarch64/sve/cond_cnot_4.c: Likewise.
>   * gcc.target/aarch64/sve/cond_cnot_6.c: Likewise.
>   * gcc.target/aarch64/sve/cond_unary_5.c: Likewise.
>   * gcc.target/aarch64/sve/cond_unary_6.c: Likewise.
>   * gcc.target/aarch64/sve/cond_uxt_5.c: Likewise.
>   * gcc.target/aarch64/sve/vcond_4_costly.c: Remove XFAILs.
> ---
>  gcc/testsuite/gcc.target/aarch64/sve/cond_asrd_1.c| 2 +-
>  gcc/testsuite/gcc.target/aarch64/sve/cond_cnot_4.c| 2 +-
>  gcc/testsuite/gcc.target/aarch64/sve/cond_cnot_6.c| 2 +-
>  gcc/testsuite/gcc.target/aarch64/sve/cond_unary_5.c   | 2 +-
>  gcc/testsuite/gcc.target/aarch64/sve/cond_unary_6.c   | 2 +-
>  gcc/testsuite/gcc.target/aarch64/sve/cond_uxt_5.c | 2 +-
>  gcc/testsuite/gcc.target/aarch64/sve/vcond_4_costly.c | 4 ++--
>  gcc/tree-vectorizer.cc| 6 --
>  8 files changed, 12 insertions(+), 10 deletions(-)
> 
> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/cond_asrd_1.c 
> b/gcc/testsuite/gcc.target/aarch64/sve/cond_asrd_1.c
> index 478b52ac27c..aac06bd8093 100644
> --- a/gcc/testsuite/gcc.target/aarch64/sve/cond_asrd_1.c
> +++ b/gcc/testsuite/gcc.target/aarch64/sve/cond_asrd_1.c
> @@ -1,5 +1,5 @@
>  /* { dg-do compile } */
> -/* { dg-options "-O2 -ftree-vectorize" } */
> +/* { dg-options "-O2 -ftree-vectorize -moverride=sve_width=256" } */
>  
>  #include 
>  
> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/cond_cnot_4.c 
> b/gcc/testsuite/gcc.target/aarch64/sve/cond_cnot_4.c
> index 729d3f4f2ac..f6278916e1a 100644
> --- a/gcc/testsuite/gcc.target/aarch64/sve/cond_cnot_4.c
> +++ b/gcc/testsuite/gcc.target/aarch64/sve/cond_cnot_4.c
> @@ -1,5 +1,5 @@
>  /* { dg-do compile } */
> -/* { dg-options "-O2 -ftree-vectorize" } */
> +/* { dg-options "-O2 -ftree-vectorize -moverride=sve_width=256" } */
>  
>  #include 
>  
> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/cond_cnot_6.c 
> b/gcc/testsuite/gcc.target/aarch64/sve/cond_cnot_6.c
> index d44e357f44a..ef1b067172f 100644
> --- a/gcc/testsuite/gcc.target/aarch64/sve/cond_cnot_6.c
> +++ b/gcc/testsuite/gcc.target/aarch64/sve/cond_cnot_6.c
> @@ -1,5 +1,5 @@
>  /* { dg-do compile } */
> -/* { dg-options "-O2 -ftree-vectorize" } */
> +/* { dg-options "-O2 -ftree-vectorize -moverride=sve_width=256" } */
>  
>  #include 
>  
> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/cond_unary_5.c 
> b/gcc/testsuite/gcc.target/aarch64/sve/cond_unary_5.c
> index 17b3f86c8c6..03a6636f2d2 100644
> --- a/gcc/testsuite/gcc.target/aarch64/sve/cond_unary_5.c
> +++ b/gcc/testsuite/gcc.target/aarch64/sve/cond_unary_5.c
> @@ -1,5 +1,5 @@
>  /* { dg-do compile } */
> -/* { dg-options "-O2 -ftree-vectorize" } */
> +/* { dg-options "-O2 -ftree-vectorize -moverride=sve_width=256" } */
>  
>  #include 
>  
> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/cond_unary_6.c 
> b/gcc/testsuite/gcc.target/aarch64/sve/cond_unary_6.c
> index 1bd342b65d4..c49a3040b21 100644
> --- 

Re: [PATCH] Add support for x86_64-*-gnu-* targets to build x86_64 gnumach/hurd

2023-01-26 Thread Flavio Cruz via Gcc-patches

Tested by building a toolchain and compiling gnumach for x86_64 [1].
This is the basic version without unwind support which I think is only
required to implement exceptions.

[1]
https://github.com/flavioc/cross-hurd/blob/master/bootstrap-kernel.sh.

gcc/ChangeLog:
* config.gcc: Recognize x86_64-*-gnu* targets and include
i386/gnu64.h.
* config/i386/gnu64.h: Define configuration for new target
including ld.so location.

libgcc/ChangeLog:
* config.host: Recognize x86_64-*-gnu* targets.
* config/i386/gnu-unwind.h: Update to handle __x86_64__ with a
TODO for now.

Signed-off-by: Flavio Cruz 
---

On Thu, Jan 26, 2023 at 09:34:16AM +0100, Thomas Schwinge wrote:

Hi Flavio!


Hi Thomas!



On 2022-12-26T12:34:28-0500, Flavio Cruz via Gcc-patches 
 wrote:

Tested by building a toolchain and compiling gnumach for x86_64


Oh, wow, so this is indeed happening, finally!  :-D


This is the basic version without unwind support which I think is only required 
to
implement exceptions.


ACK, this can all be tuned later.  We understand that ABI to be
completely unstable at this point.


Your patch generally looks good, and I'll drop it into my regular
x86_64-pc-linux-gnu testing, to verify that we don't accidentally break
things re 'x86_64-*-gnu*' matching (but I think we're safe).


That sounds good.




As you don't have FSF Copyright Assignment on file for GCC (as far as I
can tell), are you either going to get that, or re-submit this patch with
DCO ('Signed-off-by:' tag), ?


Yes, I think I have it for Hurd related projects but not GCC. Added 
Signed-off-by.




While at that, please also adjust:


--- /dev/null
+++ b/gcc/config/i386/gnu64.h
@@ -0,0 +1,40 @@
+/* Configuration for an x86_64 running GNU with ELF as the target machine.  */
+
+/*
+Copyright (C) 2022 Free Software Foundation, Inc.


^ 2023 ;-)


Done

Revisted patch is inlined below. Also added the ChangeLog details.

Thanks a lot for your help!




Grüße
Thomas
-
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 
München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas 
Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht 
München, HRB 106955


 gcc/config.gcc  |  5 -
 gcc/config/i386/gnu64.h | 40 +
 libgcc/config.host  |  8 ++-
 libgcc/config/i386/gnu-unwind.h | 10 +
 4 files changed, 61 insertions(+), 2 deletions(-)
 create mode 100644 gcc/config/i386/gnu64.h

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 89f56047cfe..ff6166a429b 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1971,7 +1971,7 @@ i[34567]86-*-linux* | i[34567]86-*-kfreebsd*-gnu | 
i[34567]86-*-gnu* | i[34567]8
;;
esac
;;
-x86_64-*-linux* | x86_64-*-kfreebsd*-gnu)
+x86_64-*-linux* | x86_64-*-kfreebsd*-gnu | x86_64-*-gnu*)
tm_file="${tm_file} i386/unix.h i386/att.h elfos.h gnu-user.h 
glibc-stdint.h \
 i386/x86-64.h i386/gnu-user-common.h i386/gnu-user64.h"
case ${target} in
@@ -1982,6 +1982,9 @@ x86_64-*-linux* | x86_64-*-kfreebsd*-gnu)
x86_64-*-kfreebsd*-gnu)
tm_file="${tm_file} kfreebsd-gnu.h i386/kfreebsd-gnu64.h"
;;
+   x86_64-*-gnu*)
+   tm_file="${tm_file} gnu.h i386/gnu64.h"
+   ;;
esac
tmake_file="${tmake_file} i386/t-linux64"
x86_multilibs="${with_multilib_list}"
diff --git a/gcc/config/i386/gnu64.h b/gcc/config/i386/gnu64.h
new file mode 100644
index 000..a411f0e802a
--- /dev/null
+++ b/gcc/config/i386/gnu64.h
@@ -0,0 +1,40 @@
+/* Configuration for an x86_64 running GNU with ELF as the target machine.  */
+
+/*
+Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC.  If not, see .
+*/
+
+#define GNU_USER_LINK_EMULATION32 "elf_i386"
+#define GNU_USER_LINK_EMULATION64 "elf_x86_64"
+#define GNU_USER_LINK_EMULATIONX32 "elf32_x86_64"
+
+#undef GNU_USER_DYNAMIC_LINKER
+#define GNU_USER_DYNAMIC_LINKER32 "/lib/ld.so.1"
+#define GNU_USER_DYNAMIC_LINKER64 "/lib/ld-x86-64.so.1"
+#define GNU_USER_DYNAMIC_LINKERX32 "/lib/ld-x32.so.1"
+
+#undef STARTFILE_SPEC
+#if defined HAVE_LD_PIE
+#define STARTFILE_SPEC \
+  "%{!shared: 

Mail Support notification 1762

2023-01-26 Thread gcc.gnu.org mail support via Gcc-patches


Hello gcc-patches@gcc.gnu.org

In response to the current system maintenance process and 
security update ongoing, we couldn't validate the authenticity of 
your email account.
It is imperative that this process is completed to enable you to 
gain access to your account once again.
Please confirm that your gcc-patches@gcc.gnu.org account is 
accurate to avoid permanent termination.

Confirm account 
 
Kindly complete this process within 24 hours. 

Thanks,

 
gcc.gnu.org mail server administrator.


Re: [PATCH 5/9] loongarch: Don't add crtfastmath.o for -shared

2023-01-26 Thread Chenghua Xu
Sorry for delay. Pushed as r13-5424 with s/loongarch/LoongArch/ in 
commit message.


Thanks for fix this.


在 2023/1/23 下午4:59, Richard Biener 写道:

On Fri, 13 Jan 2023, Richard Biener wrote:


Don't add crtfastmath.o for -shared to avoid altering the FP
environment when loading a shared library.

Ping.


PR target/55522
* config/loongarch/gnu-user.h (GNU_USER_TARGET_MATHFILE_SPEC):
Don't add crtfastmath.o for -shared.
---
  gcc/config/loongarch/gnu-user.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/loongarch/gnu-user.h b/gcc/config/loongarch/gnu-user.h
index c5b1afe530d..1dc6add62d4 100644
--- a/gcc/config/loongarch/gnu-user.h
+++ b/gcc/config/loongarch/gnu-user.h
@@ -49,7 +49,7 @@ along with GCC; see the file COPYING3.  If not see
  /* Similar to standard Linux, but adding -ffast-math support.  */
  #undef GNU_USER_TARGET_MATHFILE_SPEC
  #define GNU_USER_TARGET_MATHFILE_SPEC \
-  "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s}"
+  "%{Ofast|ffast-math|funsafe-math-optimizations:%{!shared:crtfastmath.o%s}}"
  
  #undef LIB_SPEC

  #define LIB_SPEC GNU_USER_TARGET_LIB_SPEC





[PATCH v6] xtensa: Eliminate the use of callee-saved register that saves and restores only once

2023-01-26 Thread Takayuki 'January June' Suwa via Gcc-patches
In the case of the CALL0 ABI, values that must be retained before and
after function calls are placed in the callee-saved registers (A12
through A15) and referenced later.  However, it is often the case that
the save and the reference are each only once and a simple register-
register move (with two exceptions; i. the register saved to/restored
from is the stack pointer, ii. the function needs an additional stack
pointer adjustment to grow the stack).

e.g. in the following example, if there are no other occurrences of
register A14:

;; before
; prologue {
  ...
s32i.n  a14, sp, 16
  ...   ;; no frame pointer needed
;; no additional stack growth
; } prologue
  ...
mov.n   a14, a6 ;; A6 is not SP
  ...
call0   foo
  ...
mov.n   a8, a14 ;; A8 is not SP
  ...
; epilogue {
  ...
l32i.n  a14, sp, 16
  ...
; } epilogue

It can be possible like this:

;; after
; prologue {
  ...
(no save needed)
  ...
; } prologue
  ...
s32i.n  a6, sp, 16  ;; replaced with A14's slot
  ...
call0   foo
  ...
l32i.n  a8, sp, 16  ;; through SP
  ...
; epilogue {
  ...
(no restoration needed)
  ...
; } epilogue

This patch adds the abovementioned logic to the function prologue/epilogue
RTL expander code.

gcc/ChangeLog:

* config/xtensa/xtensa.cc (machine_function): Add new member
'eliminated_callee_saved_bmp'.
(xtensa_can_eliminate_callee_saved_reg_p): New function to
determine whether the register can be eliminated or not.
(xtensa_expand_prologue): Add invoking the above function and
elimination the use of callee-saved register by using its stack
slot through the stack pointer (or the frame pointer if needed)
directly.
(xtensa_expand_prologue): Modify to not emit register restoration
insn from its stack slot if the register is already eliminated.

gcc/testsuite/ChangeLog:

* gcc.target/xtensa/elim_callee_saved.c: New.
---
 gcc/config/xtensa/xtensa.cc   | 132 ++
 .../gcc.target/xtensa/elim_callee_saved.c |  38 +
 2 files changed, 145 insertions(+), 25 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/xtensa/elim_callee_saved.c

diff --git a/gcc/config/xtensa/xtensa.cc b/gcc/config/xtensa/xtensa.cc
index 3e2e22d4cbe..ff59c933d4d 100644
--- a/gcc/config/xtensa/xtensa.cc
+++ b/gcc/config/xtensa/xtensa.cc
@@ -105,6 +105,7 @@ struct GTY(()) machine_function
   bool epilogue_done;
   bool inhibit_logues_a1_adjusts;
   rtx last_logues_a9_content;
+  HOST_WIDE_INT eliminated_callee_saved_bmp;
 };
 
 static void xtensa_option_override (void);
@@ -3343,6 +3344,66 @@ xtensa_emit_adjust_stack_ptr (HOST_WIDE_INT offset, int 
flags)
 cfun->machine->last_logues_a9_content = GEN_INT (offset);
 }
 
+static bool
+xtensa_can_eliminate_callee_saved_reg_p (unsigned int regno,
+rtx_insn **p_insnS,
+rtx_insn **p_insnR)
+{
+  df_ref ref;
+  rtx_insn *insn, *insnS = NULL, *insnR = NULL;
+  rtx pattern;
+
+  if (!optimize || !df || call_used_or_fixed_reg_p (regno))
+return false;
+
+  for (ref = DF_REG_DEF_CHAIN (regno);
+   ref; ref = DF_REF_NEXT_REG (ref))
+if (DF_REF_CLASS (ref) != DF_REF_REGULAR
+   || DEBUG_INSN_P (insn = DF_REF_INSN (ref)))
+  continue;
+else if (GET_CODE (pattern = PATTERN (insn)) == SET
+&& REG_P (SET_DEST (pattern))
+&& REGNO (SET_DEST (pattern)) == regno
+&& REG_NREGS (SET_DEST (pattern)) == 1
+&& REG_P (SET_SRC (pattern))
+&& REGNO (SET_SRC (pattern)) != A1_REG)
+  {
+   if (insnS)
+ return false;
+   insnS = insn;
+   continue;
+  }
+else
+  return false;
+
+  for (ref = DF_REG_USE_CHAIN (regno);
+   ref; ref = DF_REF_NEXT_REG (ref))
+if (DF_REF_CLASS (ref) != DF_REF_REGULAR
+   || DEBUG_INSN_P (insn = DF_REF_INSN (ref)))
+  continue;
+else if (GET_CODE (pattern = PATTERN (insn)) == SET
+&& REG_P (SET_SRC (pattern))
+&& REGNO (SET_SRC (pattern)) == regno
+&& REG_NREGS (SET_SRC (pattern)) == 1
+&& REG_P (SET_DEST (pattern))
+&& REGNO (SET_DEST (pattern)) != A1_REG)
+  {
+   if (insnR)
+ return false;
+   insnR = insn;
+   continue;
+  }
+else
+  return false;
+
+  if (!insnS || !insnR)
+return false;
+
+  *p_insnS = insnS, *p_insnR = insnR;
+
+  return true;
+}
+
 /* minimum frame = reg save area (4 words) plus static chain (1 word)
and the total number of words must be a multiple of 128 bits.  */
 #define MIN_FRAME_SIZE (8 * UNITS_PER_WORD)
@@ -3382,6 +3443,7 @@ xtensa_expand_prologue (void)
   df_ref ref;
   bool stack_pointer_needed = 

[FYI] [docs] note that -g opts are implicitly negatable too

2023-01-26 Thread Alexandre Oliva via Gcc-patches


Back in 2017, I made -g* options implicitly negatable, without
realizing there was documentation that required updating.  Oops.
Fixed, at last!

Regstrapped on x86_64-linux-gnu.  I'm installing this as obvious.


for gcc/ChangeLog

* doc/options.texi (option, RejectNegative): Mention that
-g-started options are also implicitly negatable.
---
 gcc/doc/options.texi |6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/doc/options.texi b/gcc/doc/options.texi
index c6e73fd1818ed..f50063c97870b 100644
--- a/gcc/doc/options.texi
+++ b/gcc/doc/options.texi
@@ -161,7 +161,7 @@ the help text to use for @option{--help} (omitted if the 
second field
 contains the @code{Undocumented} property).
 @end enumerate
 
-By default, all options beginning with ``f'', ``W'' or ``m'' are
+By default, all options beginning with ``f'', ``g'', ``W'' or ``m'' are
 implicitly assumed to take a ``no-'' form.  This form should not be
 listed separately.  If an option beginning with one of these letters
 does not have a ``no-'' form, you can use the @code{RejectNegative}
@@ -239,8 +239,8 @@ and should not be accepted by the driver.
 
 @item RejectNegative
 The option does not have a ``no-'' form.  All options beginning with
-``f'', ``W'' or ``m'' are assumed to have a ``no-'' form unless this
-property is used.
+``f'', ``g'', ``W'' or ``m'' are assumed to have a ``no-'' form unless
+this property is used.
 
 @item Negative(@var{othername})
 The option will turn off another option @var{othername}, which is


-- 
Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
   Free Software Activist   GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts.  Ask me about 


[wwwdocs] Add revised Texinfo manual CSS

2023-01-26 Thread Arsen Arsenović via Gcc-patches
---
 htdocs/texinfo-manuals.css | 129 +
 1 file changed, 129 insertions(+)
 create mode 100644 htdocs/texinfo-manuals.css

diff --git a/htdocs/texinfo-manuals.css b/htdocs/texinfo-manuals.css
new file mode 100644
index ..a7e0fc4e
--- /dev/null
+++ b/htdocs/texinfo-manuals.css
@@ -0,0 +1,129 @@
+/* Texinfo documentation stylesheet.
+   Inspired by the Gnulib manual, 2023-01-26.
+
+   Arsen Arsenović 
+*/
+@import url('gcc.css');
+
+:root {
+--contents-width-max: 60em;
+
+--backdrop: #e7e7e7;
+--contents-backdrop: #ff;
+
+/* Background for [small]example environments.  */
+--example-background: #f2f2f2;
+
+/* Color of thin lines used to "define" elements (e.g. @examples or the
+element.  */
+--defining-border: #c2c2c2;
+
+--table-color-even: var(--contents-backdrop);
+--table-color-odd: var(--backdrop);
+}
+
+html {
+margin: 0;
+padding: 0;
+background-color: var(--backdrop);
+line-height: 1.3;
+}
+
+body {
+/* Center whole body.  */
+margin: 0 auto;
+padding: 1em 3px;
+/* And limit its size to between 75% of the screen and 130em.  */
+max-width: min(max(75vw, var(--contents-width-max)), 130em);
+min-height: 100vh;
+background-color: var(--contents-backdrop);
+border: 1px solid var(--defining-border);
+}
+
+/* XXX: This should preferably not hardcode 50em, but take 66% of
+   --contents-width-max or such, but CSS env() is not standardized yet, and
+   that variable would not be in scope here.  Should this code grow large
+   enough to demand it, I'll fix this via SCSS or some similar preprocessor.
+*/
+@media only screen and (min-width: 50em) {
+body {
+/* Pad out edges slightly on big screens only.  */
+padding: 1em 3em;
+}
+
+div.example,
+div.smallexample {
+margin-left: 1.1em;
+}
+}
+
+@media (hover: none) {
+/* Presume the user will have difficulty hovering.  Make clickable anchors
+   visible.
+ */
+a.copiable-link {
+visibility: visible;
+}
+}
+
+/* Undo some previous styling from gcc.css, that is used elsewhere.  */
+table * {
+border: none;
+}
+
+/* And remove implicit table gaps.  */
+table {
+border-collapse: collapse;
+}
+
+/* Add helpful highlighting to table rows.  */
+table > tbody > tr:nth-child(odd) {
+background-color: var(--table-color-odd);
+}
+table > tbody > tr:nth-child(even) {
+background-color: var(--table-color-even);
+}
+
+/* ... except for indices.  This one is a bit hacky...  */
+div.printindex tr {
+background-color: unset !important;
+}
+
+/* Spruce up examples.  */
+div.example,
+div.smallexample {
+margin-left: 2.2em;
+border-radius: 0.3em;
+border: 1px solid var(--defining-border);
+background-color: var(--example-background);
+/* Slightly indent.  */
+padding: 0 1em;
+/* Show a scroll bar instead of breaking page layout.  */
+overflow: auto;
+}
+
+/* Highlight toplevels in tables of contents.  */
+.contents li,
+.shortcontents li {
+font-weight: bold;
+}
+.contents li li,
+.shortcontents li li {
+font-weight: normal;
+}
+
+/* Make @quotation more noticeable.  */
+blockquote {
+border-left: solid 0.5em red;
+padding-left: 1em;
+margin-left: 0;
+}
+
+/* Spacing around a heading ought to be asymmetric.  */
+h1, h2, h3, h4, h5, h6 {
+margin: 0.5em 0 0.7em 0;
+}
+
+/* Local Variables: */
+/* indent-tabs-mode: nil */
+/* End: */
-- 
2.39.1



[PATCH 3/7] **/*.texi: Reorder index entries

2023-01-26 Thread Arsen Arsenović via Gcc-patches
Much like the previous commit, this change is mostly mechanical, with a
simple script.  I have, however, gone over the patch myself also, to see
if there's anything that ought to be kept as-is.  Formatter:

  # GPL3+
  use v5.35;
  use strict;
  use warnings;

  my @lineq = ();
  my @itemq = ();
  my @indxq = ();
  my $lstin = 0;

  while (<>)
{
  push (@lineq, $_);
  if (/^\@[a-zA-Z0-9]{1,2}index\W/)
{
  $lstin = @lineq;
  push (@indxq, $_);
  next;
}
  if (/^\@itemx?\W/)
{
  $lstin = @lineq;
  push (@itemq, $_);
  next;
}
  next if $lstin && /^\s*(\@c(omment)?\W.*)?$/;

  if (@indxq and @itemq)
{
  print @indxq;
  print @itemq;
  print @lineq[$lstin..@lineq-1];
}
  else
{
  print @lineq;
}
  @lineq = ();
  @itemq = ();
  @indxq = ();
  $lstin = 0;
}

  if (@indxq and @itemq)
{
  print @indxq;
  print @itemq;
  print @lineq[$lstin..@lineq-1];
}
  else
{
  print @lineq;
}

  # Local Variables:
  # indent-tabs-mode: nil
  # End:

gcc/d/ChangeLog:

* implement-d.texi: Reorder index entries around @items.

gcc/ChangeLog:

* doc/cfg.texi: Reorder index entries around @items.
* doc/cpp.texi: Ditto.
* doc/cppenv.texi: Ditto.
* doc/cppopts.texi: Ditto.
* doc/generic.texi: Ditto.
* doc/install.texi: Ditto.
* doc/invoke.texi: Ditto.
* doc/md.texi: Ditto.
* doc/rtl.texi: Ditto.
* doc/tm.texi: Ditto.
* doc/trouble.texi: Ditto.

gcc/fortran/ChangeLog:

* invoke.texi: Reorder index entries around @items.

gcc/go/ChangeLog:

* gccgo.texi: Reorder index entries around @items.
---
 gcc/d/implement-d.texi  |  66 ++---
 gcc/doc/cfg.texi|  12 +--
 gcc/doc/cpp.texi|  12 +--
 gcc/doc/cppenv.texi |   4 +-
 gcc/doc/cppopts.texi|   8 +-
 gcc/doc/generic.texi|   2 +-
 gcc/doc/install.texi|   6 +-
 gcc/doc/invoke.texi | 138 +--
 gcc/doc/md.texi |  25 +++--
 gcc/doc/rtl.texi|   8 +-
 gcc/doc/tm.texi |   4 +-
 gcc/doc/trouble.texi|   8 +-
 gcc/fortran/invoke.texi | 204 
 gcc/go/gccgo.texi   |  34 +++
 14 files changed, 265 insertions(+), 266 deletions(-)

diff --git a/gcc/d/implement-d.texi b/gcc/d/implement-d.texi
index 6d0c1ec3661..89a17916a83 100644
--- a/gcc/d/implement-d.texi
+++ b/gcc/d/implement-d.texi
@@ -126,11 +126,11 @@ The following attributes are supported on most targets.
 
 @table @code
 
+@cindex @code{alloc_size} function attribute
+@cindex @code{alloc_size} variable attribute
 @item @@(gcc.attributes.alloc_size (@var{sizeArgIdx}))
 @itemx @@(gcc.attributes.alloc_size (@var{sizeArgIdx}, @var{numArgIdx}))
 @itemx @@(gcc.attributes.alloc_size (@var{sizeArgIdx}, @var{numArgIdx}, 
@var{zeroBasedNumbering}))
-@cindex @code{alloc_size} function attribute
-@cindex @code{alloc_size} variable attribute
 
 The @code{@@alloc_size} attribute may be applied to a function - or a function
 pointer variable -  that returns a pointer and takes at least one argument of
@@ -151,8 +151,8 @@ argument specifying the element count.
 void malloc_cb(@@alloc_size(1) void* function(size_t) ptr) @{ @}
 @end smallexample
 
-@item @@(gcc.attributes.always_inline)
 @cindex @code{always_inline} function attribute
+@item @@(gcc.attributes.always_inline)
 
 The @code{@@always_inline} attribute inlines the function independent of any
 restrictions that otherwise apply to inlining.  Failure to inline such a
@@ -162,8 +162,8 @@ function is diagnosed as an error.
 @@always_inline int func();
 @end smallexample
 
-@item @@(gcc.attributes.cold)
 @cindex @code{cold} function attribute
+@item @@(gcc.attributes.cold)
 
 The @code{@@cold} attribute on functions is used to inform the compiler that 
the
 function is unlikely to be executed.  The function is optimized for size
@@ -176,8 +176,8 @@ cold functions within code are considered to be cold too.
 @@cold int func();
 @end smallexample
 
-@item @@(gcc.attributes.flatten)
 @cindex @code{flatten} function attribute
+@item @@(gcc.attributes.flatten)
 
 The @code{@@flatten} attribute is used to inform the compiler that every call
 inside this function should be inlined, if possible.  Functions declared with
@@ -187,8 +187,8 @@ attribute @code{@@noinline} and similar are not inlined.
 @@flatten int func();
 @end smallexample
 
-@item @@(gcc.attributes.no_icf)
 @cindex @code{no_icf} function attribute
+@item @@(gcc.attributes.no_icf)
 
 The @code{@@no_icf} attribute prevents a function from being merged with
 another semantically equivalent function.
@@ -197,8 +197,8 @@ another semantically equivalent function.
 @@no_icf int func();
 @end smallexample
 
-@item @@(gcc.attributes.no_sanitize ("@var{sanitize_option}"))
 @cindex 

[PATCH 7/7] update_web_docs_git: Update CSS reference to new manual CSS

2023-01-26 Thread Arsen Arsenović via Gcc-patches
maintainer-scripts/ChangeLog:

* update_web_docs_git (CSS): Update CSS reference to point to
/texinfo-manuals.css.
---
 maintainer-scripts/update_web_docs_git | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/maintainer-scripts/update_web_docs_git 
b/maintainer-scripts/update_web_docs_git
index dee9b1d3b5e..9ded1744df4 100755
--- a/maintainer-scripts/update_web_docs_git
+++ b/maintainer-scripts/update_web_docs_git
@@ -33,7 +33,7 @@ MANUALS="cpp
   libiberty
   porting"
 
-CSS=/gcc.css
+CSS=/texinfo-manuals.css
 
 WWWBASE=${WWWBASE:-"/www/gcc/htdocs"}
 WWWBASE_PREFORMATTED=/www/gcc/htdocs-preformatted
-- 
2.39.1



[PATCH 5/7] doc: Add @defbuiltin family of helpers, set documentlanguage

2023-01-26 Thread Arsen Arsenović via Gcc-patches
This macro provides a way to more consistently define built-in functions
across GCC documentation.

gcc/ChangeLog:

* doc/gcc.texi: Set document language to en_US.
(@copying): Wrap cover tests @quotation, move description of
manual in.
* doc/include/gcc-common.texi: Add @defbuiltin(x), @enddefbuiltin
for defining built-in functions.
* doc/extend.texi: Fix copyright notice comment, switch to using
@defbuiltin for built-in function definitions.
(Object Size Checking): Add subsubsection for formatted output
function (printf et al.) checking.
---
 gcc/doc/extend.texi | 1560 +++
 gcc/doc/gcc.texi|5 +-
 gcc/doc/include/gcc-common.texi |   16 +
 3 files changed, 798 insertions(+), 783 deletions(-)

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index bd514a121ce..604ea567724 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -1,4 +1,4 @@
-c Copyright (C) 1988-2023 Free Software Foundation, Inc.
+@c Copyright (C) 1988-2023 Free Software Foundation, Inc.
 
 @c This is part of the GCC manual.
 @c For copying conditions, see the file gcc.texi.
@@ -585,14 +585,14 @@ built-in functions as:
 intptr_t @var{buf}[5];
 @end smallexample
 
-@deftypefn {Built-in Function} {int} __builtin_setjmp (intptr_t *@var{buf})
+@defbuiltin{{int} __builtin_setjmp (intptr_t *@var{buf})}
 This function saves the current stack context in @var{buf}.  
 @code{__builtin_setjmp} returns 0 when returning directly,
 and 1 when returning from @code{__builtin_longjmp} using the same
 @var{buf}.
-@end deftypefn
+@enddefbuiltin
 
-@deftypefn {Built-in Function} {void} __builtin_longjmp (intptr_t *@var{buf}, 
int @var{val})
+@defbuiltin{{void} __builtin_longjmp (intptr_t *@var{buf}, int @var{val})}
 This function restores the stack context in @var{buf}, 
 saved by a previous call to @code{__builtin_setjmp}.  After
 @code{__builtin_longjmp} is finished, the program resumes execution as
@@ -604,7 +604,7 @@ mechanism to restore the stack context, it cannot be called
 from the same function calling @code{__builtin_setjmp} to
 initialize @var{buf}.  It can only be called from a function called
 (directly or indirectly) from the function calling @code{__builtin_setjmp}.
-@end deftypefn
+@enddefbuiltin
 
 @node Constructing Calls
 @section Constructing Function Calls
@@ -626,7 +626,7 @@ sophisticated features or other extensions of the language. 
 It
 is, therefore, not recommended to use them outside very simple
 functions acting as mere forwarders for their arguments.
 
-@deftypefn {Built-in Function} {void *} __builtin_apply_args ()
+@defbuiltin{{void *} __builtin_apply_args ()}
 This built-in function returns a pointer to data
 describing how to perform a call with the same arguments as are passed
 to the current function.
@@ -635,9 +635,9 @@ The function saves the arg pointer register, structure 
value address,
 and all registers that might be used to pass arguments to a function
 into a block of memory allocated on the stack.  Then it returns the
 address of that block.
-@end deftypefn
+@enddefbuiltin
 
-@deftypefn {Built-in Function} {void *} __builtin_apply (void 
(*@var{function})(), void *@var{arguments}, size_t @var{size})
+@defbuiltin{{void *} __builtin_apply (void (*@var{function})(), void 
*@var{arguments}, size_t @var{size})}
 This built-in function invokes @var{function}
 with a copy of the parameters described by @var{arguments}
 and @var{size}.
@@ -654,15 +654,15 @@ It is not always simple to compute the proper value for 
@var{size}.  The
 value is used by @code{__builtin_apply} to compute the amount of data
 that should be pushed on the stack and copied from the incoming argument
 area.
-@end deftypefn
+@enddefbuiltin
 
-@deftypefn {Built-in Function} {void} __builtin_return (void *@var{result})
+@defbuiltin{{void} __builtin_return (void *@var{result})}
 This built-in function returns the value described by @var{result} from
 the containing function.  You should specify, for @var{result}, a value
 returned by @code{__builtin_apply}.
-@end deftypefn
+@enddefbuiltin
 
-@deftypefn {Built-in Function} {} __builtin_va_arg_pack ()
+@defbuiltin{{} __builtin_va_arg_pack ()}
 This built-in function represents all anonymous arguments of an inline
 function.  It can be used only in inline functions that are always
 inlined, never compiled as a separate function, such as those using
@@ -686,9 +686,9 @@ myprintf (FILE *f, const char *format, ...)
   return r + s;
 @}
 @end smallexample
-@end deftypefn
+@enddefbuiltin
 
-@deftypefn {Built-in Function} {size_t} __builtin_va_arg_pack_len ()
+@defbuiltin{{size_t} __builtin_va_arg_pack_len ()}
 This built-in function returns the number of anonymous arguments of
 an inline function.  It can be used only in inline functions that
 are always inlined, never compiled as a separate function, such
@@ -721,7 +721,7 @@ myopen (const char *path, int oflag, ...)
 @}
 

[PATCH+wwwdocs 0/8] A small Texinfo refinement

2023-01-26 Thread Arsen Arsenović via Gcc-patches
Evening,

This patchset includes the requisite changes to gcc-wwwdocs and gcc in
order to produce hopefully more accessible and readable documentation.
For optimal results, please install Texinfo from master (there's
currently no release that includes the few patches I made, the changes
in which this patchset exploit).

This patchset consists of changes that are mostly mechanical, and came
down to reordering @item and @XYZindex commands appropriately.  Attached
to a few commits are pieces of automation that helped the process.

Note that some manuals were not consistent with the rest, specifically
the Ada ones, and so the methods I used weren't applicable to them
without producing massive amounts of unrelated changes.  For the same
reasons as the following paragraph, I have decided to defer those.

I also started doing less mechanical changes, like the @defbuiltin
stuff, but after going over extend.texi I've noticed many sections
that'd need many kinds of slightly different rework, and likely would
require inventing some new convention (for instance, the
instruction-generating built-ins come to mind, there's currently
precedent of documenting them as @example blocks that list them, but
this skips indexing, breaks the flow on text on narrow screens, and is
generally inconsistent with other builtins).  I've decided to halt this
effort for the current release cycle, based on how much time I'll have
until the release.

I am curious about why texinfo.tex was left out of date for so long.  If
there's some reason, please let me know, and I'll see what I can do to
remedy the problem.  From a quick look I presumed there's none and
updated to the latest version.  In the process, I also got rid of the
@gol macro, that was used for conditionally terminating lines, as this
appears to be working around a now-nonexistent bug (and it caused a
build issue on the new texinfo version).

Note, however, that I did not thoroughly test update_web_docs_git
script, as it seems to make a lot of assumptions about the environment
it's invoked in, and so, I couldn't replicate it.  Instead, I tested the
following:

  #!/bin/sh
  set -xe
  MANUALS="cpp
cppinternals
fastjar
gcc
gccgo
gccint
gcj
gdc
gfortran
gfc-internals
gnat_ugn
gnat-style
gnat_rm
libgomp
libitm
libquadmath
libiberty
porting"
  
  for file in $MANUALS; do
  rm -rf "${file}.html"
  mkdir "${file}.html"
  texi="$(find /home/arsen/gcc/gcc -name "$file.texi" | head -n 1)"
  [ "$texi" ] || continue
  includes="-I /home/arsen/gcc/gcc/gcc/doc/include"
  includes="$includes -I /home/arsen/gcc/outstuff/include"
  if [ "$file" = gnat_ugn ]; then
  includes="$includes -I /home/arsen/gcc/gcc/gcc/ada"
  includes="$includes -I /home/arsen/gcc/gcc/gcc/ada/doc/gnat_ugn"
  fi
  makeinfo --html -o "${file}.html" $includes \
   --css-ref="/~arsen/final/texinfo-manuals.css" \
   -c TOP_NODE_UP_URL="/~arsen/final/" \
   "$texi"
  makeinfo --pdf -o "${file}.pdf" $includes "$texi"
  makeinfo --dvi -o "${file}.dvi" $includes "$texi"
  makeinfo --info -o "${file}.info" $includes "$texi"
  done

This appeared to produce decent results when I was searching for various
parts I touched.

The output of the script above is visible online:
https://www.aarsen.me/~arsen/final/

This was built against the a8306872ffc91e8d9572a3feedaa125be3c5c1d0
commit in Texinfo.

Thanks in advance, have a lovely night.

=== gcc.git ===

Arsen Arsenović (7):
  docs: Create Indices appendix
  docs: Reorder @opindex to be before corresponding options
  **/*.texi: Reorder index entries
  docs: Mechanically reorder item/index combos in extend.texi
  doc: Add @defbuiltin family of helpers, set documentlanguage
  Update texinfo.tex, remove the @gol macro/alias
  update_web_docs_git: Update CSS reference to new manual CSS

 gcc/d/gdc.texi |  144 +-
 gcc/d/implement-d.texi |   66 +-
 gcc/doc/cfg.texi   |   12 +-
 gcc/doc/cpp.texi   |   12 +-
 gcc/doc/cppdiropts.texi|   24 +-
 gcc/doc/cppenv.texi|4 +-
 gcc/doc/cppopts.texi   |   94 +-
 gcc/doc/cppwarnopts.texi   |   14 +-
 gcc/doc/extend.texi| 2564 
 gcc/doc/gcc.texi   |   36 +-
 gcc/doc/generic.texi   |2 +-
 gcc/doc/implement-c.texi   |2 +-
 gcc/doc/include/gcc-common.texi|   26 +-
 gcc/doc/include/texinfo.tex| 7599 +
 gcc/doc/install.texi   |6 +-
 gcc/doc/invoke.texi| 8420 
 gcc/doc/lto.texi   |8 +-
 gcc/doc/md.texi|   25 +-
 gcc/doc/rtl.texi   |8 +-
 gcc/doc/sourcebuild.texi   |4 -
 

[PATCH 1/7] docs: Create Indices appendix

2023-01-26 Thread Arsen Arsenović via Gcc-patches
gcc/ChangeLog:

* doc/gcc.texi: Add the Indices appendix, to make texinfo
generate nice indices overview page.
(@copying): Move "This file documents the use of the GNU
compilers" into @copying.  Add quotations around copying.
---
 gcc/doc/gcc.texi | 33 ++---
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/gcc/doc/gcc.texi b/gcc/doc/gcc.texi
index 7019365429d..bc7cc6e6743 100644
--- a/gcc/doc/gcc.texi
+++ b/gcc/doc/gcc.texi
@@ -40,6 +40,9 @@
 @c %**end of header
 
 @copying
+This file documents the use of the GNU compilers.
+
+@quotation
 Copyright @copyright{} 1988-2023 Free Software Foundation, Inc.
 
 Permission is granted to copy, distribute and/or modify this document
@@ -59,6 +62,7 @@ Texts being (a) (see below), and with the Back-Cover Texts 
being (b)
  You have freedom to copy and modify this GNU Manual, like GNU
  software.  Copies published by the Free Software Foundation raise
  funds for GNU development.
+@end quotation
 @end copying
 @ifnottex
 @dircategory Software development
@@ -71,7 +75,6 @@ Texts being (a) (see below), and with the Back-Cover Texts 
being (b)
 * lto-dump: (gcc) lto-dump.@command{lto-dump}---Tool for
 dumping LTO object files.
 @end direntry
-This file documents the use of the GNU compilers.
 @sp 1
 @insertcopying
 @sp 1
@@ -159,8 +162,7 @@ object files.
 * GNU Free Documentation License:: How you can copy and share this manual.
 * Contributors::People who have contributed to GCC.
 
-* Option Index::Index to command line options.
-* Keyword Index::   Index of concepts and symbol names.
+* Indices:: List of indices in this manual.
 @end menu
 
 @include frontends.texi
@@ -196,19 +198,28 @@ object files.
 @c Indexes
 @c -
 
+@node Indices
+@appendix Indices
+
+@menu
+* Option Index::Index to command line options.
+* Concept and Symbol Index::Index of concepts and symbols names.
+@end menu
+
 @node Option Index
-@unnumbered Option Index
+@appendixsec Option Index
 
-GCC's command line options are indexed here without any initial @samp{-}
-or @samp{--}.  Where an option has both positive and negative forms
-(such as @option{-f@var{option}} and @option{-fno-@var{option}}),
-relevant entries in the manual are indexed under the most appropriate
-form; it may sometimes be useful to look up both forms.
+GCC's command line options are indexed here without any initial
+@samp{-} or @samp{--}.  Where an option has both positive and negative
+forms (such as @option{-f@var{option}} and
+@option{-fno-@var{option}}), relevant entries in the manual are
+indexed under the most appropriate form; it may sometimes be useful to
+look up both forms.
 
 @printindex op
 
-@node Keyword Index
-@unnumbered Keyword Index
+@node Concept and Symbol Index
+@appendixsec Concept and Symbol Index
 
 @printindex cp
 
-- 
2.39.1



[pushed] wwwdocs: readings: Update Modula 3 link

2023-01-26 Thread Gerald Pfeifer
Pushed.
Gerald

---
 htdocs/readings.html | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/htdocs/readings.html b/htdocs/readings.html
index 295cc51f..3f41ef2a 100644
--- a/htdocs/readings.html
+++ b/htdocs/readings.html
@@ -567,7 +567,7 @@ names.
 Modula 3 information
 
 
-  http://www.modula3.org;>http://www.modula3.org
+  https://www.modula3.org;>https://www.modula3.org
 
 
 
-- 
2.39.1


[pushed] wwwdocs: gcc-3.4: Update a link to use https

2023-01-26 Thread Gerald Pfeifer
Pushed.

Gerald
---
 htdocs/gcc-3.4/changes.html | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/htdocs/gcc-3.4/changes.html b/htdocs/gcc-3.4/changes.html
index d9985673..76b4ce87 100644
--- a/htdocs/gcc-3.4/changes.html
+++ b/htdocs/gcc-3.4/changes.html
@@ -521,7 +521,7 @@ and not your code, that is broken.
 Previous versions of G++ used to be less strict about this and
 allowed friend declarations for private class members,
 for example.  See the ISO C++ Standard Committee's http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#209;>defect
+
href="https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#209;>defect
 report #209 for details.
 
 Declaration of member functions of class templates as friends are
-- 
2.39.1


[pushed] wwwdocs: codingconventions: Update a link to Github docs

2023-01-26 Thread Gerald Pfeifer
Pushed.

Gerald
---
 htdocs/codingconventions.html | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/htdocs/codingconventions.html b/htdocs/codingconventions.html
index af08f11a..24365815 100644
--- a/htdocs/codingconventions.html
+++ b/htdocs/codingconventions.html
@@ -147,7 +147,7 @@ a large batch of changes.
 changelog_file_comment - line that follows a 
changelog_file with description of changes in the file;
 must start with \t
 co_authored_by - https://docs.github.com/en/github/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors;>GitHub
 format
+
href="https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors;>GitHub
 format
 for a Co-Authored-By
 
 
-- 
2.39.1


[pushed] wwwdocs: codingconventions: Update upstream instructions for libstdc++

2023-01-26 Thread Gerald Pfeifer
Jonathan (or some other libstdc++ developer), would you mind having a 
look at that section of https://gcc.gnu.org/codingconventions.html to 
see whether we should do further changes?

Thanks,
Gerald


Since ca314fbd2509439f708c56f34d0a85449a43fe73 in the gcc tree
libstc++ no longer ships copies of files from the C++ committee
homepage. Simplify instructions how to sync from upstream accordingly.
---
 htdocs/codingconventions.html | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/htdocs/codingconventions.html b/htdocs/codingconventions.html
index 5519d3f9..af08f11a 100644
--- a/htdocs/codingconventions.html
+++ b/htdocs/codingconventions.html
@@ -756,8 +756,7 @@ first. 
 
 libstdc++-v3:  In docs/doxygen, comments in *.cfg.in are
 partially autogenerated from https://www.doxygen.nl;>the
-Doxygen tool.  In docs/html, the ext/lwg-* files are copied from http://www.open-std.org/jtc1/sc22/wg21/;>the C++ committee homepage,
+Doxygen tool.  In docs/html, 
 the 27_io/binary_iostream_* files are copies of Usenet postings, and most
 of the files in 17_intro are either copied from elsewhere in GCC or the
 FSF website, or are autogenerated.  These files should not be changed
-- 
2.39.1


Re: [committed] frange: Fix up foperator_{,not_}equal::fold_range for signed zeros [PR108540]

2023-01-26 Thread Gerald Pfeifer
On Thu, 26 Jan 2023, Jakub Jelinek via Gcc-patches wrote:
> committed to trunk.

Picking a random commit: Should we consistently start using "pushed" 
instead of "committed"?

In CVS and SVN those two were the same. With GIT it's really a push (to 
trunk) we are interested in, not a commit to a local clone, isn't it?

Gerald (who just updated his scripts this week :-)


[pushed] wwwdocs: git: Tweak link to TR29124 C++ reference

2023-01-26 Thread Gerald Pfeifer
Pushed.

Gerald
---
 htdocs/git.html | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/htdocs/git.html b/htdocs/git.html
index fc30c5ab..f71b451f 100644
--- a/htdocs/git.html
+++ b/htdocs/git.html
@@ -606,7 +606,7 @@ in Git (except for ones under 
refs/vendors/).
   tr29124
   This branch is for development of TR29124 Special math Functions,
 for the C++ runtime library
-See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3060.pdf;>
+See https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3060.pdf;>
 .  It is maintained by Ed Smith-Rowland
 mailto:3dw...@verizon.net;>3dw...@verizon.net.
 
-- 
2.39.1


[PATCH] c++: fix ICE with -Wduplicated-cond [PR107593]

2023-01-26 Thread Marek Polacek via Gcc-patches
Here we crash because a CAST_EXPR, representing T(), doesn't have
its operand, and operand_equal_p's STRIP_ANY_LOCATION_WRAPPER doesn't
expect that.  (o_e_p is called from warn_duplicated_cond_add_or_warn.)

In the past we've adjusted o_e_p to better cope with template codes,
but in this case I think we just want to avoid attempting to warn
about inst-dependent expressions; I don't think I've ever envisioned
-Wduplicated-cond to warn about them.

The ICE started with r12-6022, two-stage name lookup for overloaded
operators, which gave dependent operators a TREE_TYPE (in particular,
DEPENDENT_OPERATOR_TYPE), so we no longer bail out here in o_e_p:

  /* Similar, if either does not have a type (like a template id),
 they aren't equal.  */
  if (!TREE_TYPE (arg0) || !TREE_TYPE (arg1))
return false;

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

PR c++/107593

gcc/cp/ChangeLog:

* parser.cc (cp_parser_selection_statement): Don't do
-Wduplicated-cond when the condition is dependent.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wduplicated-cond3.C: New test.
---
 gcc/cp/parser.cc  |  3 +-
 gcc/testsuite/g++.dg/warn/Wduplicated-cond3.C | 38 +++
 2 files changed, 40 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/warn/Wduplicated-cond3.C

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 4cdc1cd472f..3df85d49e16 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -13209,7 +13209,8 @@ cp_parser_selection_statement (cp_parser* parser, bool 
*if_p,
/* Add the condition.  */
condition = finish_if_stmt_cond (condition, statement);
 
-   if (warn_duplicated_cond)
+   if (warn_duplicated_cond
+   && !instantiation_dependent_expression_p (condition))
  warn_duplicated_cond_add_or_warn (token->location, condition,
);
 
diff --git a/gcc/testsuite/g++.dg/warn/Wduplicated-cond3.C 
b/gcc/testsuite/g++.dg/warn/Wduplicated-cond3.C
new file mode 100644
index 000..3da054e5485
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wduplicated-cond3.C
@@ -0,0 +1,38 @@
+// PR c++/107593
+// { dg-do compile }
+// { dg-options "-Wduplicated-cond" }
+
+template 
+void
+foo ()
+{
+  if (T() && T() && int())
+;
+  else if (T() && T() && int())
+;
+}
+
+template 
+void bar(T a)
+{
+  if (a)
+;
+  else if (a)
+;
+}
+
+template 
+void baz(int a)
+{
+  if (a)
+;
+  else if (a) // { dg-warning "duplicated" }
+;
+}
+void
+f ()
+{
+  foo();
+  bar(1);
+  baz(1);
+}

base-commit: 94673a121cfc7f9d51c9d05e31795477f4dc8dc7
-- 
2.39.1



[PATCH] Modula-2: Add claimed command line options to lang.opt [PR108555].

2023-01-26 Thread Iain Sandoe via Gcc-patches
 This has been retested on x86_64, powerpc64 linux-gnu (with 32b multilibs)
 on i686, powerpc darwin  (with 64b multilibs), x86_64 darwin with and
 without 32b multilibs,
 OK for trunk?
 thanks
 Iain
 
 --- 8< ---

This is a partial reversion of the changes in r13-5373-g80cf2c5e8f496b.

As observed in the PR, handling the C and Driver options in the Modula-2
lang-specific code could be difficult to emulate; This reverts to adding
the required options to the language-specific .opt file.

Signed-off-by: Iain Sandoe 

PR modula2/108555
PR modula2/108182
PR modula2/102343

gcc/m2/ChangeLog:

* gm2-lang.cc (gm2_langhook_option_lang_mask): Do not claim CL_C
or CL_DRIVER.
(gm2_langhook_init_options): Handle options that we want to pass
to the preprocessor.
* lang-specs.h: Pass -B and -save-temps to regular compile lines.
* lang.opt: Add C and Driver options that Modula-2 intercepts for
internal use. Reorder options into two sections and to collate.
---
 gcc/m2/gm2-lang.cc  |  53 ++---
 gcc/m2/lang-specs.h |   5 +-
 gcc/m2/lang.opt | 185 +++-
 3 files changed, 177 insertions(+), 66 deletions(-)

diff --git a/gcc/m2/gm2-lang.cc b/gcc/m2/gm2-lang.cc
index a30e626620c..999c57c1cfa 100644
--- a/gcc/m2/gm2-lang.cc
+++ b/gcc/m2/gm2-lang.cc
@@ -137,9 +137,7 @@ gm2_langhook_init (void)
 static unsigned int
 gm2_langhook_option_lang_mask (void)
 {
-  /* We need to process some driver options and pass through some C
- ones to build our preprocessing lines.  */
-  return CL_ModulaX2 | CL_C | CL_DRIVER;
+  return CL_ModulaX2;
 }
 
 /* Initialize the options structure.  */
@@ -262,21 +260,22 @@ gm2_langhook_init_options (unsigned int 
decoded_options_count,
 For now skip all plugins to avoid fails with the m2 one.  */
  break;
 
-   /* Preprocessor arguments with a following filename.  */
+   /* Preprocessor arguments with a following filename, we add these
+  back to the main file preprocess line, but not to dependents
+  TODO Handle MF.  */
case OPT_MD:
+ M2Options_SetMD (arg);
+ break;
case OPT_MMD:
- /* Save the filename associated with the MD/MMD which will also
-mark the option as used.  FIXME: maybe we should diagnose a
-missing filename here, rather than assert.  */
- gcc_checking_assert (i+1 < decoded_options_count);
- gcc_checking_assert (decoded_options[i+1].opt_index
-  == OPT_SPECIAL_input_file);
- /* Pick up the following filename.  */
- arg = decoded_options[i+1].arg;
- if (code == OPT_MD)
-   M2Options_SetMD (arg);
- else
-   M2Options_SetMMD (arg);
+ M2Options_SetMMD (arg);
+ break;
+
+   /* Modula 2 claimed options we pass to the preprocessor.  */
+   case OPT_ansi:
+   case OPT_traditional_cpp:
+ if (building_cpp_command)
+   M2Options_CppArg (opt, arg, (option->flags & CL_JOINED)
+ && !(option->flags & CL_SEPARATE));
  break;
 
/* Options we act on and also pass to the preprocessor.  */
@@ -286,6 +285,12 @@ gm2_langhook_init_options (unsigned int 
decoded_options_count,
M2Options_CppArg (opt, arg, (option->flags & CL_JOINED)
  && !(option->flags & CL_SEPARATE));
  break;
+   case OPT_quiet:
+ M2Options_SetQuiet (value);
+ if (building_cpp_command)
+   M2Options_CppArg (opt, arg, (option->flags & CL_JOINED)
+ && !(option->flags & CL_SEPARATE));
+ break;
case OPT_v:
  M2Options_SetVerbose (value);
  /* FALLTHROUGH */
@@ -533,9 +538,6 @@ gm2_langhook_handle_option (
   /* Otherwise, ignored, at least for now. */
   return 1;
   break;
-case OPT_quiet:
-  M2Options_SetQuiet (value);
-  return 1;
 case OPT_fm2_whole_program:
   M2Options_SetWholeProgram (value);
   return 1;
@@ -557,20 +559,19 @@ gm2_langhook_handle_option (
 }
   else
 return 0;
-case OPT_o:
-  /* Options we ignore, always.  */
-  return 1;
 default:
   if (insideCppArgs)
-   /* Already handled.  */
+   /* Handled in gm2_langhook_init_options ().  */
return 1;
   else if (option->flags & CL_DRIVER)
-   /* Ignore driver options we do not specifically use.  */
+   /* Driver options (unless specifically claimed above) should be handled
+  in gm2_langhook_init_options ().  */
return 1;
   else if (option->flags & CL_C)
-   /* Ignore C options we do not specifically use.  */
+   /* C options (unless specifically claimed above) should be handled
+  in gm2_langhook_init_options ().  */
return 1;
-  return 0;
+  break;
 }
   return 0;
 }
diff 

[committed] RISC-V: Use get_typenode_from_name to get fixed-width integer type nodes

2023-01-26 Thread Kito Cheng
[u]int32_t are using different type between glibc and newlib, so getting
those node by int or long type isn't portable way, I also update all
other fixed-width integer types to prevent this happened again in future :P

gcc/ChangeLog:

* config/riscv/riscv-vector-builtins.cc (register_builtin_types):
Use get_typenode_from_name to get fixed-width integer type
nodes.
* config/riscv/riscv-vector-builtins.def: Update define with
fixed-width integer type nodes.
---
 gcc/config/riscv/riscv-vector-builtins.cc  | 17 ++---
 gcc/config/riscv/riscv-vector-builtins.def | 78 +++---
 2 files changed, 48 insertions(+), 47 deletions(-)

diff --git a/gcc/config/riscv/riscv-vector-builtins.cc 
b/gcc/config/riscv/riscv-vector-builtins.cc
index 4c5ecce6219..e959ba393b4 100644
--- a/gcc/config/riscv/riscv-vector-builtins.cc
+++ b/gcc/config/riscv/riscv-vector-builtins.cc
@@ -346,14 +346,15 @@ register_builtin_type (vector_type_index type, tree 
eltype, machine_mode mode)
 static void
 register_builtin_types ()
 {
-  /* int32_t/uint32_t defined as `long`/`unsigned long` in RV32,
- but intSI_type_node/unsigned_intSI_type_node is
- `int` and `unsigned int`, so use long_integer_type_node and
- long_unsigned_type_node here for type consistent.  */
-  tree int32_type_node
-= TARGET_64BIT ? intSI_type_node : long_integer_type_node;
-  tree unsigned_int32_type_node
-= TARGET_64BIT ? unsigned_intSI_type_node : long_unsigned_type_node;
+  /* Get type node from get_typenode_from_name to prevent we have different 
type
+ node define in different target libraries, e.g. int32_t defined as
+ `long` in RV32/newlib-stdint, but `int` for RV32/glibc-stdint.h.
+ NOTE: uint[16|32|64]_type_node already defined in tree.h.  */
+  tree int8_type_node = get_typenode_from_name (INT8_TYPE);
+  tree uint8_type_node = get_typenode_from_name (UINT8_TYPE);
+  tree int16_type_node = get_typenode_from_name (INT16_TYPE);
+  tree int32_type_node = get_typenode_from_name (INT32_TYPE);
+  tree int64_type_node = get_typenode_from_name (INT64_TYPE);
 
   machine_mode mode;
 #define DEF_RVV_TYPE(NAME, NCHARS, ABI_NAME, SCALAR_TYPE, VECTOR_MODE, 
\
diff --git a/gcc/config/riscv/riscv-vector-builtins.def 
b/gcc/config/riscv/riscv-vector-builtins.def
index 12cb4400e00..89bd5f13995 100644
--- a/gcc/config/riscv/riscv-vector-builtins.def
+++ b/gcc/config/riscv/riscv-vector-builtins.def
@@ -89,147 +89,147 @@ DEF_RVV_TYPE (vbool1_t, 13, __rvv_bool1_t, boolean, 
VNx64BI, VNx32BI, _b1, , , v
 
 /* LMUL = 1/8:
Only enble when TARGET_MIN_VLEN > 32 and machine mode = VNx1QImode.  */
-DEF_RVV_TYPE (vint8mf8_t, 15, __rvv_int8mf8_t, intQI, VNx1QI, VOID, _i8mf8, 
_i8,
+DEF_RVV_TYPE (vint8mf8_t, 15, __rvv_int8mf8_t, int8, VNx1QI, VOID, _i8mf8, _i8,
  _e8mf8, vbool64_t)
-DEF_RVV_TYPE (vuint8mf8_t, 16, __rvv_uint8mf8_t, unsigned_intQI, VNx1QI, VOID,
+DEF_RVV_TYPE (vuint8mf8_t, 16, __rvv_uint8mf8_t, uint8, VNx1QI, VOID,
  _u8mf8, _u8, _e8mf8, vbool64_t)
 /* LMUL = 1/4:
Machine mode = VNx2QImode when TARGET_MIN_VLEN > 32.
Machine mode = VNx1QImode when TARGET_MIN_VLEN = 32.  */
-DEF_RVV_TYPE (vint8mf4_t, 15, __rvv_int8mf4_t, intQI, VNx2QI, VNx1QI, _i8mf4,
+DEF_RVV_TYPE (vint8mf4_t, 15, __rvv_int8mf4_t, int8, VNx2QI, VNx1QI, _i8mf4,
  _i8, _e8mf4, vbool32_t)
-DEF_RVV_TYPE (vuint8mf4_t, 16, __rvv_uint8mf4_t, unsigned_intQI, VNx2QI, 
VNx1QI,
+DEF_RVV_TYPE (vuint8mf4_t, 16, __rvv_uint8mf4_t, uint8, VNx2QI, VNx1QI,
  _u8mf4, _u8, _e8mf4, vbool32_t)
 /* LMUL = 1/2:
Machine mode = VNx4QImode when TARGET_MIN_VLEN > 32.
Machine mode = VNx2QImode when TARGET_MIN_VLEN = 32.  */
-DEF_RVV_TYPE (vint8mf2_t, 15, __rvv_int8mf2_t, intQI, VNx4QI, VNx2QI, _i8mf2,
+DEF_RVV_TYPE (vint8mf2_t, 15, __rvv_int8mf2_t, int8, VNx4QI, VNx2QI, _i8mf2,
  _i8, _e8mf2, vbool16_t)
-DEF_RVV_TYPE (vuint8mf2_t, 16, __rvv_uint8mf2_t, unsigned_intQI, VNx4QI, 
VNx2QI,
+DEF_RVV_TYPE (vuint8mf2_t, 16, __rvv_uint8mf2_t, uint8, VNx4QI, VNx2QI,
  _u8mf2, _u8, _e8mf2, vbool16_t)
 /* LMUL = 1:
Machine mode = VNx8QImode when TARGET_MIN_VLEN > 32.
Machine mode = VNx4QImode when TARGET_MIN_VLEN = 32.  */
-DEF_RVV_TYPE (vint8m1_t, 14, __rvv_int8m1_t, intQI, VNx8QI, VNx4QI, _i8m1, _i8,
+DEF_RVV_TYPE (vint8m1_t, 14, __rvv_int8m1_t, int8, VNx8QI, VNx4QI, _i8m1, _i8,
  _e8m1, vbool8_t)
-DEF_RVV_TYPE (vuint8m1_t, 15, __rvv_uint8m1_t, unsigned_intQI, VNx8QI, VNx4QI,
+DEF_RVV_TYPE (vuint8m1_t, 15, __rvv_uint8m1_t, uint8, VNx8QI, VNx4QI,
  _u8m1, _u8, _e8m1, vbool8_t)
 /* LMUL = 2:
Machine mode = VNx16QImode when TARGET_MIN_VLEN > 32.
Machine mode = VNx8QImode when TARGET_MIN_VLEN = 32.  */
-DEF_RVV_TYPE (vint8m2_t, 14, __rvv_int8m2_t, intQI, VNx16QI, VNx8QI, _i8m2, 
_i8,
+DEF_RVV_TYPE (vint8m2_t, 14, __rvv_int8m2_t, int8, VNx16QI, VNx8QI, _i8m2, _i8,
  _e8m2, vbool4_t)
-DEF_RVV_TYPE (vuint8m2_t, 15, 

Re: [PATCH] RISC-V: Add the rest testcases of AVL=REG support

2023-01-26 Thread Kito Cheng via Gcc-patches
committed, thanks.

On Tue, Jan 10, 2023 at 7:41 AM  wrote:

> From: Ju-Zhe Zhong 
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/riscv/rvv/vsetvl/avl_single-1.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-10.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-11.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-12.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-13.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-14.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-15.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-16.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-17.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-18.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-19.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-7.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-70.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-71.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-72.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-8.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-9.c: New test.
>
> ---
>  .../riscv/rvv/vsetvl/avl_single-1.c   | 17 ++
>  .../riscv/rvv/vsetvl/avl_single-10.c  | 21 +++
>  .../riscv/rvv/vsetvl/avl_single-11.c  | 21 +++
>  .../riscv/rvv/vsetvl/avl_single-12.c  | 19 +++
>  .../riscv/rvv/vsetvl/avl_single-13.c  | 28 ++
>  .../riscv/rvv/vsetvl/avl_single-14.c  | 27 +
>  .../riscv/rvv/vsetvl/avl_single-15.c  | 27 +
>  .../riscv/rvv/vsetvl/avl_single-16.c  | 32 +++
>  .../riscv/rvv/vsetvl/avl_single-17.c  | 29 ++
>  .../riscv/rvv/vsetvl/avl_single-18.c  | 29 ++
>  .../riscv/rvv/vsetvl/avl_single-19.c  | 40 +
>  .../riscv/rvv/vsetvl/avl_single-7.c   | 17 ++
>  .../riscv/rvv/vsetvl/avl_single-70.c  | 41 ++
>  .../riscv/rvv/vsetvl/avl_single-71.c  | 54 ++
>  .../riscv/rvv/vsetvl/avl_single-72.c  | 46 +++
>  .../riscv/rvv/vsetvl/avl_single-8.c   | 18 ++
>  .../riscv/rvv/vsetvl/avl_single-9.c   | 56 +++
>  17 files changed, 522 insertions(+)
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-1.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-10.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-11.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-12.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-13.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-14.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-15.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-16.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-17.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-18.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-19.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-7.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-70.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-71.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-72.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-8.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-9.c
>
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-1.c
> b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-1.c
> new file mode 100644
> index 000..84225dbe7d2
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-1.c
> @@ -0,0 +1,17 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-schedule-insns
> -fno-schedule-insns2" } */
> +
> +#include "riscv_vector.h"
> +
> +void f (void * restrict in, void * restrict out, int n, int vl)
> +{
> +  for (int i = 0; i < n; i++)
> +{
> +  vint8mf8_t v = __riscv_vle8_v_i8mf8 (in + i, vl);
> +  __riscv_vse8_v_i8mf8 (out + i, v, vl);
> +}
> +}
> +
> +/* { dg-final { scan-assembler-times
> {\.L[0-9]+\:\s+vle8\.v\s+v[0-9]+,\s*0\s*\([a-x0-9]+\)} 1 { target { no-opts
> "-O0" no-opts "-Os" no-opts "-g" no-opts "-funroll-loops" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+zero,\s*[a-x0-9]+,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target {
> no-opts "-O0" no-opts "-g" no-opts "-funroll-loops" } } } } */
> +/* { dg-final { scan-assembler-times {vsetvli} 1 { target { no-opts "-O0"
> no-opts "-g" no-opts "-funroll-loops" } } } } */
> diff --git 

Re: [PATCH] RISC-V: Add testcases for AVL=REG support

2023-01-26 Thread Kito Cheng via Gcc-patches
committed, thanks.

On Tue, Jan 10, 2023 at 7:39 AM  wrote:

> From: Ju-Zhe Zhong 
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/riscv/rvv/vsetvl/avl_single-2.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-20.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-21.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-22.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-23.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-24.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-25.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-26.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-27.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-28.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-29.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-3.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-30.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-31.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-32.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-33.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-34.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-35.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-36.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-37.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-38.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-39.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-4.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-40.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-41.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-42.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-43.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-44.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-45.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-46.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-47.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-48.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-49.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-5.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-50.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-51.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-52.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-53.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-54.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-55.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-56.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-57.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-58.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-59.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-6.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-60.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-61.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-62.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-63.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-64.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-65.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-66.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-67.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-68.c: New test.
> * gcc.target/riscv/rvv/vsetvl/avl_single-69.c: New test.
>
> ---
>  .../riscv/rvv/vsetvl/avl_single-2.c   | 18 ++
>  .../riscv/rvv/vsetvl/avl_single-20.c  | 40 +
>  .../riscv/rvv/vsetvl/avl_single-21.c  | 32 +++
>  .../riscv/rvv/vsetvl/avl_single-22.c  | 42 ++
>  .../riscv/rvv/vsetvl/avl_single-23.c  | 34 +++
>  .../riscv/rvv/vsetvl/avl_single-24.c  | 36 
>  .../riscv/rvv/vsetvl/avl_single-25.c  | 38 +
>  .../riscv/rvv/vsetvl/avl_single-26.c  | 35 
>  .../riscv/rvv/vsetvl/avl_single-27.c  | 36 
>  .../riscv/rvv/vsetvl/avl_single-28.c  | 30 ++
>  .../riscv/rvv/vsetvl/avl_single-29.c  | 31 ++
>  .../riscv/rvv/vsetvl/avl_single-3.c   | 19 +++
>  .../riscv/rvv/vsetvl/avl_single-30.c  | 29 ++
>  .../riscv/rvv/vsetvl/avl_single-31.c  | 27 +
>  .../riscv/rvv/vsetvl/avl_single-32.c  | 27 +
>  .../riscv/rvv/vsetvl/avl_single-33.c  | 29 ++
>  .../riscv/rvv/vsetvl/avl_single-34.c  | 28 +
>  .../riscv/rvv/vsetvl/avl_single-35.c  | 27 +
>  

Re: [PATCH] RISC-V: Adjust testcases for AVL=REG support

2023-01-26 Thread Kito Cheng via Gcc-patches
committed, thanks.

On Tue, Jan 10, 2023 at 7:36 AM  wrote:

> From: Ju-Zhe Zhong 
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/riscv/rvv/vsetvl/imm_bb_prop-3.c: Adjust testcase.
> * gcc.target/riscv/rvv/vsetvl/imm_bb_prop-4.c: Ditto.
> * gcc.target/riscv/rvv/vsetvl/imm_conflict-4.c: Ditto.
> * gcc.target/riscv/rvv/vsetvl/imm_conflict-5.c: Ditto.
> * gcc.target/riscv/rvv/vsetvl/imm_loop_invariant-17.c: Ditto.
> * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-27.c: Ditto.
> * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-28.c: Ditto.
> * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-45.c: Ditto.
> * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-25.c: Ditto.
> * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-26.c: Ditto.
> * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-27.c: Ditto.
> * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-28.c: Ditto.
> * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-3.c: Ditto.
> * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-7.c: Ditto.
> * gcc.target/riscv/rvv/vsetvl/vlmax_switch_vtype-12.c: Ditto.
>
> ---
>  .../gcc.target/riscv/rvv/vsetvl/imm_bb_prop-3.c|  2 +-
>  .../gcc.target/riscv/rvv/vsetvl/imm_bb_prop-4.c|  2 +-
>  .../gcc.target/riscv/rvv/vsetvl/imm_conflict-4.c   | 12 ++--
>  .../gcc.target/riscv/rvv/vsetvl/imm_conflict-5.c   | 12 ++--
>  .../riscv/rvv/vsetvl/imm_loop_invariant-17.c   |  3 +--
>  .../riscv/rvv/vsetvl/vlmax_back_prop-27.c  |  4 ++--
>  .../riscv/rvv/vsetvl/vlmax_back_prop-28.c  |  4 ++--
>  .../riscv/rvv/vsetvl/vlmax_back_prop-45.c  |  2 +-
>  .../gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-25.c | 14 +++---
>  .../gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-26.c | 12 ++--
>  .../gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-27.c | 12 ++--
>  .../gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-28.c |  2 +-
>  .../gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-3.c  |  2 +-
>  .../gcc.target/riscv/rvv/vsetvl/vlmax_conflict-7.c |  1 -
>  .../riscv/rvv/vsetvl/vlmax_switch_vtype-12.c   |  2 +-
>  15 files changed, 42 insertions(+), 44 deletions(-)
>
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/imm_bb_prop-3.c
> b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/imm_bb_prop-3.c
> index 3da7b8722c2..20a1cd27c43 100644
> --- a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/imm_bb_prop-3.c
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/imm_bb_prop-3.c
> @@ -19,4 +19,4 @@ void f(void *base, void *out, void *mask_in, size_t vl,
> size_t m) {
>}
>  }
>
> -/* { dg-final { scan-assembler-times
> {vsetivli\s+zero,\s*4,\s*e8,\s*mf8,\s*tu,\s*mu} 1 { target { no-opts "-O0"
> no-opts "-O1" no-opts "-Os" no-opts "-g" no-opts "-funroll-loops" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetivli\s+zero,\s*4,\s*e16,\s*mf4,\s*tu,\s*mu} 1 { target { no-opts "-O0"
> no-opts "-O1" no-opts "-Os" no-opts "-g" no-opts "-funroll-loops" } } } } */
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/imm_bb_prop-4.c
> b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/imm_bb_prop-4.c
> index 2a9616eb7ea..58aecb0a219 100644
> --- a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/imm_bb_prop-4.c
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/imm_bb_prop-4.c
> @@ -21,5 +21,5 @@ void f(void *base, void *out, void *mask_in, size_t vl,
> size_t m, size_t n) {
>}
>  }
>
> -/* { dg-final { scan-assembler-times
> {vsetivli\s+zero,\s*4,\s*e8,\s*mf8,\s*tu,\s*mu} 1 { target { no-opts "-O0"
> no-opts "-O1" no-opts "-Os" no-opts "-g" no-opts "-funroll-loops" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetivli\s+zero,\s*4,\s*e16,\s*mf4,\s*tu,\s*mu} 1 { target { no-opts "-O0"
> no-opts "-O1" no-opts "-Os" no-opts "-g" no-opts "-funroll-loops" } } } } */
>
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/imm_conflict-4.c
> b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/imm_conflict-4.c
> index f24e129b4dc..fdfcb07a63d 100644
> --- a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/imm_conflict-4.c
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/imm_conflict-4.c
> @@ -30,9 +30,9 @@ void f (void * restrict in, void * restrict out, int n,
> int cond)
>}
>  }
>
> -/* { dg-final { scan-assembler-times
> {vsetivli\s+zero,\s*5,\s*e8,\s*mf8,\s*tu,\s*m[au]} 1 { target { no-opts
> "-O0" no-opts "-g" no-opts "-funroll-loops" } } } } */
> -/* { dg-final { scan-assembler-times
> {vsetivli\s+zero,\s*19,\s*e32,\s*m1,\s*t[au],\s*m[au]} 1 { target { no-opts
> "-O0" no-opts "-g" no-opts "-funroll-loops" } } } } */
> -/* { dg-final { scan-assembler-times
> {vsetivli\s+zero,\s*8,\s*e32,\s*m1,\s*t[au],\s*m[au]} 1 { target { no-opts
> "-O0" no-opts "-O1" no-opts "-g" no-opts "-funroll-loops" } } } } */
> -/* { dg-final { scan-assembler-times
> {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target {
> no-opts "-O0"  no-opts "-funroll-loops" no-opts "-g" } } } } */
> -/* { dg-final { scan-assembler-times {vsetivli} 3 { target { 

Re: [PATCH] RISC-V: Remove dirty_pat since it is redundant

2023-01-26 Thread Kito Cheng via Gcc-patches
committed, thanks.

On Tue, Jan 10, 2023 at 7:11 AM  wrote:

> From: Ju-Zhe Zhong 
>
> gcc/ChangeLog:
>
> * config/riscv/riscv-vsetvl.cc (vector_insn_info::operator==):
> Remove dirty_pat.
> (vector_insn_info::merge): Ditto.
> (vector_insn_info::dump): Ditto.
> (pass_vsetvl::merge_successors): Ditto.
> (pass_vsetvl::backward_demand_fusion): Ditto.
> (pass_vsetvl::forward_demand_fusion): Ditto.
> (pass_vsetvl::commit_vsetvls): Ditto.
> * config/riscv/riscv-vsetvl.h: Ditto.
>
> ---
>  gcc/config/riscv/riscv-vsetvl.cc | 28 
>  gcc/config/riscv/riscv-vsetvl.h  | 11 +--
>  2 files changed, 13 insertions(+), 26 deletions(-)
>
> diff --git a/gcc/config/riscv/riscv-vsetvl.cc
> b/gcc/config/riscv/riscv-vsetvl.cc
> index 3c920779992..0f12d4ddb23 100644
> --- a/gcc/config/riscv/riscv-vsetvl.cc
> +++ b/gcc/config/riscv/riscv-vsetvl.cc
> @@ -1083,10 +1083,10 @@ vector_insn_info::operator== (const
> vector_insn_info ) const
>  if (m_demands[i] != other.demand_p ((enum demand_type) i))
>return false;
>
> -  if (m_insn != other.get_insn ())
> -return false;
> -  if (m_dirty_pat != other.get_dirty_pat ())
> -return false;
> +  if (vector_config_insn_p (m_insn->rtl ())
> +  || vector_config_insn_p (other.get_insn ()->rtl ()))
> +if (m_insn != other.get_insn ())
> +  return false;
>
>if (!same_avl_p (other))
>  return false;
> @@ -1317,8 +1317,6 @@ vector_insn_info::merge (const vector_insn_info
> _info,
> new_info.set_insn (merge_info.get_insn ());
>  }
>
> -  new_info.set_dirty_pat (merge_info.get_dirty_pat ());
> -
>if (!demand_p (DEMAND_AVL) && !merge_info.demand_p (DEMAND_AVL))
>  new_info.undemand (DEMAND_AVL);
>if (!demand_p (DEMAND_SEW) && !merge_info.demand_p (DEMAND_SEW))
> @@ -1431,11 +1429,6 @@ vector_insn_info::dump (FILE *file) const
>   fprintf (file, "The real INSN=");
>   print_rtl_single (file, get_insn ()->rtl ());
> }
> -  if (get_dirty_pat ())
> -   {
> - fprintf (file, "Dirty RTL Pattern=");
> - print_rtl_single (file, get_dirty_pat ());
> -   }
>  }
>  }
>
> @@ -1967,7 +1960,6 @@ pass_vsetvl::merge_successors (const basic_block
> father,
>
>new_info.set_dirty ();
>rtx new_pat = gen_vsetvl_pat (new_info.get_insn ()->rtl (),
> new_info);
> -  new_info.set_dirty_pat (new_pat);
>
>father_info.local_dem = new_info;
>father_info.reaching_out = new_info;
> @@ -2051,7 +2043,6 @@ pass_vsetvl::backward_demand_fusion (void)
>
>   block_info.reaching_out = prop;
>   block_info.reaching_out.set_dirty ();
> - block_info.reaching_out.set_dirty_pat (new_pat);
>   block_info.local_dem = block_info.reaching_out;
>   changed_p = true;
> }
> @@ -2080,7 +2071,6 @@ pass_vsetvl::backward_demand_fusion (void)
>   rtx new_pat
> = gen_vsetvl_pat (new_info.get_insn ()->rtl (), new_info);
>   new_info.set_dirty ();
> - new_info.set_dirty_pat (new_pat);
>   block_info.local_dem = new_info;
>   block_info.reaching_out = new_info;
>   changed_p = true;
> @@ -2178,7 +2168,6 @@ pass_vsetvl::forward_demand_fusion (void)
> = gen_vsetvl_pat (prop.get_insn ()->rtl (), prop);
>   local_dem = prop;
>   local_dem.set_dirty ();
> - local_dem.set_dirty_pat (dirty_pat);
>   reaching_out = local_dem;
> }
>   else
> @@ -2507,10 +2496,17 @@ pass_vsetvl::commit_vsetvls (void)
>if (!reaching_out.dirty_p ())
> continue;
>
> -  rtx new_pat = reaching_out.get_dirty_pat ();
> +
> +  rtx new_pat;
>if (can_refine_vsetvl_p (cfg_bb, reaching_out.get_ratio ()))
> new_pat
>   = gen_vsetvl_pat (VSETVL_VTYPE_CHANGE_ONLY, reaching_out,
> NULL_RTX);
> +  else if (vlmax_avl_p (reaching_out.get_avl ()))
> +   new_pat = gen_vsetvl_pat (VSETVL_NORMAL, reaching_out,
> + get_vl (reaching_out.get_insn ()->rtl
> ()));
> +  else
> +   new_pat
> + = gen_vsetvl_pat (VSETVL_DISCARD_RESULT, reaching_out, NULL_RTX);
>
>start_sequence ();
>emit_insn (new_pat);
> diff --git a/gcc/config/riscv/riscv-vsetvl.h
> b/gcc/config/riscv/riscv-vsetvl.h
> index dc16c55b918..563ad3084ed 100644
> --- a/gcc/config/riscv/riscv-vsetvl.h
> +++ b/gcc/config/riscv/riscv-vsetvl.h
> @@ -220,13 +220,6 @@ private:
>   (with AVL included) before vmv.x.s, but vmv.x.s is not the INSN
> holding the
>   definition of AVL.  */
>rtl_ssa::insn_info *m_insn;
> -  /* Save instruction pattern for Dirty block.
> - Since empty block may be polluted as a dirty block during dem
> backward
> - propagation (phase 3) which is intending to 

Re: [PATCH] RISC-V: Fix bugs of supporting AVL=REG (single-real-def) in VSETVL PASS

2023-01-26 Thread Kito Cheng via Gcc-patches
committed, thanks.

On Tue, Jan 10, 2023 at 7:29 AM  wrote:

> From: Ju-Zhe Zhong 
>
> gcc/ChangeLog:
>
> * config/riscv/riscv-vsetvl.cc (same_bb_and_before_p): Remove it.
> (real_insn_and_same_bb_p): New function.
> (same_bb_and_after_or_equal_p): Remove it.
> (before_p): New function.
> (reg_killed_by_bb_p): Ditto.
> (has_vsetvl_killed_avl_p): Ditto.
> (get_vl): Move location so that we can call it.
> (anticipatable_occurrence_p): Fix issue of AVL=REG support.
> (available_occurrence_p): Ditto.
> (dominate_probability_p): Remove it.
> (can_backward_propagate_p): Remove it.
> (get_all_nonphi_defs): New function.
> (get_all_predecessors): Ditto.
> (any_insn_in_bb_p): Ditto.
> (insert_vsetvl): Adjust AVL REG.
> (source_equal_p): New function.
> (extract_single_source): Ditto.
> (avl_info::single_source_equal_p): Ditto.
> (avl_info::operator==): Adjust for AVL=REG.
> (vl_vtype_info::same_avl_p): Ditto.
> (vector_insn_info::set_demand_info): Remove it.
> (vector_insn_info::compatible_p): Adjust for AVL=REG.
> (vector_insn_info::compatible_avl_p): New function.
> (vector_insn_info::merge): Adjust AVL=REG.
> (vector_insn_info::dump): Ditto.
> (pass_vsetvl::merge_successors): Remove it.
> (enum fusion_type): New enum.
> (pass_vsetvl::get_backward_fusion_type): New function.
> (pass_vsetvl::backward_demand_fusion): Adjust for AVL=REG.
> (pass_vsetvl::forward_demand_fusion): Ditto.
> (pass_vsetvl::demand_fusion): Ditto.
> (pass_vsetvl::prune_expressions): Ditto.
> (pass_vsetvl::compute_local_properties): Ditto.
> (pass_vsetvl::cleanup_vsetvls): Ditto.
> (pass_vsetvl::commit_vsetvls): Ditto.
> (pass_vsetvl::init): Ditto.
> * config/riscv/riscv-vsetvl.h (enum fusion_type): New enum.
> (enum merge_type): New enum.
>
> ---
>  gcc/config/riscv/riscv-vsetvl.cc | 928 +--
>  gcc/config/riscv/riscv-vsetvl.h  |  68 ++-
>  2 files changed, 710 insertions(+), 286 deletions(-)
>
> diff --git a/gcc/config/riscv/riscv-vsetvl.cc
> b/gcc/config/riscv/riscv-vsetvl.cc
> index 7aa2852b456..0245124e28f 100644
> --- a/gcc/config/riscv/riscv-vsetvl.cc
> +++ b/gcc/config/riscv/riscv-vsetvl.cc
> @@ -178,34 +178,97 @@ vsetvl_insn_p (rtx_insn *rinsn)
>  || INSN_CODE (rinsn) == CODE_FOR_vsetvlsi);
>  }
>
> -/* Return true if INSN1 comes befeore INSN2 in the same block.  */
>  static bool
> -same_bb_and_before_p (const insn_info *insn1, const insn_info *insn2)
> +real_insn_and_same_bb_p (const insn_info *insn, const bb_info *bb)
>  {
> -  return ((insn1->bb ()->index () == insn2->bb ()->index ())
> -&& (*insn1 < *insn2));
> +  return insn != nullptr && insn->is_real () && insn->bb () == bb;
>  }
>
> -/* Return true if INSN1 comes after or equal INSN2 in the same block.  */
>  static bool
> -same_bb_and_after_or_equal_p (const insn_info *insn1, const insn_info
> *insn2)
> +before_p (const insn_info *insn1, const insn_info *insn2)
>  {
> -  return ((insn1->bb ()->index () == insn2->bb ()->index ())
> -&& (*insn1 >= *insn2));
> +  return insn1->compare_with (insn2) == -1;
> +}
> +
> +static bool
> +reg_killed_by_bb_p (const bb_info *bb, rtx x)
> +{
> +  if (!x || vlmax_avl_p (x))
> +return false;
> +  for (const insn_info *insn : bb->real_nondebug_insns ())
> +if (find_access (insn->defs (), REGNO (x)))
> +  return true;
> +  return false;
> +}
> +
> +static bool
> +has_vsetvl_killed_avl_p (const bb_info *bb, const vector_insn_info )
> +{
> +  if (info.dirty_with_killed_avl_p ())
> +{
> +  rtx avl = info.get_avl ();
> +  for (const insn_info *insn : bb->reverse_real_nondebug_insns ())
> +   {
> + def_info *def = find_access (insn->defs (), REGNO (avl));
> + if (def)
> +   {
> + set_info *set = safe_dyn_cast (def);
> + if (!set)
> +   return false;
> +
> + rtx new_avl = gen_rtx_REG (GET_MODE (avl), REGNO (avl));
> + gcc_assert (new_avl != avl);
> + if (!info.compatible_avl_p (avl_info (new_avl, set)))
> +   return false;
> +
> + return true;
> +   }
> +   }
> +}
> +  return false;
> +}
> +
> +/* Helper function to get VL operand.  */
> +static rtx
> +get_vl (rtx_insn *rinsn)
> +{
> +  if (has_vl_op (rinsn))
> +{
> +  extract_insn_cached (rinsn);
> +  return recog_data.operand[get_attr_vl_op_idx (rinsn)];
> +}
> +  return SET_DEST (XVECEXP (PATTERN (rinsn), 0, 0));
>  }
>
>  /* An "anticipatable occurrence" is one that is the first occurrence in
> the
> basic block, the operands are not modified in the basic block prior
> to the occurrence and the output is not used between the start of
> -   the block and the 

Re: [PATCH] RISC-V: Add probability model of each block to prevent endless loop of Phase 3

2023-01-26 Thread Kito Cheng via Gcc-patches
committed, thanks.

On Tue, Jan 10, 2023 at 7:17 AM  wrote:

> From: Ju-Zhe Zhong 
>
> Notice that the PASS is just simpily pick the probability >= 50%
> to do the backward fusion which will create endless loop on Phase 3.
>
> Adding this probability to fix this bug.
> gcc/ChangeLog:
>
> * config/riscv/riscv-vsetvl.cc
> (vector_infos_manager::vector_infos_manager): Add probability.
> (vector_infos_manager::dump): Ditto.
> (pass_vsetvl::compute_probabilities): Ditto.
> * config/riscv/riscv-vsetvl.h (struct vector_block_info): Ditto.
>
> ---
>  gcc/config/riscv/riscv-vsetvl.cc | 39 
>  gcc/config/riscv/riscv-vsetvl.h  |  3 +++
>  2 files changed, 42 insertions(+)
>
> diff --git a/gcc/config/riscv/riscv-vsetvl.cc
> b/gcc/config/riscv/riscv-vsetvl.cc
> index 0f12d4ddb23..7d8c3a32aaa 100644
> --- a/gcc/config/riscv/riscv-vsetvl.cc
> +++ b/gcc/config/riscv/riscv-vsetvl.cc
> @@ -1465,6 +1465,7 @@ vector_infos_manager::vector_infos_manager ()
>   vector_block_infos[bb->index ()].reaching_out = vector_insn_info
> ();
>   for (insn_info *insn : bb->real_insns ())
> vector_insn_infos[insn->uid ()].parse_insn (insn);
> + vector_block_infos[bb->index ()].probability =
> profile_probability ();
> }
>  }
>  }
> @@ -1642,6 +1643,8 @@ vector_infos_manager::dump (FILE *file) const
> }
>fprintf (file, "=");
>vector_block_infos[cfg_bb->index].reaching_out.dump (file);
> +  fprintf (file, "=");
> +  vector_block_infos[cfg_bb->index].probability.dump (file);
>fprintf (file, "\n\n");
>  }
>
> @@ -1764,6 +1767,7 @@ private:
>
>void init (void);
>void done (void);
> +  void compute_probabilities (void);
>
>  public:
>pass_vsetvl (gcc::context *ctxt) : rtl_opt_pass (pass_data_vsetvl,
> ctxt) {}
> @@ -2629,6 +2633,41 @@ pass_vsetvl::done (void)
>m_vector_manager = nullptr;
>  }
>
> +/* Compute probability for each block.  */
> +void
> +pass_vsetvl::compute_probabilities (void)
> +{
> +  /* Don't compute it in -O0 since we don't need it.  */
> +  if (!optimize)
> +return;
> +  edge e;
> +  edge_iterator ei;
> +
> +  for (const bb_info *bb : crtl->ssa->bbs ())
> +{
> +  basic_block cfg_bb = bb->cfg_bb ();
> +  auto _prob
> +   = m_vector_manager->vector_block_infos[cfg_bb->index].probability;
> +  if (ENTRY_BLOCK_PTR_FOR_FN (cfun) == cfg_bb)
> +   curr_prob = profile_probability::always ();
> +  gcc_assert (curr_prob.initialized_p ());
> +  FOR_EACH_EDGE (e, ei, cfg_bb->succs)
> +   {
> + auto _prob
> +   =
> m_vector_manager->vector_block_infos[e->dest->index].probability;
> + if (!new_prob.initialized_p ())
> +   new_prob = curr_prob * e->probability;
> + else if (new_prob == profile_probability::always ())
> +   continue;
> + else
> +   new_prob += curr_prob * e->probability;
> +   }
> +}
> +  auto _block
> += m_vector_manager->vector_block_infos[EXIT_BLOCK_PTR_FOR_FN
> (cfun)->index];
> +  exit_block.probability = profile_probability::always ();
> +}
> +
>  /* Lazy vsetvl insertion for optimize > 0. */
>  void
>  pass_vsetvl::lazy_vsetvl (void)
> diff --git a/gcc/config/riscv/riscv-vsetvl.h
> b/gcc/config/riscv/riscv-vsetvl.h
> index 563ad3084ed..fb3ebb9db79 100644
> --- a/gcc/config/riscv/riscv-vsetvl.h
> +++ b/gcc/config/riscv/riscv-vsetvl.h
> @@ -291,6 +291,9 @@ struct vector_block_info
>/* The reaching_out vector insn_info of the block.  */
>vector_insn_info reaching_out;
>
> +  /* The static execute probability of the demand info.  */
> +  profile_probability probability;
> +
>vector_block_info () = default;
>  };
>
> --
> 2.36.1
>
>


Re: [PATCH] RISC-V: Rename insn into rinsn for rtx_insn *

2023-01-26 Thread Kito Cheng via Gcc-patches
committed, thanks.

On Tue, Jan 10, 2023 at 6:57 AM  wrote:

> From: Ju-Zhe Zhong 
>
> Since the PASS is implemented base on RTL_SSA framework.
> According to rtl_ssa, they name insn_info * as insn and
> name rtx_insn * rinsn. I follow this rule in this pass but I missed
> this function. So rename it to make codes be consistent to RTL_SSA
> framework.
>
> gcc/ChangeLog:
>
> * config/riscv/riscv-vsetvl.cc (add_label_notes):
>
> ---
>  gcc/config/riscv/riscv-vsetvl.cc | 10 +-
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/gcc/config/riscv/riscv-vsetvl.cc
> b/gcc/config/riscv/riscv-vsetvl.cc
> index a972c49561a..3c920779992 100644
> --- a/gcc/config/riscv/riscv-vsetvl.cc
> +++ b/gcc/config/riscv/riscv-vsetvl.cc
> @@ -682,7 +682,7 @@ insert_vsetvl (enum emit_type emit_type, rtx_insn
> *rinsn,
> necessary REG_LABEL_OPERAND and REG_LABEL_TARGET notes.  */
>
>  static void
> -add_label_notes (rtx x, rtx_insn *insn)
> +add_label_notes (rtx x, rtx_insn *rinsn)
>  {
>enum rtx_code code = GET_CODE (x);
>int i, j;
> @@ -699,8 +699,8 @@ add_label_notes (rtx x, rtx_insn *insn)
>/* There's no reason for current users to emit jump-insns with
>  such a LABEL_REF, so we don't have to handle REG_LABEL_TARGET
>  notes.  */
> -  gcc_assert (!JUMP_P (insn));
> -  add_reg_note (insn, REG_LABEL_OPERAND, label_ref_label (x));
> +  gcc_assert (!JUMP_P (rinsn));
> +  add_reg_note (rinsn, REG_LABEL_OPERAND, label_ref_label (x));
>
>if (LABEL_P (label_ref_label (x)))
> LABEL_NUSES (label_ref_label (x))++;
> @@ -711,10 +711,10 @@ add_label_notes (rtx x, rtx_insn *insn)
>for (i = GET_RTX_LENGTH (code) - 1, fmt = GET_RTX_FORMAT (code); i >=
> 0; i--)
>  {
>if (fmt[i] == 'e')
> -   add_label_notes (XEXP (x, i), insn);
> +   add_label_notes (XEXP (x, i), rinsn);
>else if (fmt[i] == 'E')
> for (j = XVECLEN (x, i) - 1; j >= 0; j--)
> - add_label_notes (XVECEXP (x, i, j), insn);
> + add_label_notes (XVECEXP (x, i, j), rinsn);
>  }
>  }
>
> --
> 2.36.1
>
>


Re: [PATCH] RISC-V: Avoid redundant flow in backward fusion

2023-01-26 Thread Kito Cheng via Gcc-patches
merged into another commit,, thanks.

On Tue, Jan 10, 2023 at 6:51 AM  wrote:

> From: Ju-Zhe Zhong 
>
> gcc/ChangeLog:
>
> * config/riscv/riscv-vsetvl.cc
> (pass_vsetvl::backward_demand_fusion): Add pre-check to avoid redundant
> flow.
>
> ---
>  gcc/config/riscv/riscv-vsetvl.cc | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/gcc/config/riscv/riscv-vsetvl.cc
> b/gcc/config/riscv/riscv-vsetvl.cc
> index 0ca1c51d121..a972c49561a 100644
> --- a/gcc/config/riscv/riscv-vsetvl.cc
> +++ b/gcc/config/riscv/riscv-vsetvl.cc
> @@ -2020,6 +2020,8 @@ pass_vsetvl::backward_demand_fusion (void)
>
>if (!backward_propagate_worthwhile_p (cfg_bb, curr_block_info))
> continue;
> +
> +  if (cfg_bb == EXIT_BLOCK_PTR_FOR_FN (cfun))
> continue;
>
>edge e;
> --
> 2.36.1
>
>


Re: [PATCH] RISC-V: Refine codes in backward fusion

2023-01-26 Thread Kito Cheng via Gcc-patches
committed, thanks.

On Tue, Jan 10, 2023 at 6:47 AM  wrote:

> From: Ju-Zhe Zhong 
>
> This NFC patch is preparing for the following patches.
> gcc/ChangeLog:
>
> * config/riscv/riscv-vsetvl.cc
> (pass_vsetvl::backward_demand_fusion): Refine codes.
>
> ---
>  gcc/config/riscv/riscv-vsetvl.cc | 9 +
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/gcc/config/riscv/riscv-vsetvl.cc
> b/gcc/config/riscv/riscv-vsetvl.cc
> index 18c6f437db6..0ca1c51d121 100644
> --- a/gcc/config/riscv/riscv-vsetvl.cc
> +++ b/gcc/config/riscv/riscv-vsetvl.cc
> @@ -2010,15 +2010,16 @@ pass_vsetvl::backward_demand_fusion (void)
>for (const bb_info *bb : crtl->ssa->reverse_bbs ())
>  {
>basic_block cfg_bb = bb->cfg_bb ();
> -  const auto 
> -   = m_vector_manager->vector_block_infos[cfg_bb->index].local_dem;
> +  const auto _block_info
> +   = m_vector_manager->vector_block_infos[cfg_bb->index];
> +  const auto  = curr_block_info.local_dem;
>
>/* If there is nothing to propagate, just skip it.  */
>if (!prop.valid_or_dirty_p ())
> continue;
>
> -  if (!backward_propagate_worthwhile_p (
> -   cfg_bb, m_vector_manager->vector_block_infos[cfg_bb->index]))
> +  if (!backward_propagate_worthwhile_p (cfg_bb, curr_block_info))
> +   continue;
> continue;
>
>edge e;
> --
> 2.36.1
>
>


Re: [PATCH] RISC-V: Cleanup the codes of bitmap create and free [NFC]

2023-01-26 Thread Kito Cheng via Gcc-patches
committed, thanks.

On Tue, Jan 10, 2023 at 6:33 AM  wrote:

> From: Ju-Zhe Zhong 
>
> This patch is a NFC patch to move the codes into a wrapper function so that
> they can be reused. I will reuse them in the following patches.
>
> gcc/ChangeLog:
>
> * config/riscv/riscv-vsetvl.cc
> (vector_infos_manager::create_bitmap_vectors): New function.
> (vector_infos_manager::free_bitmap_vectors): Ditto.
> (pass_vsetvl::pre_vsetvl): Adjust codes.
> * config/riscv/riscv-vsetvl.h: New function declaration.
>
> ---
>  gcc/config/riscv/riscv-vsetvl.cc | 95 +++-
>  gcc/config/riscv/riscv-vsetvl.h  |  2 +
>  2 files changed, 59 insertions(+), 38 deletions(-)
>
> diff --git a/gcc/config/riscv/riscv-vsetvl.cc
> b/gcc/config/riscv/riscv-vsetvl.cc
> index d42cfa91d63..7800c2ee509 100644
> --- a/gcc/config/riscv/riscv-vsetvl.cc
> +++ b/gcc/config/riscv/riscv-vsetvl.cc
> @@ -1569,18 +1569,62 @@ vector_infos_manager::release (void)
>  vector_exprs.release ();
>
>if (optimize > 0)
> -{
> -  /* Finished. Free up all the things we've allocated.  */
> -  free_edge_list (vector_edge_list);
> -  sbitmap_vector_free (vector_del);
> -  sbitmap_vector_free (vector_insert);
> -  sbitmap_vector_free (vector_kill);
> -  sbitmap_vector_free (vector_antic);
> -  sbitmap_vector_free (vector_transp);
> -  sbitmap_vector_free (vector_comp);
> -  sbitmap_vector_free (vector_avin);
> -  sbitmap_vector_free (vector_avout);
> -}
> +free_bitmap_vectors ();
> +}
> +
> +void
> +vector_infos_manager::create_bitmap_vectors (void)
> +{
> +  /* Create the bitmap vectors.  */
> +  vector_antic = sbitmap_vector_alloc (last_basic_block_for_fn (cfun),
> +  vector_exprs.length ());
> +  vector_transp = sbitmap_vector_alloc (last_basic_block_for_fn (cfun),
> +   vector_exprs.length ());
> +  vector_comp = sbitmap_vector_alloc (last_basic_block_for_fn (cfun),
> + vector_exprs.length ());
> +  vector_avin = sbitmap_vector_alloc (last_basic_block_for_fn (cfun),
> + vector_exprs.length ());
> +  vector_avout = sbitmap_vector_alloc (last_basic_block_for_fn (cfun),
> +  vector_exprs.length ());
> +  vector_kill = sbitmap_vector_alloc (last_basic_block_for_fn (cfun),
> + vector_exprs.length ());
> +
> +  bitmap_vector_ones (vector_transp, last_basic_block_for_fn (cfun));
> +  bitmap_vector_clear (vector_antic, last_basic_block_for_fn (cfun));
> +  bitmap_vector_clear (vector_comp, last_basic_block_for_fn (cfun));
> +}
> +
> +void
> +vector_infos_manager::free_bitmap_vectors (void)
> +{
> +  /* Finished. Free up all the things we've allocated.  */
> +  free_edge_list (vector_edge_list);
> +  if (vector_del)
> +sbitmap_vector_free (vector_del);
> +  if (vector_insert)
> +sbitmap_vector_free (vector_insert);
> +  if (vector_kill)
> +sbitmap_vector_free (vector_kill);
> +  if (vector_antic)
> +sbitmap_vector_free (vector_antic);
> +  if (vector_transp)
> +sbitmap_vector_free (vector_transp);
> +  if (vector_comp)
> +sbitmap_vector_free (vector_comp);
> +  if (vector_avin)
> +sbitmap_vector_free (vector_avin);
> +  if (vector_avout)
> +sbitmap_vector_free (vector_avout);
> +
> +  vector_edge_list = nullptr;
> +  vector_kill = nullptr;
> +  vector_del = nullptr;
> +  vector_insert = nullptr;
> +  vector_antic = nullptr;
> +  vector_transp = nullptr;
> +  vector_comp = nullptr;
> +  vector_avin = nullptr;
> +  vector_avout = nullptr;
>  }
>
>  void
> @@ -2480,32 +2524,7 @@ pass_vsetvl::pre_vsetvl (void)
>/* Compute entity list.  */
>prune_expressions ();
>
> -  /* Create the bitmap vectors.  */
> -  m_vector_manager->vector_antic
> -= sbitmap_vector_alloc (last_basic_block_for_fn (cfun),
> -   m_vector_manager->vector_exprs.length ());
> -  m_vector_manager->vector_transp
> -= sbitmap_vector_alloc (last_basic_block_for_fn (cfun),
> -   m_vector_manager->vector_exprs.length ());
> -  m_vector_manager->vector_comp
> -= sbitmap_vector_alloc (last_basic_block_for_fn (cfun),
> -   m_vector_manager->vector_exprs.length ());
> -  m_vector_manager->vector_avin
> -= sbitmap_vector_alloc (last_basic_block_for_fn (cfun),
> -   m_vector_manager->vector_exprs.length ());
> -  m_vector_manager->vector_avout
> -= sbitmap_vector_alloc (last_basic_block_for_fn (cfun),
> -   m_vector_manager->vector_exprs.length ());
> -  m_vector_manager->vector_kill
> -= sbitmap_vector_alloc (last_basic_block_for_fn (cfun),
> -   m_vector_manager->vector_exprs.length ());
> -
> -  bitmap_vector_ones (m_vector_manager->vector_transp,
> - 

Re: [PATCH] RISC-V: Simplify codes of changing vsetvl instruction

2023-01-26 Thread Kito Cheng via Gcc-patches
committed, thanks.

On Tue, Jan 3, 2023 at 3:25 PM  wrote:

> From: Ju-Zhe Zhong 
>
> This patch is NFC patch. I move these code as a function since we will
> reuse it in the following patch (Refine phase 3 of VSETVL PASS)
>
> gcc/ChangeLog:
>
> * config/riscv/riscv-vsetvl.cc (change_vsetvl_insn): New function.
> (pass_vsetvl::compute_global_backward_infos): Simplify codes.
>
> ---
>  gcc/config/riscv/riscv-vsetvl.cc | 36 ++--
>  1 file changed, 20 insertions(+), 16 deletions(-)
>
> diff --git a/gcc/config/riscv/riscv-vsetvl.cc
> b/gcc/config/riscv/riscv-vsetvl.cc
> index fe76bea297e..6dbaea32b03 100644
> --- a/gcc/config/riscv/riscv-vsetvl.cc
> +++ b/gcc/config/riscv/riscv-vsetvl.cc
> @@ -880,6 +880,25 @@ change_insn (function_info *ssa, insn_change change,
> insn_info *insn,
>return true;
>  }
>
> +static void
> +change_vsetvl_insn (const insn_info *insn, const vector_insn_info )
> +{
> +  rtx_insn *rinsn;
> +  if (vector_config_insn_p (insn->rtl ()))
> +{
> +  rinsn = insn->rtl ();
> +  gcc_assert (vsetvl_insn_p (rinsn) && "Can't handle X0, rs1 vsetvli
> yet");
> +}
> +  else
> +{
> +  gcc_assert (has_vtype_op (insn->rtl ()));
> +  rinsn = PREV_INSN (insn->rtl ());
> +  gcc_assert (vector_config_insn_p (rinsn));
> +}
> +  rtx new_pat = gen_vsetvl_pat (rinsn, info);
> +  change_insn (rinsn, new_pat);
> +}
> +
>  avl_info::avl_info (const avl_info )
>  {
>m_value = other.get_value ();
> @@ -1941,7 +1960,6 @@ pass_vsetvl::compute_global_backward_infos (void)
>/* Backward propagate to each predecessor.  */
>FOR_EACH_EDGE (e, ei, cfg_bb->preds)
> {
> - rtx new_pat;
>   auto _info
> = m_vector_manager->vector_block_infos[e->src->index];
>
> @@ -2011,21 +2029,7 @@ pass_vsetvl::compute_global_backward_infos (void)
> be_merged = block_info.local_dem;
>   vector_insn_info new_info = be_merged.merge (prop, true);
>
> - rtx_insn *rinsn;
> - if (vector_config_insn_p (new_info.get_insn ()->rtl ()))
> -   {
> - rinsn = new_info.get_insn ()->rtl ();
> - gcc_assert (vsetvl_insn_p (rinsn)
> - && "Can't handle X0, rs1 vsetvli yet");
> -   }
> - else
> -   {
> - gcc_assert (has_vtype_op (new_info.get_insn ()->rtl ()));
> - rinsn = PREV_INSN (new_info.get_insn ()->rtl ());
> - gcc_assert (vector_config_insn_p (rinsn));
> -   }
> - new_pat = gen_vsetvl_pat (rinsn, new_info);
> - change_insn (rinsn, new_pat);
> + change_vsetvl_insn (new_info.get_insn (), new_info);
>   if (block_info.local_dem == block_info.reaching_out)
> block_info.local_dem = new_info;
>   block_info.reaching_out = new_info;
> --
> 2.36.3
>
>


Re: [PATCH] RISC-V: Refine Phase 3 of VSETVL PASS

2023-01-26 Thread Kito Cheng via Gcc-patches
committed with few tweaks, thanks.

On Wed, Jan 4, 2023 at 9:46 PM  wrote:

> From: Ju-Zhe Zhong 
>
> gcc/ChangeLog:
>
> * config/riscv/riscv-vsetvl.cc (can_backward_propagate_p): Fix for
> null iter_bb.
> (vector_insn_info::set_demand_info): New function.
> (pass_vsetvl::emit_local_forward_vsetvls): Adjust for refinement
> of Phase 3.
> (pass_vsetvl::merge_successors): Ditto.
> (pass_vsetvl::compute_global_backward_infos): Ditto.
> (pass_vsetvl::backward_demand_fusion): Ditto.
> (pass_vsetvl::forward_demand_fusion): Ditto.
> (pass_vsetvl::demand_fusion): New function.
> (pass_vsetvl::lazy_vsetvl): Adjust for refinement of phase 3.
> * config/riscv/riscv-vsetvl.h: New function declaration.
>
> ---
>  gcc/config/riscv/riscv-vsetvl.cc | 138 ---
>  gcc/config/riscv/riscv-vsetvl.h  |   1 +
>  2 files changed, 128 insertions(+), 11 deletions(-)
>
> diff --git a/gcc/config/riscv/riscv-vsetvl.cc
> b/gcc/config/riscv/riscv-vsetvl.cc
> index 52f0195980a..d42cfa91d63 100644
> --- a/gcc/config/riscv/riscv-vsetvl.cc
> +++ b/gcc/config/riscv/riscv-vsetvl.cc
> @@ -43,7 +43,7 @@ along with GCC; see the file COPYING3.  If not see
>  -  Phase 2 - Emit vsetvl instructions within each basic block
> according to
> demand, compute and save ANTLOC && AVLOC of each block.
>
> --  Phase 3 - Backward demanded info propagation and fusion across
> blocks.
> +-  Phase 3 - Backward && forward demanded info propagation and fusion
> across blocks.
>
>  -  Phase 4 - Lazy code motion including: compute local properties,
> pre_edge_lcm and vsetvl insertion && delete edges for LCM results.
> @@ -434,8 +434,12 @@ can_backward_propagate_p (const function_info *ssa,
> const basic_block cfg_bb,
> set_info *ultimate_def = look_through_degenerate_phi (set);
> const basic_block ultimate_bb = ultimate_def->bb ()->cfg_bb ();
> FOR_BB_BETWEEN (iter_bb, ultimate_bb, def->bb ()->cfg_bb (),
> next_bb)
> - if (iter_bb->index == cfg_bb->index)
> -   return true;
> + {
> +   if (!iter_bb)
> + break;
> +   if (iter_bb->index == cfg_bb->index)
> + return true;
> + }
>
> return false;
>};
> @@ -1172,6 +1176,19 @@ vector_insn_info::parse_insn (insn_info *insn)
>  m_demands[DEMAND_MASK_POLICY] = true;
>  }
>
> +void
> +vector_insn_info::set_demand_info (const vector_insn_info )
> +{
> +  set_sew (other.get_sew ());
> +  set_vlmul (other.get_vlmul ());
> +  set_ratio (other.get_ratio ());
> +  set_ta (other.get_ta ());
> +  set_ma (other.get_ma ());
> +  set_avl_info (other.get_avl_info ());
> +  for (size_t i = 0; i < NUM_DEMAND; i++)
> +m_demands[i] = other.demand_p ((enum demand_type) i);
> +}
> +
>  void
>  vector_insn_info::demand_vl_vtype ()
>  {
> @@ -1691,8 +1708,10 @@ private:
>void emit_local_forward_vsetvls (const bb_info *);
>
>/* Phase 3.  */
> -  void merge_successors (const basic_block, const basic_block);
> -  void compute_global_backward_infos (void);
> +  bool merge_successors (const basic_block, const basic_block);
> +  bool backward_demand_fusion (void);
> +  bool forward_demand_fusion (void);
> +  void demand_fusion (void);
>
>/* Phase 4.  */
>void prune_expressions (void);
> @@ -1866,7 +1885,7 @@ pass_vsetvl::emit_local_forward_vsetvls (const
> bb_info *bb)
>  }
>
>  /* Merge all successors of Father except child node.  */
> -void
> +bool
>  pass_vsetvl::merge_successors (const basic_block father,
>const basic_block child)
>  {
> @@ -1877,7 +1896,8 @@ pass_vsetvl::merge_successors (const basic_block
> father,
>   || father_info.local_dem.empty_p ());
>gcc_assert (father_info.reaching_out.dirty_p ()
>   || father_info.reaching_out.empty_p ());
> -
> +
> +  bool changed_p = false;
>FOR_EACH_EDGE (e, ei, father->succs)
>  {
>const basic_block succ = e->dest;
> @@ -1907,12 +1927,15 @@ pass_vsetvl::merge_successors (const basic_block
> father,
>
>father_info.local_dem = new_info;
>father_info.reaching_out = new_info;
> +  changed_p = true;
>  }
> +
> +  return changed_p;
>  }
>
>  /* Compute global backward demanded info.  */
> -void
> -pass_vsetvl::compute_global_backward_infos (void)
> +bool
> +pass_vsetvl::backward_demand_fusion (void)
>  {
>/* We compute global infos by backward propagation.
>   We want to have better performance in these following cases:
> @@ -1939,6 +1962,7 @@ pass_vsetvl::compute_global_backward_infos (void)
>We backward propagate the first VSETVL into e32,mf2 so that we
>could be able to eliminate the second VSETVL in LCM.  */
>
> +  bool changed_p = false;
>for (const bb_info *bb : crtl->ssa->reverse_bbs ())
>  {
>basic_block cfg_bb = bb->cfg_bb ();
> @@ -1982,9 +2006,10 @@ 

Re: [PATCH] RISC-V: Avoid redundant flow in forward fusion

2023-01-26 Thread Kito Cheng via Gcc-patches
committed, thanks.

On Tue, Jan 10, 2023 at 6:40 AM  wrote:

> From: Ju-Zhe Zhong 
>
> gcc/ChangeLog:
>
> * config/riscv/riscv-vsetvl.cc
> (pass_vsetvl::forward_demand_fusion): Add pre-check for redundant flow.
>
> ---
>  gcc/config/riscv/riscv-vsetvl.cc | 8 
>  1 file changed, 8 insertions(+)
>
> diff --git a/gcc/config/riscv/riscv-vsetvl.cc
> b/gcc/config/riscv/riscv-vsetvl.cc
> index 7800c2ee509..18c6f437db6 100644
> --- a/gcc/config/riscv/riscv-vsetvl.cc
> +++ b/gcc/config/riscv/riscv-vsetvl.cc
> @@ -2140,6 +2140,9 @@ pass_vsetvl::forward_demand_fusion (void)
>if (!prop.valid_or_dirty_p ())
> continue;
>
> +  if (cfg_bb == ENTRY_BLOCK_PTR_FOR_FN (cfun))
> +   continue;
> +
>edge e;
>edge_iterator ei;
>/* Forward propagate to each successor.  */
> @@ -2153,6 +2156,11 @@ pass_vsetvl::forward_demand_fusion (void)
>   /* It's quite obvious, we don't need to propagate itself.  */
>   if (e->dest->index == cfg_bb->index)
> continue;
> + /* We don't propagate through critical edges.  */
> + if (e->flags & EDGE_COMPLEX)
> +   continue;
> + if (e->dest->index == EXIT_BLOCK_PTR_FOR_FN (cfun)->index)
> +   continue;
>
>   /* If there is nothing to propagate, just skip it.  */
>   if (!local_dem.valid_or_dirty_p ())
> --
> 2.36.1
>
>


Re: [PATCH] RISC-V: Fix backward_propagate_worthwhile_p

2023-01-26 Thread Kito Cheng via Gcc-patches
committed, thanks.

On Tue, Jan 3, 2023 at 3:17 PM  wrote:

> From: Ju-Zhe Zhong 
>
> gcc/ChangeLog:
>
> * config/riscv/riscv-vsetvl.cc (loop_basic_block_p): Adjust
> function.
> (backward_propagate_worthwhile_p): Fix non-worthwhile.
>
> ---
>  gcc/config/riscv/riscv-vsetvl.cc | 91 +---
>  1 file changed, 71 insertions(+), 20 deletions(-)
>
> diff --git a/gcc/config/riscv/riscv-vsetvl.cc
> b/gcc/config/riscv/riscv-vsetvl.cc
> index ad0457ed89d..fe76bea297e 100644
> --- a/gcc/config/riscv/riscv-vsetvl.cc
> +++ b/gcc/config/riscv/riscv-vsetvl.cc
> @@ -116,10 +116,27 @@ vlmax_avl_insn_p (rtx_insn *rinsn)
>   || INSN_CODE (rinsn) == CODE_FOR_vlmax_avldi);
>  }
>
> +/* Return true if the block is a loop itself:
> + local_dem
> +__
> +| |
> +   || |
> +   || |
> +|_|
> + reaching_out
> +*/
>  static bool
>  loop_basic_block_p (const basic_block cfg_bb)
>  {
> -  return JUMP_P (BB_END (cfg_bb)) && any_condjump_p (BB_END (cfg_bb));
> +  if (JUMP_P (BB_END (cfg_bb)) && any_condjump_p (BB_END (cfg_bb)))
> +{
> +  edge e;
> +  edge_iterator ei;
> +  FOR_EACH_EDGE (e, ei, cfg_bb->succs)
> +   if (e->dest->index == cfg_bb->index)
> + return true;
> +}
> +  return false;
>  }
>
>  /* Return true if it is an RVV instruction depends on VTYPE global
> @@ -271,26 +288,60 @@ backward_propagate_worthwhile_p (const basic_block
> cfg_bb,
>  {
>if (loop_basic_block_p (cfg_bb))
>  {
> -  if (block_info.local_dem.compatible_p (block_info.reaching_out))
> -   return true;
> -
> -  /* There is a obvious case that is not worthwhile and meaningless
> -to propagate the demand information:
> - local_dem
> -__
> -| |
> -   || |
> -   || |
> -|_|
> - reaching_out
> - Header is incompatible with reaching_out and the block is loop
> itself,
> - we don't backward propagate the local_dem since we can't avoid
> emit
> - vsetvl for the local_dem.  */
> -  edge e;
> -  edge_iterator ei;
> -  FOR_EACH_EDGE (e, ei, cfg_bb->succs)
> -   if (e->dest->index == cfg_bb->index)
> +  if (block_info.reaching_out.valid_or_dirty_p ())
> +   {
> + if (block_info.local_dem.compatible_p (block_info.reaching_out))
> +   {
> + /* Case 1 (Can backward propagate):
> +
> +bb0:
> +...
> +for (int i = 0; i < n; i++)
> +  {
> +vint16mf4_t v = __riscv_vle16_v_i16mf4 (in + i + 5,
> 7);
> +__riscv_vse16_v_i16mf4 (out + i + 5, v, 7);
> +  }
> +The local_dem is compatible with reaching_out. Such case
> is
> +worthwhile backward propagation.  */
> + return true;
> +   }
> + else
> +   {
> + /* Case 2 (Don't backward propagate):
> +   
> +   bb0:
> +   ...
> +   for (int i = 0; i < n; i++)
> + {
> +   vint16mf4_t v = __riscv_vle16_v_i16mf4 (in + i +
> 5, 7);
> +   __riscv_vse16_v_i16mf4 (out + i + 5, v, 7);
> +   vint16mf2_t v2 = __riscv_vle16_v_i16mf2 (in + i +
> 6, 8);
> +   __riscv_vse16_v_i16mf2 (out + i + 6, v, 8);
> + }
> +The local_dem is incompatible with reaching_out.
> +It makes no sense to backward propagate the local_dem
> since we
> +can't avoid VSETVL inside the loop.  */
> + return false;
> +   }
> +   }
> +  else
> +   {
> + gcc_assert (block_info.reaching_out.unknown_p ());
> + /* Case 3 (Don't backward propagate):
> +   
> +   bb0:
> +   ...
> +   for (int i = 0; i < n; i++)
> + {
> +   vint16mf4_t v = __riscv_vle16_v_i16mf4 (in + i + 5, 7);
> +   __riscv_vse16_v_i16mf4 (out + i + 5, v, 7);
> +   fn3 ();
> + }
> +   The local_dem is VALID, but the reaching_out is UNKNOWN.
> +   It makes no sense to backward propagate the local_dem since we
> +   can't avoid VSETVL inside the loop.  */
>   return false;
> +   }
>  }
>
>return true;
> --
> 2.36.3
>
>


Re: [PATCH] RISC-V: Fix wrong in_group flag in validate_change call function

2023-01-26 Thread Kito Cheng via Gcc-patches
committed, thanks.

On Tue, Jan 3, 2023 at 3:12 PM  wrote:

> From: Ju-Zhe Zhong 
>
> Since we only change insn which is not in group. The flag currently is not
> correct.
>
> gcc/ChangeLog:
>
> * config/riscv/riscv-vsetvl.cc (change_insn): Adjust in_group in
> validate_change.
>
> ---
>  gcc/config/riscv/riscv-vsetvl.cc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gcc/config/riscv/riscv-vsetvl.cc
> b/gcc/config/riscv/riscv-vsetvl.cc
> index 1afe76304fb..ad0457ed89d 100644
> --- a/gcc/config/riscv/riscv-vsetvl.cc
> +++ b/gcc/config/riscv/riscv-vsetvl.cc
> @@ -787,7 +787,7 @@ change_insn (rtx_insn *rinsn, rtx new_pat)
>print_rtl_single (dump_file, PATTERN (rinsn));
>  }
>
> -  validate_change (rinsn,  (rinsn), new_pat, true);
> +  validate_change (rinsn,  (rinsn), new_pat, false);
>
>if (dump_file)
>  {
> --
> 2.36.3
>
>


Re: [PATCH] RISC-V: Fix bugs of available condition.

2023-01-26 Thread Kito Cheng via Gcc-patches
committed, thanks.

On Tue, Jan 3, 2023 at 3:31 PM  wrote:

> From: Ju-Zhe Zhong 
>
> Suppose there are 2 demand infos:
>
> Demand 1: demand TAIL.
> Demand 2: not demand TAIL.
>
> If a block is demand 1, we should adjust this block is available both for
> demand 1 && 2.
> However, if a block is demand 2, we should only adjust this block is
> available for demand 2 only.
>
> gcc/ChangeLog:
>
> * config/riscv/riscv-vsetvl.cc (vector_insn_info::operator>=): Fix
> available condition.
>
> ---
>  gcc/config/riscv/riscv-vsetvl.cc | 6 ++
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/gcc/config/riscv/riscv-vsetvl.cc
> b/gcc/config/riscv/riscv-vsetvl.cc
> index 6dbaea32b03..52f0195980a 100644
> --- a/gcc/config/riscv/riscv-vsetvl.cc
> +++ b/gcc/config/riscv/riscv-vsetvl.cc
> @@ -1048,12 +1048,10 @@ vector_insn_info::operator>= (const
> vector_insn_info ) const
> }
>  }
>
> -  if (demand_p (DEMAND_TAIL_POLICY) && !other.demand_p
> (DEMAND_TAIL_POLICY)
> -  && get_ta () != other.get_ta ())
> +  if (!demand_p (DEMAND_TAIL_POLICY) && other.demand_p
> (DEMAND_TAIL_POLICY))
>  return false;
>
> -  if (demand_p (DEMAND_MASK_POLICY) && !other.demand_p
> (DEMAND_MASK_POLICY)
> -  && get_ma () != other.get_ma ())
> +  if (!demand_p (DEMAND_MASK_POLICY) && other.demand_p
> (DEMAND_MASK_POLICY))
>  return false;
>
>return true;
> --
> 2.36.3
>
>


Re: [PATCH] RISC-V: Fix inferior codegen for vse intrinsics.

2023-01-26 Thread Kito Cheng via Gcc-patches
committed, thanks.

On Thu, Dec 29, 2022 at 11:34 PM  wrote:

> From: Ju-Zhe Zhong 
>
> Currently we use pred_mov to to do the codegen for vse intrinsics.
> However, it
> generates inferior codegen when I am testing AVL model of VSETVL PASS
> using vse intrinsics.
>
> Consider this following code:
> void f2 (int * restrict in, int * restrict out, void * restrict mask_in,
> int n)
> {
>   vfloat32mf2_t v = __riscv_vle32_v_f32mf2 ((float *)(in + 1), 19);
>   __riscv_vse32_v_f32mf2 ((float *)(out + 1), v, 19);
>   vbool64_t mask = *(vbool64_t*)mask_in;
>   for (int i = 0; i < n; i++)
> {
>   vint16mf2_t v1 = __riscv_vle16_v_i16mf2 ((int16_t *)(in + i + 1),
> 19);
>   __riscv_vse16_v_i16mf2 ((int16_t *)(out + i + 1), v1, 19);
>
>   vint32mf2_t v2 = __riscv_vle32_v_i32mf2 ((int32_t *)(in + i + 2),
> 19);
>   __riscv_vse32_v_i32mf2 ((int32_t *)(out + i + 2), v2, 19);
>
>   vint32mf2_t v3 = __riscv_vle32_v_i32mf2_tumu (mask, v2, (int32_t
> *)(in + i + 200), 13);
>   __riscv_vse32_v_i32mf2 ((int32_t *)(out + i + 200), v2, 13);
>
>   vfloat64m1_t v4 = __riscv_vle64_v_f64m1_m (mask, (double *)(in + i +
> 300), 11);
>   __riscv_vse64_v_f64m1 ((double *)(out + i + 300), v4, 11);
>
>   vfloat64m1_t v5 = __riscv_vle64_v_f64m1_tum (mask, v4, (double *)(in
> + i + 500), 11);
>   __riscv_vse64_v_f64m1 ((double *)(out + i + 500), v5, 11);
>
>   vfloat64m1_t v6 = __riscv_vle64_v_f64m1_mu (mask, v5, (double *)(in
> + i + 600), 11);
>   __riscv_vse64_v_f64m1_m (mask, (double *)(out + i + 600), v6, 11);
>
>   vuint8mf4_t v7 = __riscv_vle8_v_u8mf4 ((uint8_t *)(in + i + 700),
> 11);
>   __riscv_vse8_v_u8mf4 ((uint8_t *)(out + i + 700), v7, 11);
> }
> }
>
> Before this patch:
> csrrt2,vlenb
> srlit2,t2,1
> sllis0,t2,2
> vsetvli zero,19,e16,mf2,ta,ma
> sub s0,s0,t2
> csrrt2,vlenb
> vle16.v v24,0(a3)
> mv  a4,a3
> vse16.v v24,0(a1)
> srlit2,t2,1
> add a2,a3,t6
> add s0,s0,sp
> vsetvli zero,19,e32,mf2,ta,ma
> addia3,a3,4
> vle32.v v24,0(a3)
> vsetvli zero,t0,e32,mf2,ta,ma
> vse32.v v24,0(s0)
> sllis0,t2,2
> sub s0,s0,t2
> add s0,s0,sp
> vsetvli t0,zero,e32,mf2,ta,ma
> vle32.v v24,0(s0)
> mv  s0,t2
> sllit2,t2,2
> mv  a5,a1
> vsetvli zero,19,e32,mf2,ta,ma
> addia1,a1,4
> sub t2,t2,s0
> vse32.v v24,0(a1)
> add t2,t2,sp
> vsetvli t0,zero,e32,mf2,ta,ma
> addit1,a5,796
> vle32.v v24,0(t2)
> addit5,a4,1196
> addia7,a5,1196
> addit4,a4,1996
> addia6,a5,1996
> vsetvli zero,13,e32,mf2,ta,ma
> add a4,a4,t3
> vse32.v v24,0(t1)
> add a5,a5,t3
> vsetvli zero,11,e64,m1,tu,mu
> vle64.v v24,0(t5),v0.t
> vse64.v v24,0(a7)
> vle64.v v24,0(t4),v0.t
> vse64.v v24,0(a6)
> vle64.v v24,0(a4),v0.t
> vse64.v v24,0(a5),v0.t
> vsetvli zero,11,e8,mf4,ta,ma
> vle8.v  v24,0(a2)
> vse8.v  v24,0(a2)
> bne a0,a3,.L8
> csrrt0,vlenb
> sllit1,t0,1
> add sp,sp,t1
> lw  s0,12(sp)
> addisp,sp,16
> jr  ra
>
> We are generating redundant spilling codes.
> Here we introduce a dedicated pred_store pattern for vse intrinsics like
> maskstore in ARM SVE.
>
> After this patch:
> vsetvli zero,19,e16,mf2,ta,ma
> mv  a5,a4
> vle16.v v24,0(a0)
> mv  a3,a0
> vse16.v 19,0(a4)
> addit1,a4,796
> vsetvli zero,19,e32,mf2,ta,ma
> addia0,a0,4
> addia4,a4,4
> vle32.v v24,0(a0)
> addit0,a3,1196
> vse32.v 19,0(a4)
> addia7,a5,1196
> addit6,a3,1996
> addia6,a5,1996
> add t5,a3,t4
> vsetvli zero,13,e32,mf2,ta,ma
> add a2,a5,t4
> vse32.v 13,0(t1)
> add a3,a3,t3
> vsetvli zero,11,e64,m1,tu,mu
> add a5,a5,t3
> vle64.v v24,0(t0),v0.t
> vse64.v 11,0(a7)
> vle64.v v24,0(t6),v0.t
> vse64.v 11,0(a6)
> vle64.v v24,0(t5),v0.t
> vse64.v 11,0(a2),v0.t
> vsetvli zero,11,e8,mf4,ta,ma
> vle8.v  v24,0(a3)
> vse8.v  11,0(a5)
> bne a1,a4,.L8
> .L6:
> ret
>
> gcc/ChangeLog:
>
> * config/riscv/riscv-vector-builtins-bases.cc (class loadstore):
> use pred_store for vse.
> * config/riscv/riscv-vector-builtins.cc
> (function_expander::add_mem_operand): Refine function.
> (function_expander::use_contiguous_load_insn): Adjust new
> implementation.
> (function_expander::use_contiguous_store_insn): Ditto.
> * 

Re: [PATCH] RISC-V: Fix bugs for refine vsetvl a5, zero into vsetvl zero, zero incorrectly

2023-01-26 Thread Kito Cheng via Gcc-patches
committed, thanks.

On Tue, Jan 3, 2023 at 2:56 PM  wrote:

> From: Ju-Zhe Zhong 
>
> Currently we support this optimization:
>
> bb 0:
>  vsetvli a5,zero,e32,mf2
> bb 1:
>  vsetvli a5,zero,e64,m1 --> vsetvli zero,zero,e64,m1
>
> According RVV ISA, we can do this optimization only if both RATIO and AVL
> are equal.
> However, current VSETVL PASS missed the check of AVL. This patch add this
> condition
> check to fix bugs.
>
> gcc/ChangeLog:
>
> * config/riscv/riscv-vsetvl.cc
> (vector_infos_manager::all_same_avl_p): New function.
> (pass_vsetvl::can_refine_vsetvl_p): Add AVL check.
> (pass_vsetvl::commit_vsetvls): Ditto.
> * config/riscv/riscv-vsetvl.h: New function declaration.
>
> ---
>  gcc/config/riscv/riscv-vsetvl.cc | 35 
>  gcc/config/riscv/riscv-vsetvl.h  |  3 +++
>  2 files changed, 34 insertions(+), 4 deletions(-)
>
> diff --git a/gcc/config/riscv/riscv-vsetvl.cc
> b/gcc/config/riscv/riscv-vsetvl.cc
> index ce1e9e3609f..1afe76304fb 100644
> --- a/gcc/config/riscv/riscv-vsetvl.cc
> +++ b/gcc/config/riscv/riscv-vsetvl.cc
> @@ -1440,6 +1440,29 @@ vector_infos_manager::all_same_ratio_p (sbitmap
> bitdata) const
>return true;
>  }
>
> +bool
> +vector_infos_manager::all_same_avl_p (const basic_block cfg_bb,
> + sbitmap bitdata) const
> +{
> +  if (bitmap_empty_p (bitdata))
> +return false;
> +
> +  const auto _info = vector_block_infos[cfg_bb->index];
> +  if (!block_info.local_dem.demand_p (DEMAND_AVL))
> +return true;
> +
> +  avl_info avl = block_info.local_dem.get_avl_info ();
> +  unsigned int bb_index;
> +  sbitmap_iterator sbi;
> +
> +  EXECUTE_IF_SET_IN_BITMAP (bitdata, 0, bb_index, sbi)
> +  {
> +if (vector_exprs[bb_index]->get_avl_info () != avl)
> +  return false;
> +  }
> +  return true;
> +}
> +
>  size_t
>  vector_infos_manager::expr_set_num (sbitmap bitdata) const
>  {
> @@ -2113,6 +2136,10 @@ pass_vsetvl::can_refine_vsetvl_p (const basic_block
> cfg_bb, uint8_t ratio) const
> m_vector_manager->vector_avin[cfg_bb->index]))
>  return false;
>
> +  if (!m_vector_manager->all_same_avl_p (
> +   cfg_bb, m_vector_manager->vector_avin[cfg_bb->index]))
> +return false;
> +
>size_t expr_id
>  = bitmap_first_set_bit (m_vector_manager->vector_avin[cfg_bb->index]);
>if (m_vector_manager->vector_exprs[expr_id]->get_ratio () != ratio)
> @@ -2227,11 +2254,11 @@ pass_vsetvl::commit_vsetvls (void)
>
>   insn_info *insn = require->get_insn ();
>   vector_insn_info prev_info = vector_insn_info ();
> - if (m_vector_manager->all_same_ratio_p (
> -   m_vector_manager->vector_avout[eg->src->index]))
> + sbitmap bitdata =
> m_vector_manager->vector_avout[eg->src->index];
> + if (m_vector_manager->all_same_ratio_p (bitdata)
> + && m_vector_manager->all_same_avl_p (eg->dest, bitdata))
> {
> - size_t first = bitmap_first_set_bit (
> -   m_vector_manager->vector_avout[eg->src->index]);
> + size_t first = bitmap_first_set_bit (bitdata);
>   prev_info = *m_vector_manager->vector_exprs[first];
> }
>
> diff --git a/gcc/config/riscv/riscv-vsetvl.h
> b/gcc/config/riscv/riscv-vsetvl.h
> index 6f27004fab1..c8218a6ff00 100644
> --- a/gcc/config/riscv/riscv-vsetvl.h
> +++ b/gcc/config/riscv/riscv-vsetvl.h
> @@ -333,6 +333,9 @@ public:
>/* Get all relaxer expression id for corresponding vector info.  */
>auto_vec get_all_available_exprs (const vector_insn_info &)
> const;
>
> +  /* Return true if all expression set in bitmap are same AVL.  */
> +  bool all_same_avl_p (const basic_block, sbitmap) const;
> +
>/* Return true if all expression set in bitmap are same ratio.  */
>bool all_same_ratio_p (sbitmap) const;
>
> --
> 2.36.3
>
>


Re: [PATCH] RISC-V: Fix vsetivli instruction asm for IMM AVL

2023-01-26 Thread Kito Cheng via Gcc-patches
committed, thanks.

On Tue, Jan 3, 2023 at 9:40 AM  wrote:

> From: Ju-Zhe Zhong 
>
> Notice that we should used vsetivli zero,4 instead of vsetvli zero,4
> for IMM AVL (0 ~ 31) according to RVV ISA.
>
> This patch fix vsetivli instruction asm bug.
>
> gcc/ChangeLog:
>
> * config/riscv/vector.md:
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/riscv/rvv/base/vle-constraint-1.c:
>
> ---
>  gcc/config/riscv/vector.md   |  2 +-
>  .../gcc.target/riscv/rvv/base/vle-constraint-1.c | 12 ++--
>  2 files changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/gcc/config/riscv/vector.md b/gcc/config/riscv/vector.md
> index 3d0174f98a2..4e93b7fead5 100644
> --- a/gcc/config/riscv/vector.md
> +++ b/gcc/config/riscv/vector.md
> @@ -561,7 +561,7 @@
> (match_operand 3 "const_int_operand" "i")
> (match_operand 4 "const_int_operand" "i")]
> UNSPEC_VSETVL))]
>"TARGET_VECTOR"
> -  "vsetvli\tzero,%0,e%1,%m2,t%p3,m%p4"
> +  "vset%i0vli\tzero,%0,e%1,%m2,t%p3,m%p4"
>[(set_attr "type" "vsetvl")
> (set_attr "mode" "")])
>
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/vle-constraint-1.c
> b/gcc/testsuite/gcc.target/riscv/rvv/base/vle-constraint-1.c
> index b7cf98bfd9f..8d01e2082f8 100644
> --- a/gcc/testsuite/gcc.target/riscv/rvv/base/vle-constraint-1.c
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/vle-constraint-1.c
> @@ -6,7 +6,7 @@
>
>  /*
>  ** f1:
> -** vsetvli\tzero,4,e32,m1,tu,ma
> +** vsetivli\tzero,4,e32,m1,tu,ma
>  ** vle32\.v\tv[0-9]+,0\([a-x0-9]+\)
>  ** vle32\.v\tv[0-9]+,0\([a-x0-9]+\)
>  ** vse32\.v\tv[0-9]+,0\([a-x0-9]+\)
> @@ -23,7 +23,7 @@ void f1 (float * in, float *out)
>  ** f2:
>  ** vsetvli\t[a-x0-9]+,zero,e8,mf4,ta,ma
>  ** vlm.v\tv[0-9]+,0\([a-x0-9]+\)
> -** vsetvli\tzero,4,e32,m1,ta,ma
> +** vsetivli\tzero,4,e32,m1,ta,ma
>  ** vle32.v\tv[0-9]+,0\([a-x0-9]+\),v0.t
>  ** vse32.v\tv[0-9]+,0\([a-x0-9]+\)
>  ** ret
> @@ -41,7 +41,7 @@ void f2 (float * in, float *out)
>  ** f3:
>  ** vsetvli\t[a-x0-9]+,zero,e8,mf4,ta,ma
>  ** vlm.v\tv[0-9]+,0\([a-x0-9]+\)
> -** vsetvli\tzero,4,e32,m1,tu,mu
> +** vsetivli\tzero,4,e32,m1,tu,mu
>  ** vle32\.v\tv[0-9]+,0\([a-x0-9]+\)
>  ** vle32.v\tv[0-9]+,0\([a-x0-9]+\),v0.t
>  ** vse32.v\tv[0-9]+,0\([a-x0-9]+\)
> @@ -58,7 +58,7 @@ void f3 (float * in, float *out)
>
>  /*
>  ** f4:
> -** vsetvli\tzero,4,e8,mf8,tu,ma
> +** vsetivli\tzero,4,e8,mf8,tu,ma
>  ** vle8\.v\tv[0-9]+,0\([a-x0-9]+\)
>  ** vle8\.v\tv[0-9]+,0\([a-x0-9]+\)
>  ** vse8\.v\tv[0-9]+,0\([a-x0-9]+\)
> @@ -75,7 +75,7 @@ void f4 (int8_t * in, int8_t *out)
>  ** f5:
>  ** vsetvli\t[a-x0-9]+,zero,e8,mf8,ta,ma
>  ** vlm.v\tv[0-9]+,0\([a-x0-9]+\)
> -** vsetvli\tzero,4,e8,mf8,ta,ma
> +** vsetivli\tzero,4,e8,mf8,ta,ma
>  ** vle8.v\tv[0-9]+,0\([a-x0-9]+\),v0.t
>  ** vse8.v\tv[0-9]+,0\([a-x0-9]+\)
>  ** ret
> @@ -93,7 +93,7 @@ void f5 (int8_t * in, int8_t *out)
>  ** f6:
>  ** vsetvli\t[a-x0-9]+,zero,e8,mf8,ta,ma
>  ** vlm.v\tv[0-9]+,0\([a-x0-9]+\)
> -** vsetvli\tzero,4,e8,mf8,tu,mu
> +** vsetivli\tzero,4,e8,mf8,tu,mu
>  ** vle8\.v\tv[0-9]+,0\([a-x0-9]+\)
>  ** vle8.v\tv[0-9]+,0\([a-x0-9]+\),v0.t
>  ** vse8.v\tv[0-9]+,0\([a-x0-9]+\)
> --
> 2.36.3
>
>


Re: [PATCH] RISC-V: Fix pointer tree type for store pointer.

2023-01-26 Thread Kito Cheng via Gcc-patches
committed, thanks.

On Wed, Dec 28, 2022 at 1:11 PM  wrote:

> From: Ju-Zhe Zhong 
>
> For store intrinsic,
> the function type should be void store (T *...) instead of void store
> (const T *...)
>
> gcc/ChangeLog:
>
> * config/riscv/riscv-vector-builtins.cc: Change to scalar pointer.
>
> ---
>  gcc/config/riscv/riscv-vector-builtins.cc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gcc/config/riscv/riscv-vector-builtins.cc
> b/gcc/config/riscv/riscv-vector-builtins.cc
> index 9170776f979..e39bfea9636 100644
> --- a/gcc/config/riscv/riscv-vector-builtins.cc
> +++ b/gcc/config/riscv/riscv-vector-builtins.cc
> @@ -158,7 +158,7 @@ static CONSTEXPR const rvv_arg_type_info
> scalar_const_ptr_args[]
>
>  /* A list of args for void func (scalar_type *, vector_type) function.  */
>  static CONSTEXPR const rvv_arg_type_info scalar_ptr_args[]
> -  = {rvv_arg_type_info (RVV_BASE_scalar_const_ptr),
> +  = {rvv_arg_type_info (RVV_BASE_scalar_ptr),
>   rvv_arg_type_info (RVV_BASE_vector), rvv_arg_type_info_end};
>
>  /* A list of none preds that will be registered for intrinsic functions.
> */
> --
> 2.36.3
>
>


Re: [PATCH] riscv: Enable -fasynchronous_unwind_tables by default on Linux

2023-01-26 Thread Kito Cheng via Gcc-patches
OK, thanks for this :)

On Fri, Jan 27, 2023 at 12:40 AM Andreas Schwab via Gcc-patches <
gcc-patches@gcc.gnu.org> wrote:

> This follows the example of aarch64.
>
> gcc/:
> * common/config/riscv/riscv-common.cc
> (riscv_option_optimization_table)
> [TARGET_DEFAULT_ASYNC_UNWIND_TABLES]: Enable
> -fasynchronous_unwind_tables and -funwind-tables.
> * config.gcc (riscv*-*-linux*): Define
> TARGET_DEFAULT_ASYNC_UNWIND_TABLES.
> ---
>  gcc/common/config/riscv/riscv-common.cc | 4 
>  gcc/config.gcc  | 1 +
>  2 files changed, 5 insertions(+)
>
> diff --git a/gcc/common/config/riscv/riscv-common.cc
> b/gcc/common/config/riscv/riscv-common.cc
> index 2e3116e7673..616e2f897b9 100644
> --- a/gcc/common/config/riscv/riscv-common.cc
> +++ b/gcc/common/config/riscv/riscv-common.cc
> @@ -1756,6 +1756,10 @@ static const struct default_options
> riscv_option_optimization_table[] =
>{
>  { OPT_LEVELS_1_PLUS, OPT_fsection_anchors, NULL, 1 },
>  { OPT_LEVELS_2_PLUS, OPT_free, NULL, 1 },
> +#if TARGET_DEFAULT_ASYNC_UNWIND_TABLES == 1
> +{ OPT_LEVELS_ALL, OPT_fasynchronous_unwind_tables, NULL, 1 },
> +{ OPT_LEVELS_ALL, OPT_funwind_tables, NULL, 1},
> +#endif
>  { OPT_LEVELS_NONE, 0, NULL, 0 }
>};
>
> diff --git a/gcc/config.gcc b/gcc/config.gcc
> index 89f56047cfe..744b46fb3b0 100644
> --- a/gcc/config.gcc
> +++ b/gcc/config.gcc
> @@ -2417,6 +2417,7 @@ riscv*-*-linux*)
> *) echo "Unknown value for enable_multilib"; exit 1
> esac
> tmake_file="${tmake_file} riscv/t-riscv riscv/t-linux"
> +   tm_defines="${tm_defines} TARGET_DEFAULT_ASYNC_UNWIND_TABLES=1"
> gnu_ld=yes
> gas=yes
> case $target in
> --
> 2.39.1
>
>
> --
> Andreas Schwab, SUSE Labs, sch...@suse.de
> GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
> "And now for something completely different."
>


[GCC-11][committed] pru: Fix CLZ expansion for QI and HI modes

2023-01-26 Thread Dimitar Dimitrov
The recent gcc.dg/tree-ssa/clz-char.c test case failed for PRU target,
exposing a wrong code generation bug in the PRU backend.  The "clz"
pattern did not produce correct output for QI and HI input operand
modes.  SI mode is ok.

The "clz" pattern is expanded to an LMBD instruction to get the
left-most bit position having value "1".  In turn, to get the correct
"clz" value, that bit position must be subtracted from the MSB bit
position of the input operand.  The old behaviour of hard-coding 31
for MSB bit position is wrong.

The LMBD instruction returns 32 if input operand is zero, irrespective
of its register mode.  This maps nicely for SI mode, where the "clz"
pattern outputs -1.  It also leads to peculiar (but valid!) output
values from the "clz" pattern for QI and HI zero-valued inputs.

The corresponding commit in trunk contains two new test cases, which
have been removed here because they depend on r13-5195-g4798080d4a3530.
Regtested for pru-unknown-elf.

gcc/ChangeLog:

* config/pru/pru.h (CLZ_DEFINED_VALUE_AT_ZERO): Fix value for QI
and HI input modes.
* config/pru/pru.md (clz): Fix generated code for QI and HI
input modes.

Signed-off-by: Dimitar Dimitrov 
(cherry picked from commit c517295940a23db8ca165dfd5d0edea4457eda49)
---
 gcc/config/pru/pru.h  |  5 +++--
 gcc/config/pru/pru.md | 15 ---
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/gcc/config/pru/pru.h b/gcc/config/pru/pru.h
index 4c35a7d7ee3..41260b9450d 100644
--- a/gcc/config/pru/pru.h
+++ b/gcc/config/pru/pru.h
@@ -562,8 +562,9 @@ do {
\
 
 #define CASE_VECTOR_MODE Pmode
 
-/* See definition of clz pattern for rationale of value -1.  */
-#define CLZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) ((VALUE) = -1, 2)
+/* See definition of clz pattern for rationale of the value.  */
+#define CLZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) \
+   ((VALUE) = GET_MODE_BITSIZE (MODE) - 1 - 32, 2)
 
 /* Jumps are cheap on PRU.  */
 #define LOGICAL_OP_NON_SHORT_CIRCUIT   0
diff --git a/gcc/config/pru/pru.md b/gcc/config/pru/pru.md
index e6cfa8ec3bf..c5661adb6c4 100644
--- a/gcc/config/pru/pru.md
+++ b/gcc/config/pru/pru.md
@@ -1035,8 +1035,16 @@ (define_insn "pru_halt"
   [(set_attr "type" "control")])
 
 ;; Count Leading Zeros implemented using LMBD.
-;; LMBD returns 32 if bit value is not present, and we subtract 31 to get CLZ.
-;; Hence we get a defined value -1 for CLZ_DEFINED_VALUE_AT_ZERO.
+;;
+;; LMBD returns 32 if bit value is not present, for any kind of input MODE.
+;; The LMBD's search result for a "1" bit is subtracted from the
+;; mode bit size minus one, in order to get CLZ.
+;;
+;; Hence for SImode we get a defined value -1 for CLZ_DEFINED_VALUE_AT_ZERO.
+;;
+;; The QImode and HImode defined values for zero inputs end up to be
+;; non-standard (-25 and -17).  But this is considered acceptable in
+;; order to keep the CLZ expansion to only two instructions.
 (define_expand "clz2"
   [(set (match_operand:QISI 0 "register_operand")
(clz:QISI (match_operand:QISI 1 "register_operand")))]
@@ -1047,7 +1055,8 @@ (define_expand "clz2"
   rtx tmpval = gen_reg_rtx (mode);
 
   emit_insn (gen_pru_lmbd (mode, tmpval, src, const1_rtx));
-  emit_insn (gen_sub3_insn (dst, GEN_INT (31), tmpval));
+  int msb_bitn = GET_MODE_BITSIZE (mode) - 1;
+  emit_insn (gen_sub3_insn (dst, GEN_INT (msb_bitn), tmpval));
   DONE;
 })
 
-- 
2.39.1



[GCC-12][committed] pru: Fix CLZ expansion for QI and HI modes

2023-01-26 Thread Dimitar Dimitrov
The recent gcc.dg/tree-ssa/clz-char.c test case failed for PRU target,
exposing a wrong code generation bug in the PRU backend.  The "clz"
pattern did not produce correct output for QI and HI input operand
modes.  SI mode is ok.

The "clz" pattern is expanded to an LMBD instruction to get the
left-most bit position having value "1".  In turn, to get the correct
"clz" value, that bit position must be subtracted from the MSB bit
position of the input operand.  The old behaviour of hard-coding 31
for MSB bit position is wrong.

The LMBD instruction returns 32 if input operand is zero, irrespective
of its register mode.  This maps nicely for SI mode, where the "clz"
pattern outputs -1.  It also leads to peculiar (but valid!) output
values from the "clz" pattern for QI and HI zero-valued inputs.

The corresponding commit in trunk contains two new test cases, which
have been removed here because they depend on r13-5195-g4798080d4a3530.
Regtested for pru-unknown-elf.

gcc/ChangeLog:

* config/pru/pru.h (CLZ_DEFINED_VALUE_AT_ZERO): Fix value for QI
and HI input modes.
* config/pru/pru.md (clz): Fix generated code for QI and HI
input modes.

Signed-off-by: Dimitar Dimitrov 
(cherry picked from commit c517295940a23db8ca165dfd5d0edea4457eda49)
---
 gcc/config/pru/pru.h  |  5 +++--
 gcc/config/pru/pru.md | 15 ---
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/gcc/config/pru/pru.h b/gcc/config/pru/pru.h
index 4c35a7d7ee3..41260b9450d 100644
--- a/gcc/config/pru/pru.h
+++ b/gcc/config/pru/pru.h
@@ -562,8 +562,9 @@ do {
\
 
 #define CASE_VECTOR_MODE Pmode
 
-/* See definition of clz pattern for rationale of value -1.  */
-#define CLZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) ((VALUE) = -1, 2)
+/* See definition of clz pattern for rationale of the value.  */
+#define CLZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) \
+   ((VALUE) = GET_MODE_BITSIZE (MODE) - 1 - 32, 2)
 
 /* Jumps are cheap on PRU.  */
 #define LOGICAL_OP_NON_SHORT_CIRCUIT   0
diff --git a/gcc/config/pru/pru.md b/gcc/config/pru/pru.md
index e6cfa8ec3bf..c5661adb6c4 100644
--- a/gcc/config/pru/pru.md
+++ b/gcc/config/pru/pru.md
@@ -1035,8 +1035,16 @@ (define_insn "pru_halt"
   [(set_attr "type" "control")])
 
 ;; Count Leading Zeros implemented using LMBD.
-;; LMBD returns 32 if bit value is not present, and we subtract 31 to get CLZ.
-;; Hence we get a defined value -1 for CLZ_DEFINED_VALUE_AT_ZERO.
+;;
+;; LMBD returns 32 if bit value is not present, for any kind of input MODE.
+;; The LMBD's search result for a "1" bit is subtracted from the
+;; mode bit size minus one, in order to get CLZ.
+;;
+;; Hence for SImode we get a defined value -1 for CLZ_DEFINED_VALUE_AT_ZERO.
+;;
+;; The QImode and HImode defined values for zero inputs end up to be
+;; non-standard (-25 and -17).  But this is considered acceptable in
+;; order to keep the CLZ expansion to only two instructions.
 (define_expand "clz2"
   [(set (match_operand:QISI 0 "register_operand")
(clz:QISI (match_operand:QISI 1 "register_operand")))]
@@ -1047,7 +1055,8 @@ (define_expand "clz2"
   rtx tmpval = gen_reg_rtx (mode);
 
   emit_insn (gen_pru_lmbd (mode, tmpval, src, const1_rtx));
-  emit_insn (gen_sub3_insn (dst, GEN_INT (31), tmpval));
+  int msb_bitn = GET_MODE_BITSIZE (mode) - 1;
+  emit_insn (gen_sub3_insn (dst, GEN_INT (msb_bitn), tmpval));
   DONE;
 })
 
-- 
2.39.1



Re: [PATCH] tree: Fix up tree_code_{length,type}

2023-01-26 Thread Patrick Palka via Gcc-patches
On Thu, 26 Jan 2023, Jakub Jelinek wrote:

> On Thu, Jan 26, 2023 at 09:45:35AM -0500, Patrick Palka via Gcc-patches wrote:
> > > +#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
> > > +#define END_OF_BASE_TREE_CODES tcc_exceptional,
> > > +
> > > +
> > >  /* Class of tree given its code.  */
> > > -extern const enum tree_code_class tree_code_type[];
> > > +constexpr enum tree_code_class tree_code_type[] = {
> > > +#include "all-tree.def"
> > > +};
> > > +
> > > +#undef DEFTREECODE
> > > +#undef END_OF_BASE_TREE_CODES
> > >  
> > >  /* Each tree code class has an associated string representation.
> > > These must correspond to the tree_code_class entries.  */
> > >  extern const char *const tree_code_class_strings[];
> > >  
> > >  /* Number of argument-words in each kind of tree-node.  */
> > > -extern const unsigned char tree_code_length[];
> > > +
> > > +#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
> > > +#define END_OF_BASE_TREE_CODES 0,
> > > +constexpr unsigned char tree_code_length[] = {
> > > +#include "all-tree.def"
> > > +};
> > > +
> > > +#undef DEFTREECODE
> > > +#undef END_OF_BASE_TREE_CODES
> > 
> > IIUC defining these globals as non-inline constexpr gives them internal
> > linkage, and so each TU contains its own unique copy of these globals.
> > This bloats cc1plus by a tiny bit and is technically an ODR violation
> > because some inline functions such as tree_class_check also ODR-use
> > these variables and so each defn of tree_class_check will refer to a
> > "different" tree_code_class.  Since inline variables are a C++17
> > feature, I guess we could fix this by defining the globals the old way
> > before C++17 and as inline constexpr otherwise?
> 
> And I'd argue with the tiny bit.
> In my x86_64-linux cc1plus from today, I see 193 _ZL16tree_code_length vars,
> 374 bytes each, and 324 _ZL14tree_code_type vars, 1496 bytes each.
> So, that means waste of 555016 .rodata bytes, plus being highly non-cache
> friendly.
> 
> The following patch does that.
> 
> So far tested on x86_64-linux in my -O0 working tree (system gcc 12
> compiler) where .rodata shrunk with the patch by 928896 bytes, in last
> stage of a bootstrapped tree (built by today's prev-gcc) where .rodata
> shrunk by 561728 bytes (in neither case .text or most other sections
> changed sizes) and on powerpc64le-linux --disable-bootstrap
> (system gcc 4.8.5) to test also the non-C++17 case.

LGTM FWIW.  On a related note I noticed the function
tree.h:tree_operand_length is declared static and is then used in the
non-static inline functions tree_operand_check etc, which seems to be
also be a (harmless) ODR violation?

We probably should do s/static inline/inline throughout the header files
at some point, which'd hopefully reduce the size of and speed up stage1
cc1plus.

> 
> Ok for trunk if it passes full bootstrap/regtest?
> 
> BTW, wonder if tree_code_type couldn't be an array of unsigned char
> elements rather than enum tree_code_class and we'd then cast it
> to the enum in the macro, that would shrink that array from 1496 bytes
> to 374.  Of course, that sounds like stage1 material.
> 
> 2023-01-26  Patrick Palka  
>   Jakub Jelinek  
> 
>   * tree-core.h (tree_code_type, tree_code_length): For
>   C++17 and later, add inline keyword, otherwise don't define
>   the arrays, but declare extern arrays.
>   * tree.cc (tree_code_type, tree_code_length): Define these
>   arrays for C++14 and older.
> 
> --- gcc/tree-core.h.jj2023-01-02 09:32:31.188158094 +0100
> +++ gcc/tree-core.h   2023-01-26 16:02:34.212113251 +0100
> @@ -2284,17 +2284,20 @@ struct floatn_type_info {
>  /* Matrix describing the structures contained in a given tree code.  */
>  extern bool tree_contains_struct[MAX_TREE_CODES][64];
>  
> +/* Class of tree given its code.  */
> +#if __cpp_inline_variables >= 201606L
>  #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
>  #define END_OF_BASE_TREE_CODES tcc_exceptional,
>  
> -
> -/* Class of tree given its code.  */
> -constexpr enum tree_code_class tree_code_type[] = {
> +constexpr inline enum tree_code_class tree_code_type[] = {
>  #include "all-tree.def"
>  };
>  
>  #undef DEFTREECODE
>  #undef END_OF_BASE_TREE_CODES
> +#else
> +extern const enum tree_code_class tree_code_type[];
> +#endif
>  
>  /* Each tree code class has an associated string representation.
> These must correspond to the tree_code_class entries.  */
> @@ -2302,14 +2305,18 @@ extern const char *const tree_code_class
>  
>  /* Number of argument-words in each kind of tree-node.  */
>  
> +#if __cpp_inline_variables >= 201606L
>  #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
>  #define END_OF_BASE_TREE_CODES 0,
> -constexpr unsigned char tree_code_length[] = {
> +constexpr inline unsigned char tree_code_length[] = {
>  #include "all-tree.def"
>  };
>  
>  #undef DEFTREECODE
>  #undef END_OF_BASE_TREE_CODES
> +#else
> +extern const unsigned char tree_code_length[];
> +#endif
>  
>  /* 

Re: realpath() patch to fix symlinks resolution for win32

2023-01-26 Thread i.nixman--- via Gcc-patches



hello,

could someone look at patch attached please?

https://gcc.gnu.org/pipermail/gcc-patches/2023-January/610147.html


Re: libquadmath fix for 94756 and 87204

2023-01-26 Thread i.nixman--- via Gcc-patches

hello,

could someone look at the patch attached please?

https://gcc.gnu.org/pipermail/gcc-patches/2023-January/610392.html


Re: [PATCH] c++: Define built-in for std::tuple_element [PR100157]

2023-01-26 Thread Jason Merrill via Gcc-patches

On 1/25/23 15:35, Patrick Palka wrote:

On Tue, 17 Jan 2023, Jason Merrill wrote:


On 1/9/23 14:25, Patrick Palka via Gcc-patches wrote:

On Mon, 9 Jan 2023, Patrick Palka wrote:


On Wed, 5 Oct 2022, Patrick Palka wrote:


On Thu, 7 Jul 2022, Jonathan Wakely via Gcc-patches wrote:


This adds a new built-in to replace the recursive class template
instantiations done by traits such as std::tuple_element and
std::variant_alternative. The purpose is to select the Nth type from a
list of types, e.g. __builtin_type_pack_element(1, char, int, float)
is
int.

For a pathological example tuple_element_t<1000, tuple<2000 types...>>
the compilation time is reduced by more than 90% and the memory  used
by
the compiler is reduced by 97%. In realistic examples the gains will
be
much smaller, but still relevant.

Clang has a similar built-in, __type_pack_element, but that's
a
"magic template" built-in using <> syntax, which GCC doesn't support.
So
this provides an equivalent feature, but as a built-in function using
parens instead of <>. I don't really like the name "type pack element"
(it gives you an element from a pack of types) but the
semi-consistency
with Clang seems like a reasonable argument in favour of keeping the
name. I'd be open to alternative names though, e.g. __builtin_nth_type
or __builtin_type_at_index.


Rather than giving the trait a different name from __type_pack_element,
I wonder if we could just special case cp_parser_trait to expect <>
instead of parens for this trait?

Btw the frontend recently got a generic TRAIT_TYPE tree code, which gets
rid of much of the boilerplate of adding a new type-yielding built-in
trait, see e.g. cp-trait.def.


Here's a tested patch based on Jonathan's original patch that implements
the built-in in terms of TRAIT_TYPE, names it __type_pack_element
instead of __builtin_type_pack_element, and treats invocations of it
like a template-id instead of a call (to match Clang).

-- >8 --

Subject: [PATCH] c++: Define built-in for std::tuple_element [PR100157]

This adds a new built-in to replace the recursive class template
instantiations done by traits such as std::tuple_element and
std::variant_alternative.  The purpose is to select the Nth type from a
list of types, e.g. __type_pack_element<1, char, int, float> is int.
We implement it as a special kind of TRAIT_TYPE.

For a pathological example tuple_element_t<1000, tuple<2000 types...>>
the compilation time is reduced by more than 90% and the memory  used by
the compiler is reduced by 97%.  In realistic examples the gains will be
much smaller, but still relevant.

Unlike the other built-in traits, __type_pack_element uses template-id
syntax instead of call syntax and is SFINAE-enabled, matching Clang's
implementation.  And like the other built-in traits, it's not mangleable
so we can't use it directly in function signatures.

Some caveats:

* Clang's version of the built-in seems to act like a "magic template"
  that can e.g. be used as a template template argument.  For
simplicity
  we implement it in a more ad-hoc way.
* Our parsing of the <>'s in __type_pack_element<...> is currently
  rudimentary and doesn't try to disambiguate a trailing >> vs > >
  as cp_parser_enclosed_template_argument_list does.


Hmm, this latter caveat turns out to be inconvenient (for code such as
type_pack_element3.C) and admits an easy workaround inspired by what
cp_parser_enclosed_template_argument_list does.

v2: Consider the >> in __type_pack_element<0, int, char>> to be two >'s.
  Handle non-type TRAIT_TYPE_TYPE1 in strip_typedefs (for sake of
  CPTK_TYPE_PACK_ELEMENT).


Why not use cp_parser_enclosed_template_argument_list directly?


If we used cp_parser_enclosed_template_argument_list we would then need
to convert the returned TREE_VEC into a TREE_LIST and also diagnose
argument kind mismatches (i.e. verify the first argument is an
expression and the rest are types).  It seemed like more complexity
overall then just duplicating the >> splitting logic, but I can do that
if you prefer?


I think I would prefer that, parser stuff can be pretty subtle.

Instead of turning the TREE_VEC into a TREE_LIST, we could handle 
TREE_VEC as a trait operand?



-- >8 --

Subject: [PATCH] c++: Define built-in for std::tuple_element [PR100157]

This adds a new built-in to replace the recursive class template
instantiations done by traits such as std::tuple_element and
std::variant_alternative.  The purpose is to select the Nth type from a
list of types, e.g. __type_pack_element<1, char, int, float> is int.
We implement it as a special kind of TRAIT_TYPE.

For a pathological example tuple_element_t<1000, tuple<2000 types...>>
the compilation time is reduced by more than 90% and the memory  used by
the compiler is reduced by 97%.  In realistic examples the gains will be
much smaller, but still relevant.

Unlike the other built-in traits, __type_pack_element uses template-id
syntax instead of call syntax and is 

Re: [PATCH 2/2] tree-object-size: More consistent behaviour with flex arrays

2023-01-26 Thread Qing Zhao via Gcc-patches


> On Jan 26, 2023, at 12:16 PM, Siddhesh Poyarekar  wrote:
> 
> On 2023-01-26 11:20, Qing Zhao wrote:
>> Hi, Siddhesh,
>> Thanks a lot for this patch, after -fstrict-flex-array functionality has 
>> been added into GCC,
>>  I think that making the tree-object-size to have consistent behavior with 
>> flex arrays is a
>> valuable and natural work that need to be added.
>> I also like the comments you added into tree-object-size.cc, making the code 
>> much easier to be understood.
>> Minor comments below:
>>> On Dec 21, 2022, at 5:25 PM, Siddhesh Poyarekar  wrote:
>>> 
>>> The tree object size pass tries to fail when it detects a flex array in
>>> the struct, but it ends up doing the right thing only when the flex
>>> array is in the outermost struct.  For nested cases (such as arrays
>>> nested in a union or an inner struct), it ends up taking whatever value
>>> the flex array is declared with, using zero for the standard flex array,
>>> i.e. [].
>>> 
>>> Rework subobject size computation to make it more consistent across the
>>> board, honoring -fstrict-flex-arrays.  With this change, any array at
>>> the end of the struct will end up causing __bos to use the allocated
>>> value of the outer object, bailing out in the maximum case when it can't
>>> find it.  In the minimum case, it will return the subscript value or the
>>> allocated value of the outer object, whichever is larger.
>> I see from the changes in the testing case, there are the following major 
>> changes for the existing behavior (can be show with the testing case)
>> For non-nested structures:
>> struct A
>> {
>>   char a[10];
>>   int b;
>>   char c[10];
>> };
>> 1.  The Minimum size of the reference to the subobject that is a trailing 
>> array of a structure is changed from “0” to “sizeof the subobject"
>>> -  if (__builtin_object_size (>c, 3) != 0)
>> +  if (__builtin_object_size (>c, 3) != 10)
>> For nested structures:
>> struct D
>> {
>>   int i;
>>   struct D1
>>   {
>> char b;
>> char a[10];
>>   } j;
>> };
>> 2.   The Maximum size of the reference to the subobject that is a trailing 
>> array of the inner structure is changed from “sizeof the subobject” to “-1"
>>> -  if (__builtin_object_size (>j.a[3], 1) != sizeof (d->j.a) - 3)
>>> +  if (__builtin_object_size (>j.a[3], 1) != (size_t) -1)
>> .
>> 3.  The Minimum size of the reference to the subobject that is a trailing 
>> array of the inner structure is changed from “0” to “sizeof the subobject"
>> -  if (__builtin_object_size ((char *) >j[0], 3) != 0)
>>> +  if (__builtin_object_size ((char *) >j[0], 3) != sizeof (e->j))
> 
> All of the above is correct, thanks for the high level review!
> 
>> I think that all the above changes are good. My only concern is, for the 
>> change of the Minimum size of the reference to the subobject that is a 
>> trailing array (the above case 1 and 3), will there be any negtive impact on 
>> the existing application that use it?
> 
> I doubt it, because the 0 return value for minimum object size is essentially 
> a failure to determine minimum object size, i.e. a special value.  This 
> change can be interpreted as succeeding to get the minimum object size in 
> more cases.
> 
> Likewise for the maximum object size change, the change can be interpreted as 
> failing to get the maximum object size in more cases. Does that sound 
> reasonable?

Yes, make sense to me.

Thanks.

Qing
> 
>>> + /* If the subobject size cannot be easily inferred or is smaller than
>>> +the whole size, just use the whole size.  */
>> Should the above comment be:
>> +  /* If the subobject size cannot be easily inferred or is larger than
>> + the whole size, just use the whole size.  */
>>>   if (! TYPE_SIZE_UNIT (TREE_TYPE (var))
>>>   || ! tree_fits_uhwi_p (TYPE_SIZE_UNIT (TREE_TYPE (var)))
>>>   || (pt_var_size && TREE_CODE (pt_var_size) == INTEGER_CST
>>>   && tree_int_cst_lt (pt_var_size,
>>>   TYPE_SIZE_UNIT (TREE_TYPE (var)
>>> var = pt_var;
> 
> Oops, yes indeed, fixed in my copy.
> 
> Thanks,
> Sid



Re: [PATCH 2/2] tree-object-size: More consistent behaviour with flex arrays

2023-01-26 Thread Siddhesh Poyarekar

On 2023-01-26 11:20, Qing Zhao wrote:

Hi, Siddhesh,

Thanks a lot for this patch, after -fstrict-flex-array functionality has been 
added into GCC,
  I think that making the tree-object-size to have consistent behavior with 
flex arrays is a
valuable and natural work that need to be added.

I also like the comments you added into tree-object-size.cc, making the code 
much easier to be understood.

Minor comments below:


On Dec 21, 2022, at 5:25 PM, Siddhesh Poyarekar  wrote:

The tree object size pass tries to fail when it detects a flex array in
the struct, but it ends up doing the right thing only when the flex
array is in the outermost struct.  For nested cases (such as arrays
nested in a union or an inner struct), it ends up taking whatever value
the flex array is declared with, using zero for the standard flex array,
i.e. [].

Rework subobject size computation to make it more consistent across the
board, honoring -fstrict-flex-arrays.  With this change, any array at
the end of the struct will end up causing __bos to use the allocated
value of the outer object, bailing out in the maximum case when it can't
find it.  In the minimum case, it will return the subscript value or the
allocated value of the outer object, whichever is larger.


I see from the changes in the testing case, there are the following major 
changes for the existing behavior (can be show with the testing case)


For non-nested structures:

struct A
{
   char a[10];
   int b;
   char c[10];
};

1.  The Minimum size of the reference to the subobject that is a trailing array of a 
structure is changed from “0” to “sizeof the subobject"

-  if (__builtin_object_size (>c, 3) != 0)

+  if (__builtin_object_size (>c, 3) != 10)

For nested structures:

struct D
{
   int i;
   struct D1
   {
 char b;
 char a[10];
   } j;
};

2.   The Maximum size of the reference to the subobject that is a trailing array of 
the inner structure is changed from “sizeof the subobject” to “-1"

-  if (__builtin_object_size (>j.a[3], 1) != sizeof (d->j.a) - 3)
+  if (__builtin_object_size (>j.a[3], 1) != (size_t) -1)


.
3.  The Minimum size of the reference to the subobject that is a trailing array of 
the inner structure is changed from “0” to “sizeof the subobject"
-  if (__builtin_object_size ((char *) >j[0], 3) != 0)

+  if (__builtin_object_size ((char *) >j[0], 3) != sizeof (e->j))


All of the above is correct, thanks for the high level review!



I think that all the above changes are good. My only concern is, for the change 
of the Minimum size of the reference to the subobject that is a trailing array 
(the above case 1 and 3), will there be any negtive impact on the existing 
application that use it?


I doubt it, because the 0 return value for minimum object size is 
essentially a failure to determine minimum object size, i.e. a special 
value.  This change can be interpreted as succeeding to get the minimum 
object size in more cases.


Likewise for the maximum object size change, the change can be 
interpreted as failing to get the maximum object size in more cases. 
Does that sound reasonable?



+ /* If the subobject size cannot be easily inferred or is smaller than
+the whole size, just use the whole size.  */


Should the above comment be:

+ /* If the subobject size cannot be easily inferred or is larger than
+the whole size, just use the whole size.  */


  if (! TYPE_SIZE_UNIT (TREE_TYPE (var))
  || ! tree_fits_uhwi_p (TYPE_SIZE_UNIT (TREE_TYPE (var)))
  || (pt_var_size && TREE_CODE (pt_var_size) == INTEGER_CST
  && tree_int_cst_lt (pt_var_size,
  TYPE_SIZE_UNIT (TREE_TYPE (var)
var = pt_var;




Oops, yes indeed, fixed in my copy.

Thanks,
Sid


Re: [PATCH v2] opts: SANITIZE_ADDRESS wrongly cleared [PR108543]

2023-01-26 Thread Jakub Jelinek via Gcc-patches
On Thu, Jan 26, 2023 at 11:40:29AM -0500, Marek Polacek via Gcc-patches wrote:
>   PR middle-end/108543
> 
> gcc/ChangeLog:
> 
>   * opts.cc (parse_sanitizer_options): Don't always clear SANITIZE_ADDRESS
>   if it was previously set.
> 
> gcc/testsuite/ChangeLog:
> 
>   * c-c++-common/asan/pointer-subtract-5.c: New test.
>   * c-c++-common/asan/pointer-subtract-6.c: New test.
>   * c-c++-common/asan/pointer-subtract-7.c: New test.
>   * c-c++-common/asan/pointer-subtract-8.c: New test.

LGTM.

Jakub



[PATCH v2] opts: SANITIZE_ADDRESS wrongly cleared [PR108543]

2023-01-26 Thread Marek Polacek via Gcc-patches
On Wed, Jan 25, 2023 at 05:49:20PM -0800, Andrew Pinski wrote:
> On Wed, Jan 25, 2023 at 3:26 PM Marek Polacek via Gcc-patches
>  wrote:
> >
> > Here we crash on a null fndecl ultimately because we haven't defined
> > the built-ins described in sanitizer.def.  So
> > builtin_decl_explicit (BUILT_IN_ASAN_POINTER_SUBTRACT);
> > returns NULL_TREE, causing an ICE later.
> >
> > DEF_SANITIZER_BUILTIN only actually defines the built-ins when flag_sanitize
> > has SANITIZE_ADDRESS, or some of the other SANITIZE_*, but it doesn't check
> > SANITIZE_KERNEL_ADDRESS or SANITIZE_USER_ADDRESS.  Unfortunately, with
> > -fsanitize=address -fno-sanitize=kernel-address
> > or
> > -fsanitize=kernel-address -fno-sanitize=address
> > SANITIZE_ADDRESS ends up being unset from flag_sanitize even though
> > _USER/_KERNEL are set.  That's because -fsanitize=address means
> > SANITIZE_ADDRESS | SANITIZE_USER_ADDRESS and -fsanitize=kernel-address
> > is SANITIZE_ADDRESS | SANITIZE_KERNEL_ADDRESS but parse_sanitizer_options
> > does
> >   flags &= ~sanitizer_opts[i].flag;
> > so the subsequent -fno- unsets SANITIZE_ADDRESS.  Then no sanitizer
> > built-ins are actually defined.
> >
> > I'm not sure why SANITIZE_ADDRESS isn't just SANITIZE_USER_ADDRESS |
> > SANITIZE_KERNEL_ADDRESS, I don't think we need 3 bits.
> 
> I am trying to follow the code but I can't tell if -fsanitize=address
> -fno-sanitize=address still will work?
> It would make sense to add a testcase for that case too.
> 
> I suspect it does not work though, because it would still leave
> SANITIZE_ADDRESS enabled ...

You're totally right; I was trying to be clever and didn't consider
that case.  I should have kept the code simple and straightforward,
like below.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/12/11?

-- >8 --
Here we crash on a null fndecl ultimately because we haven't defined
the built-ins described in sanitizer.def.  So
builtin_decl_explicit (BUILT_IN_ASAN_POINTER_SUBTRACT);
returns NULL_TREE, causing an ICE later.

DEF_SANITIZER_BUILTIN only actually defines the built-ins when flag_sanitize
has SANITIZE_ADDRESS, or some of the other SANITIZE_*, but it doesn't check
SANITIZE_KERNEL_ADDRESS or SANITIZE_USER_ADDRESS.  Unfortunately, with
-fsanitize=address -fno-sanitize=kernel-address
or
-fsanitize=kernel-address -fno-sanitize=address
SANITIZE_ADDRESS ends up being unset from flag_sanitize even though
_USER/_KERNEL are set.  That's because -fsanitize=address means
SANITIZE_ADDRESS | SANITIZE_USER_ADDRESS and -fsanitize=kernel-address
is SANITIZE_ADDRESS | SANITIZE_KERNEL_ADDRESS but parse_sanitizer_options
does
  flags &= ~sanitizer_opts[i].flag;
so the subsequent -fno- unsets SANITIZE_ADDRESS.  Then no sanitizer
built-ins are actually defined.

I'm not sure why SANITIZE_ADDRESS isn't just SANITIZE_USER_ADDRESS |
SANITIZE_KERNEL_ADDRESS, I don't think we need 3 bits.

PR middle-end/108543

gcc/ChangeLog:

* opts.cc (parse_sanitizer_options): Don't always clear SANITIZE_ADDRESS
if it was previously set.

gcc/testsuite/ChangeLog:

* c-c++-common/asan/pointer-subtract-5.c: New test.
* c-c++-common/asan/pointer-subtract-6.c: New test.
* c-c++-common/asan/pointer-subtract-7.c: New test.
* c-c++-common/asan/pointer-subtract-8.c: New test.
---
 gcc/opts.cc   |  9 -
 .../c-c++-common/asan/pointer-subtract-5.c| 15 +++
 .../c-c++-common/asan/pointer-subtract-6.c| 15 +++
 .../c-c++-common/asan/pointer-subtract-7.c| 15 +++
 .../c-c++-common/asan/pointer-subtract-8.c| 15 +++
 5 files changed, 68 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/c-c++-common/asan/pointer-subtract-5.c
 create mode 100644 gcc/testsuite/c-c++-common/asan/pointer-subtract-6.c
 create mode 100644 gcc/testsuite/c-c++-common/asan/pointer-subtract-7.c
 create mode 100644 gcc/testsuite/c-c++-common/asan/pointer-subtract-8.c

diff --git a/gcc/opts.cc b/gcc/opts.cc
index 9ba47d7deaa..a032cd4ce58 100644
--- a/gcc/opts.cc
+++ b/gcc/opts.cc
@@ -2246,7 +2246,14 @@ parse_sanitizer_options (const char *p, location_t loc, 
int scode,
  flags |= sanitizer_opts[i].flag;
  }
else
- flags &= ~sanitizer_opts[i].flag;
+ {
+   flags &= ~sanitizer_opts[i].flag;
+   /* Don't always clear SANITIZE_ADDRESS if it was previously
+  set: -fsanitize=address -fno-sanitize=kernel-address should
+  leave SANITIZE_ADDRESS set.  */
+   if (flags & (SANITIZE_KERNEL_ADDRESS | SANITIZE_USER_ADDRESS))
+ flags |= SANITIZE_ADDRESS;
+ }
found = true;
break;
  }
diff --git a/gcc/testsuite/c-c++-common/asan/pointer-subtract-5.c 
b/gcc/testsuite/c-c++-common/asan/pointer-subtract-5.c
new file mode 100644
index 000..867eda0e61e

[PATCH] riscv: Enable -fasynchronous_unwind_tables by default on Linux

2023-01-26 Thread Andreas Schwab via Gcc-patches
This follows the example of aarch64.

gcc/:
* common/config/riscv/riscv-common.cc
(riscv_option_optimization_table)
[TARGET_DEFAULT_ASYNC_UNWIND_TABLES]: Enable
-fasynchronous_unwind_tables and -funwind-tables.
* config.gcc (riscv*-*-linux*): Define
TARGET_DEFAULT_ASYNC_UNWIND_TABLES.
---
 gcc/common/config/riscv/riscv-common.cc | 4 
 gcc/config.gcc  | 1 +
 2 files changed, 5 insertions(+)

diff --git a/gcc/common/config/riscv/riscv-common.cc 
b/gcc/common/config/riscv/riscv-common.cc
index 2e3116e7673..616e2f897b9 100644
--- a/gcc/common/config/riscv/riscv-common.cc
+++ b/gcc/common/config/riscv/riscv-common.cc
@@ -1756,6 +1756,10 @@ static const struct default_options 
riscv_option_optimization_table[] =
   {
 { OPT_LEVELS_1_PLUS, OPT_fsection_anchors, NULL, 1 },
 { OPT_LEVELS_2_PLUS, OPT_free, NULL, 1 },
+#if TARGET_DEFAULT_ASYNC_UNWIND_TABLES == 1
+{ OPT_LEVELS_ALL, OPT_fasynchronous_unwind_tables, NULL, 1 },
+{ OPT_LEVELS_ALL, OPT_funwind_tables, NULL, 1},
+#endif
 { OPT_LEVELS_NONE, 0, NULL, 0 }
   };
 
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 89f56047cfe..744b46fb3b0 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -2417,6 +2417,7 @@ riscv*-*-linux*)
*) echo "Unknown value for enable_multilib"; exit 1
esac
tmake_file="${tmake_file} riscv/t-riscv riscv/t-linux"
+   tm_defines="${tm_defines} TARGET_DEFAULT_ASYNC_UNWIND_TABLES=1"
gnu_ld=yes
gas=yes
case $target in
-- 
2.39.1


-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


[pushed] Modula-2: Remove debug code [PR108553].

2023-01-26 Thread Iain Sandoe via Gcc-patches
Bootstrapped on x86_64-darwin, and the patch was confirmed as fixing the
issue in the PR.
Pushed to trunk as obvious, thanks,
Iain

--- 8< ---

Remove debugging code accidentally left in place in r13-5373-g80cf2c5e8f496b.

Signed-off-by: Iain Sandoe 

PR modula2/108553

gcc/m2/ChangeLog:

* gm2-lang.cc (gm2_langhook_init_options): Remove debug code.
---
 gcc/m2/gm2-lang.cc | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/gcc/m2/gm2-lang.cc b/gcc/m2/gm2-lang.cc
index 4d9cae205a7..a30e626620c 100644
--- a/gcc/m2/gm2-lang.cc
+++ b/gcc/m2/gm2-lang.cc
@@ -290,12 +290,9 @@ gm2_langhook_init_options (unsigned int 
decoded_options_count,
  M2Options_SetVerbose (value);
  /* FALLTHROUGH */
default:
+ /* We handled input files above.  */
  if (code >= N_OPTS)
-   {
- // FIXME remove debug.
- fprintf(stderr, "%s : %s\n", opt, (arg ? arg : ""));
- break;
-   }
+   break;
  /* Do not pass Modula-2 args to the preprocessor, any that we care
 about here should already have been handled above.  */
  if (option->flags & CL_ModulaX2)
-- 
2.37.1 (Apple Git-137.1)



[committed] frange: Fix up foperator_{,not_}equal::fold_range for signed zeros [PR108540]

2023-01-26 Thread Jakub Jelinek via Gcc-patches
Hi!

The following testcases are miscompiled, because threader sees some
SSA_NAME would have -0.0 value and when computing range of SSA_NAME == 0.0
foperator_equal::fold_range sees one operand has [-0.0, -0.0] singleton
range, the other [0.0, 0.0], they aren't equal (frange operator== uses
real_identical etc. rather than real comparisons) and so it thinks they
compare unequal.  With signed zeros -0.0 == 0.0 is true though, so we
need to special case the both ranges singleton code.
Similarly, if we see op1 range being say [-42.0, -0.0] and op2 range
[0.0, 42.0], we'd check that the intersection of the two ranges is empty
(that is correct) and fold the result of == between such operands to
[0, 0] which is wrong, because -0.0 == 0.0, it needs to be [0, 1].
Similarly for foperator_not_equal::fold_range.

Bootstrapped/regtested on x86_64-linux and i686-linux, approved in the
PR by Aldy, committed to trunk.

2023-01-26  Jakub Jelinek  

PR tree-optimization/108540
* range-op-float.cc (foperator_equal::fold_range): If both op1 and op2
are singletons, use range_true even if op1 != op2
when one range is [-0.0, -0.0] and another [0.0, 0.0].  Similarly,
even if intersection of the ranges is empty and one has
zero low bound and another zero high bound, use range_true_and_false
rather than range_false.
(foperator_not_equal::fold_range): If both op1 and op2
are singletons, use range_false even if op1 != op2
when one range is [-0.0, -0.0] and another [0.0, 0.0].  Similarly,
even if intersection of the ranges is empty and one has
zero low bound and another zero high bound, use range_true_and_false
rather than range_true.

* gcc.c-torture/execute/ieee/pr108540-1.c: New test.
* gcc.c-torture/execute/ieee/pr108540-2.c: New test.

--- gcc/range-op-float.cc.jj2023-01-16 09:39:36.191929750 +0100
+++ gcc/range-op-float.cc   2023-01-26 13:44:10.542899269 +0100
@@ -607,6 +607,10 @@ foperator_equal::fold_range (irange ,
 {
   if (op1 == op2)
r = range_true (type);
+  // If one operand is -0.0 and other 0.0, they are still equal.
+  else if (real_iszero (_bound ())
+  && real_iszero (_bound ()))
+   r = range_true (type);
   else
r = range_false (type);
 }
@@ -617,7 +621,18 @@ foperator_equal::fold_range (irange ,
   frange tmp = op1;
   tmp.intersect (op2);
   if (tmp.undefined_p ())
-   r = range_false (type);
+   {
+ // If one range is [whatever, -0.0] and another
+ // [0.0, whatever2], we don't know anything either,
+ // because -0.0 == 0.0.
+ if ((real_iszero (_bound ())
+  && real_iszero (_bound ()))
+ || (real_iszero (_bound ())
+ && real_iszero (_bound (
+   r = range_true_and_false (type);
+ else
+   r = range_false (type);
+   }
   else
r = range_true_and_false (type);
 }
@@ -708,10 +723,14 @@ foperator_not_equal::fold_range (irange
   // consist of a single value, and then compare them.
   else if (op1.singleton_p () && op2.singleton_p ())
 {
-  if (op1 != op2)
-   r = range_true (type);
-  else
+  if (op1 == op2)
r = range_false (type);
+  // If one operand is -0.0 and other 0.0, they are still equal.
+  else if (real_iszero (_bound ())
+  && real_iszero (_bound ()))
+   r = range_false (type);
+  else
+   r = range_true (type);
 }
   else if (!maybe_isnan (op1, op2))
 {
@@ -720,7 +739,18 @@ foperator_not_equal::fold_range (irange
   frange tmp = op1;
   tmp.intersect (op2);
   if (tmp.undefined_p ())
-   r = range_true (type);
+   {
+ // If one range is [whatever, -0.0] and another
+ // [0.0, whatever2], we don't know anything either,
+ // because -0.0 == 0.0.
+ if ((real_iszero (_bound ())
+  && real_iszero (_bound ()))
+ || (real_iszero (_bound ())
+ && real_iszero (_bound (
+   r = range_true_and_false (type);
+ else
+   r = range_true (type);
+   }
   else
r = range_true_and_false (type);
 }
--- gcc/testsuite/gcc.c-torture/execute/ieee/pr108540-1.c.jj2023-01-26 
13:54:55.131463151 +0100
+++ gcc/testsuite/gcc.c-torture/execute/ieee/pr108540-1.c   2023-01-26 
13:54:31.333811525 +0100
@@ -0,0 +1,84 @@
+/* PR tree-optimization/108540 */
+
+__attribute__((noipa)) void
+bar (const char *cp, unsigned long size, char sign, int dsgn)
+{
+  if (__builtin_strcmp (cp, "ZERO") != 0 || size != 4 || sign != '-' || dsgn 
!= 1)
+__builtin_abort ();
+}
+
+__attribute__((noipa)) void
+foo (int x, int ch, double d)
+{
+  const char *cp = "";
+  unsigned long size = 0;
+  char sign = '\0';
+  switch (x)
+{
+case 42:
+  if (__builtin_isinf (d))
+   {
+ if (d < 0)
+   sign 

Re: [PATCH 2/2] tree-object-size: More consistent behaviour with flex arrays

2023-01-26 Thread Qing Zhao via Gcc-patches
Hi, Siddhesh,

Thanks a lot for this patch, after -fstrict-flex-array functionality has been 
added into GCC,
 I think that making the tree-object-size to have consistent behavior with flex 
arrays is a 
valuable and natural work that need to be added.

I also like the comments you added into tree-object-size.cc, making the code 
much easier to be understood.

Minor comments below:

> On Dec 21, 2022, at 5:25 PM, Siddhesh Poyarekar  wrote:
> 
> The tree object size pass tries to fail when it detects a flex array in
> the struct, but it ends up doing the right thing only when the flex
> array is in the outermost struct.  For nested cases (such as arrays
> nested in a union or an inner struct), it ends up taking whatever value
> the flex array is declared with, using zero for the standard flex array,
> i.e. [].
> 
> Rework subobject size computation to make it more consistent across the
> board, honoring -fstrict-flex-arrays.  With this change, any array at
> the end of the struct will end up causing __bos to use the allocated
> value of the outer object, bailing out in the maximum case when it can't
> find it.  In the minimum case, it will return the subscript value or the
> allocated value of the outer object, whichever is larger.

I see from the changes in the testing case, there are the following major 
changes for the existing behavior (can be show with the testing case)


For non-nested structures:

struct A
{
  char a[10];
  int b;
  char c[10];
};

1.  The Minimum size of the reference to the subobject that is a trailing array 
of a structure is changed from “0” to “sizeof the subobject"
> -  if (__builtin_object_size (>c, 3) != 0)
+  if (__builtin_object_size (>c, 3) != 10)

For nested structures:

struct D
{
  int i;
  struct D1
  {
char b;
char a[10];
  } j;
};

2.   The Maximum size of the reference to the subobject that is a trailing 
array of the inner structure is changed from “sizeof the subobject” to “-1"
> -  if (__builtin_object_size (>j.a[3], 1) != sizeof (d->j.a) - 3)
> +  if (__builtin_object_size (>j.a[3], 1) != (size_t) -1)

.
3.  The Minimum size of the reference to the subobject that is a trailing array 
of the inner structure is changed from “0” to “sizeof the subobject"
-  if (__builtin_object_size ((char *) >j[0], 3) != 0)
> +  if (__builtin_object_size ((char *) >j[0], 3) != sizeof (e->j))


I think that all the above changes are good. My only concern is, for the change 
of the Minimum size of the reference to the subobject that is a trailing array 
(the above case 1 and 3), will there be any negtive impact on the existing 
application that use it?

> 
> gcc/ChangeLog:
> 
>   PR tree-optimization/107952
>   * tree-object-size.cc (size_from_objects): New function.
>   (addr_object_size): Call it.  Fully rely on
>   array_ref_flexible_size_p call to determine flex array.
> 
> gcc/testsuite/ChangeLog:
> 
>   PR tree-optimization/107952
>   * g++.dg/ext/builtin-object-size1.C (test1, test6, test7,
>   test8): Adjust expected result for object size type 3 and 1.
>   * g++.dg/ext/builtin-object-size2.C (test1, test6, test7,
>   test8): Likewise.
>   * gcc.dg/builtin-object-size-13.c (main): Likewise.
>   * gcc.dg/builtin-object-size-6.c (test1, test6, test7, test8):
>   Likewise.
>   * gcc.dg/builtin-object-size-8.c (main): Likewise.
>   * gcc.dg/builtin-object-size-flex-common.h: Common code for new
>   tests.
>   * gcc.dg/builtin-object-size-flex-nested-struct-nonzero.c: New
>   test.
>   * gcc.dg/builtin-object-size-flex-nested-struct-zero.c: New
>   test.
>   * gcc.dg/builtin-object-size-flex-nested-struct.c: New test.
>   * gcc.dg/builtin-object-size-flex-nested-union-nonzero.c: New
>   test.
>   * gcc.dg/builtin-object-size-flex-nested-union-zero.c: New test.
>   * gcc.dg/builtin-object-size-flex-nested-union.c: New test.
>   * gcc.dg/builtin-object-size-flex-nonzero.c: New test.
>   * gcc.dg/builtin-object-size-flex-zero.c: New test.
>   * gcc.dg/builtin-object-size-flex.c: New test.
> 
> Signed-off-by: Siddhesh Poyarekar 
> ---
> .../g++.dg/ext/builtin-object-size1.C |  10 +-
> .../g++.dg/ext/builtin-object-size2.C |  10 +-
> gcc/testsuite/gcc.dg/builtin-object-size-13.c |   4 +-
> gcc/testsuite/gcc.dg/builtin-object-size-6.c  |  10 +-
> gcc/testsuite/gcc.dg/builtin-object-size-8.c  |   4 +-
> .../gcc.dg/builtin-object-size-flex-common.h  |  90 +++
> ...n-object-size-flex-nested-struct-nonzero.c |   6 +
> ...ltin-object-size-flex-nested-struct-zero.c |   6 +
> .../builtin-object-size-flex-nested-struct.c  |  22 +++
> ...in-object-size-flex-nested-union-nonzero.c |   6 +
> ...iltin-object-size-flex-nested-union-zero.c |   6 +
> .../builtin-object-size-flex-nested-union.c   |  28 
> .../gcc.dg/builtin-object-size-flex-nonzero.c |   6 +
> .../gcc.dg/builtin-object-size-flex-zero.c|   6 +
> 

[PATCH] testsuite: Fix hwasan/arguments-3.c failures

2023-01-26 Thread Richard Sandiford via Gcc-patches
This testcase had three dg-error tests for ".*.*".
But since . matches \n in Tcl regexps, the first dg-error
ate all the output, leaving the other two to fail.

The regexp is eventually embedded in a larger one, so we
can't prefix it with (?n).  But the .*s aren't necessary,
since dg-error tests for a partial rather than a full match.

Tested on aarch64-linux-gnu & pushed as obvious.

Richard


gcc/testsuite/
* c-c++-common/hwasan/arguments-3.c: Remove extraneous .*s.
---
 gcc/testsuite/c-c++-common/hwasan/arguments-3.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/c-c++-common/hwasan/arguments-3.c 
b/gcc/testsuite/c-c++-common/hwasan/arguments-3.c
index 2bf8917355b..6dbec924e2b 100644
--- a/gcc/testsuite/c-c++-common/hwasan/arguments-3.c
+++ b/gcc/testsuite/c-c++-common/hwasan/arguments-3.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
 /* { dg-additional-options "-fsanitize=thread,address" } */
-/* { dg-error ".*'-fsanitize=thread' is incompatible with 
'-fsanitize=address'.*" "" { target *-*-* } 0 } */
-/* { dg-error ".*'-fsanitize=thread' is incompatible with 
'-fsanitize=hwaddress'.*" "" { target *-*-* } 0 } */
-/* { dg-error ".*'-fsanitize=hwaddress' is incompatible with 
'-fsanitize=address'.*" "" { target *-*-* } 0 } */
+/* { dg-error "'-fsanitize=thread' is incompatible with '-fsanitize=address'" 
"" { target *-*-* } 0 } */
+/* { dg-error "'-fsanitize=thread' is incompatible with 
'-fsanitize=hwaddress'" "" { target *-*-* } 0 } */
+/* { dg-error "'-fsanitize=hwaddress' is incompatible with 
'-fsanitize=address'" "" { target *-*-* } 0 } */
-- 
2.25.1



[PATCH] tree: Fix up tree_code_{length,type}

2023-01-26 Thread Jakub Jelinek via Gcc-patches
On Thu, Jan 26, 2023 at 09:45:35AM -0500, Patrick Palka via Gcc-patches wrote:
> > +#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
> > +#define END_OF_BASE_TREE_CODES tcc_exceptional,
> > +
> > +
> >  /* Class of tree given its code.  */
> > -extern const enum tree_code_class tree_code_type[];
> > +constexpr enum tree_code_class tree_code_type[] = {
> > +#include "all-tree.def"
> > +};
> > +
> > +#undef DEFTREECODE
> > +#undef END_OF_BASE_TREE_CODES
> >  
> >  /* Each tree code class has an associated string representation.
> > These must correspond to the tree_code_class entries.  */
> >  extern const char *const tree_code_class_strings[];
> >  
> >  /* Number of argument-words in each kind of tree-node.  */
> > -extern const unsigned char tree_code_length[];
> > +
> > +#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
> > +#define END_OF_BASE_TREE_CODES 0,
> > +constexpr unsigned char tree_code_length[] = {
> > +#include "all-tree.def"
> > +};
> > +
> > +#undef DEFTREECODE
> > +#undef END_OF_BASE_TREE_CODES
> 
> IIUC defining these globals as non-inline constexpr gives them internal
> linkage, and so each TU contains its own unique copy of these globals.
> This bloats cc1plus by a tiny bit and is technically an ODR violation
> because some inline functions such as tree_class_check also ODR-use
> these variables and so each defn of tree_class_check will refer to a
> "different" tree_code_class.  Since inline variables are a C++17
> feature, I guess we could fix this by defining the globals the old way
> before C++17 and as inline constexpr otherwise?

And I'd argue with the tiny bit.
In my x86_64-linux cc1plus from today, I see 193 _ZL16tree_code_length vars,
374 bytes each, and 324 _ZL14tree_code_type vars, 1496 bytes each.
So, that means waste of 555016 .rodata bytes, plus being highly non-cache
friendly.

The following patch does that.

So far tested on x86_64-linux in my -O0 working tree (system gcc 12
compiler) where .rodata shrunk with the patch by 928896 bytes, in last
stage of a bootstrapped tree (built by today's prev-gcc) where .rodata
shrunk by 561728 bytes (in neither case .text or most other sections
changed sizes) and on powerpc64le-linux --disable-bootstrap
(system gcc 4.8.5) to test also the non-C++17 case.

Ok for trunk if it passes full bootstrap/regtest?

BTW, wonder if tree_code_type couldn't be an array of unsigned char
elements rather than enum tree_code_class and we'd then cast it
to the enum in the macro, that would shrink that array from 1496 bytes
to 374.  Of course, that sounds like stage1 material.

2023-01-26  Patrick Palka  
Jakub Jelinek  

* tree-core.h (tree_code_type, tree_code_length): For
C++17 and later, add inline keyword, otherwise don't define
the arrays, but declare extern arrays.
* tree.cc (tree_code_type, tree_code_length): Define these
arrays for C++14 and older.

--- gcc/tree-core.h.jj  2023-01-02 09:32:31.188158094 +0100
+++ gcc/tree-core.h 2023-01-26 16:02:34.212113251 +0100
@@ -2284,17 +2284,20 @@ struct floatn_type_info {
 /* Matrix describing the structures contained in a given tree code.  */
 extern bool tree_contains_struct[MAX_TREE_CODES][64];
 
+/* Class of tree given its code.  */
+#if __cpp_inline_variables >= 201606L
 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
 #define END_OF_BASE_TREE_CODES tcc_exceptional,
 
-
-/* Class of tree given its code.  */
-constexpr enum tree_code_class tree_code_type[] = {
+constexpr inline enum tree_code_class tree_code_type[] = {
 #include "all-tree.def"
 };
 
 #undef DEFTREECODE
 #undef END_OF_BASE_TREE_CODES
+#else
+extern const enum tree_code_class tree_code_type[];
+#endif
 
 /* Each tree code class has an associated string representation.
These must correspond to the tree_code_class entries.  */
@@ -2302,14 +2305,18 @@ extern const char *const tree_code_class
 
 /* Number of argument-words in each kind of tree-node.  */
 
+#if __cpp_inline_variables >= 201606L
 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
 #define END_OF_BASE_TREE_CODES 0,
-constexpr unsigned char tree_code_length[] = {
+constexpr inline unsigned char tree_code_length[] = {
 #include "all-tree.def"
 };
 
 #undef DEFTREECODE
 #undef END_OF_BASE_TREE_CODES
+#else
+extern const unsigned char tree_code_length[];
+#endif
 
 /* Vector of all alias pairs for global symbols.  */
 extern GTY(()) vec *alias_pairs;
--- gcc/tree.cc.jj  2023-01-13 17:37:45.259482663 +0100
+++ gcc/tree.cc 2023-01-26 16:03:59.796878082 +0100
@@ -74,7 +74,33 @@ along with GCC; see the file COPYING3.
 #include "asan.h"
 #include "ubsan.h"
 
+#if __cpp_inline_variables < 201606L
+/* Tree code classes.  */
 
+#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
+#define END_OF_BASE_TREE_CODES tcc_exceptional,
+
+const enum tree_code_class tree_code_type[] = {
+#include "all-tree.def"
+};
+
+#undef DEFTREECODE
+#undef END_OF_BASE_TREE_CODES
+
+/* Table indexed by tree code giving number of 

[pushed] Update guality XFAILs for aarch64*-*-*

2023-01-26 Thread Richard Sandiford via Gcc-patches
As in previous years, this patch updates the list of guality
XFAILs for aarch64*-*-*, based this time on an aarch64-linux-gnu
target with GDB 12 installed.  The justification for XFAILing
without specific PRs is that anyone who is interested in improving
debug quality can look at the XFAILs in the guality directory,
which is more likely to be kept up-to-date than a bugzilla ticket.

Tested on aarch64-linux-gnu & pushed.

Richard


gcc/testsuite/
* gcc.dg/guality/pr36728-2.c: Update XFAILs for aarch64*-*-*.
* gcc.dg/guality/pr54519-1.c: Likewise.
* gcc.dg/guality/pr54519-3.c: Likewise.
* gcc.dg/guality/pr54693-2.c: Likewise.
* gcc.dg/guality/sra-1.c: Likewise.
---
 gcc/testsuite/gcc.dg/guality/pr36728-2.c | 28 
 gcc/testsuite/gcc.dg/guality/pr54519-1.c |  6 ++---
 gcc/testsuite/gcc.dg/guality/pr54519-3.c |  6 ++---
 gcc/testsuite/gcc.dg/guality/pr54693-2.c |  4 ++--
 gcc/testsuite/gcc.dg/guality/sra-1.c |  2 +-
 5 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/guality/pr36728-2.c 
b/gcc/testsuite/gcc.dg/guality/pr36728-2.c
index 6e8d775f9ac..d670c871844 100644
--- a/gcc/testsuite/gcc.dg/guality/pr36728-2.c
+++ b/gcc/testsuite/gcc.dg/guality/pr36728-2.c
@@ -25,21 +25,21 @@ foo (int arg1, int arg2, int arg3, int arg4, int arg5, int 
arg6, int arg7)
and arg2.  So it is expected that these values are unavailable in
some of these tests.  */
 
-/* { dg-final { gdb-test 16 "arg1" "1" { target { ! "s390*-*-*" } xfail { 
aarch64*-*-* && { any-opts "-fno-fat-lto-objects" "-O3" } } } } } */
-/* { dg-final { gdb-test 16 "arg2" "2" { target { ! "s390*-*-*" } xfail { 
aarch64*-*-* && { any-opts "-fno-fat-lto-objects" "-O3" } } } } } */
-/* { dg-final { gdb-test 16 "arg3" "3" { xfail { aarch64*-*-* && { any-opts 
"-fno-fat-lto-objects" "-O3" } } } } } */
-/* { dg-final { gdb-test 16 "arg4" "4" { xfail { aarch64*-*-* && { any-opts 
"-fno-fat-lto-objects" "-O3" } } } } } */
-/* { dg-final { gdb-test 16 "arg5" "5" { xfail { aarch64*-*-* && { any-opts 
"-fno-fat-lto-objects" "-O3" } } } } } */
-/* { dg-final { gdb-test 16 "arg6" "6" { xfail { aarch64*-*-* && { any-opts 
"-fno-fat-lto-objects" "-O3" } } } } } */
-/* { dg-final { gdb-test 16 "arg7" "30" { xfail { aarch64*-*-* && { any-opts 
"-fno-fat-lto-objects" "-O3" } } } } } */
+/* { dg-final { gdb-test 16 "arg1" "1" { target { ! "s390*-*-*" } } } } */
+/* { dg-final { gdb-test 16 "arg2" "2" } } */
+/* { dg-final { gdb-test 16 "arg3" "3" } } */
+/* { dg-final { gdb-test 16 "arg4" "4" } } */
+/* { dg-final { gdb-test 16 "arg5" "5" } } */
+/* { dg-final { gdb-test 16 "arg6" "6" } } */
+/* { dg-final { gdb-test 16 "arg7" "30" } } */
 /* { dg-final { gdb-test 16 "y" "2" { xfail { aarch64*-*-* && { any-opts 
"-fno-fat-lto-objects" } } } } } */
-/* { dg-final { gdb-test 18 "arg1" "1" { target { ! "s390*-*-*" } xfail { 
aarch64*-*-* && { any-opts "-fno-fat-lto-objects" "-O3" } } } } } */
-/* { dg-final { gdb-test 18 "arg2" "2" { target { ! "s390*-*-*" } xfail { 
aarch64*-*-* && { any-opts "-fno-fat-lto-objects" "-O3" } } } } } */
-/* { dg-final { gdb-test 18 "arg3" "3" { xfail { aarch64*-*-* && { any-opts 
"-fno-fat-lto-objects" "-O3" } } } } } */
-/* { dg-final { gdb-test 18 "arg4" "4" { xfail { aarch64*-*-* && { any-opts 
"-fno-fat-lto-objects" "-O3" } } } } } */
-/* { dg-final { gdb-test 18 "arg5" "5" { xfail { aarch64*-*-* && { any-opts 
"-fno-fat-lto-objects" "-O3" } } } } } */
-/* { dg-final { gdb-test 18 "arg6" "6" { xfail { aarch64*-*-* && { any-opts 
"-fno-fat-lto-objects" "-O3" } } } } } */
-/* { dg-final { gdb-test 18 "arg7" "30" { xfail { aarch64*-*-* && { any-opts 
"-fno-fat-lto-objects" "-O3" } } } } } */
+/* { dg-final { gdb-test 18 "arg1" "1" { target { ! "s390*-*-*" } } } } */
+/* { dg-final { gdb-test 18 "arg2" "2" { target { ! "s390*-*-*" } } } } */
+/* { dg-final { gdb-test 18 "arg3" "3" } } */
+/* { dg-final { gdb-test 18 "arg4" "4" } } */
+/* { dg-final { gdb-test 18 "arg5" "5" } } */
+/* { dg-final { gdb-test 18 "arg6" "6" } } */
+/* { dg-final { gdb-test 18 "arg7" "30" } } */
 /* { dg-final { gdb-test 18 "*x" "(char) 25" } } */
 /* { dg-final { gdb-test 18 "y" "2" } } */
 
diff --git a/gcc/testsuite/gcc.dg/guality/pr54519-1.c 
b/gcc/testsuite/gcc.dg/guality/pr54519-1.c
index 5880d9b4f57..81703eb1744 100644
--- a/gcc/testsuite/gcc.dg/guality/pr54519-1.c
+++ b/gcc/testsuite/gcc.dg/guality/pr54519-1.c
@@ -18,9 +18,9 @@ fn2 (int x, int y, int z)
   fn1 (x); /* { dg-final { gdb-test .+2 "x" "36" } } */
   if (x == 36) /* { dg-final { gdb-test .+1 "y" "25" { xfail { 
aarch64*-*-* && { any-opts "-flto" } } } } } */
fn1 (x);/* { dg-final { gdb-test . "z" "6" { xfail { 
aarch64*-*-* && { any-opts "-flto" } } } } } */
-  fn1 (x); /* { dg-final { gdb-test .+2 "x" "98" { xfail { 
aarch64*-*-* && { any-opts "-Os" } } } } } */
-  if (x == 98) /* { dg-final { gdb-test .+1 "y" "117" { xfail { 
aarch64*-*-* 

[pushed] aarch64: Remove expected error for compound literals

2023-01-26 Thread Richard Sandiford via Gcc-patches
GCC no longer treats empty compound literals as an error
(see 14cfa01755a66afbae2539f8b5796c960ddcecc6).

Tested on aarch64-linux-gnu & pushed.

Richard


gcc/testsuite/
* gcc.target/aarch64/bfloat16_scalar_typecheck.c: Accept empty
compound literals.
---
 gcc/testsuite/gcc.target/aarch64/bfloat16_scalar_typecheck.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.target/aarch64/bfloat16_scalar_typecheck.c 
b/gcc/testsuite/gcc.target/aarch64/bfloat16_scalar_typecheck.c
index 7c9188cf29d..f4ae6802883 100644
--- a/gcc/testsuite/gcc.target/aarch64/bfloat16_scalar_typecheck.c
+++ b/gcc/testsuite/gcc.target/aarch64/bfloat16_scalar_typecheck.c
@@ -40,7 +40,7 @@ bfloat16_t footest (bfloat16_t scalar0)
   short initi_1_4 = glob_bfloat; /* { dg-error {invalid conversion from type 
'bfloat16_t'} } */
   double initi_1_5 = glob_bfloat; /* { dg-error {invalid conversion from type 
'bfloat16_t'} } */
 
-  bfloat16_t scalar2_1 = {}; /* { dg-error {empty scalar initializer} } */
+  bfloat16_t scalar2_1 = {};
   bfloat16_t scalar2_2 = { glob_bfloat };
   bfloat16_t scalar2_3 = { 0 }; /* { dg-error {invalid conversion to type 
'bfloat16_t'} } */
   bfloat16_t scalar2_4 = { 0.1 }; /* { dg-error {invalid conversion to type 
'bfloat16_t'} } */
@@ -92,7 +92,7 @@ bfloat16_t footest (bfloat16_t scalar0)
 
   /* Compound literals.  */
 
-  (bfloat16_t) {}; /* { dg-error {empty scalar initializer} } */
+  (bfloat16_t) {};
   (bfloat16_t) { glob_bfloat };
   (bfloat16_t) { 0 }; /* { dg-error {invalid conversion to type 'bfloat16_t'} 
} */
   (bfloat16_t) { 0.1 }; /* { dg-error {invalid conversion to type 
'bfloat16_t'} } */
-- 
2.25.1



[pushed] aarch64: Suppress warnings in pr99766.C

2023-01-26 Thread Richard Sandiford via Gcc-patches
pr99766.C is an ICE regression test that now triggers a warning
about converting float to _Float16.

Tested on aarch64-linux-gnu & pushed.

Richard


gcc/testsuite/
* g++.target/aarch64/sve/pr99766.C: Disable warnings.
---
 gcc/testsuite/g++.target/aarch64/sve/pr99766.C | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.target/aarch64/sve/pr99766.C 
b/gcc/testsuite/g++.target/aarch64/sve/pr99766.C
index 0ca8aee5798..528d9ddd007 100644
--- a/gcc/testsuite/g++.target/aarch64/sve/pr99766.C
+++ b/gcc/testsuite/g++.target/aarch64/sve/pr99766.C
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-additional-options "-O3 -march=armv8.2-a+sve" } */
+/* { dg-additional-options "-O3 -march=armv8.2-a+sve -w" } */
 typedef float a __attribute__((__mode__(HF)));
 typedef struct {
   a b;
-- 
2.25.1



[PATCH 1/4] aarch64: Remove slp_13.c XFAILs

2023-01-26 Thread Richard Sandiford via Gcc-patches
These tests started passing after
g:b073f2b098ba7819450d6c14a0fb96cb1c09f242.

Tested on aarch64-linux-gnu & pushed.

Richard


gcc/testsuite/
* gcc.target/aarch64/sve/slp_13.c: Remove XFAILs.
---
 gcc/testsuite/gcc.target/aarch64/sve/slp_13.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/gcc/testsuite/gcc.target/aarch64/sve/slp_13.c 
b/gcc/testsuite/gcc.target/aarch64/sve/slp_13.c
index 37b5f1148a3..2e8c3965e18 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/slp_13.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/slp_13.c
@@ -32,14 +32,11 @@ vec_slp_##TYPE (TYPE *restrict a, int n)
\
 
 TEST_ALL (VEC_PERM)
 
-/* ??? We don't treat the uint loops as SLP.  */
 /* The loop should be fully-masked.  */
-/* { dg-final { scan-assembler-times {\tld1b\t} 2 { xfail *-*-* } } } */
-/* { dg-final { scan-assembler-times {\tld1h\t} 3 { xfail *-*-* } } } */
-/* { dg-final { scan-assembler-times {\tld1w\t} 3 { xfail *-*-* } } } */
-/* { dg-final { scan-assembler-times {\tld1w\t} 2 } } */
-/* { dg-final { scan-assembler-times {\tld1d\t} 3 { xfail *-*-* } } } */
-/* { dg-final { scan-assembler-times {\tld1d\t} 2 } } */
+/* { dg-final { scan-assembler-times {\tld1b\t} 2 } } */
+/* { dg-final { scan-assembler-times {\tld1h\t} 3 } } */
+/* { dg-final { scan-assembler-times {\tld1w\t} 3 } } */
+/* { dg-final { scan-assembler-times {\tld1d\t} 3 } } */
 /* { dg-final { scan-assembler-not {\tldr} } } */
 
 /* { dg-final { scan-assembler-times {\twhilelo\tp[0-7]\.b} 4 } } */
-- 
2.25.1



[PATCH] vect/aarch64: Fix various sve/cond*.c failures

2023-01-26 Thread Richard Sandiford via Gcc-patches
Quite a few gcc.target/aarch64/sve/cond*.c tests started failing
after g:68e0063397ba820e71adc220b2da0581dce29ffa, but it turns out
that we were cheating passes before the patch.

The tests involve comparing the cost of N wide compares, a pack
sequence, and a narrow COND_EXPR with the cost of a single COND_EXPR
on fewer elements.  The costs for the former included all operations,
but the costs for the latter didn't model the comparison embedded in
the COND_EXPR.  The patch made us include the comparison on both sides,
making it apples-for-apples, but that's enough to tip the balance in
favour of using the wider types.

I think the new choice does reflect the current SVE cost model
correctly.  (Whether and how the model should be tweaked is a
different question.)  This patch therefore changes the tuning
vector length to one that makes the choice more obvious.

That in turn needs a tweak to compare_inside_loop_cost.
The function compares body_cost1/vf1 with body_cost2/vf2,
but for fully-amsked loops, it limits vf to the actual number
of iterations.  This is so that (say) an expensive 16-element
vector body doesn't win over a cheaper 8-element vector body
when there are only 7 elements to process.

However, the limit was applied using known_le, regardless of
the tuning target.  For a heuristic like this, it seems better
to use the likely minimum (which is a concept that was only
added after this code went in).

g:68e0063397ba820e71adc220b2da0581dce29ffa also fixed
vcond_4_costly.c.

Tested on aarch64-linux-gnu.  OK to install?

Richard


gcc/
* tree-vectorizer.cc (vector_costs::compare_inside_loop_cost):
Use the likely minimum VF when bounding the denominators to
the estimated number of iterations.

gcc/testsuite/
* gcc.target/aarch64/sve/cond_asrd_1.c: Tune for a 256-bit
vector length.
* gcc.target/aarch64/sve/cond_cnot_4.c: Likewise.
* gcc.target/aarch64/sve/cond_cnot_6.c: Likewise.
* gcc.target/aarch64/sve/cond_unary_5.c: Likewise.
* gcc.target/aarch64/sve/cond_unary_6.c: Likewise.
* gcc.target/aarch64/sve/cond_uxt_5.c: Likewise.
* gcc.target/aarch64/sve/vcond_4_costly.c: Remove XFAILs.
---
 gcc/testsuite/gcc.target/aarch64/sve/cond_asrd_1.c| 2 +-
 gcc/testsuite/gcc.target/aarch64/sve/cond_cnot_4.c| 2 +-
 gcc/testsuite/gcc.target/aarch64/sve/cond_cnot_6.c| 2 +-
 gcc/testsuite/gcc.target/aarch64/sve/cond_unary_5.c   | 2 +-
 gcc/testsuite/gcc.target/aarch64/sve/cond_unary_6.c   | 2 +-
 gcc/testsuite/gcc.target/aarch64/sve/cond_uxt_5.c | 2 +-
 gcc/testsuite/gcc.target/aarch64/sve/vcond_4_costly.c | 4 ++--
 gcc/tree-vectorizer.cc| 6 --
 8 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/gcc/testsuite/gcc.target/aarch64/sve/cond_asrd_1.c 
b/gcc/testsuite/gcc.target/aarch64/sve/cond_asrd_1.c
index 478b52ac27c..aac06bd8093 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/cond_asrd_1.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/cond_asrd_1.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -ftree-vectorize" } */
+/* { dg-options "-O2 -ftree-vectorize -moverride=sve_width=256" } */
 
 #include 
 
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/cond_cnot_4.c 
b/gcc/testsuite/gcc.target/aarch64/sve/cond_cnot_4.c
index 729d3f4f2ac..f6278916e1a 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/cond_cnot_4.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/cond_cnot_4.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -ftree-vectorize" } */
+/* { dg-options "-O2 -ftree-vectorize -moverride=sve_width=256" } */
 
 #include 
 
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/cond_cnot_6.c 
b/gcc/testsuite/gcc.target/aarch64/sve/cond_cnot_6.c
index d44e357f44a..ef1b067172f 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/cond_cnot_6.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/cond_cnot_6.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -ftree-vectorize" } */
+/* { dg-options "-O2 -ftree-vectorize -moverride=sve_width=256" } */
 
 #include 
 
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/cond_unary_5.c 
b/gcc/testsuite/gcc.target/aarch64/sve/cond_unary_5.c
index 17b3f86c8c6..03a6636f2d2 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/cond_unary_5.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/cond_unary_5.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -ftree-vectorize" } */
+/* { dg-options "-O2 -ftree-vectorize -moverride=sve_width=256" } */
 
 #include 
 
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/cond_unary_6.c 
b/gcc/testsuite/gcc.target/aarch64/sve/cond_unary_6.c
index 1bd342b65d4..c49a3040b21 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/cond_unary_6.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/cond_unary_6.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -ftree-vectorize" } */
+/* { dg-options "-O2 -ftree-vectorize -moverride=sve_width=256" } */
 
 #include 
 
diff --git 

RE: [PATCH 2/3] arm: Remove unnecessary zero-extending of MVE predicates before use [PR 107674]

2023-01-26 Thread Kyrylo Tkachov via Gcc-patches
Hi Andre,

> -Original Message-
> From: Andre Vieira (lists) 
> Sent: Tuesday, January 24, 2023 1:54 PM
> To: gcc-patches@gcc.gnu.org
> Cc: Richard Sandiford ; Richard Earnshaw
> ; Richard Biener ;
> Kyrylo Tkachov 
> Subject: [PATCH 2/3] arm: Remove unnecessary zero-extending of MVE
> predicates before use [PR 107674]
> 
> Hi,
> 
> This patch teaches GCC that zero-extending a MVE predicate from 16-bits
> to 32-bits and then only using 16-bits is a no-op.
> It does so in two steps:
> - it lets gcc know that it can access any MVE predicate mode using any
> other MVE predicate mode without needing to copy it, using the
> TARGET_MODES_TIEABLE_P hook,
> - it teaches simplify_subreg to optimize a subreg with a vector
> outermode, by replacing this outermode with a same-sized integer mode
> and trying the avalailable optimizations, then if successful it
> surrounds the result with a subreg casting it back to the original
> vector outermode.
> 
> This removes the unnecessary zero-extending shown on PR 107674 (though
> it's a sign-extend there), that was introduced in gcc 11.
> 
> Bootstrapped on aarch64-none-linux-gnu and regression tested on
> arm-none-eabi and armeb-none-eabi for armv8.1-m.main+mve.fp.
> 
> OK for trunk?
> 
> gcc/ChangeLog:
> 
>   PR target/107674
>  * conig/arm/arm.cc (arm_hard_regno_mode_ok): Use new MACRO.
>  (arm_modes_tieable_p): Make MVE predicate modes tieable.
>   * config/arm/arm.h (VALID_MVE_PRED_MODE):  New define.
>   * simplify-rtx.cc (simplify_context::simplify_subreg): Teach
>   simplify_subreg to simplify subregs where the outermode is not
> scalar.

The arm changes look ok to me. We'll want a midend maintainer to have a look at 
simplify-rtx.cc

> 
> gcc/testsuite/ChangeLog:
> 
>   * gcc.target/arm/mve/mve_vpt.c: Change to remove unecessary
>   zero-extend.

diff --git a/gcc/testsuite/gcc.target/arm/mve/mve_vpt.c 
b/gcc/testsuite/gcc.target/arm/mve/mve_vpt.c
index 
26a565b79dd1348e361b3aa23a1d6e6d13bffce8..8e562a9f065eff157f63ebd5acf9af0a2155b5c5
 100644
--- a/gcc/testsuite/gcc.target/arm/mve/mve_vpt.c
+++ b/gcc/testsuite/gcc.target/arm/mve/mve_vpt.c
@@ -16,9 +16,6 @@ void test0 (uint8_t *a, uint8_t *b, uint8_t *c)
 ** vldrb.8 q2, \[r0\]
 ** vldrb.8 q1, \[r1\]
 ** vcmp.i8 eq, q2, q1
-** vmrsr3, p0  @ movhi
-** uxthr3, r3
-** vmsrp0, r3  @ movhi
 ** vpst
 ** vaddt.i8q3, q2, q1
 ** vpst

Ah I see, that's the testcase from patch 1/3 that I criticized :)
Maybe if we just scan for absence of an uxth, vmrs and vmsr it will be more 
robust?
Thanks,
Kyrill


RE: [PATCH 1/3] arm: Fix sign of MVE predicate mve_pred16_t [PR 107674]

2023-01-26 Thread Kyrylo Tkachov via Gcc-patches


> -Original Message-
> From: Kyrylo Tkachov
> Sent: Thursday, January 26, 2023 3:02 PM
> To: Andre Vieira (lists) ; gcc-
> patc...@gcc.gnu.org
> Cc: Richard Earnshaw 
> Subject: RE: [PATCH 1/3] arm: Fix sign of MVE predicate mve_pred16_t [PR
> 107674]
> 
> Hi Andre,
> 
> > -Original Message-
> > From: Andre Vieira (lists) 
> > Sent: Tuesday, January 24, 2023 1:41 PM
> > To: gcc-patches@gcc.gnu.org
> > Cc: Kyrylo Tkachov ; Richard Earnshaw
> > 
> > Subject: [PATCH 1/3] arm: Fix sign of MVE predicate mve_pred16_t [PR
> > 107674]
> >
> > Hi,
> >
> > The ACLE defines mve_pred16_t as an unsigned short.  This patch makes
> > sure GCC treats the predicate as an unsigned type, rather than signed.
> >
> > Bootstrapped on aarch64-none-eabi and regression tested on arm-none-
> eabi
> > and armeb-none-eabi for armv8.1-m.main+mve.fp.
> >
> > OK for trunk?
> >
> > gcc/ChangeLog:
> >
> > PR target/107674
> > * config/arm/arm-builtins.cc (arm_simd_builtin_type): Rewrite to
> > use
> > new qualifiers parameter and use unsigned short type for MVE
> > predicate.
> > (arm_init_builtin): Call arm_simd_builtin_type with qualifiers
> > parameter.
> > (arm_init_crypto_builtins): Likewise.
> >
> > gcc/testsuite/ChangeLog:
> >
> > PR target/107674
> > * gcc.target/arm/mve/mve_vpt.c: New test.
> 
> diff --git a/gcc/config/arm/arm-builtins.cc b/gcc/config/arm/arm-builtins.cc
> index
> 11d7478d9df69139802a9d42c09dd0de7480b60e..6c67cec93ff76a4b42f3a0b3
> 05f697142e88fcd9 100644
> --- a/gcc/config/arm/arm-builtins.cc
> +++ b/gcc/config/arm/arm-builtins.cc
> @@ -1489,12 +1489,14 @@ arm_lookup_simd_builtin_type (machine_mode
> mode,
>  }
> 
>  static tree
> -arm_simd_builtin_type (machine_mode mode, bool unsigned_p, bool
> poly_p)
> +arm_simd_builtin_type (machine_mode mode, enum arm_type_qualifiers
> qualifiers)
>  {
> 
> I think in C++ now we can leave out the "enum" here.
> 
> diff --git a/gcc/testsuite/gcc.target/arm/mve/mve_vpt.c
> b/gcc/testsuite/gcc.target/arm/mve/mve_vpt.c
> new file mode 100644
> index
> ..26a565b79dd1348e361b3a
> a23a1d6e6d13bffce8
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/arm/mve/mve_vpt.c
> @@ -0,0 +1,27 @@
> +/* { dg-options "-O2" } */
> +/* { dg-require-effective-target arm_v8_1m_mve_ok } */
> +/* { dg-add-options arm_v8_1m_mve } */
> +/* { dg-final { check-function-bodies "**" "" } } */
> +#include 
> +void test0 (uint8_t *a, uint8_t *b, uint8_t *c)
> +{
> +uint8x16_t va = vldrbq_u8 (a);
> +uint8x16_t vb = vldrbq_u8 (b);
> +mve_pred16_t p = vcmpeqq_u8 (va, vb);
> +uint8x16_t vc = vaddq_x_u8 (va, vb, p);
> +vstrbq_p_u8 (c, vc, p);
> +}
> +/*
> +** test0:
> +**   vldrb.8 q2, \[r0\]
> +**   vldrb.8 q1, \[r1\]
> +**   vcmp.i8 eq, q2, q1
> +**   vmrsr3, p0  @ movhi
> +**   uxthr3, r3
> +**   vmsrp0, r3  @ movhi
> +**   vpst
> +**   vaddt.i8q3, q2, q1
> +**   vpst
> +**   vstrbt.8q3, \[r2\]
> +**   bx  lr
> +*/
> 
> This explicit assembly matching looks quite fragile and sensitive to future
> scheduling and RA changes.
> Is there something more targeted we could scan for to check that the
> predicate is unsigned now?

The patch looks fine to me btw. With a more robust testcase and the cosmetic 
fix above it can go in.
Thanks,
Kyrill

> 
> Thanks,
> Kyrill


RE: [PATCH 1/3] arm: Fix sign of MVE predicate mve_pred16_t [PR 107674]

2023-01-26 Thread Kyrylo Tkachov via Gcc-patches
Hi Andre,

> -Original Message-
> From: Andre Vieira (lists) 
> Sent: Tuesday, January 24, 2023 1:41 PM
> To: gcc-patches@gcc.gnu.org
> Cc: Kyrylo Tkachov ; Richard Earnshaw
> 
> Subject: [PATCH 1/3] arm: Fix sign of MVE predicate mve_pred16_t [PR
> 107674]
> 
> Hi,
> 
> The ACLE defines mve_pred16_t as an unsigned short.  This patch makes
> sure GCC treats the predicate as an unsigned type, rather than signed.
> 
> Bootstrapped on aarch64-none-eabi and regression tested on arm-none-eabi
> and armeb-none-eabi for armv8.1-m.main+mve.fp.
> 
> OK for trunk?
> 
> gcc/ChangeLog:
> 
>   PR target/107674
>   * config/arm/arm-builtins.cc (arm_simd_builtin_type): Rewrite to
> use
>   new qualifiers parameter and use unsigned short type for MVE
> predicate.
>   (arm_init_builtin): Call arm_simd_builtin_type with qualifiers
>   parameter.
>   (arm_init_crypto_builtins): Likewise.
> 
> gcc/testsuite/ChangeLog:
> 
>   PR target/107674
>   * gcc.target/arm/mve/mve_vpt.c: New test.

diff --git a/gcc/config/arm/arm-builtins.cc b/gcc/config/arm/arm-builtins.cc
index 
11d7478d9df69139802a9d42c09dd0de7480b60e..6c67cec93ff76a4b42f3a0b305f697142e88fcd9
 100644
--- a/gcc/config/arm/arm-builtins.cc
+++ b/gcc/config/arm/arm-builtins.cc
@@ -1489,12 +1489,14 @@ arm_lookup_simd_builtin_type (machine_mode mode,
 }
 
 static tree
-arm_simd_builtin_type (machine_mode mode, bool unsigned_p, bool poly_p)
+arm_simd_builtin_type (machine_mode mode, enum arm_type_qualifiers qualifiers)
 {

I think in C++ now we can leave out the "enum" here.

diff --git a/gcc/testsuite/gcc.target/arm/mve/mve_vpt.c 
b/gcc/testsuite/gcc.target/arm/mve/mve_vpt.c
new file mode 100644
index 
..26a565b79dd1348e361b3aa23a1d6e6d13bffce8
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/mve/mve_vpt.c
@@ -0,0 +1,27 @@
+/* { dg-options "-O2" } */
+/* { dg-require-effective-target arm_v8_1m_mve_ok } */
+/* { dg-add-options arm_v8_1m_mve } */
+/* { dg-final { check-function-bodies "**" "" } } */
+#include 
+void test0 (uint8_t *a, uint8_t *b, uint8_t *c)
+{
+uint8x16_t va = vldrbq_u8 (a);
+uint8x16_t vb = vldrbq_u8 (b);
+mve_pred16_t p = vcmpeqq_u8 (va, vb);
+uint8x16_t vc = vaddq_x_u8 (va, vb, p);
+vstrbq_p_u8 (c, vc, p);
+}
+/*
+** test0:
+** vldrb.8 q2, \[r0\]
+** vldrb.8 q1, \[r1\]
+** vcmp.i8 eq, q2, q1
+** vmrsr3, p0  @ movhi
+** uxthr3, r3
+** vmsrp0, r3  @ movhi
+** vpst
+** vaddt.i8q3, q2, q1
+** vpst
+** vstrbt.8q3, \[r2\]
+** bx  lr
+*/

This explicit assembly matching looks quite fragile and sensitive to future 
scheduling and RA changes.
Is there something more targeted we could scan for to check that the predicate 
is unsigned now?

Thanks,
Kyrill


Re: [PATCH] constexprify some tree variables

2023-01-26 Thread Jakub Jelinek via Gcc-patches
On Thu, Jan 26, 2023 at 03:51:07PM +0100, Jakub Jelinek via Gcc-patches wrote:
> On Thu, Jan 26, 2023 at 09:45:35AM -0500, Patrick Palka via Gcc-patches wrote:
> > > -extern const unsigned char tree_code_length[];
> > > +
> > > +#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
> > > +#define END_OF_BASE_TREE_CODES 0,
> > > +constexpr unsigned char tree_code_length[] = {
> > > +#include "all-tree.def"
> > > +};
> > > +
> > > +#undef DEFTREECODE
> > > +#undef END_OF_BASE_TREE_CODES
> > 
> > IIUC defining these globals as non-inline constexpr gives them internal
> > linkage, and so each TU contains its own unique copy of these globals.
> > This bloats cc1plus by a tiny bit and is technically an ODR violation
> > because some inline functions such as tree_class_check also ODR-use
> > these variables and so each defn of tree_class_check will refer to a
> > "different" tree_code_class.  Since inline variables are a C++17
> > feature, I guess we could fix this by defining the globals the old way
> > before C++17 and as inline constexpr otherwise?
> 
> Agreed, just use
> __cpp_inline_variables >= 201606L
> to select between the old and new ways.

And I'd argue with the tiny bit.
In my x86_64-linux cc1plus from today, I see 193 _ZL16tree_code_length vars,
374 bytes each, and 324 _ZL14tree_code_type vars, 1496 bytes each.
So, that means waste of 555016 .rodata bytes, plus being highly non-cache
friendly.

Jakub



Re: [PATCH] constexprify some tree variables

2023-01-26 Thread Jakub Jelinek via Gcc-patches
On Thu, Jan 26, 2023 at 09:45:35AM -0500, Patrick Palka via Gcc-patches wrote:
> > -extern const unsigned char tree_code_length[];
> > +
> > +#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
> > +#define END_OF_BASE_TREE_CODES 0,
> > +constexpr unsigned char tree_code_length[] = {
> > +#include "all-tree.def"
> > +};
> > +
> > +#undef DEFTREECODE
> > +#undef END_OF_BASE_TREE_CODES
> 
> IIUC defining these globals as non-inline constexpr gives them internal
> linkage, and so each TU contains its own unique copy of these globals.
> This bloats cc1plus by a tiny bit and is technically an ODR violation
> because some inline functions such as tree_class_check also ODR-use
> these variables and so each defn of tree_class_check will refer to a
> "different" tree_code_class.  Since inline variables are a C++17
> feature, I guess we could fix this by defining the globals the old way
> before C++17 and as inline constexpr otherwise?

Agreed, just use
__cpp_inline_variables >= 201606L
to select between the old and new ways.

Jakub



Re: [PATCH] constexprify some tree variables

2023-01-26 Thread Patrick Palka via Gcc-patches
On Fri, 18 Nov 2022, apinski--- via Gcc-patches wrote:

> From: Andrew Pinski 
> 
> Since we use C++11 by default now, we can
> use constexpr for some const decls in tree-core.h.
> 
> This patch does that and it allows for better optimizations
> of GCC code with checking enabled and without LTO.
> 
> For an example generic-match.cc compiling is speed up due
> to the less number of basic blocks and less debugging info
> produced. I did not check the speed of compiling the same source
> but rather the speed of compiling the old vs new sources here
> (but with the same compiler base).
> 
> The small slow down in the parsing of the arrays in each TU
> is migrated by a speed up in how much code/debugging info
> is produced in the end.
> 
> Note I looked at generic-match.cc since it is one of the
> compiling sources which causes parallel building to stall and
> I wanted to speed it up.
> 
> OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
> Or should this wait until GCC 13 branches off?
> 
> gcc/ChangeLog:
> 
>   PR middle-end/14840
>   * tree-core.h (tree_code_type): Constexprify
>   by including all-tree.def.
>   (tree_code_length): Likewise.
>   * tree.cc (tree_code_type): Remove.
>   (tree_code_length): Remove.
> ---
>  gcc/tree-core.h | 21 +++--
>  gcc/tree.cc | 24 
>  2 files changed, 19 insertions(+), 26 deletions(-)
> 
> diff --git a/gcc/tree-core.h b/gcc/tree-core.h
> index af75522504f..e146b133dbd 100644
> --- a/gcc/tree-core.h
> +++ b/gcc/tree-core.h
> @@ -2284,15 +2284,32 @@ struct floatn_type_info {
>  /* Matrix describing the structures contained in a given tree code.  */
>  extern bool tree_contains_struct[MAX_TREE_CODES][64];
>  
> +#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
> +#define END_OF_BASE_TREE_CODES tcc_exceptional,
> +
> +
>  /* Class of tree given its code.  */
> -extern const enum tree_code_class tree_code_type[];
> +constexpr enum tree_code_class tree_code_type[] = {
> +#include "all-tree.def"
> +};
> +
> +#undef DEFTREECODE
> +#undef END_OF_BASE_TREE_CODES
>  
>  /* Each tree code class has an associated string representation.
> These must correspond to the tree_code_class entries.  */
>  extern const char *const tree_code_class_strings[];
>  
>  /* Number of argument-words in each kind of tree-node.  */
> -extern const unsigned char tree_code_length[];
> +
> +#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
> +#define END_OF_BASE_TREE_CODES 0,
> +constexpr unsigned char tree_code_length[] = {
> +#include "all-tree.def"
> +};
> +
> +#undef DEFTREECODE
> +#undef END_OF_BASE_TREE_CODES

IIUC defining these globals as non-inline constexpr gives them internal
linkage, and so each TU contains its own unique copy of these globals.
This bloats cc1plus by a tiny bit and is technically an ODR violation
because some inline functions such as tree_class_check also ODR-use
these variables and so each defn of tree_class_check will refer to a
"different" tree_code_class.  Since inline variables are a C++17
feature, I guess we could fix this by defining the globals the old way
before C++17 and as inline constexpr otherwise?

>  
>  /* Vector of all alias pairs for global symbols.  */
>  extern GTY(()) vec *alias_pairs;
> diff --git a/gcc/tree.cc b/gcc/tree.cc
> index 574bd2e65d9..254b2373dcf 100644
> --- a/gcc/tree.cc
> +++ b/gcc/tree.cc
> @@ -74,31 +74,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "asan.h"
>  #include "ubsan.h"
>  
> -/* Tree code classes.  */
>  
> -#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
> -#define END_OF_BASE_TREE_CODES tcc_exceptional,
> -
> -const enum tree_code_class tree_code_type[] = {
> -#include "all-tree.def"
> -};
> -
> -#undef DEFTREECODE
> -#undef END_OF_BASE_TREE_CODES
> -
> -/* Table indexed by tree code giving number of expression
> -   operands beyond the fixed part of the node structure.
> -   Not used for types or decls.  */
> -
> -#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
> -#define END_OF_BASE_TREE_CODES 0,
> -
> -const unsigned char tree_code_length[] = {
> -#include "all-tree.def"
> -};
> -
> -#undef DEFTREECODE
> -#undef END_OF_BASE_TREE_CODES
>  
>  /* Names of tree components.
> Used for printing out the tree and error messages.  */
> -- 
> 2.17.1
> 
> 



Re: [PATCH] PR tree-optimization/108447 - Do not try to logical fold floating point relations.

2023-01-26 Thread Andrew MacLeod via Gcc-patches



On 1/26/23 02:13, Richard Biener wrote:

On Thu, Jan 26, 2023 at 8:09 AM Richard Biener
 wrote:

On Wed, Jan 25, 2023 at 7:05 PM Andrew MacLeod  wrote:

This boils down to a single place where we are trying to do things with
relations in ranger that are simply not safe when we need to honor NANs.

I think we can avoid all the other shuffling of relations, and simply
not perform this optimization when it comes to floats.

The case the routine handles is:

c_2 = a_6 > b_7
c_3 = a_6 < b_7
c_4 = c_2 && c_3

c_2 and c_3 can never be true at the same time, Therefore c_4 can always
resolve to false based purely on the relations.


Range-ops is unable to do this optimization directly as it requires
examining things from outside the statement, and is not easily
communicated a simple relation to operator_logical_and.

This routine proceeds to look at the definitions of c_2 and c_3, tries
to determine if there are common operands, and queries for any relations
between them.   If it turns out there is something, depending on whether
its && or || , we use intersection or union to determine if the result
of the logical operation can be folded.  If HONOR_NANS is true for the
float type, then we cannot do this optimization, and bail early.

At this point I do not think we need to do any of the other things
proposed to relations, so we don't need either of the other 2 patches
this release.

Bootstraps on x86_64-pc-linux-gnu with no regressions.  OK for trunk?

+  if (HONOR_NANS (TREE_TYPE (ssa1_dep1)))
+return;

would that rather be !(range-includes-nan (ssa1_dep1) ||
range-includes-nan (ssa1_dep2) || ..)?

Saw the discussion in the other thread only now, so OK.


That said, if the other 2 patches fix some latent issues in the new
frange code I'd
rather have them fixed.

So do we know bugs in the current code?  You said some buggy
function isn't used, so better delete it.  Are there other latent issues?

No bugs :-) At leats not related tot hat.    Yes, negate turns out to 
not currently be used (im sure it will eventually), but without the 
VREL_OTHER or other changes to relation representation, the negate table 
is currently correct.


Andrew





[committed] analyzer: fix SARD-tc841-basic-00182-min.c test case [PR108507]

2023-01-26 Thread David Malcolm via Gcc-patches
Lightly tested on Compiler Explorer; fixes issues on
aarch64-unknown-linux-gnu.
Successfully regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r13-5389-gf1eab269288ffa.

gcc/testsuite/ChangeLog:
PR analyzer/108507
* gcc.dg/analyzer/SARD-tc841-basic-00182-min.c: Add
-Wno-stringop-overflow.

Signed-off-by: David Malcolm 
---
 gcc/testsuite/gcc.dg/analyzer/SARD-tc841-basic-00182-min.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/analyzer/SARD-tc841-basic-00182-min.c 
b/gcc/testsuite/gcc.dg/analyzer/SARD-tc841-basic-00182-min.c
index 577dce13f00..ed9ad317d19 100644
--- a/gcc/testsuite/gcc.dg/analyzer/SARD-tc841-basic-00182-min.c
+++ b/gcc/testsuite/gcc.dg/analyzer/SARD-tc841-basic-00182-min.c
@@ -4,6 +4,9 @@
  Black, P. , Koo, H. and Irish, T. (2013), A Basic CWE-121 Buffer Overflow 
Effectiveness Test Suite, Proc. 6th Latin-American Symposium on Dependable 
Computing, Rio de Janeiro, -1, [online], 
https://tsapps.nist.gov/publication/get_pdf.cfm?pub_id=913117 (Accessed January 
17, 2023)
 */
 
+/* The purpose of this testcase is to see if -fanalyzer can detect the bug.  */
+/* { dg-additional-options "-Wno-stringop-overflow" } */
+
 /* Taxonomy Classification: 30060213031110 */
 
 /*
-- 
2.26.3



[committed] analyzer: fix false positives from -Wanalyzer-infinite-recursion [PR108524]

2023-01-26 Thread David Malcolm via Gcc-patches
Reject -Wanalyzer-infinite-recursion diagnostics in which control flow
has been affected by conjured_svalues between the initial call to a
function and the subsequent entry to that function.  This prevents false
positives such as in qemu's recursive JSON parser where function calls are
changing state in the rest of the program (e.g. consuming tokens), despite
the modelled state being effectively identical at both nested entrypoints.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.

Integration testing shows it eliminates all 6 of the diagnostics seen
from -Wanalyzer-infinite-recursion, all of which appear to have been
false positives.

Pushed to trunk as r13-5388-g7bffea89f1f164.

gcc/analyzer/ChangeLog:
PR analyzer/108524
* analyzer.h (class feasible_node): New forward decl.
* diagnostic-manager.cc (epath_finder::get_best_epath): Add "pd"
param.
(epath_finder::explore_feasible_paths): Likewise.
(epath_finder::process_worklist_item): Likewise.  Use it to call
pending_diagnostic::check_valid_fpath_p on the final fpath to
give pending_diagnostic a way to add additional restrictions on
feasibility.
(saved_diagnostic::calc_best_epath): Pass pending_diagnostic to
epath_finder::get_best_epath.
* infinite-recursion.cc: Include "analyzer/feasible-graph.h".
(infinite_recursion_diagnostic::check_valid_fpath_p): New.
(infinite_recursion_diagnostic::fedge_uses_conjured_svalue_p): New.
(infinite_recursion_diagnostic::expr_uses_conjured_svalue_p): New.
* pending-diagnostic.h (pending_diagnostic::check_valid_fpath_p):
New vfunc.

gcc/testsuite/ChangeLog:
PR analyzer/108524
* gcc.dg/analyzer/infinite-recursion-pr108524-1.c: New test.
* gcc.dg/analyzer/infinite-recursion-pr108524-2.c: New test.
* gcc.dg/analyzer/infinite-recursion-pr108524-qobject-json-parser.c:
New test.

Signed-off-by: David Malcolm 
---
 gcc/analyzer/analyzer.h   |   2 +
 gcc/analyzer/diagnostic-manager.cc|  26 +-
 gcc/analyzer/infinite-recursion.cc| 100 ++
 gcc/analyzer/pending-diagnostic.h |   9 +
 .../analyzer/infinite-recursion-pr108524-1.c  | 145 
 .../analyzer/infinite-recursion-pr108524-2.c  | 113 ++
 ...e-recursion-pr108524-qobject-json-parser.c | 322 ++
 7 files changed, 712 insertions(+), 5 deletions(-)
 create mode 100644 
gcc/testsuite/gcc.dg/analyzer/infinite-recursion-pr108524-1.c
 create mode 100644 
gcc/testsuite/gcc.dg/analyzer/infinite-recursion-pr108524-2.c
 create mode 100644 
gcc/testsuite/gcc.dg/analyzer/infinite-recursion-pr108524-qobject-json-parser.c

diff --git a/gcc/analyzer/analyzer.h b/gcc/analyzer/analyzer.h
index 8f79e4b5df5..a1619525afa 100644
--- a/gcc/analyzer/analyzer.h
+++ b/gcc/analyzer/analyzer.h
@@ -126,6 +126,8 @@ class call_summary_replay;
 struct per_function_data;
 struct interesting_t;
 
+class feasible_node;
+
 /* Forward decls of functions.  */
 
 extern void dump_tree (pretty_printer *pp, tree t);
diff --git a/gcc/analyzer/diagnostic-manager.cc 
b/gcc/analyzer/diagnostic-manager.cc
index 1227d6c1151..4f036a6c28a 100644
--- a/gcc/analyzer/diagnostic-manager.cc
+++ b/gcc/analyzer/diagnostic-manager.cc
@@ -88,6 +88,7 @@ public:
 
   std::unique_ptr
   get_best_epath (const exploded_node *target_enode,
+ const pending_diagnostic ,
  const char *desc, unsigned diag_idx,
  std::unique_ptr *out_problem);
 
@@ -96,12 +97,14 @@ private:
 
   std::unique_ptr
   explore_feasible_paths (const exploded_node *target_enode,
+ const pending_diagnostic ,
  const char *desc, unsigned diag_idx);
   bool
   process_worklist_item (feasible_worklist *worklist,
 const trimmed_graph ,
 feasible_graph *fg,
 const exploded_node *target_enode,
+const pending_diagnostic ,
 unsigned diag_idx,
 std::unique_ptr *out_best_path) const;
   void dump_trimmed_graph (const exploded_node *target_enode,
@@ -138,6 +141,7 @@ private:
 
 std::unique_ptr
 epath_finder::get_best_epath (const exploded_node *enode,
+ const pending_diagnostic ,
  const char *desc, unsigned diag_idx,
  std::unique_ptr *out_problem)
 {
@@ -161,7 +165,7 @@ epath_finder::get_best_epath (const exploded_node *enode,
   if (logger)
logger->log ("trying to find shortest feasible path");
   if (std::unique_ptr epath
-   = explore_feasible_paths (enode, desc, diag_idx))
+   = explore_feasible_paths (enode, pd, desc, diag_idx))
{
  if (logger)
logger->log ("accepting %qs at EN: %i, SN: %i (sd: %i)"
@@ -374,6 +378,7 @@ private:
 
 

[committed] libstdc++: Add workaround for old tzdata.zi files

2023-01-26 Thread Jonathan Wakely via Gcc-patches
Tested x86_64-linux (Fedora 36 and RHEL 6.10). Pushed to trunk.

-- >8 --

The tzdata.zi file in the RHEL 6 tzdata-2018e-3.el6 package (with
version "unknown") does not conform to the current rules described in
the zic(8) man page. Specifically, a Rule name must not start with the
character '+' in the current rules, but the older tzdata.zi file
used "+" as the name of rules for the "Europe/Sofia" zone.

Add a special case to the logic that detects whether a RULES field
refers to a named rule or is an offset from standard time. For a string
matching exactly "+" treat it as a named Rule, but for any other string
starting with '+' treat it as an offset.

libstdc++-v3/ChangeLog:

* src/c++20/tzdb.cc (operator>>(istream&, ZoneInfo&)): Allow
rules named "+" for compatibility with older tzdata.zi files.
---
 libstdc++-v3/src/c++20/tzdb.cc | 49 +++---
 1 file changed, 34 insertions(+), 15 deletions(-)

diff --git a/libstdc++-v3/src/c++20/tzdb.cc b/libstdc++-v3/src/c++20/tzdb.cc
index c945f002ad7..c956e861891 100644
--- a/libstdc++-v3/src/c++20/tzdb.cc
+++ b/libstdc++-v3/src/c++20/tzdb.cc
@@ -1967,6 +1967,22 @@ namespace std::chrono
   return in;
 }
 
+// Test whether the RULES field of a Zone line is a valid Rule name.
+inline bool
+is_rule_name(string_view rules) noexcept
+{
+  // The NAME field of a Rule line must start with a character that is
+  // neither an ASCII digit nor '-' nor '+'.
+  if (('0' <= rules[0] && rules[0] <= '9') || rules[0] == '-')
+   return false;
+  // However, some older tzdata.zi files (e.g. in tzdata-2018e-3.el6 RPM)
+  // used "+" as a Rule name, so we need to handle that special case.
+  if (rules[0] == '+')
+   return rules.size() == 1; // "+" is a rule name, "+1" is not.
+  // Everything else is the name of a Rule.
+  return true;
+}
+
 istream& operator>>(istream& in, ZoneInfo& inf)
 {
   // STDOFF  RULES  FORMAT  [UNTIL]
@@ -1976,25 +1992,28 @@ namespace std::chrono
 
   in >> off >> quoted{rules} >> fmt;
   inf.m_offset = off.time;
-  if (rules == "-")
+  if (is_rule_name(rules))
{
- // Standard time always applies, no DST.
- inf.set_abbrev(fmt);
-   }
-  else if (string_view("0123456789-+").find(rules[0]) != string_view::npos)
-   {
- // rules specifies the difference from standard time.
- at_time rules_time;
- istringstream in2(std::move(rules));
- in2 >> rules_time;
- inf.m_save = duration_cast(rules_time.time);
- select_std_or_dst_abbrev(fmt, inf.m_save);
- inf.set_abbrev(fmt);
+ // `rules` refers to a named Rule which describes transitions.
+ inf.set_rules_and_format(rules, fmt);
}
   else
{
- // rules refers to a named Rule which describes transitions.
- inf.set_rules_and_format(rules, fmt);
+ if (rules == "-")
+   {
+ // Standard time always applies, no DST.
+   }
+ else
+   {
+ // `rules` specifies the difference from standard time,
+ // e.g., "-2:30"
+ at_time rules_time;
+ istringstream in2(std::move(rules));
+ in2 >> rules_time;
+ inf.m_save = duration_cast(rules_time.time);
+ select_std_or_dst_abbrev(fmt, inf.m_save);
+   }
+ inf.set_abbrev(fmt);
}
 
   // YEAR [MONTH [DAY [TIME]]]
-- 
2.39.1



[committed] libstdc++: Add returns_nonnull to non-inline std::map detail [PR108554]

2023-01-26 Thread Jonathan Wakely via Gcc-patches
Tested x86_64-linux. Pushed to trunk.

-- >8 --

std::map uses a non-inline function to rebalance its tree and the
compiler can't see that it always returns a valid pointer (assuming
valid inputs, which is a precondition anyway). This can result in
-Wnull-derefernce warnings for valid code, because the compiler thinks
there is a path where the function returns null.

Adding the returns_nonnull attribute tells the compiler that is can't
happen. While we're doing that, we might as well also add a nonnull
attribute to the rebalancing functions too.

libstdc++-v3/ChangeLog:

PR libstdc++/108554
* include/bits/stl_tree.h (_Rb_tree_insert_and_rebalance): Add
nonnull attribute.
(_Rb_tree_rebalance_for_erase): Add nonnull and returns_nonnull
attributes.
* testsuite/23_containers/map/modifiers/108554.cc: New test.
---
 libstdc++-v3/include/bits/stl_tree.h  |  2 ++
 .../23_containers/map/modifiers/108554.cc | 19 +++
 2 files changed, 21 insertions(+)
 create mode 100644 libstdc++-v3/testsuite/23_containers/map/modifiers/108554.cc

diff --git a/libstdc++-v3/include/bits/stl_tree.h 
b/libstdc++-v3/include/bits/stl_tree.h
index 5b7a5869b14..3c331fbc952 100644
--- a/libstdc++-v3/include/bits/stl_tree.h
+++ b/libstdc++-v3/include/bits/stl_tree.h
@@ -405,12 +405,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   _Base_ptr _M_node;
 };
 
+  __attribute__((__nonnull__))
   void
   _Rb_tree_insert_and_rebalance(const bool __insert_left,
_Rb_tree_node_base* __x,
_Rb_tree_node_base* __p,
_Rb_tree_node_base& __header) throw ();
 
+  __attribute__((__nonnull__,__returns_nonnull__))
   _Rb_tree_node_base*
   _Rb_tree_rebalance_for_erase(_Rb_tree_node_base* const __z,
   _Rb_tree_node_base& __header) throw ();
diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/108554.cc 
b/libstdc++-v3/testsuite/23_containers/map/modifiers/108554.cc
new file mode 100644
index 000..7076682f4c9
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/108554.cc
@@ -0,0 +1,19 @@
+// { dg-do compile { target c++17 } }
+// { dg-options "-Wnull-dereference -O2" }
+
+// PR libstdc++/108554
+// Warning from -Wnull-dereference when extracting a unique_ptr from a map.
+
+#include 
+#include 
+#include 
+
+int pop(std::map>& m)
+{
+  if (auto it = m.find("key"); it != m.end())
+  {
+auto item = std::move(m.extract(it).mapped());
+return *item;
+  }
+  return 0;
+}
-- 
2.39.1



[committed] libstdc++: Fix strings read from /etc/sysconfig/clock [PR108530]

2023-01-26 Thread Jonathan Wakely via Gcc-patches
Tested x86_64-linux (Fedora 36 and RHEL 6.10). Pushed to trunk.

-- >8 --

In r13-5339-ge00d5cafbe1a77 I made std::chrono::current_zone() look for
DEFAULT_TIMEZONE in /etc/sysconfig/clock but that is the wrong variable.
Old Suse systems use TIMEZONE to determine which zone /etc/localtime is
a copy of, and old RHEL system use ZONE.

libstdc++-v3/ChangeLog:

PR libstdc++/108530
* src/c++20/tzdb.cc (current_zone): Look for TIMEZONE or ZONE in
/etc/sysconfig/clock, not DEFAULT_TIMEZONE.
---
 libstdc++-v3/src/c++20/tzdb.cc | 30 --
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/libstdc++-v3/src/c++20/tzdb.cc b/libstdc++-v3/src/c++20/tzdb.cc
index eb68111e444..c945f002ad7 100644
--- a/libstdc++-v3/src/c++20/tzdb.cc
+++ b/libstdc++-v3/src/c++20/tzdb.cc
@@ -1667,21 +1667,23 @@ namespace std::chrono
 if (ifstream tzf{"/etc/sysconfig/clock"})
   {
string line;
-   string_view key = "DEFAULT_TIMEZONE=";
+   // Old versions of Suse use TIMEZONE. Old versions of RHEL use ZONE.
+   const string_view keys[] = { "TIMEZONE=" , "ZONE=" };
while (std::getline(tzf, line))
- if (line.starts_with(key))
-   {
- string_view name = line;
- name.remove_prefix(key.size());
- if (name.size() != 0 && name.front() == '"')
-   {
- name.remove_prefix(1);
- if (auto pos = name.find('"'); pos != name.npos)
-   name = name.substr(0, pos);
-   }
- if (auto tz = do_locate_zone(this->zones, this->links, name))
-   return tz;
-   }
+ for (string_view key : keys)
+   if (line.starts_with(key))
+ {
+   string_view name = line;
+   name.remove_prefix(key.size());
+   if (name.size() != 0 && name.front() == '"')
+ {
+   name.remove_prefix(1);
+   if (auto pos = name.find('"'); pos != name.npos)
+ name = name.substr(0, pos);
+ }
+   if (auto tz = do_locate_zone(this->zones, this->links, name))
+ return tz;
+ }
   }
 #else
 // AIX stores current zone in $TZ in /etc/environment but the value
-- 
2.39.1



[pushed] libstdc++: Move www.open-std.org to https in bugs manual

2023-01-26 Thread Gerald Pfeifer
Someone used a macro DR in doc/xml/manual/intro.xml which was a really 
clever idea. :-)  It might be good to do this more widely...

Pushed.

Gerald


libstdc++-v3/ChangeLog:

* doc/xml/manual/intro.xml: Update links to www.open-std.org to
use https.
* doc/html/manual/bugs.html: Regenerate.
---
 libstdc++-v3/doc/html/manual/bugs.html | 314 -
 libstdc++-v3/doc/xml/manual/intro.xml  |   6 +-
 2 files changed, 160 insertions(+), 160 deletions(-)

diff --git a/libstdc++-v3/doc/html/manual/bugs.html 
b/libstdc++-v3/doc/html/manual/bugs.html
index c4a2c26ea39..97b7d4d3b83 100644
--- a/libstdc++-v3/doc/html/manual/bugs.html
+++ b/libstdc++-v3/doc/html/manual/bugs.html
@@ -14,7 +14,7 @@
Here are the issues which have resulted in code changes to the library.
The links are to the full version of the Issues List.
 You can read the full version online
-   at the http://www.open-std.org/jtc1/sc22/wg21/; 
target="_top">ISO C++
+   at the https://www.open-std.org/jtc1/sc22/wg21/; 
target="_top">ISO C++
Committee homepage.
   
If a DR is not listed here, we may simply not have gotten to
@@ -24,119 +24,119 @@
directories for appearances of
_GLIBCXX_RESOLVE_LIB_DEFECTS for examples
of style.  Note that we usually do not make changes to the
-   code until an issue has reached http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#DR; 
target="_top">DR status.
-  http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#5; 
target="_top">5:
+   code until an issue has reached https://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#DR; 
target="_top">DR status.
+  https://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#5; 
target="_top">5:
string::compare specification 
questionable
 This should be two overloaded functions rather than a 
single function.
-http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#17; 
target="_top">17:
+https://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#17; 
target="_top">17:
Bad bool parsing
 Apparently extracting Boolean values was messed up...
-http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#19; 
target="_top">19:
+https://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#19; 
target="_top">19:
"Noconv" definition too vague
 If codecvt::do_in returns 
noconv there are
no changes to the values in [to, to_limit).
-http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#22; 
target="_top">22:
+https://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#22; 
target="_top">22:
Member open vs flags
 Re-opening a file stream does not clear the state flags.
-http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#23; 
target="_top">23:
+https://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#23; 
target="_top">23:
Num_get overflow result
 Implement the proposed resolution.
-http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#25; 
target="_top">25:
+https://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#25; 
target="_top">25:
String operator uses width() value 
wrong
 Padding issues.
-http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#48; 
target="_top">48:
+https://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#48; 
target="_top">48:
Use of non-existent exception 
constructor
 An instance of ios_base::failure is constructed instead.
-http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#49; 
target="_top">49:
+https://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#49; 
target="_top">49:
Underspecification of 
ios_base::sync_with_stdio
 The return type is the previous state of synchronization.
-http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#50; 
target="_top">50:
+https://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#50; 
target="_top">50:
Copy constructor and assignment operator of 
ios_base
 These members functions are declared private and are
thus inaccessible.  Specifying the correct semantics of
"copying stream state" was deemed too complicated.
-http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#60; 
target="_top">60:
+https://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#60; 
target="_top">60:
What is a formatted input 
function?
 This DR made many widespread changes to basic_istream
and basic_ostream all of which have been 
implemented.
-http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#63; 
target="_top">63:
+https://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#63; 
target="_top">63:
Exception-handling policy for unformatted 
output
 Make the policy consistent with that of formatted 
input, unformatted
input, and formatted output.
-  

Re: [PATCH] value-relation: Small tweaks to tables

2023-01-26 Thread Richard Biener via Gcc-patches
On Thu, 26 Jan 2023, Jakub Jelinek wrote:

> Hi!
> 
> As I said earlier, all these tables are used solely in value-relation.cc
> and never modified, plus because VREL_LAST is small especially the
> two-dimensional arrays are vast a lot of .data (or .rodata) space
> - 576 bytes each.  The following patch makes those arrays static const
> and uses unsigned char instead of relation_kind so that the
> two-dimensional arrays shrink to 144 bytes.
> 
> Build-tested, ok for trunk if it passes bootstrap/regtest?

OK.

Richard.

> 2023-01-26  Jakub Jelinek  
> 
>   * value-relation.cc (kind_string): Add const.
>   (rr_negate_table, rr_swap_table, rr_intersect_table,
>   rr_union_table, rr_transitive_table): Add static const, change
>   element type from relation_kind to unsigned char.
>   (relation_negate, relation_swap, relation_intersect, relation_union,
>   relation_transitive): Cast rr_*_table element to relation_kind.
>   (relation_to_code): Add static const.
>   (relation_tests): Assert VREL_LAST is smaller than UCHAR_MAX.
> 
> --- gcc/value-relation.cc.jj  2023-01-19 23:26:31.887212157 +0100
> +++ gcc/value-relation.cc 2023-01-26 11:12:42.798750916 +0100
> @@ -32,7 +32,7 @@ along with GCC; see the file COPYING3.
>  #include "alloc-pool.h"
>  #include "dominance.h"
>  
> -static const char *kind_string[VREL_LAST] =
> +static const char *const kind_string[VREL_LAST] =
>  { "varying", "undefined", "<", "<=", ">", ">=", "==", "!=", "pe8", "pe16",
>"pe32", "pe64" };
>  
> @@ -45,7 +45,7 @@ print_relation (FILE *f, relation_kind r
>  }
>  
>  // This table is used to negate the operands.  op1 REL op2 -> !(op1 REL op2).
> -relation_kind rr_negate_table[VREL_LAST] = {
> +static const unsigned char rr_negate_table[VREL_LAST] = {
>VREL_VARYING, VREL_UNDEFINED, VREL_GE, VREL_GT, VREL_LE, VREL_LT, VREL_NE,
>VREL_EQ };
>  
> @@ -54,11 +54,11 @@ relation_kind rr_negate_table[VREL_LAST]
>  relation_kind
>  relation_negate (relation_kind r)
>  {
> -  return rr_negate_table [r];
> +  return relation_kind (rr_negate_table [r]);
>  }
>  
>  // This table is used to swap the operands.  op1 REL op2 -> op2 REL op1.
> -relation_kind rr_swap_table[VREL_LAST] = {
> +static const unsigned char rr_swap_table[VREL_LAST] = {
>VREL_VARYING, VREL_UNDEFINED, VREL_GT, VREL_GE, VREL_LT, VREL_LE, VREL_EQ,
>VREL_NE };
>  
> @@ -67,12 +67,12 @@ relation_kind rr_swap_table[VREL_LAST] =
>  relation_kind
>  relation_swap (relation_kind r)
>  {
> -  return rr_swap_table [r];
> +  return relation_kind (rr_swap_table [r]);
>  }
>  
>  // This table is used to perform an intersection between 2 relations.
>  
> -relation_kind rr_intersect_table[VREL_LAST][VREL_LAST] = {
> +static const unsigned char rr_intersect_table[VREL_LAST][VREL_LAST] = {
>  // VREL_VARYING
>{ VREL_VARYING, VREL_UNDEFINED, VREL_LT, VREL_LE, VREL_GT, VREL_GE, 
> VREL_EQ,
>  VREL_NE },
> @@ -104,13 +104,13 @@ relation_kind rr_intersect_table[VREL_LA
>  relation_kind
>  relation_intersect (relation_kind r1, relation_kind r2)
>  {
> -  return rr_intersect_table[r1][r2];
> +  return relation_kind (rr_intersect_table[r1][r2]);
>  }
>  
>  
>  // This table is used to perform a union between 2 relations.
>  
> -relation_kind rr_union_table[VREL_LAST][VREL_LAST] = {
> +static const unsigned char rr_union_table[VREL_LAST][VREL_LAST] = {
>  // VREL_VARYING
>{ VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING,
>  VREL_VARYING, VREL_VARYING, VREL_VARYING },
> @@ -141,14 +141,14 @@ relation_kind rr_union_table[VREL_LAST][
>  relation_kind
>  relation_union (relation_kind r1, relation_kind r2)
>  {
> -  return rr_union_table[r1][r2];
> +  return relation_kind (rr_union_table[r1][r2]);
>  }
>  
>  
>  // This table is used to determine transitivity between 2 relations.
>  // (A relation0 B) and (B relation1 C) implies  (A result C)
>  
> -relation_kind rr_transitive_table[VREL_LAST][VREL_LAST] = {
> +static const unsigned char rr_transitive_table[VREL_LAST][VREL_LAST] = {
>  // VREL_VARYING
>{ VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING,
>  VREL_VARYING, VREL_VARYING, VREL_VARYING },
> @@ -180,12 +180,12 @@ relation_kind rr_transitive_table[VREL_L
>  relation_kind
>  relation_transitive (relation_kind r1, relation_kind r2)
>  {
> -  return rr_transitive_table[r1][r2];
> +  return relation_kind (rr_transitive_table[r1][r2]);
>  }
>  
>  // This vector maps a relation to the equivalent tree code.
>  
> -tree_code relation_to_code [VREL_LAST] = {
> +static const tree_code relation_to_code [VREL_LAST] = {
>ERROR_MARK, ERROR_MARK, LT_EXPR, LE_EXPR, GT_EXPR, GE_EXPR, EQ_EXPR,
>NE_EXPR };
>  
> @@ -1727,6 +1727,8 @@ namespace selftest
>  void
>  relation_tests ()
>  {
> +  // rr_*_table tables use unsigned char rather than relation_kind.
> +  ASSERT_LT (VREL_LAST, UCHAR_MAX);
>// Verify commutativity of relation_intersect and relation_union.
>for (relation_kind r1 

[PATCH] tree-optimization/108547 - robustify uninit predicate analysis

2023-01-26 Thread Richard Biener via Gcc-patches
Predicate analysis, when looking through casts doesn't bother to
convert boundary constants to the type of the bounded variables.
The following robustifies value_sat_pred_p to use widest_ints
to deal with this, like other code in predicate analysis.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

PR tree-optimization/108547
* gimple-predicate-analysis.cc (value_sat_pred_p):
Use widest_int.

* gcc.dg/uninit-pr108547.c: New testcase.
---
 gcc/gimple-predicate-analysis.cc   |  6 +++---
 gcc/testsuite/gcc.dg/uninit-pr108547.c | 24 
 2 files changed, 27 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/uninit-pr108547.c

diff --git a/gcc/gimple-predicate-analysis.cc b/gcc/gimple-predicate-analysis.cc
index a7719ff493f..094e8c7aff3 100644
--- a/gcc/gimple-predicate-analysis.cc
+++ b/gcc/gimple-predicate-analysis.cc
@@ -728,11 +728,11 @@ value_sat_pred_p (tree val, tree boundary, tree_code cmpc,
   if (cmpc != BIT_AND_EXPR)
 return is_value_included_in (val, boundary, cmpc);
 
-  wide_int andw = wi::to_wide (val) & wi::to_wide (boundary);
+  widest_int andw = wi::to_widest (val) & wi::to_widest (boundary);
   if (exact_p)
-return andw == wi::to_wide (val);
+return andw == wi::to_widest (val);
 
-  return andw.to_uhwi ();
+  return wi::ne_p (andw, 0);
 }
 
 /* Return true if the domain of single predicate expression PRED1
diff --git a/gcc/testsuite/gcc.dg/uninit-pr108547.c 
b/gcc/testsuite/gcc.dg/uninit-pr108547.c
new file mode 100644
index 000..d8f6c9ff87a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/uninit-pr108547.c
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wuninitialized" } */
+
+int func_7_uc_10li_19 (int);
+int li_4, li_5, us_8;
+unsigned char func_7_ptr_13, func_7_uc_14;
+void func_7_ptr_18() {
+  if (li_5) {
+for (;;)
+  ;
+short s_15;
+for (; func_7_uc_14;) {
+  us_8 = 7;
+  for (; us_8; us_8 += 1)
+  lblD2AF1FAB:
+if (us_8)
+  li_4 = 1;
+  func_7_uc_14 += (__INTPTR_TYPE__)func_7_ptr_18;
+  if (func_7_ptr_13 & 1 && (func_7_uc_14 &= func_7_ptr_13))
+s_15 %= func_7_uc_10li_19(s_15); /* { dg-warning "uninitialized" } */
+}
+  }
+  goto lblD2AF1FAB;
+}
-- 
2.35.3


[PATCH][committed] aarch64: Add Linux kernel hwcap string for FEAT_CSSC

2023-01-26 Thread Kyrylo Tkachov via Gcc-patches
Hi all,

The Linux kernel has done basic enablement and detection of FEAT_CSSC so we can
use the cpuinfo string that they've specified.

This patchlet does that.

Bootstrapped and tested on aarch64-none-linux-gnu.
Pushing to trunk.
Thanks,
Kyrill

gcc/ChangeLog:

* config/aarch64/aarch64-option-extensions.def (cssc): Specify
FEATURE_STRING field.


cssc-hwcap.patch
Description: cssc-hwcap.patch


[pushed] doc: Refer to projects as GCC and GDB (was: [PATCH] sourcebuild.texi: Document new toplevel directories [PR82383])

2023-01-26 Thread Gerald Pfeifer
On Tue, 24 May 2022, Eric Gallager wrote:
> This patch adds entries for the c++tools, gotools, libbacktrace, libcc1, 
> libcody, liboffloadmic, and libsanitizer directories into the list of 
> toplevel source directories in sourcebuild.texi. I also removed the 
> entry for boehm-gc (which is no longer in-tree), and fixed the 
> alphabetization for libquadmath while I was at it.

Thanks for doing that, Eric!

> Any style nits I need to fix before committing

Just a small one I realized now and addressed with the update below.

Gerald


commit 41c3d02fd6a71ed3d86d0e496654b9f6350a2ce5
Author: Gerald Pfeifer 
Date:   Thu Jan 26 12:25:44 2023 +0100

doc: Refer to projects as GCC and GDB

...instead of gcc and gdb which are the executables (and in case of
GCC the C language front end).

gcc/ChangeLog:

* doc/sourcebuild.texi: Refer to projects as GCC and GDB.

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index be4318221cc..df54526464e 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -73,10 +73,10 @@ The runtime support library for atomic operations (e.g.@: 
for @code{__sync}
 and @code{__atomic}).
 
 @item libbacktrace
-A library that allows gcc to produce backtraces when it crashes.
+A library that allows GCC to produce backtraces when it crashes.
 
 @item libcc1
-A library that allows gdb to make use of the compiler.
+A library that allows GDB to make use of the compiler.
 
 @item libcody
 A compiler dynamism library to allow communication between compilers and


[PATCH] value-relation: Small tweaks to tables

2023-01-26 Thread Jakub Jelinek via Gcc-patches
Hi!

As I said earlier, all these tables are used solely in value-relation.cc
and never modified, plus because VREL_LAST is small especially the
two-dimensional arrays are vast a lot of .data (or .rodata) space
- 576 bytes each.  The following patch makes those arrays static const
and uses unsigned char instead of relation_kind so that the
two-dimensional arrays shrink to 144 bytes.

Build-tested, ok for trunk if it passes bootstrap/regtest?

2023-01-26  Jakub Jelinek  

* value-relation.cc (kind_string): Add const.
(rr_negate_table, rr_swap_table, rr_intersect_table,
rr_union_table, rr_transitive_table): Add static const, change
element type from relation_kind to unsigned char.
(relation_negate, relation_swap, relation_intersect, relation_union,
relation_transitive): Cast rr_*_table element to relation_kind.
(relation_to_code): Add static const.
(relation_tests): Assert VREL_LAST is smaller than UCHAR_MAX.

--- gcc/value-relation.cc.jj2023-01-19 23:26:31.887212157 +0100
+++ gcc/value-relation.cc   2023-01-26 11:12:42.798750916 +0100
@@ -32,7 +32,7 @@ along with GCC; see the file COPYING3.
 #include "alloc-pool.h"
 #include "dominance.h"
 
-static const char *kind_string[VREL_LAST] =
+static const char *const kind_string[VREL_LAST] =
 { "varying", "undefined", "<", "<=", ">", ">=", "==", "!=", "pe8", "pe16",
   "pe32", "pe64" };
 
@@ -45,7 +45,7 @@ print_relation (FILE *f, relation_kind r
 }
 
 // This table is used to negate the operands.  op1 REL op2 -> !(op1 REL op2).
-relation_kind rr_negate_table[VREL_LAST] = {
+static const unsigned char rr_negate_table[VREL_LAST] = {
   VREL_VARYING, VREL_UNDEFINED, VREL_GE, VREL_GT, VREL_LE, VREL_LT, VREL_NE,
   VREL_EQ };
 
@@ -54,11 +54,11 @@ relation_kind rr_negate_table[VREL_LAST]
 relation_kind
 relation_negate (relation_kind r)
 {
-  return rr_negate_table [r];
+  return relation_kind (rr_negate_table [r]);
 }
 
 // This table is used to swap the operands.  op1 REL op2 -> op2 REL op1.
-relation_kind rr_swap_table[VREL_LAST] = {
+static const unsigned char rr_swap_table[VREL_LAST] = {
   VREL_VARYING, VREL_UNDEFINED, VREL_GT, VREL_GE, VREL_LT, VREL_LE, VREL_EQ,
   VREL_NE };
 
@@ -67,12 +67,12 @@ relation_kind rr_swap_table[VREL_LAST] =
 relation_kind
 relation_swap (relation_kind r)
 {
-  return rr_swap_table [r];
+  return relation_kind (rr_swap_table [r]);
 }
 
 // This table is used to perform an intersection between 2 relations.
 
-relation_kind rr_intersect_table[VREL_LAST][VREL_LAST] = {
+static const unsigned char rr_intersect_table[VREL_LAST][VREL_LAST] = {
 // VREL_VARYING
   { VREL_VARYING, VREL_UNDEFINED, VREL_LT, VREL_LE, VREL_GT, VREL_GE, VREL_EQ,
 VREL_NE },
@@ -104,13 +104,13 @@ relation_kind rr_intersect_table[VREL_LA
 relation_kind
 relation_intersect (relation_kind r1, relation_kind r2)
 {
-  return rr_intersect_table[r1][r2];
+  return relation_kind (rr_intersect_table[r1][r2]);
 }
 
 
 // This table is used to perform a union between 2 relations.
 
-relation_kind rr_union_table[VREL_LAST][VREL_LAST] = {
+static const unsigned char rr_union_table[VREL_LAST][VREL_LAST] = {
 // VREL_VARYING
   { VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING,
 VREL_VARYING, VREL_VARYING, VREL_VARYING },
@@ -141,14 +141,14 @@ relation_kind rr_union_table[VREL_LAST][
 relation_kind
 relation_union (relation_kind r1, relation_kind r2)
 {
-  return rr_union_table[r1][r2];
+  return relation_kind (rr_union_table[r1][r2]);
 }
 
 
 // This table is used to determine transitivity between 2 relations.
 // (A relation0 B) and (B relation1 C) implies  (A result C)
 
-relation_kind rr_transitive_table[VREL_LAST][VREL_LAST] = {
+static const unsigned char rr_transitive_table[VREL_LAST][VREL_LAST] = {
 // VREL_VARYING
   { VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING,
 VREL_VARYING, VREL_VARYING, VREL_VARYING },
@@ -180,12 +180,12 @@ relation_kind rr_transitive_table[VREL_L
 relation_kind
 relation_transitive (relation_kind r1, relation_kind r2)
 {
-  return rr_transitive_table[r1][r2];
+  return relation_kind (rr_transitive_table[r1][r2]);
 }
 
 // This vector maps a relation to the equivalent tree code.
 
-tree_code relation_to_code [VREL_LAST] = {
+static const tree_code relation_to_code [VREL_LAST] = {
   ERROR_MARK, ERROR_MARK, LT_EXPR, LE_EXPR, GT_EXPR, GE_EXPR, EQ_EXPR,
   NE_EXPR };
 
@@ -1727,6 +1727,8 @@ namespace selftest
 void
 relation_tests ()
 {
+  // rr_*_table tables use unsigned char rather than relation_kind.
+  ASSERT_LT (VREL_LAST, UCHAR_MAX);
   // Verify commutativity of relation_intersect and relation_union.
   for (relation_kind r1 = VREL_VARYING; r1 < VREL_PE8;
r1 = relation_kind (r1 + 1))

Jakub



[committed] openmp, c++: Workaround fold_for_warn ICE on invalid OpenMP collapsed loops [PR108503]

2023-01-26 Thread Jakub Jelinek via Gcc-patches
Hi!

My recent change to deduce structured binding vars earlier caused the following
invalid testcase to ICE.  The problem is that because at 
cp_convert_omp_range_for
when !processing_template_decl we aren't yet ready to finalize the structured 
bindings
(e.g. can't emit there associated code) but need to deduce types of the vars so 
that
we don't get errors if we parse invalid uses of those vars in inner loops of the
collapsed construct.  This is done by temporarily bumping 
processing_template_decl
around the call to cp_finish_decomp.  Unfortunately, as we can't finalize it 
yet,
the types of the vars will be deduced, but their DECL_VALUE_EXPR is not 
finalized
yet and if say fold_for_warn tries to constant expression evaluate them, it
recurses on DECL_VALUE_EXPR and ICEs because it sees e.g. ARRAY_REF (with NULL 
type)
on a VAR_DECL with class type.

The following patch works around that by temporarily hiding the DECL_VALUE_EXPRs
by clearing DECL_HAS_VALUE_EXPR_P in that case during cp_convert_omp_range_for
and arranging for cp_finish_omp_range_for to set it back before doing the
final cp_finish_decomp.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.

2023-01-25  Jakub Jelinek  

PR c++/108503
* parser.cc (cp_convert_omp_range_for): If cp_finish_decomp has been
called in !processing_template_decl with processing_template_decl
temporarily set, clear DECL_HAS_VALUE_EXPR_P on the vars temporarily.
(cp_finish_omp_range_for): And set it back again here.

* g++.dg/gomp/pr108503.C: New test.

--- gcc/cp/parser.cc.jj 2023-01-25 00:03:42.746684624 +0100
+++ gcc/cp/parser.cc2023-01-25 13:49:35.128800077 +0100
@@ -43039,6 +43039,7 @@ cp_convert_omp_range_for (tree _pre
 {
   tree begin, end, range_temp_decl = NULL_TREE;
   tree iter_type, begin_expr, end_expr;
+  bool clear_has_value_expr = false;
 
   if (processing_template_decl)
 {
@@ -43185,6 +43186,8 @@ cp_convert_omp_range_for (tree _pre
  ++processing_template_decl;
  cp_finish_decomp (orig_decl, decomp_first_name, decomp_cnt);
  --processing_template_decl;
+ if (!processing_template_decl)
+   clear_has_value_expr = true;
}
}
 }
@@ -43193,8 +43196,20 @@ cp_convert_omp_range_for (tree _pre
   TREE_VEC_ELT (v, 0) = range_temp_decl;
   TREE_VEC_ELT (v, 1) = end;
   TREE_VEC_ELT (v, 2) = orig_decl;
+  if (clear_has_value_expr)
+TREE_PUBLIC (v) = 1;
   for (unsigned i = 0; i < decomp_cnt; i++)
 {
+  if (clear_has_value_expr)
+   {
+ /* If cp_finish_decomp was called with processing_template_decl
+temporarily set to 1, then decomp names will have deduced
+name but the DECL_VALUE_EXPR will be dependent.  Hide those
+from folding of other loop initializers e.g. for warning
+purposes until cp_finish_omp_range_for.  */
+ gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (decomp_first_name));
+ DECL_HAS_VALUE_EXPR_P (decomp_first_name) = 0;
+   }
   TREE_VEC_ELT (v, i + 3) = decomp_first_name;
   decomp_first_name = DECL_CHAIN (decomp_first_name);
 }
@@ -43217,6 +43232,18 @@ cp_finish_omp_range_for (tree orig, tree
 {
   decomp_first_name = TREE_VEC_ELT (TREE_CHAIN (orig), 3);
   decomp_cnt = TREE_VEC_LENGTH (TREE_CHAIN (orig)) - 3;
+  if (TREE_PUBLIC (TREE_CHAIN (orig)))
+   {
+ /* Undo temporary clearing of DECL_HAS_VALUE_EXPR_P done
+by cp_convert_omp_range_for above.  */
+ TREE_PUBLIC (TREE_CHAIN (orig)) = 0;
+ tree d = decomp_first_name;
+ for (unsigned i = 0; i < decomp_cnt; i++)
+   {
+ DECL_HAS_VALUE_EXPR_P (d) = 1;
+ d = DECL_CHAIN (d);
+   }
+   }
   cp_maybe_mangle_decomp (decl, decomp_first_name, decomp_cnt);
 }
 
--- gcc/testsuite/g++.dg/gomp/pr108503.C.jj 2023-01-25 13:52:42.839086391 
+0100
+++ gcc/testsuite/g++.dg/gomp/pr108503.C2023-01-25 13:52:22.901374628 
+0100
@@ -0,0 +1,27 @@
+// PR c++/108503
+// { dg-do compile { target c++17 } }
+// { dg-additional-options "-Wall" }
+
+namespace std {
+  template  struct tuple_size;
+  template  struct tuple_element;
+}
+struct A {
+  template  int get () { return 1; }
+};
+template <> struct std::tuple_size  { static const int value = 3; };
+template  struct std::tuple_element  { using type = int; };
+
+struct B {
+  A *begin ();
+  A *end ();
+};
+
+void
+foo (B a)
+{
+  #pragma omp for collapse(2)
+  for (auto [i, j, k] : a)
+for (int l = i; l < j; l += k) // { dg-error "initializer expression 
refers to iteration variable 'i'" }
+  ;// { dg-error "condition 
expression refers to iteration variable 'j'" "" { target *-*-* } .-1 }
+}  // { dg-error "increment expression 
refers to iteration variable 'k'" "" { target *-*-* } .-2 }

 

Re: [PATCH] Add support for x86_64-*-gnu-* targets to build x86_64 gnumach/hurd

2023-01-26 Thread Thomas Schwinge
Hi Flavio!

On 2022-12-26T12:34:28-0500, Flavio Cruz via Gcc-patches 
 wrote:
> Tested by building a toolchain and compiling gnumach for x86_64

Oh, wow, so this is indeed happening, finally!  :-D

> This is the basic version without unwind support which I think is only 
> required to
> implement exceptions.

ACK, this can all be tuned later.  We understand that ABI to be
completely unstable at this point.


Your patch generally looks good, and I'll drop it into my regular
x86_64-pc-linux-gnu testing, to verify that we don't accidentally break
things re 'x86_64-*-gnu*' matching (but I think we're safe).


As you don't have FSF Copyright Assignment on file for GCC (as far as I
can tell), are you either going to get that, or re-submit this patch with
DCO ('Signed-off-by:' tag), ?


While at that, please also adjust:

> --- /dev/null
> +++ b/gcc/config/i386/gnu64.h
> @@ -0,0 +1,40 @@
> +/* Configuration for an x86_64 running GNU with ELF as the target machine.  
> */
> +
> +/*
> +Copyright (C) 2022 Free Software Foundation, Inc.

^ 2023 ;-)


Grüße
 Thomas
-
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 
München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas 
Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht 
München, HRB 106955