Re: [PATCH v3 1/4] LoongArch: improved target configuration interface

2023-09-08 Thread Xi Ruoyao via Gcc-patches
On Sat, 2023-09-09 at 10:46 +0800, Yang Yujie wrote:
> The next option I can think of would be MULTILIB_EXTRA_OPTS, where 
> -fmultiflags
> fit in nicely.  However, these options won't reach the toplevel builds, and
> tweaking config-ml.in for getting it there would be quite tedious and perhaps
> unreliable:

I don't think the spec tweak should affect toplevel (or default, if you
hate the concept of toplevel) library build.

When I build GCC for a specific machine I usually use:

OPT="-O3 -march=native -pipe ..."
make {STAGE1,BOOT}_CFLAGS="$OPT" {C,CXX}FLAGS_FOR_TARGET="$OPT -g"

If the spec tweak affects the toplevel library build it will eat -march=
etc. in {C,CXX}FLAGS_FOR_TARGET silently, and I don't want this.

Or at least it should not affect --disable-multilib (IMO with --disable-
multilib the spec hack should be disabled completely).  Note that for --
enable-multilib we may use --with-default-multilib=lp64d/march=native,
but (1) this is hard to remember (2) this is not usable with --disable-
multilib.

--disable-multilib *should just work*.  Why should a non-multilib user
be punished by the cost of supporting the complex multilib
configuration, esp. today most LoongArch users don't need multilib at
all?

-- 
Xi Ruoyao 
School of Aerospace Science and Technology, Xidian University


Re: [RFC] gcc: xtensa: use salt/saltu in xtensa_expand_scc

2023-09-08 Thread Takayuki 'January June' Suwa via Gcc-patches
Hi!

On 2023/09/07 23:22, Max Filippov wrote:
> gcc/
>   * config/xtensa/predicates.md (xtensa_cstoresi_operator): Add
>   unsigned comparisons.
>   * config/xtensa/xtensa.cc (xtensa_expand_scc): Add code
>   generation of salt/saltu instructions.
>   * config/xtensa/xtensa.h (TARGET_SALT): New macro.
>   * gcc/config/xtensa/xtensa.md (salt, saltu): New instruction
>   patterns.
> ---
> I've tested it both with configurations that have salt/saltu and that
> don't.
> The inversion of the result at the end looks wasteful. I've been reading
> gccint chapter about cstoreMODE4 and the following part left me with the
> question:
> 
>   The value stored for a true condition must have 1 as its low bit,
>   or else must be negative.
> 
> Does it mean that some variants of cstoreMODE4 may return 1 and some may
> return -1 for truth, as both have 1 as its low bit?

IMHO it is nothing more than the fact that there are two possible integer 
constants that represent 'true' (the result of !0), namely either 1 or -1.
And given a certain target and configuration, it must be consistently fixed to 
one value or the other; for Xtensa, it should be an integer constant of 1.

>  If that's true we
> could use 'addi dest, dest, -1' instead of two-intruction sequence
> 'movi tmp, 1; xor dest, dest, tmp'.

An alternative way to convert 1 to 0 and 0 to 1:

neg dest, dest
addidest, 1

This requires no temporary register.


[PATCH] RISC-V: Add VLS modes VEC_PERM support[PR111311]

2023-09-08 Thread Juzhe-Zhong
This patch add VLS modes VEC_PERM support which fix these following
FAILs in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111311:

FAIL: gcc.dg/tree-ssa/forwprop-40.c scan-tree-dump-times optimized 
"BIT_FIELD_REF" 0
FAIL: gcc.dg/tree-ssa/forwprop-40.c scan-tree-dump-times optimized 
"BIT_INSERT_EXPR" 0
FAIL: gcc.dg/tree-ssa/forwprop-41.c scan-tree-dump-times optimized 
"BIT_FIELD_REF" 0
FAIL: gcc.dg/tree-ssa/forwprop-41.c scan-tree-dump-times optimized 
"BIT_INSERT_EXPR" 1

These FAILs are fixed after this patch.

gcc/ChangeLog:

* config/riscv/autovec-vls.md (*mov_vls): New pattern.
* config/riscv/autovec.md: Ditto.
* config/riscv/riscv-protos.h (cmp_lmul_le_one): New function.
(cmp_lmul_gt_one): Ditto
* config/riscv/riscv-v.cc (cmp_lmul_le_one): Ditto.
(cmp_lmul_gt_one): Ditto.
* config/riscv/riscv.cc (riscv_print_operand): Allow VLS modes.
(riscv_vectorize_vec_perm_const): Ditto.
* config/riscv/vector-iterators.md: Add VLS modes.
* config/riscv/vector.md: Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/partial/slp-1.c: Adapt test.
* gcc.target/riscv/rvv/autovec/partial/slp-16.c: Ditto.
* gcc.target/riscv/rvv/autovec/partial/slp-17.c: Ditto.
* gcc.target/riscv/rvv/autovec/partial/slp-3.c: Ditto.
* gcc.target/riscv/rvv/autovec/partial/slp-5.c: Ditto.
* gcc.target/riscv/rvv/autovec/vls/compress-1.c: New test.
* gcc.target/riscv/rvv/autovec/vls/compress-2.c: New test.
* gcc.target/riscv/rvv/autovec/vls/compress-3.c: New test.
* gcc.target/riscv/rvv/autovec/vls/compress-4.c: New test.
* gcc.target/riscv/rvv/autovec/vls/compress-5.c: New test.
* gcc.target/riscv/rvv/autovec/vls/compress-6.c: New test.
* gcc.target/riscv/rvv/autovec/vls/merge-1.c: New test.
* gcc.target/riscv/rvv/autovec/vls/merge-2.c: New test.
* gcc.target/riscv/rvv/autovec/vls/merge-3.c: New test.
* gcc.target/riscv/rvv/autovec/vls/merge-4.c: New test.
* gcc.target/riscv/rvv/autovec/vls/merge-5.c: New test.
* gcc.target/riscv/rvv/autovec/vls/merge-6.c: New test.
* gcc.target/riscv/rvv/autovec/vls/merge-7.c: New test.
* gcc.target/riscv/rvv/autovec/vls/perm-1.c: New test.
* gcc.target/riscv/rvv/autovec/vls/perm-2.c: New test.
* gcc.target/riscv/rvv/autovec/vls/perm-3.c: New test.
* gcc.target/riscv/rvv/autovec/vls/perm-4.c: New test.
* gcc.target/riscv/rvv/autovec/vls/perm-5.c: New test.
* gcc.target/riscv/rvv/autovec/vls/perm-6.c: New test.
* gcc.target/riscv/rvv/autovec/vls/perm-7.c: New test.

---
 gcc/config/riscv/autovec-vls.md   |   8 +
 gcc/config/riscv/autovec.md   |   6 +-
 gcc/config/riscv/riscv-protos.h   |   2 +
 gcc/config/riscv/riscv-v.cc   |  22 ++
 gcc/config/riscv/riscv.cc |   4 +-
 gcc/config/riscv/vector-iterators.md  | 304 +-
 gcc/config/riscv/vector.md| 302 -
 .../riscv/rvv/autovec/partial/slp-1.c |   2 +-
 .../riscv/rvv/autovec/partial/slp-16.c|   2 +-
 .../riscv/rvv/autovec/partial/slp-17.c|   2 +-
 .../riscv/rvv/autovec/partial/slp-3.c |   2 +-
 .../riscv/rvv/autovec/partial/slp-5.c |   2 +-
 .../riscv/rvv/autovec/vls/compress-1.c|   6 +
 .../riscv/rvv/autovec/vls/compress-2.c|   7 +
 .../riscv/rvv/autovec/vls/compress-3.c|   7 +
 .../riscv/rvv/autovec/vls/compress-4.c|   7 +
 .../riscv/rvv/autovec/vls/compress-5.c|   6 +
 .../riscv/rvv/autovec/vls/compress-6.c|   6 +
 .../riscv/rvv/autovec/vls/merge-1.c   |   6 +
 .../riscv/rvv/autovec/vls/merge-2.c   |   6 +
 .../riscv/rvv/autovec/vls/merge-3.c   |   6 +
 .../riscv/rvv/autovec/vls/merge-4.c   |   6 +
 .../riscv/rvv/autovec/vls/merge-5.c   |   6 +
 .../riscv/rvv/autovec/vls/merge-6.c   |   6 +
 .../riscv/rvv/autovec/vls/merge-7.c   |   6 +
 .../gcc.target/riscv/rvv/autovec/vls/perm-1.c |   6 +
 .../gcc.target/riscv/rvv/autovec/vls/perm-2.c |   6 +
 .../gcc.target/riscv/rvv/autovec/vls/perm-3.c |   6 +
 .../gcc.target/riscv/rvv/autovec/vls/perm-4.c |   8 +
 .../gcc.target/riscv/rvv/autovec/vls/perm-5.c |   6 +
 .../gcc.target/riscv/rvv/autovec/vls/perm-6.c |   6 +
 .../gcc.target/riscv/rvv/autovec/vls/perm-7.c |   6 +
 32 files changed, 607 insertions(+), 176 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/compress-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/compress-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/compress-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/compress-4.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/compress-5.c
 create mode 100644 

[Committed] RISC-V: Fix VLS floating-point operations predicate

2023-09-08 Thread Juzhe-Zhong
VLS vfadd should depend on ZVFH instead of ZVFHMIN.
Obvious fix and committed.

gcc/ChangeLog:

* config/riscv/vector-iterators.md: Fix floating-point operations 
predicate.

---
 gcc/config/riscv/vector-iterators.md | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/gcc/config/riscv/vector-iterators.md 
b/gcc/config/riscv/vector-iterators.md
index caef8157e5a..baa93b776ad 100644
--- a/gcc/config/riscv/vector-iterators.md
+++ b/gcc/config/riscv/vector-iterators.md
@@ -456,18 +456,18 @@
   (RVVM8DF "TARGET_VECTOR_ELEN_FP_64") (RVVM4DF "TARGET_VECTOR_ELEN_FP_64")
   (RVVM2DF "TARGET_VECTOR_ELEN_FP_64") (RVVM1DF "TARGET_VECTOR_ELEN_FP_64")
 
-  (V1HF "TARGET_VECTOR_VLS && TARGET_VECTOR_ELEN_FP_16")
-  (V2HF "TARGET_VECTOR_VLS && TARGET_VECTOR_ELEN_FP_16")
-  (V4HF "TARGET_VECTOR_VLS && TARGET_VECTOR_ELEN_FP_16")
-  (V8HF "TARGET_VECTOR_VLS && TARGET_VECTOR_ELEN_FP_16")
-  (V16HF "TARGET_VECTOR_VLS && TARGET_VECTOR_ELEN_FP_16")
-  (V32HF "TARGET_VECTOR_VLS && TARGET_VECTOR_ELEN_FP_16 && TARGET_MIN_VLEN >= 
64")
-  (V64HF "TARGET_VECTOR_VLS && TARGET_VECTOR_ELEN_FP_16 && TARGET_MIN_VLEN >= 
128")
-  (V128HF "TARGET_VECTOR_VLS && TARGET_VECTOR_ELEN_FP_16 && TARGET_MIN_VLEN >= 
256")
-  (V256HF "TARGET_VECTOR_VLS && TARGET_VECTOR_ELEN_FP_16 && TARGET_MIN_VLEN >= 
512")
-  (V512HF "TARGET_VECTOR_VLS && TARGET_VECTOR_ELEN_FP_16 && TARGET_MIN_VLEN >= 
1024")
-  (V1024HF "TARGET_VECTOR_VLS && TARGET_VECTOR_ELEN_FP_16 && TARGET_MIN_VLEN 
>= 2048")
-  (V2048HF "TARGET_VECTOR_VLS && TARGET_VECTOR_ELEN_FP_16 && TARGET_MIN_VLEN 
>= 4096")
+  (V1HF "TARGET_VECTOR_VLS && TARGET_ZVFH")
+  (V2HF "TARGET_VECTOR_VLS && TARGET_ZVFH")
+  (V4HF "TARGET_VECTOR_VLS && TARGET_ZVFH")
+  (V8HF "TARGET_VECTOR_VLS && TARGET_ZVFH")
+  (V16HF "TARGET_VECTOR_VLS && TARGET_ZVFH")
+  (V32HF "TARGET_VECTOR_VLS && TARGET_ZVFH && TARGET_MIN_VLEN >= 64")
+  (V64HF "TARGET_VECTOR_VLS && TARGET_ZVFH && TARGET_MIN_VLEN >= 128")
+  (V128HF "TARGET_VECTOR_VLS && TARGET_ZVFH && TARGET_MIN_VLEN >= 256")
+  (V256HF "TARGET_VECTOR_VLS && TARGET_ZVFH && TARGET_MIN_VLEN >= 512")
+  (V512HF "TARGET_VECTOR_VLS && TARGET_ZVFH && TARGET_MIN_VLEN >= 1024")
+  (V1024HF "TARGET_VECTOR_VLS && TARGET_ZVFH && TARGET_MIN_VLEN >= 2048")
+  (V2048HF "TARGET_VECTOR_VLS && TARGET_ZVFH && TARGET_MIN_VLEN >= 4096")
   (V1SF "TARGET_VECTOR_VLS && TARGET_VECTOR_ELEN_FP_32")
   (V2SF "TARGET_VECTOR_VLS && TARGET_VECTOR_ELEN_FP_32")
   (V4SF "TARGET_VECTOR_VLS && TARGET_VECTOR_ELEN_FP_32")
-- 
2.36.3



Re: [PATCH v3 1/4] LoongArch: improved target configuration interface

2023-09-08 Thread Yang Yujie
On Thu, Sep 07, 2023 at 07:54:41PM +0800, Yang Yujie wrote:
> On Thu, Sep 07, 2023 at 05:47:36PM +0800, Xi Ruoyao wrote:
> > On Thu, 2023-09-07 at 17:31 +0800, Yang Yujie wrote:
> > > > This is bad.  It makes BOOT_CFLAGS=-mlasx or CFLAGS_FOR_TARGET=-mlasx
> > > > silently ignored so we cannot test a LSX/LASX or vectorizer change with
> > > > them.
> > > > 
> > > > Why do we need to purge all user-specified -m options here?
> > > 
> > > Yes, that is an issue that I haven't considered.
> > > 
> > > The purge rules (self_specs) exist to clean up the driver-generated
> > > canonical option tuple.  These options are generated before to the
> > > injection of library-building options from --with-multilib-{list,default}.
> > > They are dependent on the default GCC settings and may not be safely
> > > overriden by any injected individual options, so we choose to start
> > > over with a purge.
> > > 
> > > Working on a patch now, Thanks!
> > 
> > I've made some local experiment too, I think we can add a "-mbuild-
> > multilib" option which does nothing but in the hacked spec we can wrap
> > the line in %{mbuild-multilib:...}:
> > 
> > %{mbuild-multilib:% > %{mabi=lp64d:-march=la464 -mno-strict-align -msimd=lsx}   
> > %{mabi=lp64s:-march=abi-default -mfpu=32}}
> > 
> > Then we can use -mbuild-multilib -mabi=lp64d for non-default multilibs
> > (or all multilibs unless --disable-multilib?).  In the document we can
> > just document mbuild-multilib as "internal use only".
> > 
> > 
> > -- 
> > Xi Ruoyao 
> > School of Aerospace Science and Technology, Xidian University
> 
> 
> My idea is to move these options out of self_spec by defining a new spec
> rule $(early_self_spec), so that they get processed by the driver before
> the canonicalization.
> 
> This also solves the problem that one cannot use -m[no-]lsx/-m[no-]lasx
> in --with-multilib-list (because they are driver-only options that are
> only recognized during the canonicalization).

Some updates on this issue -- With some experiments, I think that the most
practical way to solve this completely might still involve a symmetric
multilib build (where the toplevels are not built and installed).  Because
as you proposed, we need to inject an option like "-mbuild-multilib" (maybe
"-fmultiflags" for this purpose) somewhere to distinguish bootstrapping from
building libraries, but overriding the spec seems to always affect both cases.

The next option I can think of would be MULTILIB_EXTRA_OPTS, where -fmultiflags
fit in nicely.  However, these options won't reach the toplevel builds, and
tweaking config-ml.in for getting it there would be quite tedious and perhaps
unreliable:


diff --git a/config-ml.in b/config-ml.in
index ad0db078171..ce7f07b94a7 100644
--- a/config-ml.in
+++ b/config-ml.in
@@ -228,6 +228,9 @@ for i in `${CC-gcc} --print-multi-lib 2>/dev/null`; do
   fi
 done
 
+# Do not apply MULTILIB_EXTRA_OPTS to the toplevel by default.
+ml_toplevel_apply_extra_opts=no
+
 # Target libraries are configured for the host they run on, so we check
 # $host here, not $target.
 
@@ -577,6 +580,19 @@ cat >>Multi.tem <<\EOF
fi
 EOF
 
+# Apply MULTILIB_EXTRA_OPTS to the toplevel build.
+if [ "${ml_toplevel_apply_extra_opts}" = yes ]; then
+cat >>Multi.tem <<\EOF
+
+$(foreach i,$(shell $(CC) --print-multi-lib), \
+$(if $(i:.;%=),,$(eval ml_extra_opts := $(subst @, -,$(i:.;%=%)
+
+$(foreach ml_flags, CFLAGS CCASFLAGS CXXFLAGS FCFLAGS FFLAGS \
+ADAFLAGS GOCFLAGS GDCFLAGS CXXFLAGS LIBCFLAGS LIBCXXFLAGS \
+LDFLAGS MLTIFLAGS, $(eval override $(ml_flags) += $(ml_extra_opts)))
+EOF
+fi
+
 cat ${Makefile} Multi.tem > Makefile.tem
 rm -f ${Makefile} Multi.tem
 mv Makefile.tem ${Makefile}


Though this patch works, at least the following additional tweaks has to
be done to the toplevel to maintain a correct build / regtest / install
workflow:

- the C++ headers' install path (fixed temporarily && not very elegant)
- the fortran header path before regtests

Compared to patching for each library individually, I'd rather choose something
less painful -- not building the toplevel could save the most effort because all
the facilities are guaranteed to be present for all multilib variants.

As for the layout change of lib/gcc// directory after applying
the symmetric multilib patch, I believe the inconvenience caused would be 
minimal,
since multisubdir within that directory is private to each gcc instance.  If 
someone
really has a script that depend on libgcc's path, I would suggest using
--print-multi-dir and --print-file-name=libgcc.a, for you cannot assume the
behavior of the GCC driver without knowing which spec file it is loading 
anyways.

(We'd still be keeping --with-abi=* obsolete.  That's a good idea, thanks.)

Yujie



Re: [PATCH V3] Support folding min(poly,poly) to const

2023-09-08 Thread Lehua Ding

Committed, thanks Richard and Juzhe.

On 2023/9/8 16:57, 钟居哲 wrote:

Thanks Richard.
LGTM again from RISC-V side :).


juzhe.zh...@rivai.ai

*From:* Richard Sandiford 
*Date:* 2023-09-08 16:56
*To:* Lehua Ding 
*CC:* gcc-patches ; juzhe.zhong

*Subject:* Re: [PATCH V3] Support folding min(poly,poly) to const
Lehua Ding  writes:
 > V3 change: Address Richard's comments.
 >
 > Hi,
 >
 > This patch adds support that tries to fold `MIN (poly, poly)` to
 > a constant. Consider the following C Code:
 >
 > ```
 > void foo2 (int* restrict a, int* restrict b, int n)
 > {
 > for (int i = 0; i < 3; i += 1)
 >   a[i] += b[i];
 > }
 > ```
 >
 > Before this patch:
 >
 > ```
 > void foo2 (int * restrict a, int * restrict b, int n)
 > {
 >   vector([4,4]) int vect__7.27;
 >   vector([4,4]) int vect__6.26;
 >   vector([4,4]) int vect__4.23;
 >   unsigned long _32;
 >
 >    [local count: 268435456]:
 >   _32 = MIN_EXPR <3, POLY_INT_CST [4, 4]>;
 >   vect__4.23_20 = .MASK_LEN_LOAD (a_11(D), 32B, { -1, ... }, _32, 0);
 >   vect__6.26_15 = .MASK_LEN_LOAD (b_12(D), 32B, { -1, ... }, _32, 0);
 >   vect__7.27_9 = vect__6.26_15 + vect__4.23_20;
 >   .MASK_LEN_STORE (a_11(D), 32B, { -1, ... }, _32, 0,
vect__7.27_9); [tail call]
 >   return;
 >
 > }
 > ```
 >
 > After this patch:
 >
 > ```
 > void foo2 (int * restrict a, int * restrict b, int n)
 > {
 >   vector([4,4]) int vect__7.27;
 >   vector([4,4]) int vect__6.26;
 >   vector([4,4]) int vect__4.23;
 >
 >    [local count: 268435456]:
 >   vect__4.23_20 = .MASK_LEN_LOAD (a_11(D), 32B, { -1, ... }, 3, 0);
 >   vect__6.26_15 = .MASK_LEN_LOAD (b_12(D), 32B, { -1, ... }, 3, 0);
 >   vect__7.27_9 = vect__6.26_15 + vect__4.23_20;
 >   .MASK_LEN_STORE (a_11(D), 32B, { -1, ... }, 3, 0,
vect__7.27_9); [tail call]
 >   return;
 >
 > }
 > ```
 >
 > For RISC-V RVV, csrr and branch instructions can be reduced:
 >
 > Before this patch:
 >
 > ```
 > foo2:
 > csrr    a4,vlenb
 > srli    a4,a4,2
 > li  a5,3
 > bleu    a5,a4,.L5
 > mv  a5,a4
 > .L5:
 > vsetvli zero,a5,e32,m1,ta,ma
 > ...
 > ```
 >
 > After this patch.
 >
 > ```
 > foo2:
 > vsetivli zero,3,e32,m1,ta,ma
 > ...
 > ```
 >
 > Best,
 > Lehua
 >
 > gcc/ChangeLog:
 >
 > * fold-const.cc (can_min_p): New function.
 > (poly_int_binop): Try fold MIN_EXPR.
OK, thanks.
Richard
 > gcc/testsuite/ChangeLog:
 >
 > * gcc.target/riscv/rvv/autovec/vls/div-1.c: Adjust.
 > * gcc.target/riscv/rvv/autovec/vls/shift-3.c: Adjust.
 > * gcc.target/riscv/rvv/autovec/fold-min-poly.c: New test.
 >
 > ---
 >  gcc/fold-const.cc | 24
+++
 >  .../riscv/rvv/autovec/fold-min-poly.c | 24
+++
 >  .../gcc.target/riscv/rvv/autovec/vls/div-1.c  |  2 +-
 >  .../riscv/rvv/autovec/vls/shift-3.c   |  2 +-
 >  4 files changed, 50 insertions(+), 2 deletions(-)
 >  create mode 100644
gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c
 >
 > diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
 > index 1da498a3152..d19b4666c65 100644
 > --- a/gcc/fold-const.cc
 > +++ b/gcc/fold-const.cc
 > @@ -1213,6 +1213,25 @@ wide_int_binop (wide_int ,
 >    return true;
 >  }
 >
 > +/* Returns true if we know who is smaller or equal, ARG1 or
ARG2, and set the
 > +   min value to RES.  */
 > +bool
 > +can_min_p (const_tree arg1, const_tree arg2, poly_wide_int )
 > +{
 > +  if (known_le (wi::to_poly_widest (arg1), wi::to_poly_widest
(arg2)))
 > +    {
 > +  res = wi::to_poly_wide (arg1);
 > +  return true;
 > +    }
 > +  else if (known_le (wi::to_poly_widest (arg2),
wi::to_poly_widest (arg1)))
 > +    {
 > +  res = wi::to_poly_wide (arg2);
 > +  return true;
 > +    }
 > +
 > +  return false;
 > +}
 > +
 >  /* Combine two poly int's ARG1 and ARG2 under operation CODE to
 > produce a new constant in RES.  Return FALSE if we don't know how
 > to evaluate CODE at compile-time.  */
 > @@ -1261,6 +1280,11 @@ poly_int_binop (poly_wide_int , enum
tree_code code,
 >  return false;
 >    break;
 >
 > +    case MIN_EXPR:
 > +  if (!can_min_p (arg1, arg2, res))
 > + return false;
 > +  break;
 > +
 

Re: [PATCH v2 2/5] RISC-V: Add Types for Un-Typed zc Instructions

2023-09-08 Thread Jeff Law via Gcc-patches




On 9/8/23 12:16, Edwin Lu wrote:

This patch adds types to the untyped zc instructions. Creates a new
types "pushpop" and "mvpair" for now

gcc/ChangeLog:

* config/riscv/riscv.md: Add "csr" type
* config/riscv/zc.md: Update types

OK.

Note that once we finish this exercise, making sure any new types that 
have been created are handled by the existing scheduling descriptions 
would be good follow-up.


jeff


Re: [PATCH v2 1/5] RISC-V: Update Types for Vector Instructions

2023-09-08 Thread Jeff Law via Gcc-patches




On 9/8/23 12:16, Edwin Lu wrote:

This patch adds types to vector instructions that were added after or were
missed by the original patch
https://gcc.gnu.org/pipermail/gcc-patches/2023-August/628594.html

gcc/ChangeLog:

* config/riscv/autovec-opt.md: Update types
* config/riscv/autovec.md: likewise
I think these were all define_insn_and_splits, so just about anything 
will do.  OK.


jeff


Re: [PATCH] fortran: Remove redundant tree walk to delete element

2023-09-08 Thread Harald Anlauf via Gcc-patches

Am 08.09.23 um 12:04 schrieb Mikael Morin via Gcc-patches:

Hello,

this avoids some redundant work in the symbol deletion code, which is
used a lot by the parser to cancel statements that fail to match in the
end.
I haven't tried to measure the performance effect, if any, on a pathological 
example;
just passed the fortran testsuite on x86_64-pc-linux-gnu.
OK for master?


This is OK.

Thanks,
Harald


-- >8 --

Remove preliminary walk of the symbol tree when we are about to remove an
element.  This preliminary walk was necessary because the deletion function
updated the tree without reporting back to the caller the element it had
removed.  But knowing that element is necessary to free its memory, so one
had to first get that element before it was removed from the tree.

This change updates the main deletion function delete_treap and its public
wrapper gfc_delete_bbt so that the removed element can be known by the
caller.  This makes the preliminary walk in gfc_delete_symtree redundant,
permitting its removal.

gcc/fortran/ChangeLog:

* bbt.cc (delete_treap): Add argument REMOVED, set it to the removed
element from the tree.  Change NULL to nullptr.
(gfc_delete_bbt): Return the removed element from the tree.
* gfortran.h (gfc_delete_symtree): Remove prototype.
(gfc_delete_bbt): Set return type to pointer.
* symbol.cc (gfc_delete_symtree): Make static.  Get the element to be
freed from the result of gfc_delete_bbt.  Remove the preliminary walk to
get it.
---
  gcc/fortran/bbt.cc | 27 +++
  gcc/fortran/gfortran.h |  3 +--
  gcc/fortran/symbol.cc  |  6 ++
  3 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/gcc/fortran/bbt.cc b/gcc/fortran/bbt.cc
index 851e5e92c7b..2a032083c5c 100644
--- a/gcc/fortran/bbt.cc
+++ b/gcc/fortran/bbt.cc
@@ -168,31 +168,42 @@ delete_root (gfc_bbt *t)
 Returns the new root node of the tree.  */

  static gfc_bbt *
-delete_treap (gfc_bbt *old, gfc_bbt *t, compare_fn compare)
+delete_treap (gfc_bbt *old, gfc_bbt *t, compare_fn compare, gfc_bbt **removed)
  {
int c;

-  if (t == NULL)
-return NULL;
+  if (t == nullptr)
+{
+  if (removed)
+   *removed = nullptr;
+  return nullptr;
+}

c = (*compare) (old, t);

if (c < 0)
-t->left = delete_treap (old, t->left, compare);
+t->left = delete_treap (old, t->left, compare, removed);
if (c > 0)
-t->right = delete_treap (old, t->right, compare);
+t->right = delete_treap (old, t->right, compare, removed);
if (c == 0)
-t = delete_root (t);
+{
+  if (removed)
+   *removed = t;
+  t = delete_root (t);
+}

return t;
  }


-void
+void *
  gfc_delete_bbt (void *root, void *old, compare_fn compare)
  {
gfc_bbt **t;
+  gfc_bbt *removed;

t = (gfc_bbt **) root;
-  *t = delete_treap ((gfc_bbt *) old, *t, compare);
+  *t = delete_treap ((gfc_bbt *) old, *t, compare, );
+
+  return (void *) removed;
  }
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index b37c6bb9ad4..371f8743312 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -3510,7 +3510,6 @@ bool gfc_reference_st_label (gfc_st_label *, gfc_sl_type);
  gfc_namespace *gfc_get_namespace (gfc_namespace *, int);
  gfc_symtree *gfc_new_symtree (gfc_symtree **, const char *);
  gfc_symtree *gfc_find_symtree (gfc_symtree *, const char *);
-void gfc_delete_symtree (gfc_symtree **, const char *);
  gfc_symtree *gfc_get_unique_symtree (gfc_namespace *);
  gfc_user_op *gfc_get_uop (const char *);
  gfc_user_op *gfc_find_uop (const char *, gfc_namespace *);
@@ -3911,7 +3910,7 @@ bool gfc_inline_intrinsic_function_p (gfc_expr *);
  /* bbt.cc */
  typedef int (*compare_fn) (void *, void *);
  void gfc_insert_bbt (void *, void *, compare_fn);
-void gfc_delete_bbt (void *, void *, compare_fn);
+void * gfc_delete_bbt (void *, void *, compare_fn);

  /* dump-parse-tree.cc */
  void gfc_dump_parse_tree (gfc_namespace *, FILE *);
diff --git a/gcc/fortran/symbol.cc b/gcc/fortran/symbol.cc
index aa3cdc98c86..2cba2ea0bed 100644
--- a/gcc/fortran/symbol.cc
+++ b/gcc/fortran/symbol.cc
@@ -2948,7 +2948,7 @@ gfc_new_symtree (gfc_symtree **root, const char *name)

  /* Delete a symbol from the tree.  Does not free the symbol itself!  */

-void
+static void
  gfc_delete_symtree (gfc_symtree **root, const char *name)
  {
gfc_symtree st, *st0;
@@ -2963,10 +2963,8 @@ gfc_delete_symtree (gfc_symtree **root, const char *name)
else
  p = name;

-  st0 = gfc_find_symtree (*root, p);
-
st.name = gfc_get_string ("%s", p);
-  gfc_delete_bbt (root, , compare_symtree);
+  st0 = (gfc_symtree *) gfc_delete_bbt (root, , compare_symtree);

free (st0);
  }




[COMMITTED] [frange] Revert relation handling in LTGT_EXPR.

2023-09-08 Thread Aldy Hernandez via Gcc-patches
In trying to come up with a missing testcase for commit 979e0fbf53cd,
I've realized the patch doesn't catch anything.

A relation of VREL_EQ in foperator_ltgt::fold_range() is either both
arguments the same (x LTGT_EXPR x), which we should never emit, or two
arguments that are actually the same, in which case !NAN applies, and the
whole thing can be handled as NE_EXPR further down.

The whole FP relation thing is getting a face lift shortly, thanks to
comments from both Jakub and Andrew, but there's no need in keeping
useless code around.

gcc/ChangeLog:

* range-op-float.cc (foperator_ltgt::fold_range): Do not special
case VREL_EQ nor call frelop_early_resolve.
---
 gcc/range-op-float.cc | 15 ---
 1 file changed, 15 deletions(-)

diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index 89c401e040a..cc729e12a9e 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -2206,21 +2206,6 @@ public:
   const frange , const frange ,
   relation_trio trio = TRIO_VARYING) const final override
   {
-relation_kind rel = trio.op1_op2 ();
-
-// VREL_EQ is really VREL_(UN)EQ because we could have a NAN in
-// the operands, but since LTGT_EXPR is really a NE_EXPR without
-// the NAN, VREL_EQ & LTGT_EXPR is an impossibility.
-if (rel == VREL_EQ)
-  {
-   r = range_false (type);
-   return true;
-  }
-// ...otherwise pretend we're trying to resolve a NE_EXPR and
-// everything will "just work".
-if (frelop_early_resolve (r, type, op1, op2, trio, VREL_NE))
-  return true;
-
 if (op1.known_isnan () || op2.known_isnan ())
   {
r = range_false (type);
-- 
2.41.0



Ping: [PATCH] testsuite: Add test for already-fixed issue with _Pragma expansion [PR90400]

2023-09-08 Thread Lewis Hyatt via Gcc-patches
Hello-

May I please ping this one? It's adding a testcase prior to closing
the PR. Thanks!
https://gcc.gnu.org/pipermail/gcc-patches/2023-August/628488.html

-Lewis

On Fri, Aug 25, 2023 at 4:46 PM Lewis Hyatt  wrote:
>
> Hello-
>
> This is adding a testcase for a PR that was already incidentally fixed. OK
> to commit please? Thanks...
>
> -Lewis
>
> -- >8 --
>
> The PR was fixed by r12-5454. Since the fix was somewhat incidental,
> although related, add a testcase from PR90400 too before closing it out.
>
> gcc/testsuite/ChangeLog:
>
> PR preprocessor/90400
> * c-c++-common/cpp/pr90400.c: New test.
> ---
>  gcc/testsuite/c-c++-common/cpp/pr90400.c | 14 ++
>  1 file changed, 14 insertions(+)
>  create mode 100644 gcc/testsuite/c-c++-common/cpp/pr90400.c
>
> diff --git a/gcc/testsuite/c-c++-common/cpp/pr90400.c 
> b/gcc/testsuite/c-c++-common/cpp/pr90400.c
> new file mode 100644
> index 000..4f2cab8d6ab
> --- /dev/null
> +++ b/gcc/testsuite/c-c++-common/cpp/pr90400.c
> @@ -0,0 +1,14 @@
> +/* { dg-do compile } */
> +/* { dg-additional-options "-save-temps" } */
> +/* PR preprocessor/90400 */
> +
> +#define OUTER(x) x
> +#define FOR(x) _Pragma ("GCC unroll 0") for (x)
> +void f ()
> +{
> +/* If the pragma were to be seen prior to the expansion of FOR, as was
> +   the case before r12-5454, then the unroll pragma would complain
> +   because the immediately following statement would be ";" rather than
> +   a loop.  */
> +OUTER (; FOR (int i = 0; i != 1; ++i);) /* { dg-bogus {statement 
> expected before ';' token} } */
> +}


[PATCH, pushed] testsuite: adjust for darwin linker warning

2023-09-08 Thread FX Coudert via Gcc-patches
Pushed as obvious to fix two testsuite FAILs on darwin with recent macOS 
linkers when -no_pie is passed.

FX



0001-testsuite-adjust-for-darwin-linker-warning.patch
Description: Binary data


[PATCH v3] c++: Move consteval folding to cp_fold_r

2023-09-08 Thread Marek Polacek via Gcc-patches
On Thu, Sep 07, 2023 at 02:32:51PM -0400, Jason Merrill wrote:
> On 9/7/23 11:23, Marek Polacek wrote:
> > On Tue, Sep 05, 2023 at 04:36:34PM -0400, Jason Merrill wrote:
> > > On 9/5/23 15:59, Marek Polacek wrote:
> > > > On Tue, Sep 05, 2023 at 10:52:04AM -0400, Jason Merrill wrote:
> > > > > On 9/1/23 13:23, Marek Polacek wrote:
> > > > > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
> > > > > > 
> > > > > > -- >8 --
> > > > > > 
> > > > > > In the review of P2564:
> > > > > > 
> > > > > > it turned out that in order to correctly handle an example in the 
> > > > > > paper,
> > > > > > we should stop doing immediate evaluation in build_over_call and
> > > > > > bot_replace, and instead do it in cp_fold_r.  This patch does that.
> > > > > > 
> > > > > > Another benefit is that this is a pretty significant 
> > > > > > simplification, at
> > > > > > least in my opinion.  Also, this fixes the c++/110997 ICE (but the 
> > > > > > test
> > > > > > doesn't compile yet).
> > > > > > 
> > > > > > The main drawback seems to be that cp_fold_r doesn't process as much
> > > > > > code as we did before: uninstantiated templates
> > > > > 
> > > > > That's acceptable, it's an optional diagnostic.
> > > > > 
> > > > > > and things like "false ? foo () : 1".
> > > > > 
> > > > > This is a problem.  Maybe we want cp_fold_r to recurse into the arms 
> > > > > of a
> > > > > COND_EXPR before folding them away?  Maybe only if we know we've seen 
> > > > > an
> > > > > immediate function?
> > > > 
> > > > Unfortunately we had already thrown the dead branch away when we got to
> > > > cp_fold_r.  I wonder if we have to adjust 
> > > > cxx_eval_conditional_expression
> > > > to call cp_fold_r on the dead branch too,
> > > 
> > > Hmm, I guess so.
> > > 
> > > > perhaps with a new ff_ flag to skip the whole second switch in 
> > > > cp_fold_r?
> > > 
> > > Or factor out the immediate function handling to a separate walk function
> > > that cp_fold_r also calls?
> > 
> > I did that.
> > > > But then it's possible that the in_immediate_context checks have to 
> > > > stay.
> > > 
> > > We can just not do the walk in immediate (or mce_true) context, like we
> > > currently avoid calling cp_fold_function.
> > 
> > Right.  Unfortunately I have to check even when mce_true, consider
> > 
> >consteval int bar (int i) { if (i != 1) throw 1; return 0; }
> >constexpr int a = 0 ? bar(3) : 3;
> 
> I disagree; the call is in a manifestly constant-evaluated expression, and
> so is now considered an immediate function context, and we should accept
> that example.

Ack.  I was still living in pre-P2564 world.
 
> > > For mce_unknown I guess we'd want
> > > to set *non_constant_p instead of giving an error.
> > 
> > I did not do this because I haven't found a case where it would make
> > a difference.
> 
> I think it will given the above comment.

Correct.  For instance, in:

  consteval int bar (int i) { if (i != 1) throw 1; return 0; }

  constexpr int
  foo (bool b)
  {
return b ? bar (3) : 2;
  }

  static_assert (foo (false) == 2);

we should complain only once.  I've implemented your suggestion to set
*non_constant_p instead of giving an error for mce_unknown.

> > diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
> > index 0ca4370deab..397d5c7ec3f 100644
> > --- a/gcc/cp/constexpr.cc
> > +++ b/gcc/cp/constexpr.cc
> > @@ -2311,6 +2311,29 @@ cxx_dynamic_cast_fn_p (tree fndecl)
> >   && CP_DECL_CONTEXT (fndecl) == abi_node);
> >   }
> > +/* Return true if we are in the body of a consteval function. > +   This 
> > is in addition to in_immediate_context because that
> > +   uses current_function_decl which may not be available.  CTX is
> > +   the current constexpr context.  */
> > +
> > +static bool
> > +in_immediate_context (const constexpr_ctx *ctx)
> > +{
> > +  if (in_immediate_context ())
> > +return true;
> 
> Can't we check for mce_true here instead of looking at the call chain?

Yes.
 
> > +/* A wrapper around cp_fold_immediate_r.  */
> > +
> > +void
> > +cp_fold_immediate (tree *tp)
> > +{
> 
> Maybe return early if consteval isn't supported in the active standard?

Absolutely.

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

-- >8 --
In the review of P2564:

it turned out that in order to correctly handle an example in the paper,
we should stop doing immediate evaluation in build_over_call and
bot_replace, and instead do it in cp_fold_r.  This patch does that.

Another benefit is that this is a pretty significant simplification, at
least in my opinion.  Also, this fixes the c++/110997 ICE (but the test
doesn't compile yet).

The main drawback seems to be that cp_fold_r doesn't process
uninstantiated templates.  We still have to handle things like
"false ? foo () : 1".  To that end, I've added cp_fold_immediate, called
on dead branches in 

Re: [committed] libstdc++: Add Filesystem TS and std::stacktrace symbols to libstdc++exp.a

2023-09-08 Thread Jonathan Wakely via Gcc-patches
I forgot to say:

Tested x86_64-linux and aarch64-linux, built for avr, arm-eabi and
cris-elf.

Pushed to trunk.


On Fri, 8 Sept 2023 at 18:09, Jonathan Wakely via Libstdc++
 wrote:
>
> This consolidates the three static archives for extensions into one, so
> that -lstdc++exp can be used to provide the definitions of all unstable
> library features.
>
> The libstdc++_libbacktrace.a archive is now just a "noinst" convenience
> library that is only used during the build, not installed. Its contents
> are added to libstdc++exp.a, along with the new non-inline definitions
> of std::stacktrace symbols.
>
> The libstdc++fs.a archive is still installed, but its contents are
> duplicated in libstdc++exp.a now. This means -lstdc++exp can be used
> instead of -lstdc++fs. For targets using the GNU linker we should
> consider replacing libstdc++fs.a with a linker script that does
> INPUT(libstdc++exp.a).
>
> The tests for  could be changed to use
> -lstdc++exp instead of -lstdc++fs, which would allow removing
> src/filesystem/.libs from the LDFLAGS in scripts/testsuite_flags.in,
> but that can be done at a later date.
>
> libstdc++-v3/ChangeLog:
>
> * acinclude.m4 (GLIBCXX_CONFIGURE): Add c++23 directory.
> * configure: Regenerate.
> * doc/html/manual/*: Regenerate.
> * doc/xml/manual/using.xml: Update documentation on linking.
> * include/std/stacktrace: Remove declarations of libbacktrace
> APIs.
> (stacktrace_entry::_S_err_handler, stacktrace_entry::_S_init):
> Remove.
> (stacktrace_entry::_Info): New class.
> (stacktrace_entry::_M_get_info): Use _Info.
> (__stacktrace_impl): New class.
> (basic_stacktrace): Derive from __stacktrace_impl.
> (basic_stacktrace::current): Use __stacktrace_impl::_S_current.
> * scripts/testsuite_flags.in: Adjust LDFLAGS to find
> libstdc++exp instead of libstdc++_libbacktrace.
> * src/Makefile.am (SUBDIRS): Add c++23 directory.
> * src/Makefile.in: Regenerate.
> * src/c++20/Makefile.am: Fix comment.
> * src/c++20/Makefile.in: Regenerate.
> * src/c++23/Makefile.am: New file.
> * src/c++23/Makefile.in: New file.
> * src/c++23/stacktrace.cc: New file with definitions of
> stacktrace_entry::_Info and __stacktrace_impl members.
> * src/experimental/Makefile.am: Use LIBADD to include other
> libraries.
> * src/experimental/Makefile.in: Regenerate.
> * src/libbacktrace/Makefile.am: Use noinst_LTLIBRARIES.
> * src/libbacktrace/Makefile.in: Regenerate.
> * testsuite/19_diagnostics/stacktrace/current.cc: Adjust
> dg-options to use -lstdc++exp.
> * testsuite/19_diagnostics/stacktrace/entry.cc: Likewise.
> * testsuite/19_diagnostics/stacktrace/stacktrace.cc: Likewise.
> * testsuite/23_containers/vector/debug/assign4_backtrace_neg.cc:
> Likewise.
> ---
>  libstdc++-v3/acinclude.m4 |   2 +-
>  libstdc++-v3/configure|  16 +-
>  libstdc++-v3/doc/html/manual/using.html   |  26 +-
>  .../html/manual/using_dynamic_or_shared.html  |   4 +
>  libstdc++-v3/doc/xml/manual/using.xml |  37 +-
>  libstdc++-v3/include/std/stacktrace   | 144 +---
>  libstdc++-v3/scripts/testsuite_flags.in   |   8 +-
>  libstdc++-v3/src/Makefile.am  |   4 +-
>  libstdc++-v3/src/Makefile.in  |   7 +-
>  libstdc++-v3/src/c++20/Makefile.am|   2 +-
>  libstdc++-v3/src/c++20/Makefile.in|   2 +-
>  libstdc++-v3/src/c++23/Makefile.am| 109 +++
>  libstdc++-v3/src/c++23/Makefile.in| 747 ++
>  libstdc++-v3/src/c++23/stacktrace.cc  | 171 
>  libstdc++-v3/src/experimental/Makefile.am |  20 +
>  libstdc++-v3/src/experimental/Makefile.in |  15 +-
>  libstdc++-v3/src/libbacktrace/Makefile.am |   3 +-
>  libstdc++-v3/src/libbacktrace/Makefile.in |  88 +--
>  .../19_diagnostics/stacktrace/current.cc  |   2 +-
>  .../19_diagnostics/stacktrace/entry.cc|   2 +-
>  .../19_diagnostics/stacktrace/stacktrace.cc   |   2 +-
>  .../vector/debug/assign4_backtrace_neg.cc |   2 +-
>  22 files changed, 1185 insertions(+), 228 deletions(-)
>  create mode 100644 libstdc++-v3/src/c++23/Makefile.am
>  create mode 100644 libstdc++-v3/src/c++23/Makefile.in
>  create mode 100644 libstdc++-v3/src/c++23/stacktrace.cc
>
> diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
> index fcf79503265..34faa3c049f 100644
> --- a/libstdc++-v3/acinclude.m4
> +++ b/libstdc++-v3/acinclude.m4
> @@ -49,7 +49,7 @@ AC_DEFUN([GLIBCXX_CONFIGURE], [
># Keep these sync'd with the list in Makefile.am.  The first provides an
># expandable list at autoconf time; the second provides an expandable list
># (i.e., shell variable) at configure time.
> -  m4_define([glibcxx_SUBDIRS],[include libsupc++ 

[PATCH v2 2/5] RISC-V: Add Types for Un-Typed zc Instructions

2023-09-08 Thread Edwin Lu
This patch adds types to the untyped zc instructions. Creates a new
types "pushpop" and "mvpair" for now

gcc/ChangeLog:

* config/riscv/riscv.md: Add "csr" type
* config/riscv/zc.md: Update types

Signed-off-by: Edwin Lu 
---
Changes in V2:
  - Change "csr" type to "pushpop" and "mvpair"
---
 gcc/config/riscv/riscv.md |   6 ++-
 gcc/config/riscv/zc.md| 102 +++---
 2 files changed, 56 insertions(+), 52 deletions(-)

diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
index b630b51ee50..a6046c17fc3 100644
--- a/gcc/config/riscv/riscv.md
+++ b/gcc/config/riscv/riscv.md
@@ -316,6 +316,8 @@ (define_attr "ext_enabled" "no,yes"
 ;; condmoveconditional moves
 ;; cbocache block instructions
 ;; crypto cryptography instructions
+;; pushpopzc push and pop instructions
+;; mvpairzc move pair instructions
 ;; Classification of RVV instructions which will be added to each RVV .md 
pattern and used by scheduler.
 ;; rdvlenb vector byte length vlenb csrr read
 ;; rdvlvector length vl csrr read
@@ -425,8 +427,8 @@ (define_attr "type"
mtc,mfc,const,arith,logical,shift,slt,imul,idiv,move,fmove,fadd,fmul,
fmadd,fdiv,fcmp,fcvt,fsqrt,multi,auipc,sfb_alu,nop,trap,ghost,bitmanip,
rotate,clmul,min,max,minu,maxu,clz,ctz,cpop,
-   atomic,condmove,cbo,crypto,rdvlenb,rdvl,wrvxrm,wrfrm,rdfrm,vsetvl,
-   vlde,vste,vldm,vstm,vlds,vsts,
+   atomic,condmove,cbo,crypto,pushpop,mvpair,rdvlenb,rdvl,wrvxrm,wrfrm,
+   rdfrm,vsetvl,vlde,vste,vldm,vstm,vlds,vsts,
vldux,vldox,vstux,vstox,vldff,vldr,vstr,

vlsegde,vssegte,vlsegds,vssegts,vlsegdux,vlsegdox,vssegtux,vssegtox,vlsegdff,
vialu,viwalu,vext,vicalu,vshift,vnshift,vicmp,viminmax,
diff --git a/gcc/config/riscv/zc.md b/gcc/config/riscv/zc.md
index 77b28adde95..18b3c30c342 100644
--- a/gcc/config/riscv/zc.md
+++ b/gcc/config/riscv/zc.md
@@ -27,7 +27,7 @@ (define_insn "@gpr_multi_pop_up_to_ra_"
(const_int ]
   "TARGET_ZCMP"
   "cm.pop  {ra}, %0"
-)
+[(set_attr "type" "pushpop")])
 
 (define_insn "@gpr_multi_pop_up_to_s0_"
   [(set (reg:X SP_REGNUM)
@@ -41,7 +41,7 @@ (define_insn "@gpr_multi_pop_up_to_s0_"
(const_int ]
   "TARGET_ZCMP"
   "cm.pop  {ra, s0}, %0"
-)
+[(set_attr "type" "pushpop")])
 
 (define_insn "@gpr_multi_pop_up_to_s1_"
   [(set (reg:X SP_REGNUM)
@@ -58,7 +58,7 @@ (define_insn "@gpr_multi_pop_up_to_s1_"
(const_int ]
   "TARGET_ZCMP"
   "cm.pop  {ra, s0-s1}, %0"
-)
+[(set_attr "type" "pushpop")])
 
 (define_insn "@gpr_multi_pop_up_to_s2_"
   [(set (reg:X SP_REGNUM)
@@ -78,7 +78,7 @@ (define_insn "@gpr_multi_pop_up_to_s2_"
(const_int ]
   "TARGET_ZCMP"
   "cm.pop  {ra, s0-s2}, %0"
-)
+[(set_attr "type" "pushpop")])
 
 (define_insn "@gpr_multi_pop_up_to_s3_"
   [(set (reg:X SP_REGNUM)
@@ -101,7 +101,7 @@ (define_insn "@gpr_multi_pop_up_to_s3_"
(const_int ]
   "TARGET_ZCMP"
   "cm.pop  {ra, s0-s3}, %0"
-)
+[(set_attr "type" "pushpop")])
 
 (define_insn "@gpr_multi_pop_up_to_s4_"
   [(set (reg:X SP_REGNUM)
@@ -127,7 +127,7 @@ (define_insn "@gpr_multi_pop_up_to_s4_"
(const_int ]
   "TARGET_ZCMP"
   "cm.pop  {ra, s0-s4}, %0"
-)
+[(set_attr "type" "pushpop")])
 
 (define_insn "@gpr_multi_pop_up_to_s5_"
   [(set (reg:X SP_REGNUM)
@@ -156,7 +156,7 @@ (define_insn "@gpr_multi_pop_up_to_s5_"
(const_int ]
   "TARGET_ZCMP"
   "cm.pop  {ra, s0-s5}, %0"
-)
+[(set_attr "type" "pushpop")])
 
 (define_insn "@gpr_multi_pop_up_to_s6_"
   [(set (reg:X SP_REGNUM)
@@ -188,7 +188,7 @@ (define_insn "@gpr_multi_pop_up_to_s6_"
(const_int ]
   "TARGET_ZCMP"
   "cm.pop  {ra, s0-s6}, %0"
-)
+[(set_attr "type" "pushpop")])
 
 (define_insn "@gpr_multi_pop_up_to_s7_"
   [(set (reg:X SP_REGNUM)
@@ -223,7 +223,7 @@ (define_insn "@gpr_multi_pop_up_to_s7_"
   (const_int ]
   "TARGET_ZCMP"
   "cm.pop  {ra, s0-s7}, %0"
-)
+[(set_attr "type" "pushpop")])
 
 (define_insn "@gpr_multi_pop_up_to_s8_"
   [(set (reg:X SP_REGNUM)
@@ -261,7 +261,7 @@ (define_insn "@gpr_multi_pop_up_to_s8_"
(const_int ]
   "TARGET_ZCMP"
   "cm.pop  {ra, s0-s8}, %0"
-)
+[(set_attr "type" "pushpop")])
 
 (define_insn "@gpr_multi_pop_up_to_s9_"
   [(set (reg:X SP_REGNUM)
@@ -302,7 +302,7 @@ (define_insn "@gpr_multi_pop_up_to_s9_"
(const_int ]
   "TARGET_ZCMP"
   "cm.pop  {ra, s0-s9}, %0"
-)
+[(set_attr "type" "pushpop")])
 
 (define_insn "@gpr_multi_pop_up_to_s11_"
   [(set (reg:X SP_REGNUM)
@@ -349,7 +349,7 @@ (define_insn "@gpr_multi_pop_up_to_s11_"
(const_int ]
   "TARGET_ZCMP"
   "cm.pop  {ra, s0-s11}, %0"
-)
+[(set_attr "type" "pushpop")])
 
 (define_insn "@gpr_multi_popret_up_to_ra_"
   [(set (reg:X SP_REGNUM)
@@ -362,7 +362,7 @@ (define_insn 

[PATCH v2 1/5] RISC-V: Update Types for Vector Instructions

2023-09-08 Thread Edwin Lu
This patch adds types to vector instructions that were added after or were
missed by the original patch 
https://gcc.gnu.org/pipermail/gcc-patches/2023-August/628594.html

gcc/ChangeLog:

* config/riscv/autovec-opt.md: Update types
* config/riscv/autovec.md: likewise

Signed-off-by: Edwin Lu 
---
Changes in V2:
  - Add types to insns missed by prev version
---
 gcc/config/riscv/autovec-opt.md | 72 ++---
 gcc/config/riscv/autovec.md | 52 
 2 files changed, 83 insertions(+), 41 deletions(-)

diff --git a/gcc/config/riscv/autovec-opt.md b/gcc/config/riscv/autovec-opt.md
index 3aaee54f02a..58e80044f1e 100644
--- a/gcc/config/riscv/autovec-opt.md
+++ b/gcc/config/riscv/autovec-opt.md
@@ -628,7 +628,8 @@ (define_insn_and_split "*cond_abs"
 gen_int_mode (GET_MODE_NUNITS 
(mode), Pmode),
 const0_rtx));
   DONE;
-})
+}
+[(set_attr "type" "vector")])
 
 ;; Combine vfsqrt.v and cond_mask
 (define_insn_and_split "*cond_"
@@ -666,7 +667,8 @@ (define_insn_and_split "*copysign_neg"
   riscv_vector::emit_vlmax_insn (code_for_pred_ncopysign (mode),
   riscv_vector::BINARY_OP, operands);
   DONE;
-})
+}
+[(set_attr "type" "vector")])
 
 ;; Combine sign_extend/zero_extend(vf2) and vcond_mask
 (define_insn_and_split "*cond_"
@@ -685,7 +687,8 @@ (define_insn_and_split "*cond_"
gen_int_mode (GET_MODE_NUNITS (mode), Pmode)};
   riscv_vector::expand_cond_len_unop (icode, ops);
   DONE;
-})
+}
+[(set_attr "type" "vector")])
 
 ;; Combine sign_extend/zero_extend(vf4) and vcond_mask
 (define_insn_and_split "*cond_"
@@ -704,7 +707,8 @@ (define_insn_and_split "*cond_"
gen_int_mode (GET_MODE_NUNITS (mode), Pmode)};
   riscv_vector::expand_cond_len_unop (icode, ops);
   DONE;
-})
+}
+[(set_attr "type" "vector")])
 
 ;; Combine sign_extend/zero_extend(vf8) and vcond_mask
 (define_insn_and_split "*cond_"
@@ -723,7 +727,8 @@ (define_insn_and_split "*cond_"
gen_int_mode (GET_MODE_NUNITS (mode), Pmode)};
   riscv_vector::expand_cond_len_unop (icode, ops);
   DONE;
-})
+}
+[(set_attr "type" "vector")])
 
 ;; Combine trunc(vf2) + vcond_mask
 (define_insn_and_split "*cond_trunc"
@@ -743,7 +748,8 @@ (define_insn_and_split "*cond_trunc"
gen_int_mode (GET_MODE_NUNITS (mode), Pmode)};
   riscv_vector::expand_cond_len_unop (icode, ops);
   DONE;
-})
+}
+[(set_attr "type" "vector")])
 
 ;; Combine FP extend(vf2) and vcond_mask
 (define_insn_and_split "*cond_extend"
@@ -762,7 +768,8 @@ (define_insn_and_split "*cond_extend"
gen_int_mode (GET_MODE_NUNITS (mode), Pmode)};
   riscv_vector::expand_cond_len_unop (icode, ops);
   DONE;
-})
+}
+[(set_attr "type" "vector")])
 
 ;; Combine FP trunc(vf2) + vcond_mask
 (define_insn_and_split "*cond_trunc"
@@ -782,7 +789,8 @@ (define_insn_and_split "*cond_trunc"
gen_int_mode (GET_MODE_NUNITS (mode), Pmode)};
   riscv_vector::expand_cond_len_unop (icode, ops);
   DONE;
-})
+}
+[(set_attr "type" "vector")])
 
 ;; Combine convert(FP->INT) + vcond_mask
 (define_insn_and_split "*cond_"
@@ -802,7 +810,8 @@ (define_insn_and_split "*cond_"
gen_int_mode (GET_MODE_NUNITS (mode), Pmode)};
   riscv_vector::expand_cond_len_unop (icode, ops);
   DONE;
-})
+}
+[(set_attr "type" "vector")])
 
 ;; Combine convert(INT->FP) + vcond_mask
 (define_insn_and_split "*cond_"
@@ -822,7 +831,8 @@ (define_insn_and_split "*cond_"
gen_int_mode (GET_MODE_NUNITS (mode), Pmode)};
   riscv_vector::expand_cond_len_unop (icode, ops);
   DONE;
-})
+}
+[(set_attr "type" "vector")])
 
 ;; Combine convert(FP->2xINT) + vcond_mask
 (define_insn_and_split "*cond_"
@@ -842,7 +852,8 @@ (define_insn_and_split "*cond_"
gen_int_mode (GET_MODE_NUNITS (mode), Pmode)};
   riscv_vector::expand_cond_len_unop (icode, ops);
   DONE;
-})
+}
+[(set_attr "type" "vector")])
 
 ;; Combine convert(INT->2xFP) + vcond_mask
 (define_insn_and_split "*cond_"
@@ -862,7 +873,8 @@ (define_insn_and_split "*cond_"
gen_int_mode (GET_MODE_NUNITS (mode), Pmode)};
   riscv_vector::expand_cond_len_unop (icode, ops);
   DONE;
-})
+}
+[(set_attr "type" "vector")])
 
 ;; Combine convert(2xFP->INT) + vcond_mask
 (define_insn_and_split "*cond_"
@@ -882,7 +894,8 @@ (define_insn_and_split "*cond_"
gen_int_mode (GET_MODE_NUNITS (mode), Pmode)};
   riscv_vector::expand_cond_len_unop (icode, ops);
   DONE;
-})
+}
+[(set_attr "type" "vector")])
 
 ;; Combine convert(2xINT->FP) + vcond_mask
 (define_insn_and_split "*cond_2"
@@ -902,7 +915,8 @@ (define_insn_and_split "*cond_2"
gen_int_mode (GET_MODE_NUNITS (mode), Pmode)};
   riscv_vector::expand_cond_len_unop (icode, ops);
   DONE;
-})
+}
+[(set_attr "type" "vector")])
 
 ;; 
=
 ;; Combine extend + binop to 

[PATCH v2 0/5] RISC-V: Add Types to Untyped Instructions

2023-09-08 Thread Edwin Lu
This series adds types to the remaining untyped instructions.

Related Discussion:
https://inbox.sourceware.org/gcc-patches/12fb5088-3f28-0a69-de1e-f387371a5...@gmail.com/

Also enables assert which checks to make sure every instruction has a type

All patches were tested with rv32/rv64 linux/newlib multilib
Additional extensions tested:
gcv
gc_zba_zbb_zbc_zbs

Edwin Lu (5):
  RISC-V: Update Types for Vector Instructions
  RISC-V: Add Types for Un-Typed zc Instructions
  RISC-V: Add Types to Un-Typed Zicond Instructions
  RISC-V: Add Types to Un-Typed Zicond Instructions
  RISC-V: Remove Assert Protecting Types

 gcc/config/riscv/autovec-opt.md |  72 ++
 gcc/config/riscv/autovec.md |  52 ++--
 gcc/config/riscv/riscv.cc   |   2 -
 gcc/config/riscv/riscv.md   |  10 +++-
 gcc/config/riscv/zc.md  | 102 
 gcc/config/riscv/zicond.md  |   8 +--
 6 files changed, 147 insertions(+), 99 deletions(-)

-- 
2.42.0



[committed] libstdc++: Update outdated default -std in testing docs

2023-09-08 Thread Jonathan Wakely via Gcc-patches
Pushed to gcc-13 (I've removed/rewritten this text on trunk).

I'll push to the older branches too.

-- >8 --

libstdc++-v3/ChangeLog:

* doc/xml/manual/test.xml: Update reference to -std=gnu++14 as
the default.
* doc/html/manual/test.html: Regenerate.
---
 libstdc++-v3/doc/html/manual/test.html | 10 +-
 libstdc++-v3/doc/xml/manual/test.xml   | 10 +-
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/libstdc++-v3/doc/xml/manual/test.xml 
b/libstdc++-v3/doc/xml/manual/test.xml
index 964c53d2632..9853a284814 100644
--- a/libstdc++-v3/doc/xml/manual/test.xml
+++ b/libstdc++-v3/doc/xml/manual/test.xml
@@ -767,7 +767,7 @@ cat 27_io/objects/char/3_xin.in | a.out
 be run for a specific standard (and not later standards) using an
 effective target like c++11_only. However, this means
 the test will be skipped by default (because the default mode is
-gnu++14), and so will only run when
+gnu++17), and so will only run when
 -std=gnu++11 or -std=c++11 is used
 explicitly. For tests that require a specific standard it is better to
 use a dg-options directive:
@@ -783,13 +783,13 @@ cat 27_io/objects/char/3_xin.in | a.out
 Similarly, tests which depend on a newer standard than the default
 must use dg-options instead of (or in addition to)
 an effective target, so that they are not skipped by default.
-For example, tests for C++17 features should use
-// { dg-options "-std=gnu++17" }
+For example, tests for C++20 features should use
+// { dg-options "-std=gnu++20" }
 before any dg-do such as:
-// { dg-do run "c++17" }
+// { dg-do run { target c++20 } }
 The dg-options directive must come first, so that
 the -std flag has already been added to the options
-before checking the c++17 target.
+before checking the c++20 effective target.
   
 
 Examples of Test 
Directives
-- 
2.41.0



[PATCH] match: Don't sink comparisons into vec_cond operands.

2023-09-08 Thread Robin Dapp via Gcc-patches
Hi,

on riscv gcc.dg/pr70252.c ICEs at gimple-isel.cc:283.  This is because
we created the gimple statement

  mask__7.36_170 = VEC_COND_EXPR ;

during vrp2.

What happens is that, starting with
  maskdest = (vec_cond mask1 1 0) >= (vec_cond mask2 1 0)
we fold to
  maskdest = mask1 >= (vec_cond (mask2 1 0))
and then sink the "mask1 >=" into the vec_cond so we end up with
  maskdest = vec_cond (mask2 ? mask1 : 0),
i.e. a vec_cond with a mask "data mode".

In gimple-isel, when the target does not provide a vcond_mask
implementation for that (which none does) we fail the assertion that the
mask mode be MODE_VECTOR_INT.

To prevent this, this patch restricts the match.pd sinking pattern to
non-mask types.  I was also thinking about restricting the type of
the operands, wondering if that would be less intrusive.

Bootstrapped and regression-tested on x86 and aarch64.

Regards
 Robin

gcc/ChangeLog:

PR target/111337
* match.pd: Do not sink comparisons into vec_conds when the type
is a vector mask.
---
 gcc/match.pd | 24 +++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 8c24dae71cd..db3e698f471 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4856,7 +4856,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (vec_cond @0 (view_convert! @1) (view_convert! @2
 
 /* Sink binary operation to branches, but only if we can fold it.  */
-(for op (tcc_comparison plus minus mult bit_and bit_ior bit_xor
+(for op (plus minus mult bit_and bit_ior bit_xor
 lshift rshift rdiv trunc_div ceil_div floor_div round_div
 trunc_mod ceil_mod floor_mod round_mod min max)
 /* (c ? a : b) op (c ? d : e)  -->  c ? (a op d) : (b op e) */
@@ -4872,6 +4872,28 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (op @3 (vec_cond:s @0 @1 @2))
   (vec_cond @0 (op! @3 @1) (op! @3 @2
 
+/* Comparison sinks might be folded into vector masks which could
+   end up as "data" operand of a vec_cond
+   e.g. (vec_cond @0 (mask1) (...)).
+   gimple-isel does not handle such cases if the target does not provide
+   a vcond_mask.  Therefore, restrict the operands to non-mask classes.  */
+(for op (tcc_comparison)
+/* (c ? a : b) op (c ? d : e)  -->  c ? (a op d) : (b op e) */
+ (simplify
+  (op (vec_cond:s @0 @1 @2) (vec_cond:s @0 @3 @4))
+  (if (GET_MODE_CLASS (TYPE_MODE (type)) != MODE_VECTOR_BOOL)
+(vec_cond @0 (op! @1 @3) (op! @2 @4
+
+/* (c ? a : b) op d  -->  c ? (a op d) : (b op d) */
+ (simplify
+  (op (vec_cond:s @0 @1 @2) @3)
+  (if (GET_MODE_CLASS (TYPE_MODE (type)) != MODE_VECTOR_BOOL)
+(vec_cond @0 (op! @1 @3) (op! @2 @3
+ (simplify
+  (op @3 (vec_cond:s @0 @1 @2))
+  (if (GET_MODE_CLASS (TYPE_MODE (type)) != MODE_VECTOR_BOOL)
+(vec_cond @0 (op! @3 @1) (op! @3 @2)
+
 #if GIMPLE
 (match (nop_atomic_bit_test_and_p @0 @1 @4)
  (bit_and (convert?@4 (ATOMIC_FETCH_OR_XOR_N @2 INTEGER_CST@0 @3))
-- 
2.41.0



Re: [PATCH v2] libstdc++: Fix -Wunused-parameter warnings

2023-09-08 Thread Jonathan Wakely via Gcc-patches
On Thu, 7 Sept 2023 at 20:30, Pekka Seppänen  wrote:
>
> On 7.9.2023 19:40, Jonathan Wakely wrote:
> > On 29/08/23 15:04 +0300, Pekka Seppänen wrote:
> >> libstdc++: Fix -Wunused-parameter warnings when _GLIBCXX_USE_WCHAR_T is
> >> not defined.
> >>
> >> libstdc++-v3/ChangeLog:
> >>
> >> * src/c++11/cow-locale_init.cc: Add [[maybe_unused]] attribute.
> >> * src/c++17/fs_path.cc (path::_S_convert_loc): Likewise.
> >> * src/filesystem/path.cc (path::_S_convert_loc): Likewise.
> >> ---
> >>  libstdc++-v3/src/c++11/cow-locale_init.cc | 4 ++--
> >>  libstdc++-v3/src/c++17/fs_path.cc | 2 +-
> >>  libstdc++-v3/src/filesystem/path.cc   | 2 +-
> >>  3 files changed, 4 insertions(+), 4 deletions(-)
> >>
> >> mbstate_t>>(__loc);
> >>
> >> diff --git a/libstdc++-v3/src/c++11/cow-locale_init.cc
> >> b/libstdc++-v3/src/c++11/cow-locale_init.cc
> >> index 85277763427..9554ed1ebf9 100644
> >> --- a/libstdc++-v3/src/c++11/cow-locale_init.cc
> >> +++ b/libstdc++-v3/src/c++11/cow-locale_init.cc
> >> @@ -137,8 +137,8 @@ namespace
> >>}
> >>
> >>void
> >> -  locale::_Impl::_M_init_extra(void* cloc, void* clocm,
> >> -   const char* __s, const char* __smon)
> >> +  locale::_Impl::_M_init_extra(void* cloc, [[maybe_unused]] void*
> >> clocm,
> >> +   const char* __s, [[maybe_unused]] const char* __smon)
> >
> > This line should be split to keepo it below 80 columns.
> >
>
> Done, v2 follows.

Thanks, I'll get this one committed+pushed.


>
> > Otherwise the patch looks good, but please CC the libstdc++ list for
> > libstdc++ patches. Otherwise I won't see them, and they won't be
> > reviewed.
> >
>
> My bad, I wasn't aware of this.
>
> > Do you have a GCC copyright assignment on file? If not, please add a
> > sign-off to confirm you can submit this under the DCO terms:
> > https://gcc.gnu.org/dco.html
> >
>
> Will add.
>
> >
> >>{
> >>  auto& __cloc = *static_cast<__c_locale*>(cloc);
> >>
> >> diff --git a/libstdc++-v3/src/c++17/fs_path.cc
> >> b/libstdc++-v3/src/c++17/fs_path.cc
> >> index aaea7d2725d..d65b5482e8b 100644
> >> --- a/libstdc++-v3/src/c++17/fs_path.cc
> >> +++ b/libstdc++-v3/src/c++17/fs_path.cc
> >> @@ -1947,7 +1947,7 @@ path::_M_split_cmpts()
> >>
> >>  path::string_type
> >>  path::_S_convert_loc(const char* __first, const char* __last,
> >> - const std::locale& __loc)
> >> + [[maybe_unused]] const std::locale& __loc)
> >>  {
> >>  #if _GLIBCXX_USE_WCHAR_T
> >>auto& __cvt = std::use_facet >> mbstate_t>>(__loc);
> >> diff --git a/libstdc++-v3/src/filesystem/path.cc
> >> b/libstdc++-v3/src/filesystem/path.cc
> >> index 4c218bdae49..d04ba6d465d 100644
> >> --- a/libstdc++-v3/src/filesystem/path.cc
> >> +++ b/libstdc++-v3/src/filesystem/path.cc
> >> @@ -498,7 +498,7 @@ path::_M_trim()
> >>
> >>  path::string_type
> >>  path::_S_convert_loc(const char* __first, const char* __last,
> >> - const std::locale& __loc)
> >> + [[maybe_unused]] const std::locale& __loc)
> >>  {
> >>  #if _GLIBCXX_USE_WCHAR_T
> >>auto& __cvt = std::use_facet >
> >
>
> -- >8 --
> libstdc++: Fix -Wunused-parameter warnings when _GLIBCXX_USE_WCHAR_T is
> not defined.
>
> libstdc++-v3/ChangeLog:
>
> * src/c++11/cow-locale_init.cc: Add [[maybe_unused]] attribute.
> * src/c++17/fs_path.cc (path::_S_convert_loc): Likewise.
> * src/filesystem/path.cc (path::_S_convert_loc): Likewise.
>
> Signed-off-by: Pekka Seppänen 
> ---
>  libstdc++-v3/src/c++11/cow-locale_init.cc | 5 +++--
>  libstdc++-v3/src/c++17/fs_path.cc | 2 +-
>  libstdc++-v3/src/filesystem/path.cc   | 2 +-
>  3 files changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/libstdc++-v3/src/c++11/cow-locale_init.cc 
> b/libstdc++-v3/src/c++11/cow-locale_init.cc
> index 85277763427..f48561f5b12 100644
> --- a/libstdc++-v3/src/c++11/cow-locale_init.cc
> +++ b/libstdc++-v3/src/c++11/cow-locale_init.cc
> @@ -137,8 +137,9 @@ namespace
>}
>
>void
> -  locale::_Impl::_M_init_extra(void* cloc, void* clocm,
> -   const char* __s, const char* __smon)
> +  locale::_Impl::_M_init_extra(void* cloc, [[maybe_unused]] void* clocm,
> +  const char* __s,
> +  [[maybe_unused]] const char* __smon)
>{
>  auto& __cloc = *static_cast<__c_locale*>(cloc);
>
> diff --git a/libstdc++-v3/src/c++17/fs_path.cc 
> b/libstdc++-v3/src/c++17/fs_path.cc
> index aaea7d2725d..d65b5482e8b 100644
> --- a/libstdc++-v3/src/c++17/fs_path.cc
> +++ b/libstdc++-v3/src/c++17/fs_path.cc
> @@ -1947,7 +1947,7 @@ path::_M_split_cmpts()
>
>  path::string_type
>  path::_S_convert_loc(const char* __first, const char* __last,
> -const std::locale& __loc)
> +[[maybe_unused]] const std::locale& __loc)
>  {
>  #if _GLIBCXX_USE_WCHAR_T
>auto& __cvt = std::use_facet>(__loc);
> diff --git a/libstdc++-v3/src/filesystem/path.cc 
> 

[committed] libstdc++: Add Filesystem TS and std::stacktrace symbols to libstdc++exp.a

2023-09-08 Thread Jonathan Wakely via Gcc-patches
This consolidates the three static archives for extensions into one, so
that -lstdc++exp can be used to provide the definitions of all unstable
library features.

The libstdc++_libbacktrace.a archive is now just a "noinst" convenience
library that is only used during the build, not installed. Its contents
are added to libstdc++exp.a, along with the new non-inline definitions
of std::stacktrace symbols.

The libstdc++fs.a archive is still installed, but its contents are
duplicated in libstdc++exp.a now. This means -lstdc++exp can be used
instead of -lstdc++fs. For targets using the GNU linker we should
consider replacing libstdc++fs.a with a linker script that does
INPUT(libstdc++exp.a).

The tests for  could be changed to use
-lstdc++exp instead of -lstdc++fs, which would allow removing
src/filesystem/.libs from the LDFLAGS in scripts/testsuite_flags.in,
but that can be done at a later date.

libstdc++-v3/ChangeLog:

* acinclude.m4 (GLIBCXX_CONFIGURE): Add c++23 directory.
* configure: Regenerate.
* doc/html/manual/*: Regenerate.
* doc/xml/manual/using.xml: Update documentation on linking.
* include/std/stacktrace: Remove declarations of libbacktrace
APIs.
(stacktrace_entry::_S_err_handler, stacktrace_entry::_S_init):
Remove.
(stacktrace_entry::_Info): New class.
(stacktrace_entry::_M_get_info): Use _Info.
(__stacktrace_impl): New class.
(basic_stacktrace): Derive from __stacktrace_impl.
(basic_stacktrace::current): Use __stacktrace_impl::_S_current.
* scripts/testsuite_flags.in: Adjust LDFLAGS to find
libstdc++exp instead of libstdc++_libbacktrace.
* src/Makefile.am (SUBDIRS): Add c++23 directory.
* src/Makefile.in: Regenerate.
* src/c++20/Makefile.am: Fix comment.
* src/c++20/Makefile.in: Regenerate.
* src/c++23/Makefile.am: New file.
* src/c++23/Makefile.in: New file.
* src/c++23/stacktrace.cc: New file with definitions of
stacktrace_entry::_Info and __stacktrace_impl members.
* src/experimental/Makefile.am: Use LIBADD to include other
libraries.
* src/experimental/Makefile.in: Regenerate.
* src/libbacktrace/Makefile.am: Use noinst_LTLIBRARIES.
* src/libbacktrace/Makefile.in: Regenerate.
* testsuite/19_diagnostics/stacktrace/current.cc: Adjust
dg-options to use -lstdc++exp.
* testsuite/19_diagnostics/stacktrace/entry.cc: Likewise.
* testsuite/19_diagnostics/stacktrace/stacktrace.cc: Likewise.
* testsuite/23_containers/vector/debug/assign4_backtrace_neg.cc:
Likewise.
---
 libstdc++-v3/acinclude.m4 |   2 +-
 libstdc++-v3/configure|  16 +-
 libstdc++-v3/doc/html/manual/using.html   |  26 +-
 .../html/manual/using_dynamic_or_shared.html  |   4 +
 libstdc++-v3/doc/xml/manual/using.xml |  37 +-
 libstdc++-v3/include/std/stacktrace   | 144 +---
 libstdc++-v3/scripts/testsuite_flags.in   |   8 +-
 libstdc++-v3/src/Makefile.am  |   4 +-
 libstdc++-v3/src/Makefile.in  |   7 +-
 libstdc++-v3/src/c++20/Makefile.am|   2 +-
 libstdc++-v3/src/c++20/Makefile.in|   2 +-
 libstdc++-v3/src/c++23/Makefile.am| 109 +++
 libstdc++-v3/src/c++23/Makefile.in| 747 ++
 libstdc++-v3/src/c++23/stacktrace.cc  | 171 
 libstdc++-v3/src/experimental/Makefile.am |  20 +
 libstdc++-v3/src/experimental/Makefile.in |  15 +-
 libstdc++-v3/src/libbacktrace/Makefile.am |   3 +-
 libstdc++-v3/src/libbacktrace/Makefile.in |  88 +--
 .../19_diagnostics/stacktrace/current.cc  |   2 +-
 .../19_diagnostics/stacktrace/entry.cc|   2 +-
 .../19_diagnostics/stacktrace/stacktrace.cc   |   2 +-
 .../vector/debug/assign4_backtrace_neg.cc |   2 +-
 22 files changed, 1185 insertions(+), 228 deletions(-)
 create mode 100644 libstdc++-v3/src/c++23/Makefile.am
 create mode 100644 libstdc++-v3/src/c++23/Makefile.in
 create mode 100644 libstdc++-v3/src/c++23/stacktrace.cc

diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index fcf79503265..34faa3c049f 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -49,7 +49,7 @@ AC_DEFUN([GLIBCXX_CONFIGURE], [
   # Keep these sync'd with the list in Makefile.am.  The first provides an
   # expandable list at autoconf time; the second provides an expandable list
   # (i.e., shell variable) at configure time.
-  m4_define([glibcxx_SUBDIRS],[include libsupc++ src src/c++98 src/c++11 
src/c++17 src/c++20 src/filesystem src/libbacktrace src/experimental doc po 
testsuite python])
+  m4_define([glibcxx_SUBDIRS],[include libsupc++ src src/c++98 src/c++11 
src/c++17 src/c++20 src/c++23 src/filesystem src/libbacktrace src/experimental 
doc po testsuite python])
   SUBDIRS='glibcxx_SUBDIRS'
 
   # These need to be absolute 

Re: [PATCH] libstdc++: Reduce output of 'make check'

2023-09-08 Thread Jonathan Wakely via Gcc-patches
On Thu, 7 Sept 2023 at 14:32, Jonathan Wakely via Libstdc++
 wrote:
>
> Any objections to this change?

Pushed to trunk now.

>
> -- >8 --
>
> This removes the 39 lines of shell commands that get echoed when
> starting the testsuite. The fact that near the end of that output it
> prints `echo "WARNING: could not find \`runtest'" 1>&2; :;` makes it
> look like that warning is actually being shown the the user.
>
> Suppress echoing the recipe, so that users only see the actual output
> from the testsuite, not the makefile recipe as well.
>
> libstdc++-v3/ChangeLog:
>
> * testsuite/Makefile.am (check-DEJAGNU): Use @ in recipe.
> * testsuite/Makefile.in: Regenerate.
> ---
>  libstdc++-v3/testsuite/Makefile.am | 2 +-
>  libstdc++-v3/testsuite/Makefile.in | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/libstdc++-v3/testsuite/Makefile.am 
> b/libstdc++-v3/testsuite/Makefile.am
> index 7adc5318192..4cee585fd8e 100644
> --- a/libstdc++-v3/testsuite/Makefile.am
> +++ b/libstdc++-v3/testsuite/Makefile.am
> @@ -117,7 +117,7 @@ $(check_DEJAGNU_normal_targets): check-DEJAGNUnormal%: 
> normal%/site.exp
>
>  # Run the testsuite in normal mode.
>  check-DEJAGNU $(check_DEJAGNU_normal_targets): check-DEJAGNU%: site.exp
> -   $(if $*,@)AR="$(AR)"; export AR; \
> +   @$(if $*,@)AR="$(AR)"; export AR; \
> RANLIB="$(RANLIB)"; export RANLIB; \
> if [ -z "$*" ] && [ -n "$(filter -j%, $(MFLAGS))" ]; then \
>   rm -rf normal-parallel || true; \
>



Re: [PATCH] libbacktrace: Fix unconditional -Werror

2023-09-08 Thread Jonathan Wakely via Gcc-patches
On Fri, 8 Sept 2023 at 11:10, Jonathan Wakely  wrote:
>
> The patch looks good, thanks. I noticed the unconditional -Werror the other 
> day when testing a build on avr.
>
> N.B. All patches should go to gcc-patches (as well as a more specific list 
> like libstdc++ when appropriate).
>
> OK for trunk

I've pushed this now - thanks again.

>
>
>
> On Fri, 8 Sept 2023, 10:49 Alexey Lapshin via Libstdc++, 
>  wrote:
>>
>> Added to CC: jwak...@redhat.com, h...@axis.com
>>
>>
>> On Fri, 2023-09-08 at 12:39 +0400, Alexey Lapshin wrote:
>> > -Werror flag should depend on --enable-werror configure option
>> >
>> > ---
>> >  libstdc++-v3/src/libbacktrace/Makefile.am | 2 +-
>> >  libstdc++-v3/src/libbacktrace/Makefile.in | 2 +-
>> >  2 files changed, 2 insertions(+), 2 deletions(-)
>> >
>> > diff --git a/libstdc++-v3/src/libbacktrace/Makefile.am 
>> > b/libstdc++-v3/src/libbacktrace/Makefile.am
>> > index 9abf9dd64a1..27c1ea570e0 100644
>> > --- a/libstdc++-v3/src/libbacktrace/Makefile.am
>> > +++ b/libstdc++-v3/src/libbacktrace/Makefile.am
>> > @@ -45,7 +45,7 @@ libstdc___libbacktrace_la_CPPFLAGS = \
>> > $(BACKTRACE_CPPFLAGS)
>> >
>> >  WARN_FLAGS = -W -Wall -Wwrite-strings -Wmissing-format-attribute \
>> > --Wcast-qual -Werror
>> > +-Wcast-qual
>> >  C_WARN_FLAGS = $(WARN_FLAGS) -Wstrict-prototypes -Wmissing-prototypes 
>> > -Wold-style-definition -Wno-unused-but-set-variable
>> >  CXX_WARN_FLAGS = $(WARN_FLAGS) -Wno-unused-parameter
>> >  AM_CFLAGS = $(C_WARN_FLAGS)
>> > diff --git a/libstdc++-v3/src/libbacktrace/Makefile.in 
>> > b/libstdc++-v3/src/libbacktrace/Makefile.in
>> > index 1c1242d8827..b78c8443751 100644
>> > --- a/libstdc++-v3/src/libbacktrace/Makefile.in
>> > +++ b/libstdc++-v3/src/libbacktrace/Makefile.in
>> > @@ -368,7 +368,7 @@ VTV_CXXFLAGS = @VTV_CXXFLAGS@
>> >  VTV_CXXLINKFLAGS = @VTV_CXXLINKFLAGS@
>> >  VTV_PCH_CXXFLAGS = @VTV_PCH_CXXFLAGS@
>> >  WARN_FLAGS = -W -Wall -Wwrite-strings -Wmissing-format-attribute \
>> > --Wcast-qual -Werror
>> > +-Wcast-qual
>> >
>> >  XMLCATALOG = @XMLCATALOG@
>> >  XMLLINT = @XMLLINT@
>>



Re: [PATCH 01/13] [APX EGPR] middle-end: Add insn argument to base_reg_class

2023-09-08 Thread Vladimir Makarov via Gcc-patches



On 8/31/23 04:20, Hongyu Wang wrote:

@@ -2542,6 +2542,8 @@ the code of the immediately enclosing expression 
(@code{MEM} for the top level
  of an address, @code{ADDRESS} for something that occurs in an
  @code{address_operand}).  @var{index_code} is the code of the corresponding
  index expression if @var{outer_code} is @code{PLUS}; @code{SCRATCH} otherwise.
+@code{insn} indicates insn specific base register class should be subset
+of the original base register class.
  @end defmac


I'd prefer more general description of 'insn' argument for the macros.  
Something like that:


@code{insn} can be used to define an insn-specific base register class.




[PATCH] Allow target attributes in non-gnu namespaces

2023-09-08 Thread Richard Sandiford via Gcc-patches
Currently there are four static sources of attributes:

- LANG_HOOKS_ATTRIBUTE_TABLE
- LANG_HOOKS_COMMON_ATTRIBUTE_TABLE
- LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE
- TARGET_ATTRIBUTE_TABLE

All of the attributes in these tables go in the "gnu" namespace.
This means that they can use the traditional GNU __attribute__((...))
syntax and the standard [[gnu::...]] syntax.

Standard attributes are registered dynamically with a null namespace.
There are no supported attributes in other namespaces (clang, vendor
namespaces, etc.).

This patch tries to generalise things by making the namespace
part of the attribute specification.

It's usual for multiple attributes to be defined in the same namespace,
so rather than adding the namespace to each individual definition,
it seemed better to group attributes in the same namespace together.
This would also allow us to reuse the same table for clang attributes
that are written with the GNU syntax, or other similar situations
where the attribute can be accessed via multiple "spellings".

The patch therefore adds a scoped_attribute_specs that contains
a namespace and a list of attributes in that namespace.

It's still possible to have multiple scoped_attribute_specs
for the same namespace.  E.g. it makes sense to keep the
C++-specific, C/C++-common, and format-related attributes in
separate tables, even though they're all GNU attributes.

Current lists of attributes are terminated by a null name.
Rather than keep that for the new structure, it seemed neater
to use an array_slice.  This also makes the tables slighly more
compact.

In general, a target might want to support attributes in multiple
namespaces.  Rather than have a separate hook for each possibility
(like the three langhooks above), it seemed better to make
TARGET_ATTRIBUTE_TABLE a table of tables.  Specifically, it's
an array_slice of scoped_attribute_specs.

We can do the same thing for langhooks, which allows the three hooks
above to be merged into a single LANG_HOOKS_ATTRIBUTE_TABLE.
It also allows the standard attributes to be registered statically
and checked by the usual attribs.cc checks.

The patch adds a TARGET_GNU_ATTRIBUTES helper for the common case
in which a target wants a single table of gnu attributes.  It can
only be used if the table is free of preprocessor directives.

There are probably other things we need to do to make vendor namespaces
work smoothly.  E.g. in principle it would be good to make exclusion
sets namespace-aware.  But to some extent we have that with standard
vs. gnu attributes too.  This patch is just supposed to be a first step.

Bootstrapped & regtested on aarch64-linux-gnu and x86_64-linux-gnu.
Also tested on the full target list in config-list.mk.  OK to install?

Richard


gcc/
* attribs.h (scoped_attribute_specs): New structure.
(register_scoped_attributes): Take a reference to a
scoped_attribute_specs instead of separate namespace and array
parameters.
* plugin.h (register_scoped_attributes): Likewise.
* attribs.cc (register_scoped_attributes): Likewise.
(attribute_tables): Change into an array of scoped_attribute_specs
pointers.  Reduce to 1 element for frontends and 1 element for targets.
(empty_attribute_table): Delete.
(check_attribute_tables): Update for changes to attribute_tables.
Use a hash_set to identify duplicates.
(handle_ignored_attributes_option): Update for above changes.
(init_attributes): Likewise.
(excl_pair): Delete.
(test_attribute_exclusions): Update for above changes.  Don't
enforce symmetry for standard attributes in the top-level namespace.
* langhooks-def.h (LANG_HOOKS_COMMON_ATTRIBUTE_TABLE): Delete.
(LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE): Likewise.
(LANG_HOOKS_INITIALIZER): Update accordingly.
(LANG_HOOKS_ATTRIBUTE_TABLE): Define to an empty constructor.
* langhooks.h (lang_hooks::common_attribute_table): Delete.
(lang_hooks::format_attribute_table): Likewise.
(lang_hooks::attribute_table): Redefine to an array of
scoped_attribute_specs pointers.
* target-def.h (TARGET_GNU_ATTRIBUTES): New macro.
* target.def (attribute_spec): Redefine to return an array of
scoped_attribute_specs pointers.
* tree-inline.cc (function_attribute_inlinable_p): Update accordingly.
* doc/tm.texi: Regenerate.
* config/aarch64/aarch64.cc (aarch64_attribute_table): Define using
TARGET_GNU_ATTRIBUTES.
* config/alpha/alpha.cc (vms_attribute_table): Likewise.
* config/avr/avr.cc (avr_attribute_table): Likewise.
* config/bfin/bfin.cc (bfin_attribute_table): Likewise.
* config/bpf/bpf.cc (bpf_attribute_table): Likewise.
* config/csky/csky.cc (csky_attribute_table): Likewise.
* config/epiphany/epiphany.cc (epiphany_attribute_table): Likewise.
* config/gcn/gcn.cc (gcn_attribute_table): 

PING^4: [PATCH V4, rs6000] Disable generation of scalar modulo instructions

2023-09-08 Thread Pat Haugen via Gcc-patches

Ping.

On 6/30/23 2:26 PM, Pat Haugen via Gcc-patches wrote:

Updated from prior version to address latest review comment (simplify
umod3).

Disable generation of scalar modulo instructions.

It was recently discovered that the scalar modulo instructions can suffer
noticeable performance issues for certain input values. This patch disables
their generation since the equivalent div/mul/sub sequence does not suffer
the same problem.

Bootstrapped and regression tested on powerpc64/powerpc64le.
Ok for master and backports after burn in?

-Pat


2023-06-30  Pat Haugen  

gcc/
     * config/rs6000/rs6000.cc (rs6000_rtx_costs): Check if disabling
     scalar modulo.
     * config/rs6000/rs6000.h (RS6000_DISABLE_SCALAR_MODULO): New.
     * config/rs6000/rs6000.md (mod3, *mod3): Disable.
     (define_expand umod3): New.
     (define_insn umod3): Rename to *umod3 and disable.
     (umodti3, modti3): Disable.

gcc/testsuite/
     * gcc.target/powerpc/clone1.c: Add xfails.
     * gcc.target/powerpc/clone3.c: Likewise.
     * gcc.target/powerpc/mod-1.c: Update scan strings and add xfails.
     * gcc.target/powerpc/mod-2.c: Likewise.
     * gcc.target/powerpc/p10-vdivq-vmodq.c: Add xfails.




Re: [PATCH 3/3] [V2] [RISC-V] support cm.mva01s cm.mvsa01 in zcmp

2023-09-08 Thread Jeff Law via Gcc-patches




On 9/7/23 20:06, Fei Gao wrote:

On 2023-09-08 04:33  Palmer Dabbelt  wrote:


On Thu, 07 Sep 2023 13:16:36 PDT (-0700), dimi...@dinux.eu wrote:

Hi,

This patch appears to have caused PR 111259.

Hi Patrick

We're reproducing the issue also.

One thing that puzzles me is why a zcmp predicate casused
a regression in rv64gc single lib build. The new define_insn
and define_peephole2 are all gated by TARGET_ZCMP, which
is false when building libgcc.
Operand predicates are checked for validity before the insn condition is 
checked.


Jeff


[PATCH v3] libcpp: add function to check XID properties

2023-09-08 Thread Arthur Cohen
From: Raiki Tamura 

Fixed to include the enum's name which I had forgotten to commit.

Thanks



This commit adds a new function intended for checking the XID properties
of a possibly unicode character, as well as the accompanying enum
describing the possible properties.

libcpp/ChangeLog:

* charset.cc (cpp_check_xid_property): New.
* include/cpplib.h
(cpp_check_xid_property): New.
(enum cpp_xid_property): New.

Signed-off-by: Raiki Tamura 
---
 libcpp/charset.cc   | 36 
 libcpp/include/cpplib.h |  7 +++
 2 files changed, 43 insertions(+)

diff --git a/libcpp/charset.cc b/libcpp/charset.cc
index 7b625c9956a..a92ba75539e 100644
--- a/libcpp/charset.cc
+++ b/libcpp/charset.cc
@@ -1256,6 +1256,42 @@ _cpp_uname2c_uax44_lm2 (const char *name, size_t len, 
char *canon_name)
   return result;
 }
 
+/* Returns flags representing the XID properties of the given codepoint.  */
+unsigned int
+cpp_check_xid_property (cppchar_t c)
+{
+  // fast path for ASCII
+  if (c < 0x80)
+  {
+if (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'))
+  return CPP_XID_START | CPP_XID_CONTINUE;
+if (('0' <= c && c <= '9') || c == '_')
+  return CPP_XID_CONTINUE;
+  }
+
+  if (c > UCS_LIMIT)
+return 0;
+
+  int mn, mx, md;
+  mn = 0;
+  mx = ARRAY_SIZE (ucnranges) - 1;
+  while (mx != mn)
+{
+  md = (mn + mx) / 2;
+  if (c <= ucnranges[md].end)
+  mx = md;
+  else
+  mn = md + 1;
+}
+
+  unsigned short flags = ucnranges[mn].flags;
+
+  if (flags & CXX23)
+return CPP_XID_START | CPP_XID_CONTINUE;
+  if (flags & NXX23)
+return CPP_XID_CONTINUE;
+  return 0;
+}
 
 /* Returns 1 if C is valid in an identifier, 2 if C is valid except at
the start of an identifier, and 0 if C is not valid in an
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index fcdaf082b09..583e3071e90 100644
--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -1606,4 +1606,11 @@ bool cpp_valid_utf8_p (const char *data, size_t 
num_bytes);
 bool cpp_is_combining_char (cppchar_t c);
 bool cpp_is_printable_char (cppchar_t c);
 
+enum cpp_xid_property {
+  CPP_XID_START = 1,
+  CPP_XID_CONTINUE = 2
+};
+
+unsigned int cpp_check_xid_property (cppchar_t c);
+
 #endif /* ! LIBCPP_CPPLIB_H */
-- 
2.40.0



Re: [V3][PATCH 2/3] Use the counted_by atribute info in builtin object size [PR108896]

2023-09-08 Thread Qing Zhao via Gcc-patches
Ping.

thanks.

Qing

> On Aug 25, 2023, at 11:24 AM, Qing Zhao  wrote:
> 
> Use the counted_by atribute info in builtin object size to compute the
> subobject size for flexible array members.
> 
> gcc/ChangeLog:
> 
>   PR C/108896
>   * tree-object-size.cc (addr_object_size): Use the counted_by
>   attribute info.
>   * tree.cc (component_ref_has_counted_by_p): New function.
>   (component_ref_get_counted_by): New function.
>   * tree.h (component_ref_has_counted_by_p): New prototype.
>   (component_ref_get_counted_by): New prototype.
> 
> gcc/testsuite/ChangeLog:
> 
>   PR C/108896
>   * gcc.dg/flex-array-counted-by-2.c: New test.
>   * gcc.dg/flex-array-counted-by-3.c: New test.
> ---
> .../gcc.dg/flex-array-counted-by-2.c  |  74 ++
> .../gcc.dg/flex-array-counted-by-3.c  | 210 ++
> gcc/tree-object-size.cc   |  37 ++-
> gcc/tree.cc   |  95 +++-
> gcc/tree.h|  10 +
> 5 files changed, 418 insertions(+), 8 deletions(-)
> create mode 100644 gcc/testsuite/gcc.dg/flex-array-counted-by-2.c
> create mode 100644 gcc/testsuite/gcc.dg/flex-array-counted-by-3.c
> 
> diff --git a/gcc/testsuite/gcc.dg/flex-array-counted-by-2.c 
> b/gcc/testsuite/gcc.dg/flex-array-counted-by-2.c
> new file mode 100644
> index ..ec580c1f1f01
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/flex-array-counted-by-2.c
> @@ -0,0 +1,74 @@
> +/* test the attribute counted_by and its usage in
> + * __builtin_dynamic_object_size.  */ 
> +/* { dg-do run } */
> +/* { dg-options "-O2" } */
> +
> +#include "builtin-object-size-common.h"
> +
> +#define expect(p, _v) do { \
> +size_t v = _v; \
> +if (p == v) \
> + __builtin_printf ("ok:  %s == %zd\n", #p, p); \
> +else \
> + {  \
> +   __builtin_printf ("WAT: %s == %zd (expected %zd)\n", #p, p, v); \
> +   FAIL (); \
> + } \
> +} while (0);
> +
> +struct flex {
> +  int b;
> +  int c[];
> +} *array_flex;
> +
> +struct annotated {
> +  int b;
> +  int c[] __attribute__ ((counted_by (b)));
> +} *array_annotated;
> +
> +struct nested_annotated {
> +  struct {
> +union {
> +  int b;
> +  float f;   
> +};
> +int n;
> +  };
> +  int c[] __attribute__ ((counted_by (b)));
> +} *array_nested_annotated;
> +
> +void __attribute__((__noinline__)) setup (int normal_count, int attr_count)
> +{
> +  array_flex
> += (struct flex *)malloc (sizeof (struct flex)
> +  + normal_count *  sizeof (int));
> +  array_flex->b = normal_count;
> +
> +  array_annotated
> += (struct annotated *)malloc (sizeof (struct annotated)
> +   + attr_count *  sizeof (int));
> +  array_annotated->b = attr_count;
> +
> +  array_nested_annotated
> += (struct nested_annotated *)malloc (sizeof (struct nested_annotated)
> +  + attr_count *  sizeof (int));
> +  array_nested_annotated->b = attr_count;
> +
> +  return;
> +}
> +
> +void __attribute__((__noinline__)) test ()
> +{
> +expect(__builtin_dynamic_object_size(array_flex->c, 1), -1);
> +expect(__builtin_dynamic_object_size(array_annotated->c, 1),
> +array_annotated->b * sizeof (int));
> +expect(__builtin_dynamic_object_size(array_nested_annotated->c, 1),
> +array_nested_annotated->b * sizeof (int));
> +}
> +
> +int main(int argc, char *argv[])
> +{
> +  setup (10,10);   
> +  test ();
> +  DONE ();
> +}
> diff --git a/gcc/testsuite/gcc.dg/flex-array-counted-by-3.c 
> b/gcc/testsuite/gcc.dg/flex-array-counted-by-3.c
> new file mode 100644
> index ..a0c3cb88ec71
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/flex-array-counted-by-3.c
> @@ -0,0 +1,210 @@
> +/* test the attribute counted_by and its usage in
> +__builtin_dynamic_object_size: what's the correct behavior when the
> +allocation size mismatched with the value of counted_by attribute?  */
> +/* { dg-do run } */
> +/* { dg-options "-O -fstrict-flex-arrays=3" } */
> +
> +#include "builtin-object-size-common.h"
> +
> +struct annotated {
> +  size_t foo;
> +  char others;
> +  char array[] __attribute__((counted_by (foo)));
> +};
> +
> +#define expect(p, _v) do { \
> +size_t v = _v; \
> +if (p == v) \
> +__builtin_printf ("ok:  %s == %zd\n", #p, p); \
> +else \
> +{  \
> +  __builtin_printf ("WAT: %s == %zd (expected %zd)\n", #p, p, v); \
> +   FAIL (); \
> +} \
> +} while (0);
> +
> +#define noinline __attribute__((__noinline__))
> +#define SIZE_BUMP 10 
> +#define MAX(a, b) ((a) > (b) ? (a) : (b))
> +#define MIN(a, b) ((a) < (b) ? (a) : (b))
> +
> +/* In general, Due to type casting, the type for the pointee of a pointer
> +   does not say anything about the object it points to,
> +   So, __builtin_object_size can not directly use the type of the pointee
> +   to decide the size of the object the pointer points to.
> +
> +   

[PATCH v2] libcpp: add function to check XID properties

2023-09-08 Thread Arthur Cohen
From: Raiki Tamura 

This commit adds a new function intended for checking the XID properties
of a possibly unicode character, as well as the accompanying enum
describing the possible properties.

libcpp/ChangeLog:

* charset.cc (cpp_check_xid_property): New.
* include/cpplib.h
(cpp_check_xid_property): New.
(enum cpp_xid_property): New.

Signed-off-by: Raiki Tamura 
---
 libcpp/charset.cc   | 36 
 libcpp/include/cpplib.h |  7 +++
 2 files changed, 43 insertions(+)

diff --git a/libcpp/charset.cc b/libcpp/charset.cc
index 7b625c9956a..a92ba75539e 100644
--- a/libcpp/charset.cc
+++ b/libcpp/charset.cc
@@ -1256,6 +1256,42 @@ _cpp_uname2c_uax44_lm2 (const char *name, size_t len, 
char *canon_name)
   return result;
 }
 
+/* Returns flags representing the XID properties of the given codepoint.  */
+unsigned int
+cpp_check_xid_property (cppchar_t c)
+{
+  // fast path for ASCII
+  if (c < 0x80)
+  {
+if (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'))
+  return CPP_XID_START | CPP_XID_CONTINUE;
+if (('0' <= c && c <= '9') || c == '_')
+  return CPP_XID_CONTINUE;
+  }
+
+  if (c > UCS_LIMIT)
+return 0;
+
+  int mn, mx, md;
+  mn = 0;
+  mx = ARRAY_SIZE (ucnranges) - 1;
+  while (mx != mn)
+{
+  md = (mn + mx) / 2;
+  if (c <= ucnranges[md].end)
+  mx = md;
+  else
+  mn = md + 1;
+}
+
+  unsigned short flags = ucnranges[mn].flags;
+
+  if (flags & CXX23)
+return CPP_XID_START | CPP_XID_CONTINUE;
+  if (flags & NXX23)
+return CPP_XID_CONTINUE;
+  return 0;
+}
 
 /* Returns 1 if C is valid in an identifier, 2 if C is valid except at
the start of an identifier, and 0 if C is not valid in an
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index fcdaf082b09..013d276f384 100644
--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -1606,4 +1606,11 @@ bool cpp_valid_utf8_p (const char *data, size_t 
num_bytes);
 bool cpp_is_combining_char (cppchar_t c);
 bool cpp_is_printable_char (cppchar_t c);
 
+enum {
+  CPP_XID_START = 1,
+  CPP_XID_CONTINUE = 2
+};
+
+unsigned int cpp_check_xid_property (cppchar_t c);
+
 #endif /* ! LIBCPP_CPPLIB_H */
-- 
2.40.0



Re: [V3][PATCH 3/3] Use the counted_by attribute information in bound sanitizer[PR108896]

2023-09-08 Thread Qing Zhao via Gcc-patches
Ping.

thanks.

Qing

> On Aug 25, 2023, at 11:24 AM, Qing Zhao  wrote:
> 
> Use the counted_by attribute information in bound sanitizer.
> 
> gcc/c-family/ChangeLog:
> 
>   PR C/108896
>   * c-ubsan.cc (ubsan_instrument_bounds): Use counted_by attribute
>   information.
> 
> gcc/testsuite/ChangeLog:
> 
>   PR C/108896
>   * gcc.dg/ubsan/flex-array-counted-by-bounds.c: New test.
>   * gcc.dg/ubsan/flex-array-counted-by-bounds-2.c: New test.
> ---
> gcc/c-family/c-ubsan.cc   | 16 +++
> .../ubsan/flex-array-counted-by-bounds-2.c| 27 +++
> .../ubsan/flex-array-counted-by-bounds.c  | 46 +++
> 3 files changed, 89 insertions(+)
> create mode 100644 gcc/testsuite/gcc.dg/ubsan/flex-array-counted-by-bounds-2.c
> create mode 100644 gcc/testsuite/gcc.dg/ubsan/flex-array-counted-by-bounds.c
> 
> diff --git a/gcc/c-family/c-ubsan.cc b/gcc/c-family/c-ubsan.cc
> index 51aa83a378d2..a99e8433069f 100644
> --- a/gcc/c-family/c-ubsan.cc
> +++ b/gcc/c-family/c-ubsan.cc
> @@ -362,6 +362,10 @@ ubsan_instrument_bounds (location_t loc, tree array, 
> tree *index,
> {
>   tree type = TREE_TYPE (array);
>   tree domain = TYPE_DOMAIN (type);
> +  /* whether the array ref is a flexible array member with valid counted_by
> + attribute.  */
> +  bool fam_has_count_attr = false;
> +  tree counted_by = NULL_TREE;
> 
>   if (domain == NULL_TREE)
> return NULL_TREE;
> @@ -375,6 +379,17 @@ ubsan_instrument_bounds (location_t loc, tree array, 
> tree *index,
> && COMPLETE_TYPE_P (type)
> && integer_zerop (TYPE_SIZE (type)))
>   bound = build_int_cst (TREE_TYPE (TYPE_MIN_VALUE (domain)), -1);
> +  /* If the array ref is to flexible array member field which has
> +  counted_by attribute.  We can use the information from the
> +  attribute as the bound to instrument the reference.  */
> +  else if ((counted_by = component_ref_get_counted_by (array))
> + != NULL_TREE)
> + {
> +   fam_has_count_attr = true;
> +   bound = fold_build2 (MINUS_EXPR, TREE_TYPE (counted_by),
> +counted_by,
> +build_int_cst (TREE_TYPE (counted_by), 1));
> + }
>   else
>   return NULL_TREE;
> }
> @@ -387,6 +402,7 @@ ubsan_instrument_bounds (location_t loc, tree array, tree 
> *index,
>  -fsanitize=bounds-strict.  */
>   tree base = get_base_address (array);
>   if (!sanitize_flags_p (SANITIZE_BOUNDS_STRICT)
> +  && !fam_has_count_attr
>   && TREE_CODE (array) == COMPONENT_REF
>   && base && (INDIRECT_REF_P (base) || TREE_CODE (base) == MEM_REF))
> {
> diff --git a/gcc/testsuite/gcc.dg/ubsan/flex-array-counted-by-bounds-2.c 
> b/gcc/testsuite/gcc.dg/ubsan/flex-array-counted-by-bounds-2.c
> new file mode 100644
> index ..77ec333509d0
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/ubsan/flex-array-counted-by-bounds-2.c
> @@ -0,0 +1,27 @@
> +/* test the attribute counted_by and its usage in
> +   bounds sanitizer combined with VLA.  */
> +/* { dg-do run } */
> +/* { dg-options "-fsanitize=bounds" } */
> +
> +#include 
> +
> +void __attribute__((__noinline__)) setup_and_test_vla (int n, int m)
> +{
> +   struct foo {
> +   int n;
> +   int p[][n] __attribute__((counted_by(n)));
> +   } *f;
> +
> +   f = (struct foo *) malloc (sizeof(struct foo) + m*sizeof(int[n]));
> +   f->n = m;
> +   f->p[m][n-1]=1;
> +   return;
> +}
> +
> +int main(int argc, char *argv[])
> +{
> +  setup_and_test_vla (10, 11);
> +  return 0;
> +}
> +
> +/* { dg-output "17:8: runtime error: index 11 out of bounds for type" } */
> diff --git a/gcc/testsuite/gcc.dg/ubsan/flex-array-counted-by-bounds.c 
> b/gcc/testsuite/gcc.dg/ubsan/flex-array-counted-by-bounds.c
> new file mode 100644
> index ..81eaeb3f2681
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/ubsan/flex-array-counted-by-bounds.c
> @@ -0,0 +1,46 @@
> +/* test the attribute counted_by and its usage in
> +   bounds sanitizer.  */
> +/* { dg-do run } */
> +/* { dg-options "-fsanitize=bounds" } */
> +
> +#include 
> +
> +struct flex {
> +  int b;
> +  int c[];
> +} *array_flex;
> +
> +struct annotated {
> +  int b;
> +  int c[] __attribute__ ((counted_by (b)));
> +} *array_annotated;
> +
> +void __attribute__((__noinline__)) setup (int normal_count, int 
> annotated_count)
> +{
> +  array_flex
> += (struct flex *)malloc (sizeof (struct flex)
> +  + normal_count *  sizeof (int));
> +  array_flex->b = normal_count;
> +
> +  array_annotated
> += (struct annotated *)malloc (sizeof (struct annotated)
> +   + annotated_count *  sizeof (int));
> +  array_annotated->b = annotated_count;
> +
> +  return;
> +}
> +
> +void __attribute__((__noinline__)) test (int normal_index, int 
> annotated_index)
> +{
> +  array_flex->c[normal_index] = 1;
> +  array_annotated->c[annotated_index] = 2;
> +}
> +
> +int main(int argc, char *argv[])
> +{
> 

Re: [V3][PATCH 1/3] Provide counted_by attribute to flexible array member field (PR108896)

2023-09-08 Thread Qing Zhao via Gcc-patches
PIng.

thanks.

Qing

> On Aug 25, 2023, at 11:24 AM, Qing Zhao  wrote:
> 
> Provide a new counted_by attribute to flexible array member field.
> 
> 'counted_by (COUNT)'
> The 'counted_by' attribute may be attached to the flexible array
> member of a structure.  It indicates that the number of the
> elements of the array is given by the field named "COUNT" in the
> same structure as the flexible array member.  GCC uses this
> information to improve the results of the array bound sanitizer and
> the '__builtin_dynamic_object_size'.
> 
> For instance, the following code:
> 
>  struct P {
>size_t count;
>char other;
>char array[] __attribute__ ((counted_by (count)));
>  } *p;
> 
> specifies that the 'array' is a flexible array member whose number
> of elements is given by the field 'count' in the same structure.
> 
> The field that represents the number of the elements should have an
> integer type.  An explicit 'counted_by' annotation defines a
> relationship between two objects, 'p->array' and 'p->count', that
> 'p->array' has _at least_ 'p->count' number of elements available.
> This relationship must hold even after any of these related objects
> are updated.  It's the user's responsibility to make sure this
> relationship to be kept all the time.  Otherwise the results of the
> array bound sanitizer and the '__builtin_dynamic_object_size' might
> be incorrect.
> 
> For instance, in the following example, the allocated array has
> less elements than what's specified by the 'sbuf->count', this is
> an user error.  As a result, out-of-bounds access to the array
> might not be detected.
> 
>  #define SIZE_BUMP 10
>  struct P *sbuf;
>  void alloc_buf (size_t nelems)
>  {
>sbuf = (struct P *) malloc (MAX (sizeof (struct P),
>   (offsetof (struct P, array[0])
>+ nelems * sizeof (char;
>sbuf->count = nelems + SIZE_BUMP;
>/* This is invalid when the sbuf->array has less than sbuf->count
>   elements.  */
>  }
> 
> In the following example, the 2nd update to the field 'sbuf->count'
> of the above structure will permit out-of-bounds access to the
> array 'sbuf>array' as well.
> 
>  #define SIZE_BUMP 10
>  struct P *sbuf;
>  void alloc_buf (size_t nelems)
>  {
>sbuf = (struct P *) malloc (MAX (sizeof (struct P),
>   (offsetof (struct P, array[0])
>+ (nelems + SIZE_BUMP) * sizeof 
> (char;
>sbuf->count = nelems;
>/* This is valid when the sbuf->array has at least sbuf->count
>   elements.  */
>  }
>  void use_buf (int index)
>  {
>sbuf->count = sbuf->count + SIZE_BUMP + 1;
>/* Now the value of sbuf->count is larger than the number
>   of elements of sbuf->array.  */
>sbuf->array[index] = 0;
>/* then the out-of-bound access to this array
>   might not be detected.  */
>  }
> 
> gcc/c-family/ChangeLog:
> 
>   PR C/108896
>   * c-attribs.cc (handle_counted_by_attribute): New function.
>   (attribute_takes_identifier_p): Add counted_by attribute to the list.
>   * c-common.cc (c_flexible_array_member_type_p): ...To this.
>   * c-common.h (c_flexible_array_member_type_p): New prototype.
> 
> gcc/c/ChangeLog:
> 
>   PR C/108896
>   * c-decl.cc (flexible_array_member_type_p): Renamed and moved to...
>   (add_flexible_array_elts_to_size): Use renamed function.
>   (is_flexible_array_member_p): Use renamed function.
>   (verify_counted_by_attribute): New function.
>   (finish_struct): Use renamed function and verify counted_by
>   attribute.
> 
> gcc/ChangeLog:
> 
>   PR C/108896
>   * doc/extend.texi: Document attribute counted_by.
>   * tree.cc (get_named_field): New function.
>   * tree.h (get_named_field): New prototype.
> 
> gcc/testsuite/ChangeLog:
> 
>   PR C/108896
>   * gcc.dg/flex-array-counted-by.c: New test.
> ---
> gcc/c-family/c-attribs.cc| 54 -
> gcc/c-family/c-common.cc | 13 
> gcc/c-family/c-common.h  |  1 +
> gcc/c/c-decl.cc  | 79 +++-
> gcc/doc/extend.texi  | 77 +++
> gcc/testsuite/gcc.dg/flex-array-counted-by.c | 40 ++
> gcc/tree.cc  | 40 ++
> gcc/tree.h   |  5 ++
> 8 files changed, 291 insertions(+), 18 deletions(-)
> create mode 100644 gcc/testsuite/gcc.dg/flex-array-counted-by.c
> 
> diff --git 

Re: [V3][PATCH 0/3] New attribute "counted_by" to annotate bounds for C99 FAM(PR108896)

2023-09-08 Thread Qing Zhao via Gcc-patches
Ping.  

Thanks.

Qing

> On Aug 25, 2023, at 11:24 AM, Qing Zhao  wrote:
> 
> This is the 3rd version of the patch, per our discussion based on the
> review comments for the 1st and 2nd version, the major changes in this
> version are:
> 
> ***Against 1st version:
> 1. change the name "element_count" to "counted_by";
> 2. change the parameter for the attribute from a STRING to an
> Identifier;
> 3. Add logic and testing cases to handle anonymous structure/unions;
> 4. Clarify documentation to permit the situation when the allocation
> size is larger than what's specified by "counted_by", at the same time,
> it's user's error if allocation size is smaller than what's specified by
> "counted_by";
> 5. Add a complete testing case for using counted_by attribute in
> __builtin_dynamic_object_size when there is mismatch between the
> allocation size and the value of "counted_by", the expecting behavior
> for each case and the explanation on why in the comments. 
> 
> ***Against 2rd version:
> 1. Identify a tree node sharing issue and fixed it in the routine
>   "component_ref_get_counted_ty" of tree.cc;
> 2. Update the documentation and testing cases with the clear usage
>   of the fomula to compute the allocation size:
> MAX (sizeof (struct A), offsetof (struct A, array[0]) + counted_by * 
> sizeof(element))
>   (the algorithm used in tree-object-size.cc is correct).
> 
> In this set of patches, the major functionality provided is:
> 
> 1. a new attribute "counted_by";
> 2. use this new attribute in bound sanitizer;
> 3. use this new attribute in dynamic object size for subobject size;
> 
> As discussed, I plan to add two more separate patches sets after this initial
> patch set is approved and committed.
> 
> set 1. A new warning option and a new sanitizer option for the user error
>  when the allocation size is smaller than the value of "counted_by".
> set 2. An improvement to __builtin_dynamic_object_size  for whole-object
>  size of the structure with FAM annaoted with counted_by. 
> 
> there are also some existing bugs in tree-object-size.cc identified
> during the study, and PRs were filed to record them. these bugs will 
> be fixed seperately with individual patches:
> 
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111030
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111040
> 
> Bootstrapped and regression tested on both aarch64 and X86, no issue.
> 
> Please see more details on the description of this work on:
> 
> https://gcc.gnu.org/pipermail/gcc-patches/2023-May/619708.html
> 
> and more discussions on
> https://gcc.gnu.org/pipermail/gcc-patches/2023-August/626376.html
> 
> Okay for committing?
> 
> thanks.
> 
> Qing
> 
> Qing Zhao (3):
>  Provide counted_by attribute to flexible array member field (PR108896)
>  Use the counted_by atribute info in builtin object size [PR108896]
>  Use the counted_by attribute information in bound sanitizer[PR108896]
> 
> gcc/c-family/c-attribs.cc |  54 -
> gcc/c-family/c-common.cc  |  13 ++
> gcc/c-family/c-common.h   |   1 +
> gcc/c-family/c-ubsan.cc   |  16 ++
> gcc/c/c-decl.cc   |  79 +--
> gcc/doc/extend.texi   |  77 +++
> .../gcc.dg/flex-array-counted-by-2.c  |  74 ++
> .../gcc.dg/flex-array-counted-by-3.c  | 210 ++
> gcc/testsuite/gcc.dg/flex-array-counted-by.c  |  40 
> .../ubsan/flex-array-counted-by-bounds-2.c|  27 +++
> .../ubsan/flex-array-counted-by-bounds.c  |  46 
> gcc/tree-object-size.cc   |  37 ++-
> gcc/tree.cc   | 133 +++
> gcc/tree.h|  15 ++
> 14 files changed, 797 insertions(+), 25 deletions(-)
> create mode 100644 gcc/testsuite/gcc.dg/flex-array-counted-by-2.c
> create mode 100644 gcc/testsuite/gcc.dg/flex-array-counted-by-3.c
> create mode 100644 gcc/testsuite/gcc.dg/flex-array-counted-by.c
> create mode 100644 gcc/testsuite/gcc.dg/ubsan/flex-array-counted-by-bounds-2.c
> create mode 100644 gcc/testsuite/gcc.dg/ubsan/flex-array-counted-by-bounds.c
> 
> -- 
> 2.31.1
> 



Re: Skip a number of C++ test cases for '-fno-exceptions' testing (was: Support in the GCC(/C++) test suites for '-fno-exceptions')

2023-09-08 Thread Thomas Schwinge
Hi!

GCC/C++ front end maintainers, please provide input on the overall
approach here:

On 2023-06-15T17:15:54+0200, I wrote:
> On 2023-06-06T20:31:21+0100, Jonathan Wakely  wrote:
>> On Tue, 6 Jun 2023 at 20:14, Thomas Schwinge  wrote:
>>> This issue comes up in context of me working on C++ support for GCN and
>>> nvptx target.  Those targets shall default to '-fno-exceptions' -- or,
>>> "in other words", '-fexceptions' is not supported.  (Details omitted
>>> here.)
>>>
>>> It did seem clear to me that with such a configuration it'll be hard to
>>> get clean test results.  Then I found code in
>>> 'gcc/testsuite/lib/gcc-dg.exp:gcc-dg-prune':
>>>
>>> # If exceptions are disabled, mark tests expecting exceptions to be 
>>> enabled
>>> # as unsupported.
>>> if { ![check_effective_target_exceptions_enabled] } {
>>> if [regexp "(^|\n)\[^\n\]*: error: exception handling disabled" 
>>> $text] {
>>> return "::unsupported::exception handling disabled"
>>> }
>>>
>>> ..., which, in a way, sounds as if the test suite generally is meant to
>>> produce useful results for '-fno-exceptions', nice surprise!
>>>
>>> Running x86_64-pc-linux-gnu (not yet GCN, nvptx) 'make check' with:
>>>
>>> RUNTESTFLAGS='--target_board=unix/-fno-exceptions\{,-m32\}'
>>>
>>> ..., I find that indeed this does work for a lot of test cases, where we
>>> then get (random example):
>>>
>>>  PASS: g++.dg/coroutines/pr99710.C  (test for errors, line 23)
>>> -PASS: g++.dg/coroutines/pr99710.C (test for excess errors)
>>> +UNSUPPORTED: g++.dg/coroutines/pr99710.C: exception handling disabled
>>>
>>> ..., due to:
>>>
>>>  [...]/g++.dg/coroutines/pr99710.C: In function 'task my_coro()':
>>> +[...]/g++.dg/coroutines/pr99710.C:18:10: error: exception handling 
>>> disabled, use '-fexceptions' to enable
>>>  [...]/g++.dg/coroutines/pr99710.C:23:7: error: await expressions are 
>>> not permitted in handlers
>>>  compiler exited with status 1
>>>
>>> But, we're nowhere near clean test results: PASS -> FAIL as well as
>>> XFAIL -> XPASS regressions, due to 'error: exception handling disabled'
>>> precluding other diagnostics seems to be one major issue.
>>>
>>> Is there interest in me producing the obvious (?) changes to those test
>>> cases, such that compiler g++ as well as target library libstdc++ test
>>> results are reasonably clean?  (If you think that's all "wasted effort",
>>> then I suppose I'll just locally ignore any FAILs/XPASSes/UNRESOLVEDs
>>> that appear in combination with
>>> 'UNSUPPORTED: [...]: exception handling disabled'.)
>>
>> I would welcome that for libstdc++. [...]

> Per your and my changes a few days ago, we've already got libstdc++
> covered, [...]

> Not having heard anything contrary regarding the compiler side of things,
> I've now been working on that, see below.
>
>> We already have a handful of tests that use #if __cpp_exceptions to make
>> those parts conditional on exception support.
>
> Yes, that's an option not for all but certainly for some test cases.
> (I'm not looking into that now -- but this may in fact be a good
> beginner-level task, will add to ).
>
>>> Otherwise, a number of test cases need DejaGnu directives
>>> conditionalized on 'target exceptions_enabled'.
>
> Before I get to such things, even simpler: OK to push the attached
> "Skip a number of C++ test cases for '-fno-exceptions' testing"?

I've re-attached my patch from a few months ago:
"Skip a number of C++ test cases for '-fno-exceptions' testing".
(I'd obviously re-check for current master branch before 'git push'.)

If there is interest in this at all, I'd then later complete and submit
my more or less WIP patches for the slightly more involved test case
scenarios.


Grüße
 Thomas


>>> (Or,
>>> 'error: exception handling disabled' made a "really late" diagnostic, so
>>> that it doesn't preclude other diagnostics?  I'll have a look.  Well,
>>> maybe something like: in fact do not default to '-fno-exceptions', but
>>> instead emit 'error: exception handling disabled' only if in a "really
>>> late" pass we run into exceptions-related constructs that we cannot
>>> support.  That'd also avoid PASS -> UNSUPPORTED "regressions" when
>>> exception handling in fact gets optimized away, for example.  I like that
>>> idea, conceptually -- but is it feasible to implement..?)
>>
>> IMHO just [...] using [an effective target keyword] in test
>> selectors seems simpler, and doesn't require changes to the compiler, just
>> the tests.
>
> I still like the idea, but yes, I've mentally put it on file "for later"
> (ha, ha, ha...) -- it doesn't seem obvious to implement.
>
>
> 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
>From 

Re: [PATCH] libcpp: add function to check XID properties

2023-09-08 Thread Jakub Jelinek via Gcc-patches
On Fri, Sep 08, 2023 at 02:58:40PM +0200, Arthur Cohen wrote:
> From: Raiki Tamura 
> 
> libcpp/ChangeLog:
> 
>   * charset.cc (check_xid_property):new function to check XID_Start and 
> XID_Continue
>   * include/cpplib.h (check_xid_property):add enum representing XID 
> properties

Just random comments, not a proper review.
1) functions exported from libcpp should IMNSHO use the cpp_ prefix
2) similarly the enumerators should be prefixed with CPP_
3) formatting of the ChangeLog entry is incorrect.  There should be a space
after ): followed by uppercase rather than lowercase letter, descriptions
should end with . and there should be line wrapping so that it fits into 80
columns.  For a new function, one can just say New. or New function.,
doesn't need to describe what it is good for.  And the include/cpplib.h
changes don't describe what actually changed.  A new anonymous enum (why not
a named one?) was added, and check_xid_property declared.

> --- a/libcpp/include/cpplib.h
> +++ b/libcpp/include/cpplib.h
> @@ -1606,4 +1606,11 @@ bool cpp_valid_utf8_p (const char *data, size_t 
> num_bytes);
>  bool cpp_is_combining_char (cppchar_t c);
>  bool cpp_is_printable_char (cppchar_t c);
>  
> +enum {
> +   XID_START = 1,
> +   XID_CONTINUE = 2

Formatting.  There should be indentation just by 2 columns rather than 3.

Jakub



[PATCH] libcpp: add function to check XID properties

2023-09-08 Thread Arthur Cohen
From: Raiki Tamura 

libcpp/ChangeLog:

* charset.cc (check_xid_property):new function to check XID_Start and 
XID_Continue
* include/cpplib.h (check_xid_property):add enum representing XID 
properties

Signed-off-by: Raiki Tamura 
---
 libcpp/charset.cc   | 36 
 libcpp/include/cpplib.h |  7 +++
 2 files changed, 43 insertions(+)

diff --git a/libcpp/charset.cc b/libcpp/charset.cc
index 7b625c9956a..5d6d7aed325 100644
--- a/libcpp/charset.cc
+++ b/libcpp/charset.cc
@@ -1256,6 +1256,42 @@ _cpp_uname2c_uax44_lm2 (const char *name, size_t len, 
char *canon_name)
   return result;
 }
 
+/* Returns flags representing the XID properties of the given codepoint.  */
+unsigned int
+check_xid_property (cppchar_t c)
+{
+  // fast path for ASCII
+  if (c < 0x80)
+  {
+if (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'))
+  return XID_START | XID_CONTINUE;
+if (('0' <= c && c <= '9') || c == '_')
+  return XID_CONTINUE;
+  }
+
+  if (c > UCS_LIMIT)
+return 0;
+
+  int mn, mx, md;
+  mn = 0;
+  mx = ARRAY_SIZE (ucnranges) - 1;
+  while (mx != mn)
+{
+  md = (mn + mx) / 2;
+  if (c <= ucnranges[md].end)
+  mx = md;
+  else
+  mn = md + 1;
+}
+
+  unsigned short flags = ucnranges[mn].flags;
+
+  if (flags & CXX23)
+return XID_START | XID_CONTINUE;
+  if (flags & NXX23)
+return XID_CONTINUE;
+  return 0;
+}
 
 /* Returns 1 if C is valid in an identifier, 2 if C is valid except at
the start of an identifier, and 0 if C is not valid in an
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index fcdaf082b09..4ad75f877d9 100644
--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -1606,4 +1606,11 @@ bool cpp_valid_utf8_p (const char *data, size_t 
num_bytes);
 bool cpp_is_combining_char (cppchar_t c);
 bool cpp_is_printable_char (cppchar_t c);
 
+enum {
+   XID_START = 1,
+   XID_CONTINUE = 2
+};
+
+unsigned int check_xid_property (cppchar_t c);
+
 #endif /* ! LIBCPP_CPPLIB_H */
-- 
2.40.0



[PATCH] Fix PR 111331: wrong code for `a > 28 ? MIN : 29`

2023-09-08 Thread Andrew Pinski via Gcc-patches
The problem here is after r6-7425-ga9fee7cdc3c62d0e51730,
the comparison to see if the transformation could be done was using the
wrong value. Instead of see if the inner was LE (for MIN and GE for MAX)
the outer value, it was comparing the inner to the value used in the comparison
which was wrong.
The match pattern copied the same logic mistake when they were added in
r14-1411-g17cca3c43e2f49 .

OK? Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

PR tree-optimization/111331
* match.pd (`(a CMP CST1) ? max : a`):
Fix the LE/GE comparison to the correct value.
* tree-ssa-phiopt.cc (minmax_replacement):
Fix the LE/GE comparison for the
`(a CMP CST1) ? max : a` optimization.

gcc/testsuite/ChangeLog:

PR tree-optimization/111331
* gcc.c-torture/execute/pr111331-1.c: New test.
* gcc.c-torture/execute/pr111331-2.c: New test.
* gcc.c-torture/execute/pr111331-3.c: New test.
---
 gcc/match.pd  |  4 ++--
 .../gcc.c-torture/execute/pr111331-1.c| 17 +
 .../gcc.c-torture/execute/pr111331-2.c| 19 +++
 .../gcc.c-torture/execute/pr111331-3.c| 15 +++
 gcc/tree-ssa-phiopt.cc|  8 
 5 files changed, 57 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr111331-1.c
 create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr111331-2.c
 create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr111331-3.c

diff --git a/gcc/match.pd b/gcc/match.pd
index 8c24dae71cd..c7b6db4b543 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -5438,11 +5438,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 }
 (if ((cmp == LT_EXPR || cmp == LE_EXPR)
 && code == MIN_EXPR
- && integer_nonzerop (fold_build2 (LE_EXPR, boolean_type_node, @3, 
@1)))
+ && integer_nonzerop (fold_build2 (LE_EXPR, boolean_type_node, @3, 
@4)))
  (min @2 @4)
  (if ((cmp == GT_EXPR || cmp == GE_EXPR)
  && code == MAX_EXPR
-  && integer_nonzerop (fold_build2 (GE_EXPR, boolean_type_node, @3, 
@1)))
+  && integer_nonzerop (fold_build2 (GE_EXPR, boolean_type_node, @3, 
@4)))
   (max @2 @4))
 
 #if GIMPLE
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr111331-1.c 
b/gcc/testsuite/gcc.c-torture/execute/pr111331-1.c
new file mode 100644
index 000..4c7f4fdbaa9
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr111331-1.c
@@ -0,0 +1,17 @@
+int a;
+int b;
+int c(int d, int e, int f) {
+  if (d < e)
+return e;
+  if (d > f)
+return f;
+  return d;
+}
+int main() {
+  int g = -1;
+  a = c(b + 30, 29, g + 29);
+  volatile t = a;
+  if (t != 28)
+__builtin_abort();
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr111331-2.c 
b/gcc/testsuite/gcc.c-torture/execute/pr111331-2.c
new file mode 100644
index 000..5c677f2caa9
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr111331-2.c
@@ -0,0 +1,19 @@
+
+int a;
+int b;
+
+int main() {
+  int d = b+30;
+  {
+int t;
+if (d < 29)
+  t =  29;
+else
+  t = (d > 28) ? 28 : d;
+a = t;
+  }
+  volatile int t = a;
+  if (a != 28)
+__builtin_abort();
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr111331-3.c 
b/gcc/testsuite/gcc.c-torture/execute/pr111331-3.c
new file mode 100644
index 000..213d9bdd539
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr111331-3.c
@@ -0,0 +1,15 @@
+int a;
+int b;
+
+int main() {
+  int d = b+30;
+  {
+int t;
+t = d < 29 ? 29 : ((d > 28) ? 28 : d);
+a = t;
+  }
+  volatile int t = a;
+  if (a != 28)
+__builtin_abort();
+  return 0;
+}
diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index 9993bbe5b76..9b44ca9758a 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -2073,7 +2073,7 @@ minmax_replacement (basic_block cond_bb, basic_block 
middle_bb, basic_block alt_
 
  /* We need BOUND <= LARGER.  */
  if (!integer_nonzerop (fold_build2 (LE_EXPR, boolean_type_node,
- bound, larger)))
+ bound, arg_false)))
return false;
}
  else if (operand_equal_for_phi_arg_p (arg_false, smaller)
@@ -2104,7 +2104,7 @@ minmax_replacement (basic_block cond_bb, basic_block 
middle_bb, basic_block alt_
 
  /* We need BOUND >= SMALLER.  */
  if (!integer_nonzerop (fold_build2 (GE_EXPR, boolean_type_node,
- bound, smaller)))
+ bound, arg_false)))
return false;
}
  else
@@ -2144,7 +2144,7 @@ minmax_replacement (basic_block cond_bb, basic_block 
middle_bb, basic_block alt_
 
  /* We need BOUND >= LARGER.  */
  if 

Re: [PATCH] riscv: xtheadbb: Fix extendqi insn

2023-09-08 Thread Philipp Tomsich
Applied to master. Thanks!
Philipp.

On Fri, 8 Sept 2023 at 14:17, Kito Cheng  wrote:

> LGTM
>
> Christoph Muellner 於 2023年9月8日 週五,14:00寫道:
>
>> From: Christoph Müllner 
>>
>> Recently three SPEC CPU 2017 benchmarks broke when using xtheadbb:
>> * 500.perlbench_r
>> * 525.x264_r
>> * 557.xz_r
>>
>> Tracing the issue down revealed, that we emit a 'th.ext xN,xN,15,0'
>> for a extendqi insn, which is obviously wrong.
>> This patch splits the common 'extend2_th_ext'
>> insn into two 'extendqi' and 'extendhi' insns,
>> which emit the right extension instruction.
>> Additionally, this patch adds test cases for these insns.
>>
>> Signed-off-by: Christoph Müllner 
>>
>> gcc/ChangeLog:
>>
>> * config/riscv/thead.md
>> (*extend2_th_ext):
>> Remove broken INSN.
>> (*extendhi2_th_ext): New INSN.
>> (*extendqi2_th_ext): New INSN.
>>
>> gcc/testsuite/ChangeLog:
>>
>> * gcc.target/riscv/xtheadbb-ext-2.c: New test.
>> * gcc.target/riscv/xtheadbb-ext-3.c: New test.
>> ---
>>  gcc/config/riscv/thead.md   | 17 ++---
>>  gcc/testsuite/gcc.target/riscv/xtheadbb-ext-2.c | 12 
>>  gcc/testsuite/gcc.target/riscv/xtheadbb-ext-3.c | 12 
>>  3 files changed, 38 insertions(+), 3 deletions(-)
>>  create mode 100644 gcc/testsuite/gcc.target/riscv/xtheadbb-ext-2.c
>>  create mode 100644 gcc/testsuite/gcc.target/riscv/xtheadbb-ext-3.c
>>
>> diff --git a/gcc/config/riscv/thead.md b/gcc/config/riscv/thead.md
>> index 29f98dec3a8..05d1b32bd94 100644
>> --- a/gcc/config/riscv/thead.md
>> +++ b/gcc/config/riscv/thead.md
>> @@ -58,14 +58,25 @@ (define_insn "*th_ext4"
>>[(set_attr "type" "bitmanip")
>> (set_attr "mode" "")])
>>
>> -(define_insn "*extend2_th_ext"
>> +(define_insn "*extendhi2_th_ext"
>>[(set (match_operand:SUPERQI 0 "register_operand" "=r,r")
>> (sign_extend:SUPERQI
>> -   (match_operand:SHORT 1 "nonimmediate_operand" "r,m")))]
>> +   (match_operand:HI 1 "nonimmediate_operand" "r,m")))]
>>"TARGET_XTHEADBB"
>>"@
>> th.ext\t%0,%1,15,0
>> -   l\t%0,%1"
>> +   lh\t%0,%1"
>> +  [(set_attr "type" "bitmanip,load")
>> +   (set_attr "mode" "")])
>> +
>> +(define_insn "*extendqi2_th_ext"
>> +  [(set (match_operand:SUPERQI 0 "register_operand" "=r,r")
>> +   (sign_extend:SUPERQI
>> +   (match_operand:QI 1 "nonimmediate_operand" "r,m")))]
>> +  "TARGET_XTHEADBB"
>> +  "@
>> +   th.ext\t%0,%1,7,0
>> +   lb\t%0,%1"
>>[(set_attr "type" "bitmanip,load")
>> (set_attr "mode" "")])
>>
>> diff --git a/gcc/testsuite/gcc.target/riscv/xtheadbb-ext-2.c
>> b/gcc/testsuite/gcc.target/riscv/xtheadbb-ext-2.c
>> new file mode 100644
>> index 000..4645b9c56df
>> --- /dev/null
>> +++ b/gcc/testsuite/gcc.target/riscv/xtheadbb-ext-2.c
>> @@ -0,0 +1,12 @@
>> +/* { dg-do compile } */
>> +/* { dg-options "-march=rv64gc_xtheadbb" { target { rv64 } } } */
>> +/* { dg-options "-march=rv32gc_xtheadbb" { target { rv32 } } } */
>> +/* { dg-skip-if "" { *-*-* } { "-O0" "-Os" "-Og" "-Oz" } } */
>> +
>> +signed long extqi(signed char i)
>> +{
>> +return --i;
>> +}
>> +
>> +/* { dg-final { scan-assembler "th.ext\ta\[0-9\]+,a\[0-9\]+,7,0" } } */
>> +/* { dg-final { scan-assembler-not "th.ext\ta\[0-9\]+,a\[0-9\]+,15,0" }
>> } */
>> diff --git a/gcc/testsuite/gcc.target/riscv/xtheadbb-ext-3.c
>> b/gcc/testsuite/gcc.target/riscv/xtheadbb-ext-3.c
>> new file mode 100644
>> index 000..2c9ebbc563a
>> --- /dev/null
>> +++ b/gcc/testsuite/gcc.target/riscv/xtheadbb-ext-3.c
>> @@ -0,0 +1,12 @@
>> +/* { dg-do compile } */
>> +/* { dg-options "-march=rv64gc_xtheadbb" { target { rv64 } } } */
>> +/* { dg-options "-march=rv32gc_xtheadbb" { target { rv32 } } } */
>> +/* { dg-skip-if "" { *-*-* } { "-O0" "-Os" "-Og" "-Oz" } } */
>> +
>> +signed long exthi(signed short i)
>> +{
>> +return --i;
>> +}
>> +
>> +/* { dg-final { scan-assembler "th.ext\ta\[0-9\]+,a\[0-9\]+,15,0" } } */
>> +/* { dg-final { scan-assembler-not "th.ext\ta\[0-9\]+,a\[0-9\]+,7,0" } }
>> */
>> --
>> 2.41.0
>>
>>


Re: [PATCH] libstdc++: Reduce output of 'make check'

2023-09-08 Thread Jonathan Wakely via Gcc-patches
On Fri, 8 Sept 2023 at 13:15, Eric Gallager  wrote:
>
> On Fri, Sep 8, 2023 at 6:32 AM Jonathan Wakely  wrote:
> >
> > On Fri, 8 Sept 2023 at 03:16, Eric Gallager  wrote:
> > >
> > > Maybe use $(AM_V_at) instead? That would allow it to be controlled by
> > > the --enable-silent-rules flag to configure, as well as make V=1 vs.
> > > make V=0 too.
> >
> > I see two problems with that. Firstly, nobody uses that configure
> > option, so the net result would be that these 39 lines are still
> > printed for everybody.
> >
> > Secondly, why would anybody ever want this output? Having it
> > configurable (and default to noisy) just doesn't seem helpful.
> >
> > This is the output I'm talking about:
> >
> > make: Entering directory
> > '/home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/testsuite'
> > make  check-DEJAGNU
> > make[1]: Entering directory
> > '/home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/testsuite'
> > Making a new site.exp file...
> > AR="ar --plugin /home/jwakely/src/gcc/build/./gcc/liblto_plugin.so";
> > export AR; \
> > RANLIB="ranlib --plugin
> > /home/jwakely/src/gcc/build/./gcc/liblto_plugin.so"; export RANLIB; \
> > if [ -z "" ] && [ -n "" ]; then \
> >  rm -rf normal-parallel || true; \
> >  mkdir normal-parallel; \
> >  make  check-DEJAGNUnormal1 check-DEJAGNUnormal2 check-DEJAGNUnormal3
> > check-DEJAGNUnormal4 check-DEJAGNUnormal5 check-DEJAGNUnormal6
> > check-DEJAGNUnormal7 c
> > heck-DEJAGNUnormal8 check-DEJAGNUnormal9 check-DEJAGNUnormal10
> > check-DEJAGNUnormal11 check-DEJAGNUnormal12 check-DEJAGNUnormal13
> > check-DEJAGNUnormal14 check
> > -DEJAGNUnormal15 check-DEJAGNUnormal16 check-DEJAGNUnormal17
> > check-DEJAGNUnormal18 check-DEJAGNUnormal19 check-DEJAGNUnormal20
> > check-DEJAGNUnormal21 check-D
> > EJAGNUnormal22 check-DEJAGNUnormal23 check-DEJAGNUnormal24
> > check-DEJAGNUnormal25 check-DEJAGNUnormal26 check-DEJAGNUnormal27
> > check-DEJAGNUnormal28 check-DEJ
> > AGNUnormal29 check-DEJAGNUnormal30 check-DEJAGNUnormal31
> > check-DEJAGNUnormal32 check-DEJAGNUnormal33 check-DEJAGNUnormal34
> > check-DEJAGNUnormal35 check-DEJAG
> > NUnormal36 check-DEJAGNUnormal37 check-DEJAGNUnormal38
> > check-DEJAGNUnormal39 check-DEJAGNUnormal40 check-DEJAGNUnormal41
> > check-DEJAGNUnormal42 check-DEJAGNU
> > normal43 check-DEJAGNUnormal44 check-DEJAGNUnormal45
> > check-DEJAGNUnormal46 check-DEJAGNUnormal47 check-DEJAGNUnormal48
> > check-DEJAGNUnormal49 check-DEJAGNUno
> > rmal50 check-DEJAGNUnormal51 check-DEJAGNUnormal52
> > check-DEJAGNUnormal53 check-DEJAGNUnormal54 check-DEJAGNUnormal55
> > check-DEJAGNUnormal56 check-DEJAGNUnorm
> > al57 check-DEJAGNUnormal58 check-DEJAGNUnormal59 check-DEJAGNUnormal60
> > check-DEJAGNUnormal61 check-DEJAGNUnormal62 check-DEJAGNUnormal63
> > check-DEJAGNUnormal
> > 64 check-DEJAGNUnormal65 check-DEJAGNUnormal66 check-DEJAGNUnormal67
> > check-DEJAGNUnormal68 check-DEJAGNUnormal69 check-DEJAGNUnormal70
> > check-DEJAGNUnormal71
> > check-DEJAGNUnormal72 check-DEJAGNUnormal73 check-DEJAGNUnormal74
> > check-DEJAGNUnormal75 check-DEJAGNUnormal76 check-DEJAGNUnormal77
> > check-DEJAGNUnormal78 c
> > heck-DEJAGNUnormal79 check-DEJAGNUnormal80 check-DEJAGNUnormal81
> > check-DEJAGNUnormal82 check-DEJAGNUnormal83 check-DEJAGNUnormal84
> > check-DEJAGNUnormal85 che
> > ck-DEJAGNUnormal86 check-DEJAGNUnormal87 check-DEJAGNUnormal88
> > check-DEJAGNUnormal89 check-DEJAGNUnormal90 check-DEJAGNUnormal91
> > check-DEJAGNUnormal92 check
> > -DEJAGNUnormal93 check-DEJAGNUnormal94 check-DEJAGNUnormal95
> > check-DEJAGNUnormal96 check-DEJAGNUnormal97 check-DEJAGNUnormal98
> > check-DEJAGNUnormal99 check-D
> > EJAGNUnormal100 check-DEJAGNUnormal101 check-DEJAGNUnormal102
> > check-DEJAGNUnormal103 check-DEJAGNUnormal104 check-DEJAGNUnormal105
> > check-DEJAGNUnormal106 ch
> > eck-DEJAGNUnormal107 check-DEJAGNUnormal108 check-DEJAGNUnormal109
> > check-DEJAGNUnormal110 check-DEJAGNUnormal111 check-DEJAGNUnormal112
> > check-DEJAGNUnormal1
> > 13 check-DEJAGNUnormal114 check-DEJAGNUnormal115
> > check-DEJAGNUnormal116 check-DEJAGNUnormal117 check-DEJAGNUnormal118
> > check-DEJAGNUnormal119 check-DEJAGNUno
> > rmal120 check-DEJAGNUnormal121 check-DEJAGNUnormal122
> > check-DEJAGNUnormal123 check-DEJAGNUnormal124 check-DEJAGNUnormal125
> > check-DEJAGNUnormal126 check-DEJA
> > GNUnormal127 check-DEJAGNUnormal128; \
> >  rm -rf normal-parallel || true; \
> >  for idx in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
> > 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
> > 46 47 48 49 50 51
> > 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
> > 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
> > 98 99 100 101 102
> > 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
> > 120 121 122 123 124 125 126 127 128; do \
> >if [ -d normal$idx ]; then \
> >  mv -f normal$idx/libstdc++.sum normal$idx/libstdc++.sum.sep; \
> >  mv -f 

Re: [PATCH] riscv: xtheadbb: Fix extendqi insn

2023-09-08 Thread Kito Cheng via Gcc-patches
LGTM

Christoph Muellner 於 2023年9月8日 週五,14:00寫道:

> From: Christoph Müllner 
>
> Recently three SPEC CPU 2017 benchmarks broke when using xtheadbb:
> * 500.perlbench_r
> * 525.x264_r
> * 557.xz_r
>
> Tracing the issue down revealed, that we emit a 'th.ext xN,xN,15,0'
> for a extendqi insn, which is obviously wrong.
> This patch splits the common 'extend2_th_ext'
> insn into two 'extendqi' and 'extendhi' insns,
> which emit the right extension instruction.
> Additionally, this patch adds test cases for these insns.
>
> Signed-off-by: Christoph Müllner 
>
> gcc/ChangeLog:
>
> * config/riscv/thead.md
> (*extend2_th_ext):
> Remove broken INSN.
> (*extendhi2_th_ext): New INSN.
> (*extendqi2_th_ext): New INSN.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/riscv/xtheadbb-ext-2.c: New test.
> * gcc.target/riscv/xtheadbb-ext-3.c: New test.
> ---
>  gcc/config/riscv/thead.md   | 17 ++---
>  gcc/testsuite/gcc.target/riscv/xtheadbb-ext-2.c | 12 
>  gcc/testsuite/gcc.target/riscv/xtheadbb-ext-3.c | 12 
>  3 files changed, 38 insertions(+), 3 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/riscv/xtheadbb-ext-2.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/xtheadbb-ext-3.c
>
> diff --git a/gcc/config/riscv/thead.md b/gcc/config/riscv/thead.md
> index 29f98dec3a8..05d1b32bd94 100644
> --- a/gcc/config/riscv/thead.md
> +++ b/gcc/config/riscv/thead.md
> @@ -58,14 +58,25 @@ (define_insn "*th_ext4"
>[(set_attr "type" "bitmanip")
> (set_attr "mode" "")])
>
> -(define_insn "*extend2_th_ext"
> +(define_insn "*extendhi2_th_ext"
>[(set (match_operand:SUPERQI 0 "register_operand" "=r,r")
> (sign_extend:SUPERQI
> -   (match_operand:SHORT 1 "nonimmediate_operand" "r,m")))]
> +   (match_operand:HI 1 "nonimmediate_operand" "r,m")))]
>"TARGET_XTHEADBB"
>"@
> th.ext\t%0,%1,15,0
> -   l\t%0,%1"
> +   lh\t%0,%1"
> +  [(set_attr "type" "bitmanip,load")
> +   (set_attr "mode" "")])
> +
> +(define_insn "*extendqi2_th_ext"
> +  [(set (match_operand:SUPERQI 0 "register_operand" "=r,r")
> +   (sign_extend:SUPERQI
> +   (match_operand:QI 1 "nonimmediate_operand" "r,m")))]
> +  "TARGET_XTHEADBB"
> +  "@
> +   th.ext\t%0,%1,7,0
> +   lb\t%0,%1"
>[(set_attr "type" "bitmanip,load")
> (set_attr "mode" "")])
>
> diff --git a/gcc/testsuite/gcc.target/riscv/xtheadbb-ext-2.c
> b/gcc/testsuite/gcc.target/riscv/xtheadbb-ext-2.c
> new file mode 100644
> index 000..4645b9c56df
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/xtheadbb-ext-2.c
> @@ -0,0 +1,12 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv64gc_xtheadbb" { target { rv64 } } } */
> +/* { dg-options "-march=rv32gc_xtheadbb" { target { rv32 } } } */
> +/* { dg-skip-if "" { *-*-* } { "-O0" "-Os" "-Og" "-Oz" } } */
> +
> +signed long extqi(signed char i)
> +{
> +return --i;
> +}
> +
> +/* { dg-final { scan-assembler "th.ext\ta\[0-9\]+,a\[0-9\]+,7,0" } } */
> +/* { dg-final { scan-assembler-not "th.ext\ta\[0-9\]+,a\[0-9\]+,15,0" } }
> */
> diff --git a/gcc/testsuite/gcc.target/riscv/xtheadbb-ext-3.c
> b/gcc/testsuite/gcc.target/riscv/xtheadbb-ext-3.c
> new file mode 100644
> index 000..2c9ebbc563a
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/xtheadbb-ext-3.c
> @@ -0,0 +1,12 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv64gc_xtheadbb" { target { rv64 } } } */
> +/* { dg-options "-march=rv32gc_xtheadbb" { target { rv32 } } } */
> +/* { dg-skip-if "" { *-*-* } { "-O0" "-Os" "-Og" "-Oz" } } */
> +
> +signed long exthi(signed short i)
> +{
> +return --i;
> +}
> +
> +/* { dg-final { scan-assembler "th.ext\ta\[0-9\]+,a\[0-9\]+,15,0" } } */
> +/* { dg-final { scan-assembler-not "th.ext\ta\[0-9\]+,a\[0-9\]+,7,0" } }
> */
> --
> 2.41.0
>
>


[PATCH] pretty-print: Fix up pp_wide_int [PR111329]

2023-09-08 Thread Jakub Jelinek via Gcc-patches
Hi!

The recent pp_wide_int changes for _BitInt support (because not all
wide_ints fit into the small fixed size digit_buffer anymore) apparently
broke
+FAIL: gcc.dg/analyzer/out-of-bounds-diagram-1-debug.c (test for excess errors)
+FAIL: gcc.dg/analyzer/out-of-bounds-diagram-1-debug.c 2 blank line(s) in output
+FAIL: gcc.dg/analyzer/out-of-bounds-diagram-1-debug.c expected multiline 
pattern lines 17-39
(and I couldn't reproduce that in bisect seed (which is -O0 compiled) and
thought it would be some analyzer diagnostic bug).

The problem is that analyzer uses pp_wide_int with a function call in the
second argument.  Previously, when pp_wide_int macro just did
  print_dec (W, pp_buffer (PP)->digit_buffer, SGN);
  pp_string (PP, pp_buffer (PP)->digit_buffer);
it worked, because the const wide_int_ref & first argument to print_dec
bound to a temporary, which was only destructed at the end of the full
statement after print_dec was called.
But with my changes where I need to first compare the precision of the
const wide_int_ref & to decide whether to use digit_buffer or XALLOCAVEC
something larger, this means that pp_wide_int_ref binds to a temporary
which is destroyed at the end of full statement which is the
  const wide_int_ref _wide_int_ref = (W);
declaration, so then invokes UB accessing a destructed temporary.

The following patch fixes it by rewriting pp_wide_int into an inline
function, so that the end of the full statement is the end of the inline
function call.  As functions using alloca aren't normally inlined, I've
also split that part into a separate out of line function.  Putting that
into pretty-print.cc didn't work, e.g. the gm2 binary doesn't link,
because pretty-print.o is in libcommon.a, but wide-print-print.o which
defines print_dec is not.  So I've put that out of line function into
wide-int-print.cc instead.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2023-09-08  Jakub Jelinek  

PR middle-end/111329
* pretty-print.h (pp_wide_int): Rewrite from macro into inline
function.  For printing values which don't fit into digit_buffer
use out-of-line function.
* wide-int-print.h (pp_wide_int_large): Declare.
* wide-int-print.cc: Include pretty-print.h.
(pp_wide_int_large): Define.

--- gcc/pretty-print.h.jj   2023-09-06 14:36:53.485246347 +0200
+++ gcc/pretty-print.h  2023-09-08 11:11:21.173649942 +0200
@@ -333,28 +333,6 @@ pp_get_prefix (const pretty_printer *pp)
 #define pp_decimal_int(PP, I)  pp_scalar (PP, "%d", I)
 #define pp_unsigned_wide_integer(PP, I) \
pp_scalar (PP, HOST_WIDE_INT_PRINT_UNSIGNED, (unsigned HOST_WIDE_INT) I)
-#define pp_wide_int(PP, W, SGN)\
-  do   \
-{  \
-  const wide_int_ref _wide_int_ref = (W);   \
-  unsigned int pp_wide_int_prec\
-   = pp_wide_int_ref.get_precision (); \
-  if ((pp_wide_int_prec + 3) / 4   \
- > sizeof (pp_buffer (PP)->digit_buffer) - 3)  \
-   {   \
- char *pp_wide_int_buf \
-   = XALLOCAVEC (char, (pp_wide_int_prec + 3) / 4 + 3);\
- print_dec (pp_wide_int_ref, pp_wide_int_buf, SGN);\
- pp_string (PP, pp_wide_int_buf);  \
-   }   \
-  else \
-   {   \
- print_dec (pp_wide_int_ref,   \
-pp_buffer (PP)->digit_buffer, SGN);\
- pp_string (PP, pp_buffer (PP)->digit_buffer); \
-   }   \
-}  \
-  while (0)
 #define pp_vrange(PP, R)   \
   do   \
 {  \
@@ -453,6 +431,19 @@ pp_wide_integer (pretty_printer *pp, HOS
   pp_scalar (pp, HOST_WIDE_INT_PRINT_DEC, i);
 }
 
+inline void
+pp_wide_int (pretty_printer *pp, const wide_int_ref , signop sgn)
+{
+  unsigned int prec = w.get_precision ();
+  if (UNLIKELY ((prec + 3) / 4 > sizeof (pp_buffer (pp)->digit_buffer) - 3))
+pp_wide_int_large (pp, w, sgn);
+  else
+{
+  print_dec (w, pp_buffer (pp)->digit_buffer, sgn);
+  pp_string (pp, pp_buffer (pp)->digit_buffer);
+}
+}
+
 template
 void pp_wide_integer (pretty_printer *pp, const poly_int_pod &);
 
--- gcc/wide-int-print.h.jj 2023-09-08 11:03:48.320944156 +0200
+++ gcc/wide-int-print.h2023-09-08 11:11:46.982292282 +0200
@@ -34,5 

Re: [PATCH] libstdc++: Reduce output of 'make check'

2023-09-08 Thread Eric Gallager via Gcc-patches
On Fri, Sep 8, 2023 at 6:32 AM Jonathan Wakely  wrote:
>
> On Fri, 8 Sept 2023 at 03:16, Eric Gallager  wrote:
> >
> > Maybe use $(AM_V_at) instead? That would allow it to be controlled by
> > the --enable-silent-rules flag to configure, as well as make V=1 vs.
> > make V=0 too.
>
> I see two problems with that. Firstly, nobody uses that configure
> option, so the net result would be that these 39 lines are still
> printed for everybody.
>
> Secondly, why would anybody ever want this output? Having it
> configurable (and default to noisy) just doesn't seem helpful.
>
> This is the output I'm talking about:
>
> make: Entering directory
> '/home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/testsuite'
> make  check-DEJAGNU
> make[1]: Entering directory
> '/home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/testsuite'
> Making a new site.exp file...
> AR="ar --plugin /home/jwakely/src/gcc/build/./gcc/liblto_plugin.so";
> export AR; \
> RANLIB="ranlib --plugin
> /home/jwakely/src/gcc/build/./gcc/liblto_plugin.so"; export RANLIB; \
> if [ -z "" ] && [ -n "" ]; then \
>  rm -rf normal-parallel || true; \
>  mkdir normal-parallel; \
>  make  check-DEJAGNUnormal1 check-DEJAGNUnormal2 check-DEJAGNUnormal3
> check-DEJAGNUnormal4 check-DEJAGNUnormal5 check-DEJAGNUnormal6
> check-DEJAGNUnormal7 c
> heck-DEJAGNUnormal8 check-DEJAGNUnormal9 check-DEJAGNUnormal10
> check-DEJAGNUnormal11 check-DEJAGNUnormal12 check-DEJAGNUnormal13
> check-DEJAGNUnormal14 check
> -DEJAGNUnormal15 check-DEJAGNUnormal16 check-DEJAGNUnormal17
> check-DEJAGNUnormal18 check-DEJAGNUnormal19 check-DEJAGNUnormal20
> check-DEJAGNUnormal21 check-D
> EJAGNUnormal22 check-DEJAGNUnormal23 check-DEJAGNUnormal24
> check-DEJAGNUnormal25 check-DEJAGNUnormal26 check-DEJAGNUnormal27
> check-DEJAGNUnormal28 check-DEJ
> AGNUnormal29 check-DEJAGNUnormal30 check-DEJAGNUnormal31
> check-DEJAGNUnormal32 check-DEJAGNUnormal33 check-DEJAGNUnormal34
> check-DEJAGNUnormal35 check-DEJAG
> NUnormal36 check-DEJAGNUnormal37 check-DEJAGNUnormal38
> check-DEJAGNUnormal39 check-DEJAGNUnormal40 check-DEJAGNUnormal41
> check-DEJAGNUnormal42 check-DEJAGNU
> normal43 check-DEJAGNUnormal44 check-DEJAGNUnormal45
> check-DEJAGNUnormal46 check-DEJAGNUnormal47 check-DEJAGNUnormal48
> check-DEJAGNUnormal49 check-DEJAGNUno
> rmal50 check-DEJAGNUnormal51 check-DEJAGNUnormal52
> check-DEJAGNUnormal53 check-DEJAGNUnormal54 check-DEJAGNUnormal55
> check-DEJAGNUnormal56 check-DEJAGNUnorm
> al57 check-DEJAGNUnormal58 check-DEJAGNUnormal59 check-DEJAGNUnormal60
> check-DEJAGNUnormal61 check-DEJAGNUnormal62 check-DEJAGNUnormal63
> check-DEJAGNUnormal
> 64 check-DEJAGNUnormal65 check-DEJAGNUnormal66 check-DEJAGNUnormal67
> check-DEJAGNUnormal68 check-DEJAGNUnormal69 check-DEJAGNUnormal70
> check-DEJAGNUnormal71
> check-DEJAGNUnormal72 check-DEJAGNUnormal73 check-DEJAGNUnormal74
> check-DEJAGNUnormal75 check-DEJAGNUnormal76 check-DEJAGNUnormal77
> check-DEJAGNUnormal78 c
> heck-DEJAGNUnormal79 check-DEJAGNUnormal80 check-DEJAGNUnormal81
> check-DEJAGNUnormal82 check-DEJAGNUnormal83 check-DEJAGNUnormal84
> check-DEJAGNUnormal85 che
> ck-DEJAGNUnormal86 check-DEJAGNUnormal87 check-DEJAGNUnormal88
> check-DEJAGNUnormal89 check-DEJAGNUnormal90 check-DEJAGNUnormal91
> check-DEJAGNUnormal92 check
> -DEJAGNUnormal93 check-DEJAGNUnormal94 check-DEJAGNUnormal95
> check-DEJAGNUnormal96 check-DEJAGNUnormal97 check-DEJAGNUnormal98
> check-DEJAGNUnormal99 check-D
> EJAGNUnormal100 check-DEJAGNUnormal101 check-DEJAGNUnormal102
> check-DEJAGNUnormal103 check-DEJAGNUnormal104 check-DEJAGNUnormal105
> check-DEJAGNUnormal106 ch
> eck-DEJAGNUnormal107 check-DEJAGNUnormal108 check-DEJAGNUnormal109
> check-DEJAGNUnormal110 check-DEJAGNUnormal111 check-DEJAGNUnormal112
> check-DEJAGNUnormal1
> 13 check-DEJAGNUnormal114 check-DEJAGNUnormal115
> check-DEJAGNUnormal116 check-DEJAGNUnormal117 check-DEJAGNUnormal118
> check-DEJAGNUnormal119 check-DEJAGNUno
> rmal120 check-DEJAGNUnormal121 check-DEJAGNUnormal122
> check-DEJAGNUnormal123 check-DEJAGNUnormal124 check-DEJAGNUnormal125
> check-DEJAGNUnormal126 check-DEJA
> GNUnormal127 check-DEJAGNUnormal128; \
>  rm -rf normal-parallel || true; \
>  for idx in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
> 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
> 46 47 48 49 50 51
> 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
> 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
> 98 99 100 101 102
> 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
> 120 121 122 123 124 125 126 127 128; do \
>if [ -d normal$idx ]; then \
>  mv -f normal$idx/libstdc++.sum normal$idx/libstdc++.sum.sep; \
>  mv -f normal$idx/libstdc++.log normal$idx/libstdc++.log.sep; \
>fi; \
>  done; \
>  /bin/sh 
> /home/jwakely/src/gcc/gcc/libstdc++-v3/testsuite/../../contrib/dg-extract-results.sh
> \
>normal[0-9]*/libstdc++.sum.sep > libstdc++.sum; \
>  /bin/sh 
> 

More '#ifdef ASM_OUTPUT_DEF' -> 'if (TARGET_SUPPORTS_ALIASES)' etc. (was: [PATCH][v2] Introduce TARGET_SUPPORTS_ALIASES)

2023-09-08 Thread Thomas Schwinge
Hi!

On 2017-08-10T15:42:13+0200, Jan Hubicka  wrote:
>> On 07/31/2017 11:57 AM, Yuri Gribov wrote:
>> > On Mon, Jul 31, 2017 at 9:04 AM, Martin Liška  wrote:
>> >> Doing the transformation suggested by Honza.

... which was:

| On 2017-07-24T16:06:22+0200, Jan Hubicka  wrote:
| > we probably should turn ASM_OUTPUT_DEF ifdefs into a conditional compilation
| > incrementally.

>> >From 78ee08b25d22125cb1fa248bac98ef1e84504761 Mon Sep 17 00:00:00 2001
>> From: marxin 
>> Date: Tue, 25 Jul 2017 13:11:28 +0200
>> Subject: [PATCH] Introduce TARGET_SUPPORTS_ALIASES

..., and got pushed as commit a8b522b483ebb8c972ecfde8779a7a6ec16aecd6
(Subversion r251048) "Introduce TARGET_SUPPORTS_ALIASES".

I don't know if that was actually intentional here, or just an
"accident", but such changes actually allow that a back end may or may
not provide symbol aliasing support ('TARGET_SUPPORTS_ALIASES')
independent of '#ifdef ASM_OUTPUT_DEF', and in particular, depending not
just on static but instead on dynamic (run-time) configuration.  This is
relevant for the nvptx back end's '-malias' flag.

There did remain a few instances where we currently still assume that
from '#ifdef ASM_OUTPUT_DEF' follows 'TARGET_SUPPORTS_ALIASES', which I'm
adjusting in the attached (with '--ignore-space-change', for easy review)
"More '#ifdef ASM_OUTPUT_DEF' -> 'if (TARGET_SUPPORTS_ALIASES)' etc.".
OK to push?

These changes are necessary to cure nvptx regressions raised in

"[nvptx] Use .alias directive for mptx >= 6.3", addressing the comment:
"[...] remains to be analyzed".


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
>From 4c725226c3657adb775af274876de5077b8fbf45 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Thu, 7 Sep 2023 22:15:08 +0200
Subject: [PATCH] More '#ifdef ASM_OUTPUT_DEF' -> 'if
 (TARGET_SUPPORTS_ALIASES)' etc.

Per commit a8b522b483ebb8c972ecfde8779a7a6ec16aecd6 (Subversion r251048)
"Introduce TARGET_SUPPORTS_ALIASES", there is the idea that a back end may or
may not provide symbol aliasing support ('TARGET_SUPPORTS_ALIASES') independent
of '#ifdef ASM_OUTPUT_DEF', and in particular, depending not just on static but
instead on dynamic (run-time) configuration.  There did remain a few instances
where we currently still assume that from '#ifdef ASM_OUTPUT_DEF' follows
'TARGET_SUPPORTS_ALIASES'.  Change these to 'if (TARGET_SUPPORTS_ALIASES)',
similarly, or 'gcc_checking_assert (TARGET_SUPPORTS_ALIASES);'.

	gcc/
	* ipa-icf.cc (sem_item::target_supports_symbol_aliases_p):
	'gcc_checking_assert (TARGET_SUPPORTS_ALIASES);' before
	'return true;'.
	* ipa-visibility.cc (function_and_variable_visibility): Change
	'#ifdef ASM_OUTPUT_DEF' to 'if (TARGET_SUPPORTS_ALIASES)'.
	* varasm.cc (output_constant_pool_contents)
	[#ifdef ASM_OUTPUT_DEF]:
	'gcc_checking_assert (TARGET_SUPPORTS_ALIASES);'.
	(do_assemble_alias) [#ifdef ASM_OUTPUT_DEF]:
	'if (!TARGET_SUPPORTS_ALIASES)',
	'gcc_checking_assert (seen_error ());'.
	(assemble_alias): Change '#if !defined (ASM_OUTPUT_DEF)' to
	'if (!TARGET_SUPPORTS_ALIASES)'.
	(default_asm_output_anchor):
	'gcc_checking_assert (TARGET_SUPPORTS_ALIASES);'.
---
 gcc/ipa-icf.cc|  1 +
 gcc/ipa-visibility.cc |  8 +---
 gcc/varasm.cc | 13 ++---
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/gcc/ipa-icf.cc b/gcc/ipa-icf.cc
index 836d0914ded..bbdfd445397 100644
--- a/gcc/ipa-icf.cc
+++ b/gcc/ipa-icf.cc
@@ -218,6 +218,7 @@ sem_item::target_supports_symbol_aliases_p (void)
 #if !defined (ASM_OUTPUT_DEF) || (!defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL))
   return false;
 #else
+  gcc_checking_assert (TARGET_SUPPORTS_ALIASES);
   return true;
 #endif
 }
diff --git a/gcc/ipa-visibility.cc b/gcc/ipa-visibility.cc
index 8ec82bb333e..8ce56114ee3 100644
--- a/gcc/ipa-visibility.cc
+++ b/gcc/ipa-visibility.cc
@@ -622,7 +622,8 @@ function_and_variable_visibility (bool whole_program)
   /* All aliases should be processed at this point.  */
   gcc_checking_assert (!alias_pairs || !alias_pairs->length ());
 
-#ifdef ASM_OUTPUT_DEF
+  if (TARGET_SUPPORTS_ALIASES)
+{
   FOR_EACH_DEFINED_FUNCTION (node)
 	{
 	  if (node->get_availability () != AVAIL_INTERPOSABLE
@@ -643,7 +644,8 @@ function_and_variable_visibility (bool whole_program)
 
 	  if (!alias)
 		{
-	  alias = dyn_cast (node->noninterposable_alias ());
+		  alias
+		= dyn_cast (node->noninterposable_alias ());
 		  gcc_assert (alias && alias != node);
 		}
 
@@ -656,7 +658,7 @@ function_and_variable_visibility (bool whole_program)
 		}
 	}
 	}
-#endif
+}
 
   FOR_EACH_FUNCTION (node)
 {
diff --git a/gcc/varasm.cc b/gcc/varasm.cc
index 53f0cc61922..40d6081a3fa 100644
--- 

Re: [PATCH] riscv: thead: Fix mode attribute for extension patterns

2023-09-08 Thread Philipp Tomsich
Applied to master. Thanks!
Philipp.

On Fri, 8 Sept 2023 at 10:13, Kito Cheng  wrote:

> LGTM
>
> Christoph Muellner  於 2023年9月8日 週五 14:16 寫道:
>
>> From: Christoph Müllner 
>>
>> The mode attribute of an extension pattern is usually set to the target
>> type.
>> Let's follow this convention consistently for xtheadbb.
>>
>> Signed-off-by: Christoph Müllner 
>>
>> gcc/ChangeLog:
>>
>> * config/riscv/thead.md: Use more appropriate mode attributes
>> for extensions.
>> ---
>>  gcc/config/riscv/thead.md | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/gcc/config/riscv/thead.md b/gcc/config/riscv/thead.md
>> index 05d1b32bd94..2287b752ea1 100644
>> --- a/gcc/config/riscv/thead.md
>> +++ b/gcc/config/riscv/thead.md
>> @@ -101,7 +101,7 @@ (define_insn "*zero_extendsidi2_th_extu"
>> th.extu\t%0,%1,31,0
>> lwu\t%0,%1"
>>[(set_attr "type" "bitmanip,load")
>> -   (set_attr "mode" "SI")])
>> +   (set_attr "mode" "DI")])
>>
>>  (define_insn "*zero_extendhi2_th_extu"
>>[(set (match_operand:GPR 0 "register_operand" "=r,r")
>> @@ -111,7 +111,7 @@ (define_insn "*zero_extendhi2_th_extu"
>> th.extu\t%0,%1,15,0
>> lhu\t%0,%1"
>>[(set_attr "type" "bitmanip,load")
>> -   (set_attr "mode" "HI")])
>> +   (set_attr "mode" "")])
>>
>>  (define_insn "*th_clz2"
>>[(set (match_operand:X 0 "register_operand" "=r")
>> --
>> 2.41.0
>>
>>


[committed] Update contrib + libgomp ChangeLogs for failed reject-commit testing (was: [Patch] contrib/gcc-changelog: Check whether revert-commit exists)

2023-09-08 Thread Tobias Burnus

On 07.09.23 11:38, Jakub Jelinek wrote:

On Thu, Sep 07, 2023 at 11:30:53AM +0200, Tobias Burnus wrote:

contrib/gcc-changelog: Check whether revert-commit exists
...

I think not should precede technically (or should we just drop technically)?


'technically' has been dropped (twice), based on the IRC discussion (in
the original commit and in a follow-up fixing commit as the re-commit
patch missed it).

Otherwise, the patch has been applied - but we did struggle with getting
it copied over to the right location on the server + getting it to work.

Last status: The check does work locally but did not for "git push"; in
principle, it should also work on the server but it failed when last
tested. While several directories on the server have now the new script,
it is unclear whether the (or all the) relevant one(s) have it and
whether the script itself is fine or not.

In any case, attached is the commit that rectifies the ChangeLog files
and also lists in the log-message part what the related commits did and
didn't do.

Committed as r14-3806-g478c37e7234530 - after the "Daily Bump", which
also required the same temporary work around as for the original issue.

Tobias
-
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
commit 478c37e72345307fad0aa06e0dae133eae206b0c
Author: Tobias Burnus 
Date:   Fri Sep 8 12:02:02 2023 +0200

Update contrib + libgomp ChangeLogs for failed reject-commit testing

The following commit should have enabled checking for invalid revert hashes;
it worked locally - but did work as pre-commit hook on sourceware
as it wasn't copied to the hook directory:
r14-3777-gff20bce9f58 contrib/gcc-changelog: Check whether revert-commit exists

Hence, the following revert commit was wrongly applied:
r14-3778-gfbbd9001e9b Revert "contrib/gcc-changelog: Check whether revert-commit exists"
(In this commit: contrib/ChangeLog update for the revert.)

r14-3779-g69e83181ebc contrib/gcc-changelog: Check whether revert-commit exists
Re-applied the commit with a commit-log typo fixed but missing a late commit.

r14-3780-g1b0934b7276 Revert "contrib/gcc-changelog: Check whether revert-commit exists"
This commit still came through but re-instated the late wording fix in
contrib/gcc-changelog/git_commit.py.
(In this commit: contrib/ChangeLog update for the wording change.)

r14-3781-gd22cd7745ff Revert: "Another revert test with a bogus hash"
Another attempt to get a reject, but it still came through.
It removed tailing whitespace in libgomp/target.c
(In this commit: libgomp/ChangeLog was for the whitespace removal.)

diff --git a/contrib/ChangeLog b/contrib/ChangeLog
index e49bbe30446..403a095512c 100644
--- a/contrib/ChangeLog
+++ b/contrib/ChangeLog
@@ -1,3 +1,8 @@
+2023-09-07  Tobias Burnus  
+
+	* gcc-changelog/git_commit.py (GitCommit.__init__,
+	to_changelog_entries): Fix lost wording fix.
+
 2023-09-07  Tobias Burnus  
 
 	* gcc-changelog/git_commit.py (GitCommit.__init__):
@@ -9,6 +14,20 @@
 	call super() with commit_to_info_hook=None instead
 	of a lambda function.
 
+2023-09-07  Tobias Burnus  
+
+	Revert:
+	2023-09-07  Tobias Burnus  
+
+	* gcc-changelog/git_commit.py (GitCommit.__init__):
+	Handle commit_to_info_hook = None; otherwise, if None,
+	regard it as error.
+	(to_changelog_entries): Handle commit_to_info_hook = None;
+	if info is None, create a warning for it.
+	* gcc-changelog/git_email.py (GitEmail.__init__):
+	call super() with commit_to_info_hook=None instead
+	of a lamda function.
+
 2023-09-07  Tobias Burnus  
 
 	* gcc-changelog/git_commit.py (GitCommit.__init__):
diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog
index dbd5e4fc4ee..fb96155394e 100644
--- a/libgomp/ChangeLog
+++ b/libgomp/ChangeLog
@@ -5,6 +5,10 @@
 	omp_get_default_allocator.
 	(OMP_ALLOCATOR): Fix ICV var name; add see-also references.
 
+2023-09-07  Tobias Burnus  
+
+	* target.c (gomp_unload_device): Remove tailing whitespace.
+
 2023-09-04  Tobias Burnus  
 	Thomas Schwinge  
 


[PATCH v2] RISC-V: Implement TLS Descriptors.

2023-09-08 Thread Tatsuyuki Ishi via Gcc-patches
This implements TLS Descriptors (TLSDESC) as specified in [1].

In TLSDESC instruction sequence, the first instruction relocates against
the target TLS variable, while subsequent instructions relocates against
the address of the first. Such usage of labels are not well-supported
within GCC. Due to this, the 4-instruction sequence is implemented as a
single RTX insn.

The default remains to be the traditional TLS model, but can be configured
with --with_tls={trad,desc}. The choice can be revisited once toolchain
and libc support ships.

[1]: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/373.

gcc/Changelog:
* config/riscv/riscv.opt: Add -mtls-dialect to configure TLS flavor.
* config.gcc: Add --with_tls configuration option to change the default
TLS flavor.
* config/riscv/riscv.h: Add TARGET_TLSDESC determined from
-mtls-dialect and with_tls defaults.
* config/riscv/riscv-opts.h: Define enum riscv_tls_type for the two TLS
flavors.
* config/riscv/riscv-protos.h: Define SYMBOL_TLSDESC symbol type.
* config/riscv/riscv.md: Add instruction sequence for TLSDESC.
* config/riscv/riscv.cc (riscv_symbol_insns): Add instruction sequence
length data for TLSDESC.
(riscv_legitimize_tls_address): Add lowering of TLSDESC.
---
No regression in gcc tests for rv64gc, tested alongside the binutils and
glibc implementation. Tested with --with_tls=desc.

v2: Add with_tls configuration option, and a few readability improvements.
Added Changelog.
Thanks Kito Cheng for the review.

This contribution is made on behalf of Blue Whale Systems, which has
copyright assignment on file with the FSF.

 gcc/config.gcc  | 15 ++-
 gcc/config/riscv/riscv-opts.h   |  6 ++
 gcc/config/riscv/riscv-protos.h |  5 +++--
 gcc/config/riscv/riscv.cc   | 24 
 gcc/config/riscv/riscv.h|  9 +++--
 gcc/config/riscv/riscv.md   | 21 -
 gcc/config/riscv/riscv.opt  | 14 ++
 7 files changed, 84 insertions(+), 10 deletions(-)

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 415e0e1ebc5..86df7b89016 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -2434,6 +2434,7 @@ riscv*-*-linux*)
# Force .init_array support.  The configure script cannot always
# automatically detect that GAS supports it, yet we require it.
gcc_cv_initfini_array=yes
+   with_tls=${with_tls:-trad}
;;
 riscv*-*-elf* | riscv*-*-rtems*)
tm_file="elfos.h newlib-stdint.h ${tm_file} riscv/elf.h"
@@ -2476,6 +2477,7 @@ riscv*-*-freebsd*)
# Force .init_array support.  The configure script cannot always
# automatically detect that GAS supports it, yet we require it.
gcc_cv_initfini_array=yes
+   with_tls=${with_tls:-trad}
;;
 
 loongarch*-*-linux*)
@@ -4566,7 +4568,7 @@ case "${target}" in
;;
 
riscv*-*-*)
-   supported_defaults="abi arch tune riscv_attribute isa_spec"
+   supported_defaults="abi arch tune riscv_attribute isa_spec tls"
 
case "${target}" in
riscv-* | riscv32*) xlen=32 ;;
@@ -4694,6 +4696,17 @@ case "${target}" in
;;
esac
fi
+   # Handle --with-tls.
+   case "$with_tls" in
+"" \
+| trad | desc)
+# OK
+;;
+*)
+echo "Unknown TLS method used in --with-tls=$with_tls" 1>&2
+exit 1
+;;
+esac
 
# Handle --with-multilib-list.
if test "x${with_multilib_list}" != xdefault; then
diff --git a/gcc/config/riscv/riscv-opts.h b/gcc/config/riscv/riscv-opts.h
index 378a17699cd..db03f35430a 100644
--- a/gcc/config/riscv/riscv-opts.h
+++ b/gcc/config/riscv/riscv-opts.h
@@ -319,4 +319,10 @@ enum riscv_entity
 #define TARGET_VECTOR_VLS  
\
   (TARGET_VECTOR && riscv_autovec_preference == RVV_SCALABLE)
 
+/* TLS types.  */
+enum riscv_tls_type {
+  TLS_TRADITIONAL,
+  TLS_DESCRIPTORS
+};
+
 #endif /* ! GCC_RISCV_OPTS_H */
diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h
index 472c00dc439..9b7471f7591 100644
--- a/gcc/config/riscv/riscv-protos.h
+++ b/gcc/config/riscv/riscv-protos.h
@@ -33,9 +33,10 @@ enum riscv_symbol_type {
   SYMBOL_TLS,
   SYMBOL_TLS_LE,
   SYMBOL_TLS_IE,
-  SYMBOL_TLS_GD
+  SYMBOL_TLS_GD,
+  SYMBOL_TLSDESC,
 };
-#define NUM_SYMBOL_TYPES (SYMBOL_TLS_GD + 1)
+#define NUM_SYMBOL_TYPES (SYMBOL_TLSDESC + 1)
 
 /* Classifies an address.
 
diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 49062bef9fc..c158e224aaa 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -799,6 +799,7 @@ static int riscv_symbol_insns (enum riscv_symbol_type type)
 case SYMBOL_ABSOLUTE: return 2; /* LUI + the reference.  */
 case 

Re: [PATCH] libstdc++: Reduce output of 'make check'

2023-09-08 Thread Jonathan Wakely via Gcc-patches
On Fri, 8 Sept 2023 at 03:16, Eric Gallager  wrote:
>
> Maybe use $(AM_V_at) instead? That would allow it to be controlled by
> the --enable-silent-rules flag to configure, as well as make V=1 vs.
> make V=0 too.

I see two problems with that. Firstly, nobody uses that configure
option, so the net result would be that these 39 lines are still
printed for everybody.

Secondly, why would anybody ever want this output? Having it
configurable (and default to noisy) just doesn't seem helpful.

This is the output I'm talking about:

make: Entering directory
'/home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/testsuite'
make  check-DEJAGNU
make[1]: Entering directory
'/home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/testsuite'
Making a new site.exp file...
AR="ar --plugin /home/jwakely/src/gcc/build/./gcc/liblto_plugin.so";
export AR; \
RANLIB="ranlib --plugin
/home/jwakely/src/gcc/build/./gcc/liblto_plugin.so"; export RANLIB; \
if [ -z "" ] && [ -n "" ]; then \
 rm -rf normal-parallel || true; \
 mkdir normal-parallel; \
 make  check-DEJAGNUnormal1 check-DEJAGNUnormal2 check-DEJAGNUnormal3
check-DEJAGNUnormal4 check-DEJAGNUnormal5 check-DEJAGNUnormal6
check-DEJAGNUnormal7 c
heck-DEJAGNUnormal8 check-DEJAGNUnormal9 check-DEJAGNUnormal10
check-DEJAGNUnormal11 check-DEJAGNUnormal12 check-DEJAGNUnormal13
check-DEJAGNUnormal14 check
-DEJAGNUnormal15 check-DEJAGNUnormal16 check-DEJAGNUnormal17
check-DEJAGNUnormal18 check-DEJAGNUnormal19 check-DEJAGNUnormal20
check-DEJAGNUnormal21 check-D
EJAGNUnormal22 check-DEJAGNUnormal23 check-DEJAGNUnormal24
check-DEJAGNUnormal25 check-DEJAGNUnormal26 check-DEJAGNUnormal27
check-DEJAGNUnormal28 check-DEJ
AGNUnormal29 check-DEJAGNUnormal30 check-DEJAGNUnormal31
check-DEJAGNUnormal32 check-DEJAGNUnormal33 check-DEJAGNUnormal34
check-DEJAGNUnormal35 check-DEJAG
NUnormal36 check-DEJAGNUnormal37 check-DEJAGNUnormal38
check-DEJAGNUnormal39 check-DEJAGNUnormal40 check-DEJAGNUnormal41
check-DEJAGNUnormal42 check-DEJAGNU
normal43 check-DEJAGNUnormal44 check-DEJAGNUnormal45
check-DEJAGNUnormal46 check-DEJAGNUnormal47 check-DEJAGNUnormal48
check-DEJAGNUnormal49 check-DEJAGNUno
rmal50 check-DEJAGNUnormal51 check-DEJAGNUnormal52
check-DEJAGNUnormal53 check-DEJAGNUnormal54 check-DEJAGNUnormal55
check-DEJAGNUnormal56 check-DEJAGNUnorm
al57 check-DEJAGNUnormal58 check-DEJAGNUnormal59 check-DEJAGNUnormal60
check-DEJAGNUnormal61 check-DEJAGNUnormal62 check-DEJAGNUnormal63
check-DEJAGNUnormal
64 check-DEJAGNUnormal65 check-DEJAGNUnormal66 check-DEJAGNUnormal67
check-DEJAGNUnormal68 check-DEJAGNUnormal69 check-DEJAGNUnormal70
check-DEJAGNUnormal71
check-DEJAGNUnormal72 check-DEJAGNUnormal73 check-DEJAGNUnormal74
check-DEJAGNUnormal75 check-DEJAGNUnormal76 check-DEJAGNUnormal77
check-DEJAGNUnormal78 c
heck-DEJAGNUnormal79 check-DEJAGNUnormal80 check-DEJAGNUnormal81
check-DEJAGNUnormal82 check-DEJAGNUnormal83 check-DEJAGNUnormal84
check-DEJAGNUnormal85 che
ck-DEJAGNUnormal86 check-DEJAGNUnormal87 check-DEJAGNUnormal88
check-DEJAGNUnormal89 check-DEJAGNUnormal90 check-DEJAGNUnormal91
check-DEJAGNUnormal92 check
-DEJAGNUnormal93 check-DEJAGNUnormal94 check-DEJAGNUnormal95
check-DEJAGNUnormal96 check-DEJAGNUnormal97 check-DEJAGNUnormal98
check-DEJAGNUnormal99 check-D
EJAGNUnormal100 check-DEJAGNUnormal101 check-DEJAGNUnormal102
check-DEJAGNUnormal103 check-DEJAGNUnormal104 check-DEJAGNUnormal105
check-DEJAGNUnormal106 ch
eck-DEJAGNUnormal107 check-DEJAGNUnormal108 check-DEJAGNUnormal109
check-DEJAGNUnormal110 check-DEJAGNUnormal111 check-DEJAGNUnormal112
check-DEJAGNUnormal1
13 check-DEJAGNUnormal114 check-DEJAGNUnormal115
check-DEJAGNUnormal116 check-DEJAGNUnormal117 check-DEJAGNUnormal118
check-DEJAGNUnormal119 check-DEJAGNUno
rmal120 check-DEJAGNUnormal121 check-DEJAGNUnormal122
check-DEJAGNUnormal123 check-DEJAGNUnormal124 check-DEJAGNUnormal125
check-DEJAGNUnormal126 check-DEJA
GNUnormal127 check-DEJAGNUnormal128; \
 rm -rf normal-parallel || true; \
 for idx in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
46 47 48 49 50 51
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
98 99 100 101 102
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
120 121 122 123 124 125 126 127 128; do \
   if [ -d normal$idx ]; then \
 mv -f normal$idx/libstdc++.sum normal$idx/libstdc++.sum.sep; \
 mv -f normal$idx/libstdc++.log normal$idx/libstdc++.log.sep; \
   fi; \
 done; \
 /bin/sh 
/home/jwakely/src/gcc/gcc/libstdc++-v3/testsuite/../../contrib/dg-extract-results.sh
\
   normal[0-9]*/libstdc++.sum.sep > libstdc++.sum; \
 /bin/sh 
/home/jwakely/src/gcc/gcc/libstdc++-v3/testsuite/../../contrib/dg-extract-results.sh
-L \
   normal[0-9]*/libstdc++.log.sep > libstdc++.log; \
 exit 0; \
fi; \
srcdir=`CDPATH="${ZSH_VERSION+.}:" && cd
/home/jwakely/src/gcc/gcc/libstdc++-v3/testsuite && pwd`; export
srcdir; \

Re: [PATCH] libbacktrace: Fix unconditional -Werror

2023-09-08 Thread Jonathan Wakely via Gcc-patches
The patch looks good, thanks. I noticed the unconditional -Werror the other
day when testing a build on avr.

N.B. All patches should go to gcc-patches (as well as a more specific list
like libstdc++ when appropriate).

OK for trunk



On Fri, 8 Sept 2023, 10:49 Alexey Lapshin via Libstdc++, <
libstd...@gcc.gnu.org> wrote:

> Added to CC: jwak...@redhat.com, h...@axis.com
>
>
> On Fri, 2023-09-08 at 12:39 +0400, Alexey Lapshin wrote:
> > -Werror flag should depend on --enable-werror configure option
> >
> > ---
> >  libstdc++-v3/src/libbacktrace/Makefile.am | 2 +-
> >  libstdc++-v3/src/libbacktrace/Makefile.in | 2 +-
> >  2 files changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/libstdc++-v3/src/libbacktrace/Makefile.am
> b/libstdc++-v3/src/libbacktrace/Makefile.am
> > index 9abf9dd64a1..27c1ea570e0 100644
> > --- a/libstdc++-v3/src/libbacktrace/Makefile.am
> > +++ b/libstdc++-v3/src/libbacktrace/Makefile.am
> > @@ -45,7 +45,7 @@ libstdc___libbacktrace_la_CPPFLAGS = \
> > $(BACKTRACE_CPPFLAGS)
> >
> >  WARN_FLAGS = -W -Wall -Wwrite-strings -Wmissing-format-attribute \
> > --Wcast-qual -Werror
> > +-Wcast-qual
> >  C_WARN_FLAGS = $(WARN_FLAGS) -Wstrict-prototypes -Wmissing-prototypes
> -Wold-style-definition -Wno-unused-but-set-variable
> >  CXX_WARN_FLAGS = $(WARN_FLAGS) -Wno-unused-parameter
> >  AM_CFLAGS = $(C_WARN_FLAGS)
> > diff --git a/libstdc++-v3/src/libbacktrace/Makefile.in
> b/libstdc++-v3/src/libbacktrace/Makefile.in
> > index 1c1242d8827..b78c8443751 100644
> > --- a/libstdc++-v3/src/libbacktrace/Makefile.in
> > +++ b/libstdc++-v3/src/libbacktrace/Makefile.in
> > @@ -368,7 +368,7 @@ VTV_CXXFLAGS = @VTV_CXXFLAGS@
> >  VTV_CXXLINKFLAGS = @VTV_CXXLINKFLAGS@
> >  VTV_PCH_CXXFLAGS = @VTV_PCH_CXXFLAGS@
> >  WARN_FLAGS = -W -Wall -Wwrite-strings -Wmissing-format-attribute \
> > --Wcast-qual -Werror
> > +-Wcast-qual
> >
> >  XMLCATALOG = @XMLCATALOG@
> >  XMLLINT = @XMLLINT@
>
>


[PATCH] fortran: Remove redundant tree walk to delete element

2023-09-08 Thread Mikael Morin via Gcc-patches
Hello,

this avoids some redundant work in the symbol deletion code, which is
used a lot by the parser to cancel statements that fail to match in the
end.
I haven't tried to measure the performance effect, if any, on a pathological 
example;
just passed the fortran testsuite on x86_64-pc-linux-gnu.
OK for master?

-- >8 --

Remove preliminary walk of the symbol tree when we are about to remove an
element.  This preliminary walk was necessary because the deletion function
updated the tree without reporting back to the caller the element it had
removed.  But knowing that element is necessary to free its memory, so one
had to first get that element before it was removed from the tree.

This change updates the main deletion function delete_treap and its public
wrapper gfc_delete_bbt so that the removed element can be known by the
caller.  This makes the preliminary walk in gfc_delete_symtree redundant,
permitting its removal.

gcc/fortran/ChangeLog:

* bbt.cc (delete_treap): Add argument REMOVED, set it to the removed
element from the tree.  Change NULL to nullptr.
(gfc_delete_bbt): Return the removed element from the tree.
* gfortran.h (gfc_delete_symtree): Remove prototype.
(gfc_delete_bbt): Set return type to pointer.
* symbol.cc (gfc_delete_symtree): Make static.  Get the element to be
freed from the result of gfc_delete_bbt.  Remove the preliminary walk to
get it.
---
 gcc/fortran/bbt.cc | 27 +++
 gcc/fortran/gfortran.h |  3 +--
 gcc/fortran/symbol.cc  |  6 ++
 3 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/gcc/fortran/bbt.cc b/gcc/fortran/bbt.cc
index 851e5e92c7b..2a032083c5c 100644
--- a/gcc/fortran/bbt.cc
+++ b/gcc/fortran/bbt.cc
@@ -168,31 +168,42 @@ delete_root (gfc_bbt *t)
Returns the new root node of the tree.  */
 
 static gfc_bbt *
-delete_treap (gfc_bbt *old, gfc_bbt *t, compare_fn compare)
+delete_treap (gfc_bbt *old, gfc_bbt *t, compare_fn compare, gfc_bbt **removed)
 {
   int c;
 
-  if (t == NULL)
-return NULL;
+  if (t == nullptr)
+{
+  if (removed)
+   *removed = nullptr;
+  return nullptr;
+}
 
   c = (*compare) (old, t);
 
   if (c < 0)
-t->left = delete_treap (old, t->left, compare);
+t->left = delete_treap (old, t->left, compare, removed);
   if (c > 0)
-t->right = delete_treap (old, t->right, compare);
+t->right = delete_treap (old, t->right, compare, removed);
   if (c == 0)
-t = delete_root (t);
+{
+  if (removed)
+   *removed = t;
+  t = delete_root (t);
+}
 
   return t;
 }
 
 
-void
+void *
 gfc_delete_bbt (void *root, void *old, compare_fn compare)
 {
   gfc_bbt **t;
+  gfc_bbt *removed;
 
   t = (gfc_bbt **) root;
-  *t = delete_treap ((gfc_bbt *) old, *t, compare);
+  *t = delete_treap ((gfc_bbt *) old, *t, compare, );
+
+  return (void *) removed;
 }
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index b37c6bb9ad4..371f8743312 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -3510,7 +3510,6 @@ bool gfc_reference_st_label (gfc_st_label *, gfc_sl_type);
 gfc_namespace *gfc_get_namespace (gfc_namespace *, int);
 gfc_symtree *gfc_new_symtree (gfc_symtree **, const char *);
 gfc_symtree *gfc_find_symtree (gfc_symtree *, const char *);
-void gfc_delete_symtree (gfc_symtree **, const char *);
 gfc_symtree *gfc_get_unique_symtree (gfc_namespace *);
 gfc_user_op *gfc_get_uop (const char *);
 gfc_user_op *gfc_find_uop (const char *, gfc_namespace *);
@@ -3911,7 +3910,7 @@ bool gfc_inline_intrinsic_function_p (gfc_expr *);
 /* bbt.cc */
 typedef int (*compare_fn) (void *, void *);
 void gfc_insert_bbt (void *, void *, compare_fn);
-void gfc_delete_bbt (void *, void *, compare_fn);
+void * gfc_delete_bbt (void *, void *, compare_fn);
 
 /* dump-parse-tree.cc */
 void gfc_dump_parse_tree (gfc_namespace *, FILE *);
diff --git a/gcc/fortran/symbol.cc b/gcc/fortran/symbol.cc
index aa3cdc98c86..2cba2ea0bed 100644
--- a/gcc/fortran/symbol.cc
+++ b/gcc/fortran/symbol.cc
@@ -2948,7 +2948,7 @@ gfc_new_symtree (gfc_symtree **root, const char *name)
 
 /* Delete a symbol from the tree.  Does not free the symbol itself!  */
 
-void
+static void
 gfc_delete_symtree (gfc_symtree **root, const char *name)
 {
   gfc_symtree st, *st0;
@@ -2963,10 +2963,8 @@ gfc_delete_symtree (gfc_symtree **root, const char *name)
   else
 p = name;
 
-  st0 = gfc_find_symtree (*root, p);
-
   st.name = gfc_get_string ("%s", p);
-  gfc_delete_bbt (root, , compare_symtree);
+  st0 = (gfc_symtree *) gfc_delete_bbt (root, , compare_symtree);
 
   free (st0);
 }
-- 
2.40.1



Re:[pushed] [PATCH] LoongArch: Enable -fsched-pressure by default at -O1 and higher.

2023-09-08 Thread chenglulu

Pushed to r14-3805.

在 2023/9/8 下午4:32, Xi Ruoyao 写道:

On Fri, 2023-09-08 at 16:29 +0800, Guo Jie wrote:

Hi,

What I wanna change is "gcc/common/config/loongarch/loongarch-
common.cc",

and the patch is automatically generated by "git gcc-commit-mklog".

Is it necessary to  to remove "common/" ?

My bad.  I didn't realized the file has been moved to common.

Don't change it :(.


Thanks for the review.


在 2023/9/8 下午4:06, Xi Ruoyao 写道:

On Fri, 2023-09-08 at 10:00 +0800, Guo Jie wrote:

gcc/ChangeLog:

  * common/config/loongarch/loongarch-common.cc:

"common/" should be removed.  You can use "git gcc-verify" to figure
out
this kind of error before sending a patch in the future.


  (default_options loongarch_option_optimization_table):
  Default to -fsched-pressure.

"Default to -fsched-pressure at -O1 or above."

Otherwise OK.


---
   gcc/common/config/loongarch/loongarch-common.cc | 1 +
   1 file changed, 1 insertion(+)

diff --git a/gcc/common/config/loongarch/loongarch-common.cc
b/gcc/common/config/loongarch/loongarch-common.cc
index c5ed37d27a6..b6901910b70 100644
--- a/gcc/common/config/loongarch/loongarch-common.cc
+++ b/gcc/common/config/loongarch/loongarch-common.cc
@@ -36,6 +36,7 @@ static const struct default_options
loongarch_option_optimization_table[] =
     { OPT_LEVELS_ALL, OPT_fasynchronous_unwind_tables, NULL, 1 },
     { OPT_LEVELS_1_PLUS, OPT_fsection_anchors, NULL, 1 },
     { OPT_LEVELS_2_PLUS, OPT_free, NULL, 1 },
+  { OPT_LEVELS_1_PLUS, OPT_fsched_pressure, NULL, 1 },
     { OPT_LEVELS_NONE, 0, NULL, 0 }
   };
   




Re:[pushed] [PATCH] LoongArch: Fix unintentional bash-ism in r14-3665.

2023-09-08 Thread chenglulu

Pushed to r14-3804.

在 2023/9/6 下午8:19, Richard Sandiford 写道:

Yang Yujie  writes:

gcc/ChangeLog:

* config.gcc: remove non-POSIX syntax "<<<".

OK.  Thanks for the quick fix.

Richard.


---
  gcc/config.gcc | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config.gcc b/gcc/config.gcc
index b2fe7c7ceef..6d4c8becd28 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -5189,7 +5189,7 @@ case "${target}" in
if test x${parse_state} = x"abi-base"; then
# Base ABI type
case ${component} in
-   lp64d | lp64f | lp64s) elem_tmp="ABI_BASE_$(tr a-z 
A-Z <<< ${component}),";;
+   lp64d | lp64f | lp64s) 
elem_tmp="ABI_BASE_$(echo ${component} | tr a-z A-Z),";;
*)
echo "Unknown base ABI \"${component}\" in 
--with-multilib-list." 1>&2
exit 1




Re: [pushed][PATCH v2] LoongArch: Adjust C++ multilib header layout.

2023-09-08 Thread chenglulu

PUshed to r14-3803.

在 2023/9/7 下午2:50, Yang Yujie 写道:

For LoongArch, the toplevel library build is always aliased to
one of the multilib variants.  This patch installs it with the
actual MULTISUBDIR (instead of ".") so that the headers can be
reached by the compiler.

This patch is an update of
https://gcc.gnu.org/pipermail/gcc-patches/2023-September/629435.html

libstdc++-v3/ChangeLog:

* configure.host: Register t-loongarch in tmake_file.
* config/cpu/loongarch/t-loongarch: New file.  Manually refresh
MULTISUBDIR with $(shell $(CXX) --print-multi-directory).
---
  libstdc++-v3/config/cpu/loongarch/t-loongarch | 1 +
  libstdc++-v3/configure.host   | 5 -
  2 files changed, 5 insertions(+), 1 deletion(-)
  create mode 100644 libstdc++-v3/config/cpu/loongarch/t-loongarch

diff --git a/libstdc++-v3/config/cpu/loongarch/t-loongarch 
b/libstdc++-v3/config/cpu/loongarch/t-loongarch
new file mode 100644
index 000..adfc8ebb93e
--- /dev/null
+++ b/libstdc++-v3/config/cpu/loongarch/t-loongarch
@@ -0,0 +1 @@
+AM_MAKEFLAGS += " MULTISUBDIR=/$(shell $(CXX) --print-multi-directory)"
diff --git a/libstdc++-v3/configure.host b/libstdc++-v3/configure.host
index 9e7c7f02dfd..9dc42ad3edb 100644
--- a/libstdc++-v3/configure.host
+++ b/libstdc++-v3/configure.host
@@ -315,7 +315,10 @@ esac
  # Set any OS-dependent and CPU-dependent bits.
  # THIS TABLE IS SORTED.  KEEP IT THAT WAY.
  case "${host}" in
-  *-*-linux* | *-*-uclinux*)
+ loongarch*)
+tmake_file="cpu/loongarch/t-loongarch"
+;;
+ *-*-linux* | *-*-uclinux*)
  case "${host_cpu}" in
i[567]86)
  abi_baseline_pair=i486-linux-gnu




Re: [PATCH] Fortran: runtime bounds-checking in presence of array constructors [PR31059]

2023-09-08 Thread Mikael Morin via Gcc-patches

Le 01/09/2023 à 22:48, Harald Anlauf a écrit :

Hi Mikael,

On 9/1/23 10:41, Mikael Morin via Gcc-patches wrote:

May I suggest to handle functions the same way?


I'll have a look at them, but will need to gather a few
suitable testcases first.

I have just opened PR111339 
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111339) to track the case 
of functions separately.


Re: [PATCH] riscv: bitmanip: Remove duplicate zero_extendhi2 pattern

2023-09-08 Thread Philipp Tomsich
Committed as 'obvious' to master. Thanks!
Philipp.

On Fri, 8 Sept 2023 at 08:53, Christoph Muellner <
christoph.muell...@vrull.eu> wrote:

> From: Christoph Müllner 
>
> We currently have two identical zero_extendhi2 patterns:
> * '*zero_extendhi2_zbb'
> * '*zero_extendhi2_bitmanip'
>
> This patch removes the *_zbb pattern and ensures that all sign- and
> zero-extensions use the postfix '_bitmanip'.
>
> Signed-off-by: Christoph Müllner 
>
> gcc/ChangeLog:
>
> * config/riscv/bitmanip.md
> (*extend2_zbb):
> Rename postfix to _bitmanip.
> (*extend2_bitmanip): Renamed pattern.
> (*zero_extendhi2_zbb): Remove duplicated pattern.
> ---
>  gcc/config/riscv/bitmanip.md | 13 +
>  1 file changed, 1 insertion(+), 12 deletions(-)
>
> diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md
> index 1544ef4e125..431b3292213 100644
> --- a/gcc/config/riscv/bitmanip.md
> +++ b/gcc/config/riscv/bitmanip.md
> @@ -283,7 +283,7 @@ (define_insn "*zero_extendhi2_bitmanip"
>[(set_attr "type" "bitmanip,load")
> (set_attr "mode" "")])
>
> -(define_insn "*extend2_zbb"
> +(define_insn "*extend2_bitmanip"
>[(set (match_operand:SUPERQI   0 "register_operand" "=r,r")
> (sign_extend:SUPERQI
> (match_operand:SHORT 1 "nonimmediate_operand" " r,m")))]
> @@ -294,17 +294,6 @@ (define_insn "*extend2_zbb"
>[(set_attr "type" "bitmanip,load")
> (set_attr "mode" "")])
>
> -(define_insn "*zero_extendhi2_zbb"
> -  [(set (match_operand:GPR0 "register_operand" "=r,r")
> -   (zero_extend:GPR
> -   (match_operand:HI 1 "nonimmediate_operand" " r,m")))]
> -  "TARGET_ZBB"
> -  "@
> -   zext.h\t%0,%1
> -   lhu\t%0,%1"
> -  [(set_attr "type" "bitmanip,load")
> -   (set_attr "mode" "HI")])
> -
>  (define_expand "rotrdi3"
>[(set (match_operand:DI 0 "register_operand")
> (rotatert:DI (match_operand:DI 1 "register_operand")
> --
> 2.41.0
>
>


Re: [PATCH v2 1/3] libgomp, nvptx: low-latency memory allocator

2023-09-08 Thread Tobias Burnus

Hi Andrew,

some early comments. I think in general, the direction/patches are fine,
but I have some comments:

On 02.08.23 19:00, Andrew Stubbs wrote:

This patch adds support for allocating low-latency ".shared" memory on
NVPTX GPU device, via the omp_low_lat_mem_space and omp_alloc.  The memory
can be allocated, reallocated, and freed using a basic but fast algorithm,
is thread safe and the size of the low-latency heap can be configured using
the GOMP_NVPTX_LOWLAT_POOL environment variable.

The use of the PTX dynamic_smem_size feature means that low-latency allocator
will not work with the PTX 3.1 multilib.


This probably fits better to 2/3 in the series, but you really should
document the nvptx part, namely:

- that omp_low_lat_mem_space is supported on nvptx

- its limitations (access is restricted to the contention group, i.e.
all threads of a team) → implication on the supported allocators.

- the default size of this memory (8 kiB) and the GOMP_NVPTX_LOWLAT_POOL
environment variable, possibly with mentioning that there is some
internal overhead* which is worsen when using high alignment values. (*
– due to basic_allocator book keeping and for storing pointer to the
OpenMP allocator struct.)

- if I understand it correctly, our default build supports sm_30 and
uses PTX ISA version 3.1 for it. If so, I think we should mention that
nvptx GCC has to be configured with with-arch=sm_... >= sm_53 (=
supported version >=4.1) and, during compilation, no -march= < that
configure-time value may be specified. (Cf. also
https://gcc.gnu.org/install/specific.html#nvptx-x-none )

I think this best fits into
https://gcc.gnu.org/onlinedocs/libgomp/nvptx.html – but one could also
argue that it should be put elsewhere.

It probably makes sense to add a 'See also:' to
https://gcc.gnu.org/onlinedocs/libgomp/Memory-allocation.html pointing
to https://gcc.gnu.org/onlinedocs/libgomp/Offload-Target-Specifics.html

* * *

BTW: I think the following should be "...MINOR__ >= 1":


+#if __PTX_ISA_VERSION_MAJOR__ > 4 \
+|| (__PTX_ISA_VERSION_MAJOR__ == 4 && __PTX_ISA_VERSION_MAJOR__ >= 1)


* * *

Regarding patch 2/3 and MEMSPACE_VALIDATE.

In general, I wonder how to handle memory spaces (and traits) that
aren't supported. Namely, when to return 0L and when to silently use
ignore the trait / use another memory space.

The current omp_init_allocator code only returns omp_null_allocator for
invalid value – or for pinned memory (as it is unsupported). [RFC: Shall
we keep doing so – or return omp_null_mem_alloc more often? →
https://gcc.gnu.org/PR111044 for this question, improving libmemkind
usage, and extending the allocator-related documentation.]

As we do it on the host, I think auto-fallback to omp_default_mem_space
is is also find for nvptx (and gcn), but not as done in 2/3 but slightly
different:

(a) In omp_init_allocator, there should be a check whether it is
supported, if not, we can fallback to using default memory space. (In
line with the current code host + 1/2+2/3 nvptx behaviour.)

Note: That's not the same as the current 2/3 patch. Currently, if
MEMSPACE_VALIDATE fails, a retry is attempted – but the outcome depends
on the value for 'fallback'. When changing the memory space during
omp_init_allocator, only failed 'malloc' will give abort with abort_fb.

(b) For nvptx_memspace_validate, I think an additional check should be
done based on the __PTX_ISA_VERSION* as it feels off if plugin first
claims support for it but later unconditionally uses malloc at runtime.

(c) We also need to handle omp_low_lat_mem_alloc. I think the spec
implies access:all but nvptx/gcn only support cgroup (+ pteams +
thread), potentially leading to wrong code. Example (hopefully, I got
the syntax right:

#pragma omp target uses_allocator(omp_low_lat_mem_alloc)

#pragma omp teams firstprivate(var) allocate(omp_low_lat_mem_alloc: var)

#pragma omp distribute parallel for

...

#omp atomic ...

... var ...


The current 2/3 checks in alloc/calloc/realloc only cover user-defined
allocators; if we move the check for user-defined allocators to
omp_init_allocator, we actually only need to handle predefined
allocators in alloc/calloc/realloc.

And finally: As mentioned off list, I believe that for the patch 2/3,
the pteam should be cgroup (contention group), i.e. about all threads of
a team / implicit parallel and not only the innermost parallel (pteam).
That actually matches the "access != all" check, but I think "access =
cgroup" should also be tested for in the testsuite.

* * *

3/3 patch for GCN: I think the situation is similar, except that there
is no ISA version issue and most is handled by 1/3 and 2/3 such that
only updating documentation remains.

* * *


libgomp/ChangeLog:

  * allocator.c (MEMSPACE_ALLOC): New macro.
  (MEMSPACE_CALLOC): New macro.
  (MEMSPACE_REALLOC): New macro.
  (MEMSPACE_FREE): New macro.


BTW: You could (but are not required to) combine multiple macro/function
names to a single '(name1, 

[PATCH] gimple-match: Do not try UNCOND optimization with COND_LEN.

2023-09-08 Thread Robin Dapp via Gcc-patches
Hi,

found in slp-reduc-7.c, this patch prevents optimizing e.g.
 COND_LEN_ADD ({-1, ... }, a, 0, c, len, bias)
unconditionally into just "a".

Currently, we assume that COND_LEN operations can be optimized similarly
to COND operations.  As the length is part of the mask (and usually not
compile-time constant), we must not perform any optimization that relies
on just the mask being "true".

Bootstrap and testsuite are unchanged on aarch64 and x86.

Regards
 Robin

gcc/ChangeLog:

* gimple-match-exports.cc (maybe_resimplify_conditional_op):
Check for length masking.
---
 gcc/gimple-match-exports.cc | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/gcc/gimple-match-exports.cc b/gcc/gimple-match-exports.cc
index b36027b0bad..73be9f4f4c3 100644
--- a/gcc/gimple-match-exports.cc
+++ b/gcc/gimple-match-exports.cc
@@ -262,7 +262,8 @@ maybe_resimplify_conditional_op (gimple_seq *seq, 
gimple_match_op *res_op,
   if (!res_op->cond.cond)
 return false;
 
-  if (!res_op->cond.else_value
+  if (!res_op->cond.len
+  && !res_op->cond.else_value
   && res_op->code.is_tree_code ())
 {
   /* The "else" value doesn't matter.  If the "then" value is a
@@ -301,9 +302,12 @@ maybe_resimplify_conditional_op (gimple_seq *seq, 
gimple_match_op *res_op,
 
   /* If the "then" value is a gimple value and the "else" value matters,
  create a VEC_COND_EXPR between them, then see if it can be further
- simplified.  */
+ simplified.
+ Don't do this if we have a COND_LEN_ as that would make us lose the
+ length masking.  */
   gimple_match_op new_op;
-  if (res_op->cond.else_value
+  if (!res_op->cond.len
+  && res_op->cond.else_value
   && VECTOR_TYPE_P (res_op->type)
   && gimple_simplified_result_is_gimple_val (res_op))
 {
@@ -314,7 +318,7 @@ maybe_resimplify_conditional_op (gimple_seq *seq, 
gimple_match_op *res_op,
   return gimple_resimplify3 (seq, res_op, valueize);
 }
 
-  /* Otherwise try rewriting the operation as an IFN_COND_* call.
+  /* Otherwise try rewriting the operation as an IFN_COND_(LEN_)* call.
  Again, this isn't a simplification in itself, since it's what
  RES_OP already described.  */
   if (convert_conditional_op (res_op, _op))
-- 
2.41.0



Re: Re: [PATCH V3] Support folding min(poly,poly) to const

2023-09-08 Thread 钟居哲
Thanks Richard.
LGTM again from RISC-V side :).



juzhe.zh...@rivai.ai
 
From: Richard Sandiford
Date: 2023-09-08 16:56
To: Lehua Ding
CC: gcc-patches; juzhe.zhong
Subject: Re: [PATCH V3] Support folding min(poly,poly) to const
Lehua Ding  writes:
> V3 change: Address Richard's comments.
>
> Hi,
>
> This patch adds support that tries to fold `MIN (poly, poly)` to
> a constant. Consider the following C Code:
>
> ```
> void foo2 (int* restrict a, int* restrict b, int n)
> {
> for (int i = 0; i < 3; i += 1)
>   a[i] += b[i];
> }
> ```
>
> Before this patch:
>
> ```
> void foo2 (int * restrict a, int * restrict b, int n)
> {
>   vector([4,4]) int vect__7.27;
>   vector([4,4]) int vect__6.26;
>   vector([4,4]) int vect__4.23;
>   unsigned long _32;
>
>[local count: 268435456]:
>   _32 = MIN_EXPR <3, POLY_INT_CST [4, 4]>;
>   vect__4.23_20 = .MASK_LEN_LOAD (a_11(D), 32B, { -1, ... }, _32, 0);
>   vect__6.26_15 = .MASK_LEN_LOAD (b_12(D), 32B, { -1, ... }, _32, 0);
>   vect__7.27_9 = vect__6.26_15 + vect__4.23_20;
>   .MASK_LEN_STORE (a_11(D), 32B, { -1, ... }, _32, 0, vect__7.27_9); [tail 
> call]
>   return;
>
> }
> ```
>
> After this patch:
>
> ```
> void foo2 (int * restrict a, int * restrict b, int n)
> {
>   vector([4,4]) int vect__7.27;
>   vector([4,4]) int vect__6.26;
>   vector([4,4]) int vect__4.23;
>
>[local count: 268435456]:
>   vect__4.23_20 = .MASK_LEN_LOAD (a_11(D), 32B, { -1, ... }, 3, 0);
>   vect__6.26_15 = .MASK_LEN_LOAD (b_12(D), 32B, { -1, ... }, 3, 0);
>   vect__7.27_9 = vect__6.26_15 + vect__4.23_20;
>   .MASK_LEN_STORE (a_11(D), 32B, { -1, ... }, 3, 0, vect__7.27_9); [tail call]
>   return;
>
> }
> ```
>
> For RISC-V RVV, csrr and branch instructions can be reduced:
>
> Before this patch:
>
> ```
> foo2:
> csrra4,vlenb
> srlia4,a4,2
> li  a5,3
> bleua5,a4,.L5
> mv  a5,a4
> .L5:
> vsetvli zero,a5,e32,m1,ta,ma
> ...
> ```
>
> After this patch.
>
> ```
> foo2:
> vsetivli zero,3,e32,m1,ta,ma
> ...
> ```
>
> Best,
> Lehua
>
> gcc/ChangeLog:
>
> * fold-const.cc (can_min_p): New function.
> (poly_int_binop): Try fold MIN_EXPR.
 
OK, thanks.
 
Richard
 
> gcc/testsuite/ChangeLog:
>
> * gcc.target/riscv/rvv/autovec/vls/div-1.c: Adjust.
> * gcc.target/riscv/rvv/autovec/vls/shift-3.c: Adjust.
> * gcc.target/riscv/rvv/autovec/fold-min-poly.c: New test.
>
> ---
>  gcc/fold-const.cc | 24 +++
>  .../riscv/rvv/autovec/fold-min-poly.c | 24 +++
>  .../gcc.target/riscv/rvv/autovec/vls/div-1.c  |  2 +-
>  .../riscv/rvv/autovec/vls/shift-3.c   |  2 +-
>  4 files changed, 50 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c
>
> diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
> index 1da498a3152..d19b4666c65 100644
> --- a/gcc/fold-const.cc
> +++ b/gcc/fold-const.cc
> @@ -1213,6 +1213,25 @@ wide_int_binop (wide_int ,
>return true;
>  }
>  
> +/* Returns true if we know who is smaller or equal, ARG1 or ARG2, and set the
> +   min value to RES.  */
> +bool
> +can_min_p (const_tree arg1, const_tree arg2, poly_wide_int )
> +{
> +  if (known_le (wi::to_poly_widest (arg1), wi::to_poly_widest (arg2)))
> +{
> +  res = wi::to_poly_wide (arg1);
> +  return true;
> +}
> +  else if (known_le (wi::to_poly_widest (arg2), wi::to_poly_widest (arg1)))
> +{
> +  res = wi::to_poly_wide (arg2);
> +  return true;
> +}
> +
> +  return false;
> +}
> +
>  /* Combine two poly int's ARG1 and ARG2 under operation CODE to
> produce a new constant in RES.  Return FALSE if we don't know how
> to evaluate CODE at compile-time.  */
> @@ -1261,6 +1280,11 @@ poly_int_binop (poly_wide_int , enum tree_code 
> code,
>  return false;
>break;
>  
> +case MIN_EXPR:
> +  if (!can_min_p (arg1, arg2, res))
> + return false;
> +  break;
> +
>  default:
>return false;
>  }
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c 
> b/gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c
> new file mode 100644
> index 000..de4c472c76e
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c
> @@ -0,0 +1,24 @@
> +/* { dg-do compile } */
> +/* { dg-options " -march=rv64gcv_zvl128b -mabi=lp64d -O3 --param 
> riscv-autovec-preference=scalable --param riscv-autovec-lmul=m1 
> -fno-vect-cost-model" } */
> +
> +void foo1 (int* restrict a, int* restrict b, int n)
> +{
> +for (int i = 0; i < 4; i += 1)
> +  a[i] += b[i];
> +}
> +
> +void foo2 (int* restrict a, int* restrict b, int n)
> +{
> +for (int i = 0; i < 3; i += 1)
> +  a[i] += b[i];
> +}
> +
> +void foo3 (int* restrict a, int* restrict b, int n)
> +{
> +for (int i = 0; i < 5; i += 1)
> +  a[i] += b[i];
> +}
> +
> +/* { dg-final { scan-assembler-not {\tcsrr\t} } } */
> +/* { dg-final { scan-assembler 

Re: [PATCH V3] Support folding min(poly,poly) to const

2023-09-08 Thread Richard Sandiford via Gcc-patches
Lehua Ding  writes:
> V3 change: Address Richard's comments.
>
> Hi,
>
> This patch adds support that tries to fold `MIN (poly, poly)` to
> a constant. Consider the following C Code:
>
> ```
> void foo2 (int* restrict a, int* restrict b, int n)
> {
> for (int i = 0; i < 3; i += 1)
>   a[i] += b[i];
> }
> ```
>
> Before this patch:
>
> ```
> void foo2 (int * restrict a, int * restrict b, int n)
> {
>   vector([4,4]) int vect__7.27;
>   vector([4,4]) int vect__6.26;
>   vector([4,4]) int vect__4.23;
>   unsigned long _32;
>
>[local count: 268435456]:
>   _32 = MIN_EXPR <3, POLY_INT_CST [4, 4]>;
>   vect__4.23_20 = .MASK_LEN_LOAD (a_11(D), 32B, { -1, ... }, _32, 0);
>   vect__6.26_15 = .MASK_LEN_LOAD (b_12(D), 32B, { -1, ... }, _32, 0);
>   vect__7.27_9 = vect__6.26_15 + vect__4.23_20;
>   .MASK_LEN_STORE (a_11(D), 32B, { -1, ... }, _32, 0, vect__7.27_9); [tail 
> call]
>   return;
>
> }
> ```
>
> After this patch:
>
> ```
> void foo2 (int * restrict a, int * restrict b, int n)
> {
>   vector([4,4]) int vect__7.27;
>   vector([4,4]) int vect__6.26;
>   vector([4,4]) int vect__4.23;
>
>[local count: 268435456]:
>   vect__4.23_20 = .MASK_LEN_LOAD (a_11(D), 32B, { -1, ... }, 3, 0);
>   vect__6.26_15 = .MASK_LEN_LOAD (b_12(D), 32B, { -1, ... }, 3, 0);
>   vect__7.27_9 = vect__6.26_15 + vect__4.23_20;
>   .MASK_LEN_STORE (a_11(D), 32B, { -1, ... }, 3, 0, vect__7.27_9); [tail call]
>   return;
>
> }
> ```
>
> For RISC-V RVV, csrr and branch instructions can be reduced:
>
> Before this patch:
>
> ```
> foo2:
> csrra4,vlenb
> srlia4,a4,2
> li  a5,3
> bleua5,a4,.L5
> mv  a5,a4
> .L5:
> vsetvli zero,a5,e32,m1,ta,ma
> ...
> ```
>
> After this patch.
>
> ```
> foo2:
>   vsetivlizero,3,e32,m1,ta,ma
> ...
> ```
>
> Best,
> Lehua
>
> gcc/ChangeLog:
>
>   * fold-const.cc (can_min_p): New function.
>   (poly_int_binop): Try fold MIN_EXPR.

OK, thanks.

Richard

> gcc/testsuite/ChangeLog:
>
>   * gcc.target/riscv/rvv/autovec/vls/div-1.c: Adjust.
>   * gcc.target/riscv/rvv/autovec/vls/shift-3.c: Adjust.
>   * gcc.target/riscv/rvv/autovec/fold-min-poly.c: New test.
>
> ---
>  gcc/fold-const.cc | 24 +++
>  .../riscv/rvv/autovec/fold-min-poly.c | 24 +++
>  .../gcc.target/riscv/rvv/autovec/vls/div-1.c  |  2 +-
>  .../riscv/rvv/autovec/vls/shift-3.c   |  2 +-
>  4 files changed, 50 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c
>
> diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
> index 1da498a3152..d19b4666c65 100644
> --- a/gcc/fold-const.cc
> +++ b/gcc/fold-const.cc
> @@ -1213,6 +1213,25 @@ wide_int_binop (wide_int ,
>return true;
>  }
>  
> +/* Returns true if we know who is smaller or equal, ARG1 or ARG2, and set the
> +   min value to RES.  */
> +bool
> +can_min_p (const_tree arg1, const_tree arg2, poly_wide_int )
> +{
> +  if (known_le (wi::to_poly_widest (arg1), wi::to_poly_widest (arg2)))
> +{
> +  res = wi::to_poly_wide (arg1);
> +  return true;
> +}
> +  else if (known_le (wi::to_poly_widest (arg2), wi::to_poly_widest (arg1)))
> +{
> +  res = wi::to_poly_wide (arg2);
> +  return true;
> +}
> +
> +  return false;
> +}
> +
>  /* Combine two poly int's ARG1 and ARG2 under operation CODE to
> produce a new constant in RES.  Return FALSE if we don't know how
> to evaluate CODE at compile-time.  */
> @@ -1261,6 +1280,11 @@ poly_int_binop (poly_wide_int , enum tree_code 
> code,
>   return false;
>break;
>  
> +case MIN_EXPR:
> +  if (!can_min_p (arg1, arg2, res))
> + return false;
> +  break;
> +
>  default:
>return false;
>  }
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c 
> b/gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c
> new file mode 100644
> index 000..de4c472c76e
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c
> @@ -0,0 +1,24 @@
> +/* { dg-do compile } */
> +/* { dg-options " -march=rv64gcv_zvl128b -mabi=lp64d -O3 --param 
> riscv-autovec-preference=scalable --param riscv-autovec-lmul=m1 
> -fno-vect-cost-model" } */
> +
> +void foo1 (int* restrict a, int* restrict b, int n)
> +{
> +for (int i = 0; i < 4; i += 1)
> +  a[i] += b[i];
> +}
> +
> +void foo2 (int* restrict a, int* restrict b, int n)
> +{
> +for (int i = 0; i < 3; i += 1)
> +  a[i] += b[i];
> +}
> +
> +void foo3 (int* restrict a, int* restrict b, int n)
> +{
> +for (int i = 0; i < 5; i += 1)
> +  a[i] += b[i];
> +}
> +
> +/* { dg-final { scan-assembler-not {\tcsrr\t} } } */
> +/* { dg-final { scan-assembler {\tvsetivli\tzero,4,e32,m1,t[au],m[au]} } } */
> +/* { dg-final { scan-assembler {\tvsetivli\tzero,3,e32,m1,t[au],m[au]} } } */
> diff --git 

[PATCH V3] Support folding min(poly,poly) to const

2023-09-08 Thread Lehua Ding
V3 change: Address Richard's comments.

Hi,

This patch adds support that tries to fold `MIN (poly, poly)` to
a constant. Consider the following C Code:

```
void foo2 (int* restrict a, int* restrict b, int n)
{
for (int i = 0; i < 3; i += 1)
  a[i] += b[i];
}
```

Before this patch:

```
void foo2 (int * restrict a, int * restrict b, int n)
{
  vector([4,4]) int vect__7.27;
  vector([4,4]) int vect__6.26;
  vector([4,4]) int vect__4.23;
  unsigned long _32;

   [local count: 268435456]:
  _32 = MIN_EXPR <3, POLY_INT_CST [4, 4]>;
  vect__4.23_20 = .MASK_LEN_LOAD (a_11(D), 32B, { -1, ... }, _32, 0);
  vect__6.26_15 = .MASK_LEN_LOAD (b_12(D), 32B, { -1, ... }, _32, 0);
  vect__7.27_9 = vect__6.26_15 + vect__4.23_20;
  .MASK_LEN_STORE (a_11(D), 32B, { -1, ... }, _32, 0, vect__7.27_9); [tail call]
  return;

}
```

After this patch:

```
void foo2 (int * restrict a, int * restrict b, int n)
{
  vector([4,4]) int vect__7.27;
  vector([4,4]) int vect__6.26;
  vector([4,4]) int vect__4.23;

   [local count: 268435456]:
  vect__4.23_20 = .MASK_LEN_LOAD (a_11(D), 32B, { -1, ... }, 3, 0);
  vect__6.26_15 = .MASK_LEN_LOAD (b_12(D), 32B, { -1, ... }, 3, 0);
  vect__7.27_9 = vect__6.26_15 + vect__4.23_20;
  .MASK_LEN_STORE (a_11(D), 32B, { -1, ... }, 3, 0, vect__7.27_9); [tail call]
  return;

}
```

For RISC-V RVV, csrr and branch instructions can be reduced:

Before this patch:

```
foo2:
csrra4,vlenb
srlia4,a4,2
li  a5,3
bleua5,a4,.L5
mv  a5,a4
.L5:
vsetvli zero,a5,e32,m1,ta,ma
...
```

After this patch.

```
foo2:
vsetivlizero,3,e32,m1,ta,ma
...
```

Best,
Lehua

gcc/ChangeLog:

* fold-const.cc (can_min_p): New function.
(poly_int_binop): Try fold MIN_EXPR.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vls/div-1.c: Adjust.
* gcc.target/riscv/rvv/autovec/vls/shift-3.c: Adjust.
* gcc.target/riscv/rvv/autovec/fold-min-poly.c: New test.

---
 gcc/fold-const.cc | 24 +++
 .../riscv/rvv/autovec/fold-min-poly.c | 24 +++
 .../gcc.target/riscv/rvv/autovec/vls/div-1.c  |  2 +-
 .../riscv/rvv/autovec/vls/shift-3.c   |  2 +-
 4 files changed, 50 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c

diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 1da498a3152..d19b4666c65 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -1213,6 +1213,25 @@ wide_int_binop (wide_int ,
   return true;
 }
 
+/* Returns true if we know who is smaller or equal, ARG1 or ARG2, and set the
+   min value to RES.  */
+bool
+can_min_p (const_tree arg1, const_tree arg2, poly_wide_int )
+{
+  if (known_le (wi::to_poly_widest (arg1), wi::to_poly_widest (arg2)))
+{
+  res = wi::to_poly_wide (arg1);
+  return true;
+}
+  else if (known_le (wi::to_poly_widest (arg2), wi::to_poly_widest (arg1)))
+{
+  res = wi::to_poly_wide (arg2);
+  return true;
+}
+
+  return false;
+}
+
 /* Combine two poly int's ARG1 and ARG2 under operation CODE to
produce a new constant in RES.  Return FALSE if we don't know how
to evaluate CODE at compile-time.  */
@@ -1261,6 +1280,11 @@ poly_int_binop (poly_wide_int , enum tree_code code,
return false;
   break;
 
+case MIN_EXPR:
+  if (!can_min_p (arg1, arg2, res))
+   return false;
+  break;
+
 default:
   return false;
 }
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c
new file mode 100644
index 000..de4c472c76e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-options " -march=rv64gcv_zvl128b -mabi=lp64d -O3 --param 
riscv-autovec-preference=scalable --param riscv-autovec-lmul=m1 
-fno-vect-cost-model" } */
+
+void foo1 (int* restrict a, int* restrict b, int n)
+{
+for (int i = 0; i < 4; i += 1)
+  a[i] += b[i];
+}
+
+void foo2 (int* restrict a, int* restrict b, int n)
+{
+for (int i = 0; i < 3; i += 1)
+  a[i] += b[i];
+}
+
+void foo3 (int* restrict a, int* restrict b, int n)
+{
+for (int i = 0; i < 5; i += 1)
+  a[i] += b[i];
+}
+
+/* { dg-final { scan-assembler-not {\tcsrr\t} } } */
+/* { dg-final { scan-assembler {\tvsetivli\tzero,4,e32,m1,t[au],m[au]} } } */
+/* { dg-final { scan-assembler {\tvsetivli\tzero,3,e32,m1,t[au],m[au]} } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/div-1.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/div-1.c
index f3388a86e38..40224c69458 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/div-1.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/div-1.c
@@ -55,4 +55,4 @@ DEF_OP_VV (div, 512, int64_t, /)
 
 /* { dg-final { scan-assembler-times 
{vdivu?\.vv\s+v[0-9]+,\s*v[0-9]+,\s*v[0-9]+} 42 

[PATCH] xtensa: Optimize several boolean evaluations of EQ/NE against constant zero

2023-09-08 Thread Takayuki 'January June' Suwa via Gcc-patches
An idiomatic implementation of boolean evaluation of whether a register is
zero or not in Xtensa is to assign 0 and 1 to the temporary and destination,
and then issue the MOV[EQ/NE]Z machine instruction
(See 8.3.2 Instruction Idioms, Xtensa ISA refman., p.599):

;; A2 = (A3 != 0) ? 1 : 0;
movi.n  a9, 1
movi.n  a2, 0
movnez  a2, a9, a3  ;; if (A3 != 0) A2 = A9;

As you can see in the above idiom, if the source and destination are the
same register, a move instruction from the source to another temporary
register must be prepended:

;; A2 = (A2 == 0) ? 1 : 0;
mov.n   a10, a2
movi.n  a9, 1
movi.n  a2, 0
moveqz  a2, a9, a10  ;; if (A10 == 0) A2 = A9;

Fortunately, we can reduce the number of instructions and temporary
registers with a few tweaks:

;; A2 = (A3 != 0) ? 1 : 0;
movi.n  a2, 1
moveqz  a2, a3, a3  ;; if (A3 == 0) A2 = A3;

;; A2 = (A2 != 0) ? 1 : 0;
movi.n  a9, 1
movnez  a2, a9, a2  ;; if (A2 != 0) A2 = A9;

;; A2 = (A3 == 0) ? 1 : 0;
movi.n  a2, -1
moveqz  a2, a3, a3  ;; if (A3 == 0) A2 = A3;
addi.n  a2, a2, 1

;; A2 = (A2 == 0) ? 1 : 0;
movi.n  a9, -1
movnez  a2, a9, a2  ;; if (A2 != 0) A2 = A9;
addi.n  a2, a2, 1

Additionally, if TARGET_NSA is configured, the fact that it returns 32 iff
the source of the NSAU machine instruction is 0, otherwise less than, can be
used in boolean evaluation of EQ comparison.

;; A2 = (A3 == 0) ? 1 : 0;
nsaua2, a3  ;; Source and destination can be the same register
srlia2, a2, 5

Furthermore, this patch also saves one instruction when determining whether
the ANDing with mask values in which 1s are lined up from the upper or lower
bit end (for example, 0xFFE0 or 0x003F) is 0 or not.

gcc/ChangeLog:

* config/xtensa/xtensa.cc (xtensa_expand_scc):
Revert the changes from the last patch, as the work in the RTL
expansion pass is too far to determine the physical registers.
* config/xtensa/xtensa.md (*eqne_INT_MIN): Ditto.
(eq_zero_NSA, eqne_zero, *eqne_zero_masked_bits): New patterns.
---
 gcc/config/xtensa/xtensa.cc |  35 +--
 gcc/config/xtensa/xtensa.md | 112 
 2 files changed, 113 insertions(+), 34 deletions(-)

diff --git a/gcc/config/xtensa/xtensa.cc b/gcc/config/xtensa/xtensa.cc
index 1afaa1cc94e..2481b028ca1 100644
--- a/gcc/config/xtensa/xtensa.cc
+++ b/gcc/config/xtensa/xtensa.cc
@@ -994,41 +994,8 @@ xtensa_expand_scc (rtx operands[4], machine_mode cmp_mode)
   rtx cmp;
   rtx one_tmp, zero_tmp;
   rtx (*gen_fn) (rtx, rtx, rtx, rtx, rtx);
-  enum rtx_code code = GET_CODE (operands[1]);
 
-  if (cmp_mode == SImode && CONST_INT_P (operands[3])
-  && (code == EQ || code == NE))
-switch (INTVAL (operands[3]))
-  {
-  case 0:
-   if (TARGET_MINMAX)
- {
-   one_tmp = force_reg (SImode, const1_rtx);
-   emit_insn (gen_uminsi3 (dest, operands[2], one_tmp));
-   if (code == EQ)
- emit_insn (gen_xorsi3 (dest, dest, one_tmp));
-   return 1;
- }
-   break;
-  case -2147483648:
-   if (TARGET_ABS)
- {
-   emit_insn (gen_abssi2 (dest, operands[2]));
-   if (code == EQ)
- emit_insn (gen_lshrsi3 (dest, dest, GEN_INT (31)));
-   else
- {
-   emit_insn (gen_ashrsi3 (dest, dest, GEN_INT (31)));
-   emit_insn (gen_addsi3 (dest, dest, const1_rtx));
- }
-   return 1;
- }
-   break;
-  default:
-   break;
-  }
-
-  if (! (cmp = gen_conditional_move (code, cmp_mode,
+  if (! (cmp = gen_conditional_move (GET_CODE (operands[1]), cmp_mode,
 operands[2], operands[3])))
 return 0;
 
diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md
index d6505e7eb70..6476fdc395a 100644
--- a/gcc/config/xtensa/xtensa.md
+++ b/gcc/config/xtensa/xtensa.md
@@ -3188,6 +3188,118 @@
  (const_int 5)
  (const_int 6)))])
 
+(define_insn_and_split "eq_zero_NSA"
+  [(set (match_operand:SI 0 "register_operand" "=a")
+   (eq:SI (match_operand:SI 1 "register_operand" "r")
+  (const_int 0)))]
+  "TARGET_NSA"
+  "#"
+  "&& 1"
+  [(set (match_dup 0)
+   (clz:SI (match_dup 1)))
+   (set (match_dup 0)
+   (lshiftrt:SI (match_dup 0)
+(const_int 5)))]
+  ""
+  [(set_attr "type""move")
+   (set_attr "mode""SI")
+   (set_attr "length"  "6")])
+
+(define_insn_and_split "eqne_zero"
+  [(set (match_operand:SI 0 "register_operand" "=a,")
+   (match_operator:SI 2 "boolean_operator"
+   [(match_operand:SI 1 "register_operand" "0,r")
+(const_int 0)]))
+   (clobber (match_scratch:SI 3 "=,X"))]
+  ""
+  "#"
+  "&& reload_completed"
+  [(const_int 0)]
+{
+  enum rtx_code code = GET_CODE 

Re: [PATCH V2] Support folding min(poly,poly) to const

2023-09-08 Thread Lehua Ding
Sorry, just realised that the poly_int_tree_p tests are redundant. The 
caller has already checked that.


Indeed, I will removed poly_int_tree_p tests like the following code. 
Thanks for timely remind.


/* Returns true if we know who is smaller or equal, ARG1 or ARG2, and 
set the

   min value to RES.  */
bool
can_min_p (const_tree arg1, const_tree arg2, poly_wide_int )
{
  if (known_le (wi::to_poly_widest (arg1), wi::to_poly_widest (arg2)))
{
  res = wi::to_poly_wide (arg1);
  return true;
}
  else if (known_le (wi::to_poly_widest (arg2), wi::to_poly_widest (arg1)))
{
  res = wi::to_poly_wide (arg2);
  return true;
}

  return false;
}

--
Best,
Lehua



[PATCH] testsuite: Fix gcc.target/arm/mve/mve_vadcq_vsbcq_fpscr_overwrite.c

2023-09-08 Thread Christophe Lyon via Gcc-patches
The test was declaring 'int *carry;' and wrote to '*carry' without
initializing 'carry' first, leading to an attempt to write at address
zero, and a crash.

Fix by declaring 'int carry;' and passing '' instead of 'carry'
as parameter.

2023-09-08  Christophe Lyon  

gcc/testsuite/
* gcc.target/arm/mve/mve_vadcq_vsbcq_fpscr_overwrite.c: Fix.
---
 .../arm/mve/mve_vadcq_vsbcq_fpscr_overwrite.c | 34 +--
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/gcc/testsuite/gcc.target/arm/mve/mve_vadcq_vsbcq_fpscr_overwrite.c 
b/gcc/testsuite/gcc.target/arm/mve/mve_vadcq_vsbcq_fpscr_overwrite.c
index a8c6cce67c8..931c9d2f30b 100644
--- a/gcc/testsuite/gcc.target/arm/mve/mve_vadcq_vsbcq_fpscr_overwrite.c
+++ b/gcc/testsuite/gcc.target/arm/mve/mve_vadcq_vsbcq_fpscr_overwrite.c
@@ -7,7 +7,7 @@
 
 volatile int32x4_t c1;
 volatile uint32x4_t c2;
-int *carry;
+int carry;
 
 int
 main ()
@@ -21,45 +21,45 @@ main ()
   uint32x4_t inactive2 = vcreateq_u32 (0, 0);
 
   mve_pred16_t p = 0x;
-  (*carry) = 0x;
+  carry = 0x;
 
   __builtin_arm_set_fpscr_nzcvqc (0);
-  c1 = vadcq (a1, b1, carry);
+  c1 = vadcq (a1, b1, );
   if (__builtin_arm_get_fpscr_nzcvqc () & !0x2000)
 __builtin_abort ();
-  (*carry) = 0x;
+  carry = 0x;
   __builtin_arm_set_fpscr_nzcvqc (0);
-  c2 = vadcq (a2, b2, carry);
+  c2 = vadcq (a2, b2, );
   if (__builtin_arm_get_fpscr_nzcvqc () & !0x2000)
 __builtin_abort ();
-  (*carry) = 0x;
+  carry = 0x;
   __builtin_arm_set_fpscr_nzcvqc (0);
-  c1 = vsbcq (a1, b1, carry);
+  c1 = vsbcq (a1, b1, );
   if (__builtin_arm_get_fpscr_nzcvqc () & !0x2000)
 __builtin_abort ();
-  (*carry) = 0x;
+  carry = 0x;
   __builtin_arm_set_fpscr_nzcvqc (0);
-  c2 = vsbcq (a2, b2, carry);
+  c2 = vsbcq (a2, b2, );
   if (__builtin_arm_get_fpscr_nzcvqc () & !0x2000)
 __builtin_abort ();
-  (*carry) = 0x;
+  carry = 0x;
   __builtin_arm_set_fpscr_nzcvqc (0);
-  c1 = vadcq_m (inactive1, a1, b1, carry, p);
+  c1 = vadcq_m (inactive1, a1, b1, , p);
   if (__builtin_arm_get_fpscr_nzcvqc () & !0x2000)
 __builtin_abort ();
-  (*carry) = 0x;
+  carry = 0x;
   __builtin_arm_set_fpscr_nzcvqc (0);
-  c2 = vadcq_m (inactive2, a2, b2, carry, p);
+  c2 = vadcq_m (inactive2, a2, b2, , p);
   if (__builtin_arm_get_fpscr_nzcvqc () & !0x2000)
 __builtin_abort ();
-  (*carry) = 0x;
+  carry = 0x;
   __builtin_arm_set_fpscr_nzcvqc (0);
-  c1 = vsbcq_m (inactive1, a1, b1, carry, p);
+  c1 = vsbcq_m (inactive1, a1, b1, , p);
   if (__builtin_arm_get_fpscr_nzcvqc () & !0x2000)
 __builtin_abort ();
-  (*carry) = 0x;
+  carry = 0x;
   __builtin_arm_set_fpscr_nzcvqc (0);
-  c2 = vsbcq_m (inactive2, a2, b2, carry, p);
+  c2 = vsbcq_m (inactive2, a2, b2, , p);
   if (__builtin_arm_get_fpscr_nzcvqc () & !0x2000)
 __builtin_abort ();
 
-- 
2.34.1



Re: [Patch] contrib/gcc-changelog: Check whether revert-commit exists

2023-09-08 Thread Jakub Jelinek via Gcc-patches
On Fri, Sep 08, 2023 at 10:25:42AM +0200, Christophe Lyon wrote:
> Revert "libstdc++: Use GLIBCXX_CHECK_LINKER_FEATURES for cross-builds
> (PR111238)"
> 
> diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
> index 8f7b01e0563..0c60149d7f6 100644
> --- a/libstdc++-v3/ChangeLog
> +++ b/libstdc++-v3/ChangeLog
> @@ -4,6 +4,16 @@
> for freestanding.
> * configure: Regenerate.
> 
> +2023-09-04  Christophe Lyon  
> +
> +   Revert
> +   2023-09-04  Christophe Lyon  
> +
> +   PR libstdc++/111238
> +   * configure: Regenerate.
> +   * configure.ac: Call GLIBCXX_CHECK_LINKER_FEATURES in cross,
> +   non-Canadian builds.
> +
>  2023-09-04  Christophe Lyon  
> 
> PR libstdc++/111238
> 
> I inserted my "Revert"  ChangeLog entry between the entry I want to declare
> reverted and Jonathan's more recent patch about GLIBCXX_ENABLE_BACKTRACE.
> Is that OK for the commit hooks?

Yes, thanks.

Jakub



Re: [PATCH] LoongArch: Enable -fsched-pressure by default at -O1 and higher.

2023-09-08 Thread Xi Ruoyao via Gcc-patches
On Fri, 2023-09-08 at 16:29 +0800, Guo Jie wrote:
> Hi,
> 
> What I wanna change is "gcc/common/config/loongarch/loongarch-
> common.cc",
> 
> and the patch is automatically generated by "git gcc-commit-mklog".
> 
> Is it necessary to  to remove "common/" ?

My bad.  I didn't realized the file has been moved to common.

Don't change it :(.

> Thanks for the review.
> 
> 
> 在 2023/9/8 下午4:06, Xi Ruoyao 写道:
> > On Fri, 2023-09-08 at 10:00 +0800, Guo Jie wrote:
> > > gcc/ChangeLog:
> > > 
> > >  * common/config/loongarch/loongarch-common.cc:
> > "common/" should be removed.  You can use "git gcc-verify" to figure
> > out
> > this kind of error before sending a patch in the future.
> > 
> > >  (default_options loongarch_option_optimization_table):
> > >  Default to -fsched-pressure.
> > "Default to -fsched-pressure at -O1 or above."
> > 
> > Otherwise OK.
> > 
> > > ---
> > >   gcc/common/config/loongarch/loongarch-common.cc | 1 +
> > >   1 file changed, 1 insertion(+)
> > > 
> > > diff --git a/gcc/common/config/loongarch/loongarch-common.cc
> > > b/gcc/common/config/loongarch/loongarch-common.cc
> > > index c5ed37d27a6..b6901910b70 100644
> > > --- a/gcc/common/config/loongarch/loongarch-common.cc
> > > +++ b/gcc/common/config/loongarch/loongarch-common.cc
> > > @@ -36,6 +36,7 @@ static const struct default_options
> > > loongarch_option_optimization_table[] =
> > >     { OPT_LEVELS_ALL, OPT_fasynchronous_unwind_tables, NULL, 1 },
> > >     { OPT_LEVELS_1_PLUS, OPT_fsection_anchors, NULL, 1 },
> > >     { OPT_LEVELS_2_PLUS, OPT_free, NULL, 1 },
> > > +  { OPT_LEVELS_1_PLUS, OPT_fsched_pressure, NULL, 1 },
> > >     { OPT_LEVELS_NONE, 0, NULL, 0 }
> > >   };
> > >   
> 

-- 
Xi Ruoyao 
School of Aerospace Science and Technology, Xidian University


Re: [PATCH V2] Support folding min(poly,poly) to const

2023-09-08 Thread Richard Sandiford via Gcc-patches
Richard Sandiford  writes:
> Lehua Ding  writes:
>> Hi,
>>
>> This patch adds support that tries to fold `MIN (poly, poly)` to
>> a constant. Consider the following C Code:
>>
>> ```
>> void foo2 (int* restrict a, int* restrict b, int n)
>> {
>> for (int i = 0; i < 3; i += 1)
>>   a[i] += b[i];
>> }
>> ```
>>
>> Before this patch:
>>
>> ```
>> void foo2 (int * restrict a, int * restrict b, int n)
>> {
>>   vector([4,4]) int vect__7.27;
>>   vector([4,4]) int vect__6.26;
>>   vector([4,4]) int vect__4.23;
>>   unsigned long _32;
>>
>>[local count: 268435456]:
>>   _32 = MIN_EXPR <3, POLY_INT_CST [4, 4]>;
>>   vect__4.23_20 = .MASK_LEN_LOAD (a_11(D), 32B, { -1, ... }, _32, 0);
>>   vect__6.26_15 = .MASK_LEN_LOAD (b_12(D), 32B, { -1, ... }, _32, 0);
>>   vect__7.27_9 = vect__6.26_15 + vect__4.23_20;
>>   .MASK_LEN_STORE (a_11(D), 32B, { -1, ... }, _32, 0, vect__7.27_9); [tail 
>> call]
>>   return;
>>
>> }
>> ```
>>
>> After this patch:
>>
>> ```
>> void foo2 (int * restrict a, int * restrict b, int n)
>> {
>>   vector([4,4]) int vect__7.27;
>>   vector([4,4]) int vect__6.26;
>>   vector([4,4]) int vect__4.23;
>>
>>[local count: 268435456]:
>>   vect__4.23_20 = .MASK_LEN_LOAD (a_11(D), 32B, { -1, ... }, 3, 0);
>>   vect__6.26_15 = .MASK_LEN_LOAD (b_12(D), 32B, { -1, ... }, 3, 0);
>>   vect__7.27_9 = vect__6.26_15 + vect__4.23_20;
>>   .MASK_LEN_STORE (a_11(D), 32B, { -1, ... }, 3, 0, vect__7.27_9); [tail 
>> call]
>>   return;
>>
>> }
>> ```
>>
>> For RISC-V RVV, csrr and branch instructions can be reduced:
>>
>> Before this patch:
>>
>> ```
>> foo2:
>> csrra4,vlenb
>> srlia4,a4,2
>> li  a5,3
>> bleua5,a4,.L5
>> mv  a5,a4
>> .L5:
>> vsetvli zero,a5,e32,m1,ta,ma
>> ...
>> ```
>>
>> After this patch.
>>
>> ```
>> foo2:
>>  vsetivlizero,3,e32,m1,ta,ma
>> ...
>> ```
>>
>> Best,
>> Lehua
>>
>> gcc/ChangeLog:
>>
>>  * fold-const.cc (can_min_p): New function.
>>  (poly_int_binop): Try fold MIN_EXPR.
>
> OK, thanks.

Sorry, just realised that the poly_int_tree_p tests are redundant.
The caller has already checked that.

Richard

> Richard
>
>> gcc/testsuite/ChangeLog:
>>
>>  * gcc.target/riscv/rvv/autovec/vls/div-1.c: Adjust.
>>  * gcc.target/riscv/rvv/autovec/vls/shift-3.c: Adjust.
>>  * gcc.target/riscv/rvv/autovec/fold-min-poly.c: New test.
>>
>> ---
>>  gcc/fold-const.cc | 27 +++
>>  .../riscv/rvv/autovec/fold-min-poly.c | 24 +
>>  .../gcc.target/riscv/rvv/autovec/vls/div-1.c  |  2 +-
>>  .../riscv/rvv/autovec/vls/shift-3.c   |  2 +-
>>  4 files changed, 53 insertions(+), 2 deletions(-)
>>  create mode 100644 
>> gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c
>>
>> diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
>> index 1da498a3152..ba4b6f3f3a3 100644
>> --- a/gcc/fold-const.cc
>> +++ b/gcc/fold-const.cc
>> @@ -1213,6 +1213,28 @@ wide_int_binop (wide_int ,
>>return true;
>>  }
>>  
>> +/* Returns true if we know who is smaller or equal, ARG1 or ARG2, and set 
>> the
>> +   min value to RES.  */
>> +bool
>> +can_min_p (const_tree arg1, const_tree arg2, poly_wide_int )
>> +{
>> +  if (!poly_int_tree_p (arg1) || !poly_int_tree_p (arg2))
>> +return false;
>> +
>> +  if (known_le (wi::to_poly_widest (arg1), wi::to_poly_widest (arg2)))
>> +{
>> +  res = wi::to_poly_wide (arg1);
>> +  return true;
>> +}
>> +  else if (known_le (wi::to_poly_widest (arg2), wi::to_poly_widest (arg1)))
>> +{
>> +  res = wi::to_poly_wide (arg2);
>> +  return true;
>> +}
>> +
>> +  return false;
>> +}
>> +
>>  /* Combine two poly int's ARG1 and ARG2 under operation CODE to
>> produce a new constant in RES.  Return FALSE if we don't know how
>> to evaluate CODE at compile-time.  */
>> @@ -1261,6 +1283,11 @@ poly_int_binop (poly_wide_int , enum tree_code 
>> code,
>>  return false;
>>break;
>>  
>> +case MIN_EXPR:
>> +  if (!can_min_p (arg1, arg2, res))
>> +return false;
>> +  break;
>> +
>>  default:
>>return false;
>>  }
>> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c 
>> b/gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c
>> new file mode 100644
>> index 000..de4c472c76e
>> --- /dev/null
>> +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c
>> @@ -0,0 +1,24 @@
>> +/* { dg-do compile } */
>> +/* { dg-options " -march=rv64gcv_zvl128b -mabi=lp64d -O3 --param 
>> riscv-autovec-preference=scalable --param riscv-autovec-lmul=m1 
>> -fno-vect-cost-model" } */
>> +
>> +void foo1 (int* restrict a, int* restrict b, int n)
>> +{
>> +for (int i = 0; i < 4; i += 1)
>> +  a[i] += b[i];
>> +}
>> +
>> +void foo2 (int* restrict a, int* restrict b, int n)
>> +{
>> +for (int i = 0; i < 3; i += 1)
>> +  a[i] += b[i];
>> +}
>> +
>> +void foo3 (int* restrict a, int* restrict b, 

RE: [PATCH] RISC-V: Suppress bogus warning for VLS types

2023-09-08 Thread Li, Pan2 via Gcc-patches
Committed, thanks Kito.

Pan

-Original Message-
From: Gcc-patches  On Behalf 
Of Kito Cheng via Gcc-patches
Sent: Friday, September 8, 2023 4:27 PM
To: Juzhe-Zhong 
Cc: GCC Patches ; Kito Cheng 
Subject: Re: [PATCH] RISC-V: Suppress bogus warning for VLS types

LGTM

Juzhe-Zhong  於 2023年9月8日 週五 16:20 寫道:

> This patch fixes over 100+ bogus FAILs due to experimental vector ABI
> warning.
>
> gcc/ChangeLog:
>
> * config/riscv/riscv.cc (riscv_pass_in_vector_p): Only allow RVV
> type.
>
> ---
>  gcc/config/riscv/riscv.cc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
> index 9f0c8bbe9ed..81682d95ba4 100644
> --- a/gcc/config/riscv/riscv.cc
> +++ b/gcc/config/riscv/riscv.cc
> @@ -4414,7 +4414,7 @@ riscv_pass_in_vector_p (const_tree type)
>  {
>static int warned = 0;
>
> -  if (type && riscv_v_ext_mode_p (TYPE_MODE (type)) && !warned)
> +  if (type && riscv_vector::lookup_vector_type_attribute (type) &&
> !warned)
>  {
>warning (OPT_Wpsabi,
>"ABI for the vector type is currently in experimental stage
> and "
> --
> 2.36.3
>
>


Re: [PATCH] LoongArch: Enable -fsched-pressure by default at -O1 and higher.

2023-09-08 Thread Guo Jie

Hi,

What I wanna change is "gcc/common/config/loongarch/loongarch-common.cc",

and the patch is automatically generated by "git gcc-commit-mklog".

Is it necessary to  to remove "common/" ?

Thanks for the review.


在 2023/9/8 下午4:06, Xi Ruoyao 写道:

On Fri, 2023-09-08 at 10:00 +0800, Guo Jie wrote:

gcc/ChangeLog:

 * common/config/loongarch/loongarch-common.cc:

"common/" should be removed.  You can use "git gcc-verify" to figure out
this kind of error before sending a patch in the future.


 (default_options loongarch_option_optimization_table):
 Default to -fsched-pressure.

"Default to -fsched-pressure at -O1 or above."

Otherwise OK.


---
  gcc/common/config/loongarch/loongarch-common.cc | 1 +
  1 file changed, 1 insertion(+)

diff --git a/gcc/common/config/loongarch/loongarch-common.cc
b/gcc/common/config/loongarch/loongarch-common.cc
index c5ed37d27a6..b6901910b70 100644
--- a/gcc/common/config/loongarch/loongarch-common.cc
+++ b/gcc/common/config/loongarch/loongarch-common.cc
@@ -36,6 +36,7 @@ static const struct default_options
loongarch_option_optimization_table[] =
    { OPT_LEVELS_ALL, OPT_fasynchronous_unwind_tables, NULL, 1 },
    { OPT_LEVELS_1_PLUS, OPT_fsection_anchors, NULL, 1 },
    { OPT_LEVELS_2_PLUS, OPT_free, NULL, 1 },
+  { OPT_LEVELS_1_PLUS, OPT_fsched_pressure, NULL, 1 },
    { OPT_LEVELS_NONE, 0, NULL, 0 }
  };
  




Re: Re: [PATCH V2] Support folding min(poly,poly) to const

2023-09-08 Thread 钟居哲
Thanks Richard and Lehua.

LGTM from RISC-V side.



juzhe.zh...@rivai.ai
 
From: Richard Sandiford
Date: 2023-09-08 16:12
To: Lehua Ding
CC: gcc-patches; richard.guenther; juzhe.zhong; jeffreyalaw
Subject: Re: [PATCH V2] Support folding min(poly,poly) to const
Lehua Ding  writes:
> Hi,
>
> This patch adds support that tries to fold `MIN (poly, poly)` to
> a constant. Consider the following C Code:
>
> ```
> void foo2 (int* restrict a, int* restrict b, int n)
> {
> for (int i = 0; i < 3; i += 1)
>   a[i] += b[i];
> }
> ```
>
> Before this patch:
>
> ```
> void foo2 (int * restrict a, int * restrict b, int n)
> {
>   vector([4,4]) int vect__7.27;
>   vector([4,4]) int vect__6.26;
>   vector([4,4]) int vect__4.23;
>   unsigned long _32;
>
>[local count: 268435456]:
>   _32 = MIN_EXPR <3, POLY_INT_CST [4, 4]>;
>   vect__4.23_20 = .MASK_LEN_LOAD (a_11(D), 32B, { -1, ... }, _32, 0);
>   vect__6.26_15 = .MASK_LEN_LOAD (b_12(D), 32B, { -1, ... }, _32, 0);
>   vect__7.27_9 = vect__6.26_15 + vect__4.23_20;
>   .MASK_LEN_STORE (a_11(D), 32B, { -1, ... }, _32, 0, vect__7.27_9); [tail 
> call]
>   return;
>
> }
> ```
>
> After this patch:
>
> ```
> void foo2 (int * restrict a, int * restrict b, int n)
> {
>   vector([4,4]) int vect__7.27;
>   vector([4,4]) int vect__6.26;
>   vector([4,4]) int vect__4.23;
>
>[local count: 268435456]:
>   vect__4.23_20 = .MASK_LEN_LOAD (a_11(D), 32B, { -1, ... }, 3, 0);
>   vect__6.26_15 = .MASK_LEN_LOAD (b_12(D), 32B, { -1, ... }, 3, 0);
>   vect__7.27_9 = vect__6.26_15 + vect__4.23_20;
>   .MASK_LEN_STORE (a_11(D), 32B, { -1, ... }, 3, 0, vect__7.27_9); [tail call]
>   return;
>
> }
> ```
>
> For RISC-V RVV, csrr and branch instructions can be reduced:
>
> Before this patch:
>
> ```
> foo2:
> csrra4,vlenb
> srlia4,a4,2
> li  a5,3
> bleua5,a4,.L5
> mv  a5,a4
> .L5:
> vsetvli zero,a5,e32,m1,ta,ma
> ...
> ```
>
> After this patch.
>
> ```
> foo2:
> vsetivli zero,3,e32,m1,ta,ma
> ...
> ```
>
> Best,
> Lehua
>
> gcc/ChangeLog:
>
> * fold-const.cc (can_min_p): New function.
> (poly_int_binop): Try fold MIN_EXPR.
 
OK, thanks.
 
Richard
 
> gcc/testsuite/ChangeLog:
>
> * gcc.target/riscv/rvv/autovec/vls/div-1.c: Adjust.
> * gcc.target/riscv/rvv/autovec/vls/shift-3.c: Adjust.
> * gcc.target/riscv/rvv/autovec/fold-min-poly.c: New test.
>
> ---
>  gcc/fold-const.cc | 27 +++
>  .../riscv/rvv/autovec/fold-min-poly.c | 24 +
>  .../gcc.target/riscv/rvv/autovec/vls/div-1.c  |  2 +-
>  .../riscv/rvv/autovec/vls/shift-3.c   |  2 +-
>  4 files changed, 53 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c
>
> diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
> index 1da498a3152..ba4b6f3f3a3 100644
> --- a/gcc/fold-const.cc
> +++ b/gcc/fold-const.cc
> @@ -1213,6 +1213,28 @@ wide_int_binop (wide_int ,
>return true;
>  }
>  
> +/* Returns true if we know who is smaller or equal, ARG1 or ARG2, and set the
> +   min value to RES.  */
> +bool
> +can_min_p (const_tree arg1, const_tree arg2, poly_wide_int )
> +{
> +  if (!poly_int_tree_p (arg1) || !poly_int_tree_p (arg2))
> +return false;
> +
> +  if (known_le (wi::to_poly_widest (arg1), wi::to_poly_widest (arg2)))
> +{
> +  res = wi::to_poly_wide (arg1);
> +  return true;
> +}
> +  else if (known_le (wi::to_poly_widest (arg2), wi::to_poly_widest (arg1)))
> +{
> +  res = wi::to_poly_wide (arg2);
> +  return true;
> +}
> +
> +  return false;
> +}
> +
>  /* Combine two poly int's ARG1 and ARG2 under operation CODE to
> produce a new constant in RES.  Return FALSE if we don't know how
> to evaluate CODE at compile-time.  */
> @@ -1261,6 +1283,11 @@ poly_int_binop (poly_wide_int , enum tree_code 
> code,
>  return false;
>break;
>  
> +case MIN_EXPR:
> +  if (!can_min_p (arg1, arg2, res))
> + return false;
> +  break;
> +
>  default:
>return false;
>  }
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c 
> b/gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c
> new file mode 100644
> index 000..de4c472c76e
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c
> @@ -0,0 +1,24 @@
> +/* { dg-do compile } */
> +/* { dg-options " -march=rv64gcv_zvl128b -mabi=lp64d -O3 --param 
> riscv-autovec-preference=scalable --param riscv-autovec-lmul=m1 
> -fno-vect-cost-model" } */
> +
> +void foo1 (int* restrict a, int* restrict b, int n)
> +{
> +for (int i = 0; i < 4; i += 1)
> +  a[i] += b[i];
> +}
> +
> +void foo2 (int* restrict a, int* restrict b, int n)
> +{
> +for (int i = 0; i < 3; i += 1)
> +  a[i] += b[i];
> +}
> +
> +void foo3 (int* restrict a, int* restrict b, int n)
> +{
> +for (int i = 0; i < 5; i += 1)
> +  a[i] += b[i];
> +}
> +
> +/* { dg-final { 

Re: [PATCH] RISC-V: Suppress bogus warning for VLS types

2023-09-08 Thread Kito Cheng via Gcc-patches
LGTM

Juzhe-Zhong  於 2023年9月8日 週五 16:20 寫道:

> This patch fixes over 100+ bogus FAILs due to experimental vector ABI
> warning.
>
> gcc/ChangeLog:
>
> * config/riscv/riscv.cc (riscv_pass_in_vector_p): Only allow RVV
> type.
>
> ---
>  gcc/config/riscv/riscv.cc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
> index 9f0c8bbe9ed..81682d95ba4 100644
> --- a/gcc/config/riscv/riscv.cc
> +++ b/gcc/config/riscv/riscv.cc
> @@ -4414,7 +4414,7 @@ riscv_pass_in_vector_p (const_tree type)
>  {
>static int warned = 0;
>
> -  if (type && riscv_v_ext_mode_p (TYPE_MODE (type)) && !warned)
> +  if (type && riscv_vector::lookup_vector_type_attribute (type) &&
> !warned)
>  {
>warning (OPT_Wpsabi,
>"ABI for the vector type is currently in experimental stage
> and "
> --
> 2.36.3
>
>


Re: [Patch] contrib/gcc-changelog: Check whether revert-commit exists

2023-09-08 Thread Christophe Lyon via Gcc-patches
On Thu, 7 Sept 2023 at 11:45, Jakub Jelinek  wrote:

> On Thu, Sep 07, 2023 at 10:20:19AM +0200, Christophe Lyon via Gcc-patches
> wrote:
> > On Tue, 5 Sept 2023 at 16:38, Tobias Burnus 
> wrote:
> >
> > > That's based on the fail
> > > https://gcc.gnu.org/pipermail/gccadmin/2023q3/020349.html
> > > and on the discussion on IRC.
> > >
> >
> > Sorry I didn't notice the problem, nor the discussion on IRC, but I can
> see
> > that my commits created the problem, sorry for that.
> >
> > I'm not sure how your patch would have prevented me from doing this?
> > What happened is that I had 3 patches on top of master
> > - HEAD: the one I wanted to push
> > - HEAD-1: revert of HEAD-2
>
> git reset HEAD^
> instead of committing a revert would be better I think.
>

The patch I reverted locally was still under discussion, so I wanted to
keep it around until we made a decision.
But yeah.


> > - HEAD-2:  libstdc-Use-GLIBCXX_CHECK_LINKER_FEATURES-for.patch
> >
> > I had actually forgotten about HEAD-1 and HEAD-2, HEAD was unrelated to
> > those, so when I pushed, I pushed 3 commits while I thought there was
> only
> > one.
> > I did run contrib/gcc-changelog/git_check_commit.py (I realize I'm not
> sure
> > whether I used git_check_commit.py or git_commit.py), but only on HEAD
> > since I had forgotten about the other two.
>
> Could you please remove your
> 2023-09-04  Christophe Lyon  
>
> PR libstdc++/111238
> * configure: Regenerate.
> * configure.ac: Call GLIBCXX_CHECK_LINKER_FEATURES in cross,
> non-Canadian builds.
> libstdc++-v3/ChangeLog entry if that commit is indeed not in (or add
> a Revert: entry for it right after it if you think it needs to be in)?
> That is a part I haven't done, my/Arsen's hacks to make the version update
> get through basically ignored that revert commit.
>
> ChangeLog files can be changed by commits which only touch ChangeLog files
> and nothing else (ok, date stamp too, but please don't update that), no
> ChangeLog in the message needs to be provided for such changes.
>

Like so:
 commit d2bb261dbf282bbb258e1e5f17c1b6230327e076 (HEAD -> master)
Author: Christophe Lyon 
Date:   Fri Sep 8 08:13:32 2023 +

Revert "libstdc++: Use GLIBCXX_CHECK_LINKER_FEATURES for cross-builds
(PR111238)"

diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 8f7b01e0563..0c60149d7f6 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -4,6 +4,16 @@
for freestanding.
* configure: Regenerate.

+2023-09-04  Christophe Lyon  
+
+   Revert
+   2023-09-04  Christophe Lyon  
+
+   PR libstdc++/111238
+   * configure: Regenerate.
+   * configure.ac: Call GLIBCXX_CHECK_LINKER_FEATURES in cross,
+   non-Canadian builds.
+
 2023-09-04  Christophe Lyon  

PR libstdc++/111238

I inserted my "Revert"  ChangeLog entry between the entry I want to declare
reverted and Jonathan's more recent patch about GLIBCXX_ENABLE_BACKTRACE.
Is that OK for the commit hooks?


Jakub
>
>


[PATCH] RISC-V: Suppress bogus warning for VLS types

2023-09-08 Thread Juzhe-Zhong
This patch fixes over 100+ bogus FAILs due to experimental vector ABI warning.

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_pass_in_vector_p): Only allow RVV type.

---
 gcc/config/riscv/riscv.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 9f0c8bbe9ed..81682d95ba4 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -4414,7 +4414,7 @@ riscv_pass_in_vector_p (const_tree type)
 {
   static int warned = 0;
 
-  if (type && riscv_v_ext_mode_p (TYPE_MODE (type)) && !warned)
+  if (type && riscv_vector::lookup_vector_type_attribute (type) && !warned)
 {
   warning (OPT_Wpsabi,
   "ABI for the vector type is currently in experimental stage and "
-- 
2.36.3



RE: [PATCH] RISC-V: Fix incorrect nregs calculation for VLS modes

2023-09-08 Thread Li, Pan2 via Gcc-patches
Committed, thanks Kito.

Pan

-Original Message-
From: Gcc-patches  On Behalf 
Of Kito Cheng via Gcc-patches
Sent: Friday, September 8, 2023 4:12 PM
To: Juzhe-Zhong 
Cc: GCC Patches ; Kito Cheng 
Subject: Re: [PATCH] RISC-V: Fix incorrect nregs calculation for VLS modes

LGTM

Juzhe-Zhong  於 2023年9月8日 週五 15:52 寫道:

> This patch fixes obvious bug: TARGET_MIN_VLEN is bitsize.
>
> All these following bugs are fixed with this patch:
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O0  (internal compiler
> error: in gen_reg_rtx, at emit-rtl.cc:1176)
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O0  (test for excess
> errors)
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O1  (internal compiler
> error: in gen_reg_rtx, at emit-rtl.cc:1176)
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O1  (test for excess
> errors)
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O2  (internal compiler
> error: in gen_reg_rtx, at emit-rtl.cc:1176)
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O2  (test for excess
> errors)
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O2 -flto
> -fno-use-linker-plugin -flto-partition=none  (internal compiler error: in
> gen_reg_rtx, at emit-rtl.cc:1176)
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O2 -flto
> -fno-use-linker-plugin -flto-partition=none  (test for excess errors)
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O2 -flto
> -fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error: in
> gen_reg_rtx, at emit-rtl.cc:1176)
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O2 -flto
> -fuse-linker-plugin -fno-fat-lto-objects  (test for excess errors)
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O3 -g  (internal compiler
> error: in gen_reg_rtx, at emit-rtl.cc:1176)
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O3 -g  (test for excess
> errors)
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -Os  (internal compiler
> error: in gen_reg_rtx, at emit-rtl.cc:1176)
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -Os  (test for excess
> errors)
> FAIL: gcc.target/riscv/rvv/base/mov-13.c (internal compiler error: in
> partial_subreg_p, at rtl.h:3186)
> FAIL: gcc.target/riscv/rvv/base/mov-13.c (test for excess errors)
> FAIL: gcc.target/riscv/rvv/base/spill-1.c (internal compiler error: in
> partial_subreg_p, at rtl.h:3186)
> FAIL: gcc.target/riscv/rvv/base/spill-1.c (test for excess errors)
> FAIL: gcc.target/riscv/rvv/base/spill-2.c (internal compiler error: in
> partial_subreg_p, at rtl.h:3186)
> FAIL: gcc.target/riscv/rvv/base/spill-2.c (test for excess errors)
> FAIL: gcc.target/riscv/rvv/base/spill-3.c (internal compiler error: in
> partial_subreg_p, at rtl.h:3186)
> FAIL: gcc.target/riscv/rvv/base/spill-3.c (test for excess errors)
> FAIL: gcc.target/riscv/rvv/base/spill-4.c (internal compiler error: in
> partial_subreg_p, at rtl.h:3186)
> FAIL: gcc.target/riscv/rvv/base/spill-4.c (test for excess errors)
> FAIL: gcc.target/riscv/rvv/base/spill-5.c (internal compiler error: in
> partial_subreg_p, at rtl.h:3186)
> FAIL: gcc.target/riscv/rvv/base/spill-5.c (test for excess errors)
> FAIL: gcc.target/riscv/rvv/base/spill-6.c (internal compiler error: in
> partial_subreg_p, at rtl.h:3186)
> FAIL: gcc.target/riscv/rvv/base/spill-6.c (test for excess errors)
> FAIL: gcc.target/riscv/rvv/base/spill-sp-adjust.c (internal compiler
> error: in partial_subreg_p, at rtl.h:3186)
> FAIL: gcc.target/riscv/rvv/base/spill-sp-adjust.c (test for excess errors)
>
> gcc/ChangeLog:
>
> * config/riscv/riscv.cc (riscv_hard_regno_nregs): Fix bug.
>
> ---
>  gcc/config/riscv/riscv.cc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
> index c0c9c990a23..9f0c8bbe9ed 100644
> --- a/gcc/config/riscv/riscv.cc
> +++ b/gcc/config/riscv/riscv.cc
> @@ -7548,7 +7548,7 @@ riscv_hard_regno_nregs (unsigned int regno,
> machine_mode mode)
>/* For VLS modes, we allocate registers according to TARGET_MIN_VLEN.
> */
>if (riscv_v_ext_vls_mode_p (mode))
>  {
> -  int size = GET_MODE_SIZE (mode).to_constant ();
> +  int size = GET_MODE_BITSIZE (mode).to_constant ();
>if (size < TARGET_MIN_VLEN)
> return 1;
>else
> --
> 2.36.3
>
>


Re: [PATCH] riscv: thead: Fix mode attribute for extension patterns

2023-09-08 Thread Kito Cheng via Gcc-patches
LGTM

Christoph Muellner  於 2023年9月8日 週五 14:16 寫道:

> From: Christoph Müllner 
>
> The mode attribute of an extension pattern is usually set to the target
> type.
> Let's follow this convention consistently for xtheadbb.
>
> Signed-off-by: Christoph Müllner 
>
> gcc/ChangeLog:
>
> * config/riscv/thead.md: Use more appropriate mode attributes
> for extensions.
> ---
>  gcc/config/riscv/thead.md | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/gcc/config/riscv/thead.md b/gcc/config/riscv/thead.md
> index 05d1b32bd94..2287b752ea1 100644
> --- a/gcc/config/riscv/thead.md
> +++ b/gcc/config/riscv/thead.md
> @@ -101,7 +101,7 @@ (define_insn "*zero_extendsidi2_th_extu"
> th.extu\t%0,%1,31,0
> lwu\t%0,%1"
>[(set_attr "type" "bitmanip,load")
> -   (set_attr "mode" "SI")])
> +   (set_attr "mode" "DI")])
>
>  (define_insn "*zero_extendhi2_th_extu"
>[(set (match_operand:GPR 0 "register_operand" "=r,r")
> @@ -111,7 +111,7 @@ (define_insn "*zero_extendhi2_th_extu"
> th.extu\t%0,%1,15,0
> lhu\t%0,%1"
>[(set_attr "type" "bitmanip,load")
> -   (set_attr "mode" "HI")])
> +   (set_attr "mode" "")])
>
>  (define_insn "*th_clz2"
>[(set (match_operand:X 0 "register_operand" "=r")
> --
> 2.41.0
>
>


Re: [PATCH V2] Support folding min(poly,poly) to const

2023-09-08 Thread Richard Sandiford via Gcc-patches
Lehua Ding  writes:
> Hi,
>
> This patch adds support that tries to fold `MIN (poly, poly)` to
> a constant. Consider the following C Code:
>
> ```
> void foo2 (int* restrict a, int* restrict b, int n)
> {
> for (int i = 0; i < 3; i += 1)
>   a[i] += b[i];
> }
> ```
>
> Before this patch:
>
> ```
> void foo2 (int * restrict a, int * restrict b, int n)
> {
>   vector([4,4]) int vect__7.27;
>   vector([4,4]) int vect__6.26;
>   vector([4,4]) int vect__4.23;
>   unsigned long _32;
>
>[local count: 268435456]:
>   _32 = MIN_EXPR <3, POLY_INT_CST [4, 4]>;
>   vect__4.23_20 = .MASK_LEN_LOAD (a_11(D), 32B, { -1, ... }, _32, 0);
>   vect__6.26_15 = .MASK_LEN_LOAD (b_12(D), 32B, { -1, ... }, _32, 0);
>   vect__7.27_9 = vect__6.26_15 + vect__4.23_20;
>   .MASK_LEN_STORE (a_11(D), 32B, { -1, ... }, _32, 0, vect__7.27_9); [tail 
> call]
>   return;
>
> }
> ```
>
> After this patch:
>
> ```
> void foo2 (int * restrict a, int * restrict b, int n)
> {
>   vector([4,4]) int vect__7.27;
>   vector([4,4]) int vect__6.26;
>   vector([4,4]) int vect__4.23;
>
>[local count: 268435456]:
>   vect__4.23_20 = .MASK_LEN_LOAD (a_11(D), 32B, { -1, ... }, 3, 0);
>   vect__6.26_15 = .MASK_LEN_LOAD (b_12(D), 32B, { -1, ... }, 3, 0);
>   vect__7.27_9 = vect__6.26_15 + vect__4.23_20;
>   .MASK_LEN_STORE (a_11(D), 32B, { -1, ... }, 3, 0, vect__7.27_9); [tail call]
>   return;
>
> }
> ```
>
> For RISC-V RVV, csrr and branch instructions can be reduced:
>
> Before this patch:
>
> ```
> foo2:
> csrra4,vlenb
> srlia4,a4,2
> li  a5,3
> bleua5,a4,.L5
> mv  a5,a4
> .L5:
> vsetvli zero,a5,e32,m1,ta,ma
> ...
> ```
>
> After this patch.
>
> ```
> foo2:
>   vsetivlizero,3,e32,m1,ta,ma
> ...
> ```
>
> Best,
> Lehua
>
> gcc/ChangeLog:
>
>   * fold-const.cc (can_min_p): New function.
>   (poly_int_binop): Try fold MIN_EXPR.

OK, thanks.

Richard

> gcc/testsuite/ChangeLog:
>
>   * gcc.target/riscv/rvv/autovec/vls/div-1.c: Adjust.
>   * gcc.target/riscv/rvv/autovec/vls/shift-3.c: Adjust.
>   * gcc.target/riscv/rvv/autovec/fold-min-poly.c: New test.
>
> ---
>  gcc/fold-const.cc | 27 +++
>  .../riscv/rvv/autovec/fold-min-poly.c | 24 +
>  .../gcc.target/riscv/rvv/autovec/vls/div-1.c  |  2 +-
>  .../riscv/rvv/autovec/vls/shift-3.c   |  2 +-
>  4 files changed, 53 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c
>
> diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
> index 1da498a3152..ba4b6f3f3a3 100644
> --- a/gcc/fold-const.cc
> +++ b/gcc/fold-const.cc
> @@ -1213,6 +1213,28 @@ wide_int_binop (wide_int ,
>return true;
>  }
>  
> +/* Returns true if we know who is smaller or equal, ARG1 or ARG2, and set the
> +   min value to RES.  */
> +bool
> +can_min_p (const_tree arg1, const_tree arg2, poly_wide_int )
> +{
> +  if (!poly_int_tree_p (arg1) || !poly_int_tree_p (arg2))
> +return false;
> +
> +  if (known_le (wi::to_poly_widest (arg1), wi::to_poly_widest (arg2)))
> +{
> +  res = wi::to_poly_wide (arg1);
> +  return true;
> +}
> +  else if (known_le (wi::to_poly_widest (arg2), wi::to_poly_widest (arg1)))
> +{
> +  res = wi::to_poly_wide (arg2);
> +  return true;
> +}
> +
> +  return false;
> +}
> +
>  /* Combine two poly int's ARG1 and ARG2 under operation CODE to
> produce a new constant in RES.  Return FALSE if we don't know how
> to evaluate CODE at compile-time.  */
> @@ -1261,6 +1283,11 @@ poly_int_binop (poly_wide_int , enum tree_code 
> code,
>   return false;
>break;
>  
> +case MIN_EXPR:
> +  if (!can_min_p (arg1, arg2, res))
> + return false;
> +  break;
> +
>  default:
>return false;
>  }
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c 
> b/gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c
> new file mode 100644
> index 000..de4c472c76e
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c
> @@ -0,0 +1,24 @@
> +/* { dg-do compile } */
> +/* { dg-options " -march=rv64gcv_zvl128b -mabi=lp64d -O3 --param 
> riscv-autovec-preference=scalable --param riscv-autovec-lmul=m1 
> -fno-vect-cost-model" } */
> +
> +void foo1 (int* restrict a, int* restrict b, int n)
> +{
> +for (int i = 0; i < 4; i += 1)
> +  a[i] += b[i];
> +}
> +
> +void foo2 (int* restrict a, int* restrict b, int n)
> +{
> +for (int i = 0; i < 3; i += 1)
> +  a[i] += b[i];
> +}
> +
> +void foo3 (int* restrict a, int* restrict b, int n)
> +{
> +for (int i = 0; i < 5; i += 1)
> +  a[i] += b[i];
> +}
> +
> +/* { dg-final { scan-assembler-not {\tcsrr\t} } } */
> +/* { dg-final { scan-assembler {\tvsetivli\tzero,4,e32,m1,t[au],m[au]} } } */
> +/* { dg-final { scan-assembler {\tvsetivli\tzero,3,e32,m1,t[au],m[au]} } } */
> diff --git 

Re: [PATCH] RISC-V: Fix incorrect nregs calculation for VLS modes

2023-09-08 Thread Kito Cheng via Gcc-patches
LGTM

Juzhe-Zhong  於 2023年9月8日 週五 15:52 寫道:

> This patch fixes obvious bug: TARGET_MIN_VLEN is bitsize.
>
> All these following bugs are fixed with this patch:
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O0  (internal compiler
> error: in gen_reg_rtx, at emit-rtl.cc:1176)
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O0  (test for excess
> errors)
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O1  (internal compiler
> error: in gen_reg_rtx, at emit-rtl.cc:1176)
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O1  (test for excess
> errors)
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O2  (internal compiler
> error: in gen_reg_rtx, at emit-rtl.cc:1176)
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O2  (test for excess
> errors)
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O2 -flto
> -fno-use-linker-plugin -flto-partition=none  (internal compiler error: in
> gen_reg_rtx, at emit-rtl.cc:1176)
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O2 -flto
> -fno-use-linker-plugin -flto-partition=none  (test for excess errors)
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O2 -flto
> -fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error: in
> gen_reg_rtx, at emit-rtl.cc:1176)
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O2 -flto
> -fuse-linker-plugin -fno-fat-lto-objects  (test for excess errors)
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O3 -g  (internal compiler
> error: in gen_reg_rtx, at emit-rtl.cc:1176)
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O3 -g  (test for excess
> errors)
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -Os  (internal compiler
> error: in gen_reg_rtx, at emit-rtl.cc:1176)
> FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -Os  (test for excess
> errors)
> FAIL: gcc.target/riscv/rvv/base/mov-13.c (internal compiler error: in
> partial_subreg_p, at rtl.h:3186)
> FAIL: gcc.target/riscv/rvv/base/mov-13.c (test for excess errors)
> FAIL: gcc.target/riscv/rvv/base/spill-1.c (internal compiler error: in
> partial_subreg_p, at rtl.h:3186)
> FAIL: gcc.target/riscv/rvv/base/spill-1.c (test for excess errors)
> FAIL: gcc.target/riscv/rvv/base/spill-2.c (internal compiler error: in
> partial_subreg_p, at rtl.h:3186)
> FAIL: gcc.target/riscv/rvv/base/spill-2.c (test for excess errors)
> FAIL: gcc.target/riscv/rvv/base/spill-3.c (internal compiler error: in
> partial_subreg_p, at rtl.h:3186)
> FAIL: gcc.target/riscv/rvv/base/spill-3.c (test for excess errors)
> FAIL: gcc.target/riscv/rvv/base/spill-4.c (internal compiler error: in
> partial_subreg_p, at rtl.h:3186)
> FAIL: gcc.target/riscv/rvv/base/spill-4.c (test for excess errors)
> FAIL: gcc.target/riscv/rvv/base/spill-5.c (internal compiler error: in
> partial_subreg_p, at rtl.h:3186)
> FAIL: gcc.target/riscv/rvv/base/spill-5.c (test for excess errors)
> FAIL: gcc.target/riscv/rvv/base/spill-6.c (internal compiler error: in
> partial_subreg_p, at rtl.h:3186)
> FAIL: gcc.target/riscv/rvv/base/spill-6.c (test for excess errors)
> FAIL: gcc.target/riscv/rvv/base/spill-sp-adjust.c (internal compiler
> error: in partial_subreg_p, at rtl.h:3186)
> FAIL: gcc.target/riscv/rvv/base/spill-sp-adjust.c (test for excess errors)
>
> gcc/ChangeLog:
>
> * config/riscv/riscv.cc (riscv_hard_regno_nregs): Fix bug.
>
> ---
>  gcc/config/riscv/riscv.cc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
> index c0c9c990a23..9f0c8bbe9ed 100644
> --- a/gcc/config/riscv/riscv.cc
> +++ b/gcc/config/riscv/riscv.cc
> @@ -7548,7 +7548,7 @@ riscv_hard_regno_nregs (unsigned int regno,
> machine_mode mode)
>/* For VLS modes, we allocate registers according to TARGET_MIN_VLEN.
> */
>if (riscv_v_ext_vls_mode_p (mode))
>  {
> -  int size = GET_MODE_SIZE (mode).to_constant ();
> +  int size = GET_MODE_BITSIZE (mode).to_constant ();
>if (size < TARGET_MIN_VLEN)
> return 1;
>else
> --
> 2.36.3
>
>


Re: [PATCH] LoongArch: Enable -fsched-pressure by default at -O1 and higher.

2023-09-08 Thread Xi Ruoyao via Gcc-patches
On Fri, 2023-09-08 at 10:00 +0800, Guo Jie wrote:
> gcc/ChangeLog:
> 
> * common/config/loongarch/loongarch-common.cc:

"common/" should be removed.  You can use "git gcc-verify" to figure out
this kind of error before sending a patch in the future.

> (default_options loongarch_option_optimization_table):
> Default to -fsched-pressure.

"Default to -fsched-pressure at -O1 or above."

Otherwise OK.

> ---
>  gcc/common/config/loongarch/loongarch-common.cc | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/gcc/common/config/loongarch/loongarch-common.cc
> b/gcc/common/config/loongarch/loongarch-common.cc
> index c5ed37d27a6..b6901910b70 100644
> --- a/gcc/common/config/loongarch/loongarch-common.cc
> +++ b/gcc/common/config/loongarch/loongarch-common.cc
> @@ -36,6 +36,7 @@ static const struct default_options
> loongarch_option_optimization_table[] =
>    { OPT_LEVELS_ALL, OPT_fasynchronous_unwind_tables, NULL, 1 },
>    { OPT_LEVELS_1_PLUS, OPT_fsection_anchors, NULL, 1 },
>    { OPT_LEVELS_2_PLUS, OPT_free, NULL, 1 },
> +  { OPT_LEVELS_1_PLUS, OPT_fsched_pressure, NULL, 1 },
>    { OPT_LEVELS_NONE, 0, NULL, 0 }
>  };
>  

-- 
Xi Ruoyao 
School of Aerospace Science and Technology, Xidian University


[PATCH] RISC-V: Fix incorrect nregs calculation for VLS modes

2023-09-08 Thread Juzhe-Zhong
This patch fixes obvious bug: TARGET_MIN_VLEN is bitsize.

All these following bugs are fixed with this patch:
FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O0  (internal compiler error: 
in gen_reg_rtx, at emit-rtl.cc:1176)
FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O0  (test for excess errors)
FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O1  (internal compiler error: 
in gen_reg_rtx, at emit-rtl.cc:1176)
FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O1  (test for excess errors)
FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O2  (internal compiler error: 
in gen_reg_rtx, at emit-rtl.cc:1176)
FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O2  (test for excess errors)
FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O2 -flto -fno-use-linker-plugin 
-flto-partition=none  (internal compiler error: in gen_reg_rtx, at 
emit-rtl.cc:1176)
FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O2 -flto -fno-use-linker-plugin 
-flto-partition=none  (test for excess errors)
FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O2 -flto -fuse-linker-plugin 
-fno-fat-lto-objects  (internal compiler error: in gen_reg_rtx, at 
emit-rtl.cc:1176)
FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O2 -flto -fuse-linker-plugin 
-fno-fat-lto-objects  (test for excess errors)
FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O3 -g  (internal compiler 
error: in gen_reg_rtx, at emit-rtl.cc:1176)
FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -O3 -g  (test for excess errors)
FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -Os  (internal compiler error: 
in gen_reg_rtx, at emit-rtl.cc:1176)
FAIL: gcc.target/riscv/zero-scratch-regs-3.c   -Os  (test for excess errors)
FAIL: gcc.target/riscv/rvv/base/mov-13.c (internal compiler error: in 
partial_subreg_p, at rtl.h:3186)
FAIL: gcc.target/riscv/rvv/base/mov-13.c (test for excess errors)
FAIL: gcc.target/riscv/rvv/base/spill-1.c (internal compiler error: in 
partial_subreg_p, at rtl.h:3186)
FAIL: gcc.target/riscv/rvv/base/spill-1.c (test for excess errors)
FAIL: gcc.target/riscv/rvv/base/spill-2.c (internal compiler error: in 
partial_subreg_p, at rtl.h:3186)
FAIL: gcc.target/riscv/rvv/base/spill-2.c (test for excess errors)
FAIL: gcc.target/riscv/rvv/base/spill-3.c (internal compiler error: in 
partial_subreg_p, at rtl.h:3186)
FAIL: gcc.target/riscv/rvv/base/spill-3.c (test for excess errors)
FAIL: gcc.target/riscv/rvv/base/spill-4.c (internal compiler error: in 
partial_subreg_p, at rtl.h:3186)
FAIL: gcc.target/riscv/rvv/base/spill-4.c (test for excess errors)
FAIL: gcc.target/riscv/rvv/base/spill-5.c (internal compiler error: in 
partial_subreg_p, at rtl.h:3186)
FAIL: gcc.target/riscv/rvv/base/spill-5.c (test for excess errors)
FAIL: gcc.target/riscv/rvv/base/spill-6.c (internal compiler error: in 
partial_subreg_p, at rtl.h:3186)
FAIL: gcc.target/riscv/rvv/base/spill-6.c (test for excess errors)
FAIL: gcc.target/riscv/rvv/base/spill-sp-adjust.c (internal compiler error: in 
partial_subreg_p, at rtl.h:3186)
FAIL: gcc.target/riscv/rvv/base/spill-sp-adjust.c (test for excess errors)

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_hard_regno_nregs): Fix bug.

---
 gcc/config/riscv/riscv.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index c0c9c990a23..9f0c8bbe9ed 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -7548,7 +7548,7 @@ riscv_hard_regno_nregs (unsigned int regno, machine_mode 
mode)
   /* For VLS modes, we allocate registers according to TARGET_MIN_VLEN.  */
   if (riscv_v_ext_vls_mode_p (mode))
 {
-  int size = GET_MODE_SIZE (mode).to_constant ();
+  int size = GET_MODE_BITSIZE (mode).to_constant ();
   if (size < TARGET_MIN_VLEN)
return 1;
   else
-- 
2.36.3



Re: [PATCH] Support folding min(poly,poly) to const

2023-09-08 Thread Lehua Ding

Hi Richard,

On 2023/9/8 14:37, Richard Sandiford wrote:
I think this should instead use poly_int_tree_p and wi::to_poly_widest. 
There's no need to handle int64 and uint64 separately. (And there's no 
need to handle just 64-bit types.)


Thanks for the correction. I used wi::to_poly_wide(instead of 
wi::to_poly_widest) incorrectly and found that the returned type did not 
implement some functions such as known_le.
Here is the V2 patch: 
https://gcc.gnu.org/pipermail/gcc-patches/2023-September/629659.html


--
Best,
Lehua



[PATCH V2] Support folding min(poly,poly) to const

2023-09-08 Thread Lehua Ding
Hi,

This patch adds support that tries to fold `MIN (poly, poly)` to
a constant. Consider the following C Code:

```
void foo2 (int* restrict a, int* restrict b, int n)
{
for (int i = 0; i < 3; i += 1)
  a[i] += b[i];
}
```

Before this patch:

```
void foo2 (int * restrict a, int * restrict b, int n)
{
  vector([4,4]) int vect__7.27;
  vector([4,4]) int vect__6.26;
  vector([4,4]) int vect__4.23;
  unsigned long _32;

   [local count: 268435456]:
  _32 = MIN_EXPR <3, POLY_INT_CST [4, 4]>;
  vect__4.23_20 = .MASK_LEN_LOAD (a_11(D), 32B, { -1, ... }, _32, 0);
  vect__6.26_15 = .MASK_LEN_LOAD (b_12(D), 32B, { -1, ... }, _32, 0);
  vect__7.27_9 = vect__6.26_15 + vect__4.23_20;
  .MASK_LEN_STORE (a_11(D), 32B, { -1, ... }, _32, 0, vect__7.27_9); [tail call]
  return;

}
```

After this patch:

```
void foo2 (int * restrict a, int * restrict b, int n)
{
  vector([4,4]) int vect__7.27;
  vector([4,4]) int vect__6.26;
  vector([4,4]) int vect__4.23;

   [local count: 268435456]:
  vect__4.23_20 = .MASK_LEN_LOAD (a_11(D), 32B, { -1, ... }, 3, 0);
  vect__6.26_15 = .MASK_LEN_LOAD (b_12(D), 32B, { -1, ... }, 3, 0);
  vect__7.27_9 = vect__6.26_15 + vect__4.23_20;
  .MASK_LEN_STORE (a_11(D), 32B, { -1, ... }, 3, 0, vect__7.27_9); [tail call]
  return;

}
```

For RISC-V RVV, csrr and branch instructions can be reduced:

Before this patch:

```
foo2:
csrra4,vlenb
srlia4,a4,2
li  a5,3
bleua5,a4,.L5
mv  a5,a4
.L5:
vsetvli zero,a5,e32,m1,ta,ma
...
```

After this patch.

```
foo2:
vsetivlizero,3,e32,m1,ta,ma
...
```

Best,
Lehua

gcc/ChangeLog:

* fold-const.cc (can_min_p): New function.
(poly_int_binop): Try fold MIN_EXPR.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vls/div-1.c: Adjust.
* gcc.target/riscv/rvv/autovec/vls/shift-3.c: Adjust.
* gcc.target/riscv/rvv/autovec/fold-min-poly.c: New test.

---
 gcc/fold-const.cc | 27 +++
 .../riscv/rvv/autovec/fold-min-poly.c | 24 +
 .../gcc.target/riscv/rvv/autovec/vls/div-1.c  |  2 +-
 .../riscv/rvv/autovec/vls/shift-3.c   |  2 +-
 4 files changed, 53 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c

diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 1da498a3152..ba4b6f3f3a3 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -1213,6 +1213,28 @@ wide_int_binop (wide_int ,
   return true;
 }
 
+/* Returns true if we know who is smaller or equal, ARG1 or ARG2, and set the
+   min value to RES.  */
+bool
+can_min_p (const_tree arg1, const_tree arg2, poly_wide_int )
+{
+  if (!poly_int_tree_p (arg1) || !poly_int_tree_p (arg2))
+return false;
+
+  if (known_le (wi::to_poly_widest (arg1), wi::to_poly_widest (arg2)))
+{
+  res = wi::to_poly_wide (arg1);
+  return true;
+}
+  else if (known_le (wi::to_poly_widest (arg2), wi::to_poly_widest (arg1)))
+{
+  res = wi::to_poly_wide (arg2);
+  return true;
+}
+
+  return false;
+}
+
 /* Combine two poly int's ARG1 and ARG2 under operation CODE to
produce a new constant in RES.  Return FALSE if we don't know how
to evaluate CODE at compile-time.  */
@@ -1261,6 +1283,11 @@ poly_int_binop (poly_wide_int , enum tree_code code,
return false;
   break;
 
+case MIN_EXPR:
+  if (!can_min_p (arg1, arg2, res))
+   return false;
+  break;
+
 default:
   return false;
 }
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c
new file mode 100644
index 000..de4c472c76e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-options " -march=rv64gcv_zvl128b -mabi=lp64d -O3 --param 
riscv-autovec-preference=scalable --param riscv-autovec-lmul=m1 
-fno-vect-cost-model" } */
+
+void foo1 (int* restrict a, int* restrict b, int n)
+{
+for (int i = 0; i < 4; i += 1)
+  a[i] += b[i];
+}
+
+void foo2 (int* restrict a, int* restrict b, int n)
+{
+for (int i = 0; i < 3; i += 1)
+  a[i] += b[i];
+}
+
+void foo3 (int* restrict a, int* restrict b, int n)
+{
+for (int i = 0; i < 5; i += 1)
+  a[i] += b[i];
+}
+
+/* { dg-final { scan-assembler-not {\tcsrr\t} } } */
+/* { dg-final { scan-assembler {\tvsetivli\tzero,4,e32,m1,t[au],m[au]} } } */
+/* { dg-final { scan-assembler {\tvsetivli\tzero,3,e32,m1,t[au],m[au]} } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/div-1.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/div-1.c
index f3388a86e38..40224c69458 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/div-1.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/div-1.c
@@ -55,4 +55,4 @@ DEF_OP_VV (div, 512, int64_t, /)
 
 /* { dg-final { scan-assembler-times 

[PATCH] riscv: bitmanip: Remove duplicate zero_extendhi2 pattern

2023-09-08 Thread Christoph Muellner
From: Christoph Müllner 

We currently have two identical zero_extendhi2 patterns:
* '*zero_extendhi2_zbb'
* '*zero_extendhi2_bitmanip'

This patch removes the *_zbb pattern and ensures that all sign- and
zero-extensions use the postfix '_bitmanip'.

Signed-off-by: Christoph Müllner 

gcc/ChangeLog:

* config/riscv/bitmanip.md (*extend2_zbb):
Rename postfix to _bitmanip.
(*extend2_bitmanip): Renamed pattern.
(*zero_extendhi2_zbb): Remove duplicated pattern.
---
 gcc/config/riscv/bitmanip.md | 13 +
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md
index 1544ef4e125..431b3292213 100644
--- a/gcc/config/riscv/bitmanip.md
+++ b/gcc/config/riscv/bitmanip.md
@@ -283,7 +283,7 @@ (define_insn "*zero_extendhi2_bitmanip"
   [(set_attr "type" "bitmanip,load")
(set_attr "mode" "")])
 
-(define_insn "*extend2_zbb"
+(define_insn "*extend2_bitmanip"
   [(set (match_operand:SUPERQI   0 "register_operand" "=r,r")
(sign_extend:SUPERQI
(match_operand:SHORT 1 "nonimmediate_operand" " r,m")))]
@@ -294,17 +294,6 @@ (define_insn "*extend2_zbb"
   [(set_attr "type" "bitmanip,load")
(set_attr "mode" "")])
 
-(define_insn "*zero_extendhi2_zbb"
-  [(set (match_operand:GPR0 "register_operand" "=r,r")
-   (zero_extend:GPR
-   (match_operand:HI 1 "nonimmediate_operand" " r,m")))]
-  "TARGET_ZBB"
-  "@
-   zext.h\t%0,%1
-   lhu\t%0,%1"
-  [(set_attr "type" "bitmanip,load")
-   (set_attr "mode" "HI")])
-
 (define_expand "rotrdi3"
   [(set (match_operand:DI 0 "register_operand")
(rotatert:DI (match_operand:DI 1 "register_operand")
-- 
2.41.0



Re: [PATCH] Support folding min(poly,poly) to const

2023-09-08 Thread Richard Sandiford via Gcc-patches
Lehua Ding  writes:
> Hi,
>
> This patch adds support that tries to fold `MIN (poly, poly)` to
> a constant. Consider the following C Code:
>
> ```
> void foo2 (int* restrict a, int* restrict b, int n)
> {
> for (int i = 0; i < 3; i += 1)
>   a[i] += b[i];
> }
> ```
>
> Before this patch:
>
> ```
> void foo2 (int * restrict a, int * restrict b, int n)
> {
>   vector([4,4]) int vect__7.27;
>   vector([4,4]) int vect__6.26;
>   vector([4,4]) int vect__4.23;
>   unsigned long _32;
>
>[local count: 268435456]:
>   _32 = MIN_EXPR <3, POLY_INT_CST [4, 4]>;
>   vect__4.23_20 = .MASK_LEN_LOAD (a_11(D), 32B, { -1, ... }, _32, 0);
>   vect__6.26_15 = .MASK_LEN_LOAD (b_12(D), 32B, { -1, ... }, _32, 0);
>   vect__7.27_9 = vect__6.26_15 + vect__4.23_20;
>   .MASK_LEN_STORE (a_11(D), 32B, { -1, ... }, _32, 0, vect__7.27_9); [tail 
> call]
>   return;
>
> }
> ```
>
> After this patch:
>
> ```
> void foo2 (int * restrict a, int * restrict b, int n)
> {
>   vector([4,4]) int vect__7.27;
>   vector([4,4]) int vect__6.26;
>   vector([4,4]) int vect__4.23;
>
>[local count: 268435456]:
>   vect__4.23_20 = .MASK_LEN_LOAD (a_11(D), 32B, { -1, ... }, 3, 0);
>   vect__6.26_15 = .MASK_LEN_LOAD (b_12(D), 32B, { -1, ... }, 3, 0);
>   vect__7.27_9 = vect__6.26_15 + vect__4.23_20;
>   .MASK_LEN_STORE (a_11(D), 32B, { -1, ... }, 3, 0, vect__7.27_9); [tail call]
>   return;
>
> }
> ```
>
> For RISC-V RVV, one branch instruction can be reduced:
>
> Before this patch:
>
> ```
> foo2:
> csrra4,vlenb
> srlia4,a4,2
> li  a5,3
> bleua5,a4,.L5
> mv  a5,a4
> .L5:
> vsetvli zero,a5,e32,m1,ta,ma
> ...
> ```
>
> After this patch.
>
> ```
> foo2:
>   vsetivlizero,3,e32,m1,ta,ma
> ...
> ```
>
> Best,
> Lehua
>
> gcc/ChangeLog:
>
>   * fold-const.cc (can_min_p): New function.
>   (poly_int_binop): Try fold MIN_EXPR.
>
> gcc/testsuite/ChangeLog:
>
>   * gcc.target/riscv/rvv/autovec/vls/div-1.c: Adjust.
>   * gcc.target/riscv/rvv/autovec/vls/shift-3.c: Adjust.
>   * gcc.target/riscv/rvv/autovec/fold-min-poly.c: New test.
>
> ---
>  gcc/fold-const.cc | 33 +++
>  .../riscv/rvv/autovec/fold-min-poly.c | 24 ++
>  .../gcc.target/riscv/rvv/autovec/vls/div-1.c  |  2 +-
>  .../riscv/rvv/autovec/vls/shift-3.c   |  2 +-
>  4 files changed, 59 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c
>
> diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
> index 1da498a3152..f7f793cc326 100644
> --- a/gcc/fold-const.cc
> +++ b/gcc/fold-const.cc
> @@ -1213,6 +1213,34 @@ wide_int_binop (wide_int ,
>return true;
>  }
>  
> +/* Returns true if we know who is smaller or equal, ARG1 or ARG2., and set 
> the
> +   min value to RES.  */
> +bool
> +can_min_p (const_tree arg1, const_tree arg2, poly_wide_int )
> +{
> +  if (tree_fits_poly_int64_p (arg1) && tree_fits_poly_int64_p (arg2))
> +{
> +  if (known_le (tree_to_poly_int64 (arg1), tree_to_poly_int64 (arg2)))
> + res = wi::to_poly_wide (arg1);
> +  else if (known_le (tree_to_poly_int64 (arg2), tree_to_poly_int64 
> (arg1)))
> + res = wi::to_poly_wide (arg2);
> +  else
> + return false;
> +}
> +  else if (tree_fits_poly_uint64_p (arg1) && tree_fits_poly_uint64_p (arg2))
> +{
> +  if (known_le (tree_to_poly_uint64 (arg1), tree_to_poly_uint64 (arg2)))
> + res = wi::to_poly_wide (arg1);
> +  else if (known_le (tree_to_poly_int64 (arg2), tree_to_poly_int64 
> (arg1)))
> + res = wi::to_poly_wide (arg2);
> +  else
> + return false;
> +}
> +  else
> +return false;
> +  return true;
> +}

I think this should instead use poly_int_tree_p and wi::to_poly_widest.
There's no need to handle int64 and uint64 separately.  (And there's
no need to handle just 64-bit types.)

Thanks,
Richard

> +
>  /* Combine two poly int's ARG1 and ARG2 under operation CODE to
> produce a new constant in RES.  Return FALSE if we don't know how
> to evaluate CODE at compile-time.  */
> @@ -1261,6 +1289,11 @@ poly_int_binop (poly_wide_int , enum tree_code 
> code,
>   return false;
>break;
>  
> +case MIN_EXPR:
> +  if (!can_min_p (arg1, arg2, res))
> + return false;
> +  break;
> +
>  default:
>return false;
>  }
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c 
> b/gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c
> new file mode 100644
> index 000..de4c472c76e
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/fold-min-poly.c
> @@ -0,0 +1,24 @@
> +/* { dg-do compile } */
> +/* { dg-options " -march=rv64gcv_zvl128b -mabi=lp64d -O3 --param 
> riscv-autovec-preference=scalable --param riscv-autovec-lmul=m1 
> -fno-vect-cost-model" } */
> +
> +void foo1 (int* restrict a, int* restrict b, int n)
> +{
> +for (int i = 0; i < 

Re: [PATCH V5 0/3] RISC-V: Add an experimental vector calling convention

2023-09-08 Thread Lehua Ding

Pushed to trunk with few testcase modifications, e.g. adding { target
{ riscv_vector } } to dg-run and adding -march / -mabi for compile
tests.


Thank you so much Kito for your help :)

--
Best,
Lehua



[PATCH] riscv: thead: Fix mode attribute for extension patterns

2023-09-08 Thread Christoph Muellner
From: Christoph Müllner 

The mode attribute of an extension pattern is usually set to the target type.
Let's follow this convention consistently for xtheadbb.

Signed-off-by: Christoph Müllner 

gcc/ChangeLog:

* config/riscv/thead.md: Use more appropriate mode attributes
for extensions.
---
 gcc/config/riscv/thead.md | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/config/riscv/thead.md b/gcc/config/riscv/thead.md
index 05d1b32bd94..2287b752ea1 100644
--- a/gcc/config/riscv/thead.md
+++ b/gcc/config/riscv/thead.md
@@ -101,7 +101,7 @@ (define_insn "*zero_extendsidi2_th_extu"
th.extu\t%0,%1,31,0
lwu\t%0,%1"
   [(set_attr "type" "bitmanip,load")
-   (set_attr "mode" "SI")])
+   (set_attr "mode" "DI")])
 
 (define_insn "*zero_extendhi2_th_extu"
   [(set (match_operand:GPR 0 "register_operand" "=r,r")
@@ -111,7 +111,7 @@ (define_insn "*zero_extendhi2_th_extu"
th.extu\t%0,%1,15,0
lhu\t%0,%1"
   [(set_attr "type" "bitmanip,load")
-   (set_attr "mode" "HI")])
+   (set_attr "mode" "")])
 
 (define_insn "*th_clz2"
   [(set (match_operand:X 0 "register_operand" "=r")
-- 
2.41.0



Re: [PATCH] Support folding min(poly,poly) to const

2023-09-08 Thread Lehua Ding

Hi Andrew,

On 2023/9/8 13:28, Andrew Pinski wrote:

On Thu, Sep 7, 2023 at 10:25 PM Lehua Ding  wrote:


Hi,

This patch adds support that tries to fold `MIN (poly, poly)` to
a constant. Consider the following C Code:


Does it make sense to handle max also?



At the moment I can't construct a C program that can generates MIN_EXPR, 
so I don't add it, although I implement both min and max locally.


--
Best,
Lehua



[PATCH] riscv: xtheadbb: Fix extendqi insn

2023-09-08 Thread Christoph Muellner
From: Christoph Müllner 

Recently three SPEC CPU 2017 benchmarks broke when using xtheadbb:
* 500.perlbench_r
* 525.x264_r
* 557.xz_r

Tracing the issue down revealed, that we emit a 'th.ext xN,xN,15,0'
for a extendqi insn, which is obviously wrong.
This patch splits the common 'extend2_th_ext'
insn into two 'extendqi' and 'extendhi' insns,
which emit the right extension instruction.
Additionally, this patch adds test cases for these insns.

Signed-off-by: Christoph Müllner 

gcc/ChangeLog:

* config/riscv/thead.md (*extend2_th_ext):
Remove broken INSN.
(*extendhi2_th_ext): New INSN.
(*extendqi2_th_ext): New INSN.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/xtheadbb-ext-2.c: New test.
* gcc.target/riscv/xtheadbb-ext-3.c: New test.
---
 gcc/config/riscv/thead.md   | 17 ++---
 gcc/testsuite/gcc.target/riscv/xtheadbb-ext-2.c | 12 
 gcc/testsuite/gcc.target/riscv/xtheadbb-ext-3.c | 12 
 3 files changed, 38 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/xtheadbb-ext-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/xtheadbb-ext-3.c

diff --git a/gcc/config/riscv/thead.md b/gcc/config/riscv/thead.md
index 29f98dec3a8..05d1b32bd94 100644
--- a/gcc/config/riscv/thead.md
+++ b/gcc/config/riscv/thead.md
@@ -58,14 +58,25 @@ (define_insn "*th_ext4"
   [(set_attr "type" "bitmanip")
(set_attr "mode" "")])
 
-(define_insn "*extend2_th_ext"
+(define_insn "*extendhi2_th_ext"
   [(set (match_operand:SUPERQI 0 "register_operand" "=r,r")
(sign_extend:SUPERQI
-   (match_operand:SHORT 1 "nonimmediate_operand" "r,m")))]
+   (match_operand:HI 1 "nonimmediate_operand" "r,m")))]
   "TARGET_XTHEADBB"
   "@
th.ext\t%0,%1,15,0
-   l\t%0,%1"
+   lh\t%0,%1"
+  [(set_attr "type" "bitmanip,load")
+   (set_attr "mode" "")])
+
+(define_insn "*extendqi2_th_ext"
+  [(set (match_operand:SUPERQI 0 "register_operand" "=r,r")
+   (sign_extend:SUPERQI
+   (match_operand:QI 1 "nonimmediate_operand" "r,m")))]
+  "TARGET_XTHEADBB"
+  "@
+   th.ext\t%0,%1,7,0
+   lb\t%0,%1"
   [(set_attr "type" "bitmanip,load")
(set_attr "mode" "")])
 
diff --git a/gcc/testsuite/gcc.target/riscv/xtheadbb-ext-2.c 
b/gcc/testsuite/gcc.target/riscv/xtheadbb-ext-2.c
new file mode 100644
index 000..4645b9c56df
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/xtheadbb-ext-2.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_xtheadbb" { target { rv64 } } } */
+/* { dg-options "-march=rv32gc_xtheadbb" { target { rv32 } } } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Os" "-Og" "-Oz" } } */
+
+signed long extqi(signed char i)
+{
+return --i;
+}
+
+/* { dg-final { scan-assembler "th.ext\ta\[0-9\]+,a\[0-9\]+,7,0" } } */
+/* { dg-final { scan-assembler-not "th.ext\ta\[0-9\]+,a\[0-9\]+,15,0" } } */
diff --git a/gcc/testsuite/gcc.target/riscv/xtheadbb-ext-3.c 
b/gcc/testsuite/gcc.target/riscv/xtheadbb-ext-3.c
new file mode 100644
index 000..2c9ebbc563a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/xtheadbb-ext-3.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_xtheadbb" { target { rv64 } } } */
+/* { dg-options "-march=rv32gc_xtheadbb" { target { rv32 } } } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Os" "-Og" "-Oz" } } */
+
+signed long exthi(signed short i)
+{
+return --i;
+}
+
+/* { dg-final { scan-assembler "th.ext\ta\[0-9\]+,a\[0-9\]+,15,0" } } */
+/* { dg-final { scan-assembler-not "th.ext\ta\[0-9\]+,a\[0-9\]+,7,0" } } */
-- 
2.41.0