Re: [PATCH v2] C, ObjC: Add -Wunterminated-string-initialization

2023-10-01 Thread Martin Uecker


(I shortened the recipient list)

Am Sonntag, dem 01.10.2023 um 02:55 +0200 schrieb Alejandro Colomar:

> > 
...
> I ran the tests, and get some unexpected failure.  I used dg-warning,
> but maybe I used it wrong?  Here's the output:
> 
> ```
> output is:
> /home/alx/src/gnu/gcc/wustr/gcc/testsuite/gcc.dg/Wunterminated-string-initialization.c:5:14:
>  warning: initializer-string for array of 'char' is too long 
> [-Wunterminated-string-initi
> alization]
> 
> FAIL: gcc.dg/Wunterminated-string-initialization.c  (test for warnings, line 
> 5)
> ```
> 
> And here's the test:
> 
> ```
> /* { dg-do compile } */
> /* { dg-options "-Wunterminated-string-initialization" } */
> 
> char a1[] = "a";
> char a2[1] = "a"; /* { dg-warning "unterminated char sequence" } */
> char a3[2] = "a";
> ```
> 
> Why isn't it expecting the warning?

Because the text does not match the actual output above?
You should see an additional FAIL for an excess warning.

Martin






Re: [PATCH v6] RISC-V:Optimize the MASK opt generation

2023-10-01 Thread Kito Cheng
Committed to trunk, thanks Feng :)

On Sat, Sep 30, 2023 at 3:34 AM Jeff Law  wrote:
>
>
>
> On 9/12/23 03:18, Feng Wang wrote:
> > New patch add some comments and update docs for this new usage.
> > ---
> > Accoring to Kito's advice, using "MASK(name) Var(other_flag_name)"
> > to generate MASK and TARGET MACRO automatically.
> > This patch improve the MACRO generation of MASK_* and TARGET_*.
> > Due to the more and more riscv extensions are added, the default target_flag
> > is full.
> > Before this patch,if you want to add new MACRO,you should define the
> > MACRO in the riscv-opts.h manually.
> > After this patch, you just need two steps:
> > 1.Define the new TargetVariable.
> > 2.Define "MASK(name) Var(new_target_flag).
> >
> > gcc/ChangeLog:
> >
> >  * config/riscv/riscv-opts.h (MASK_ZICSR):
> >  (MASK_ZIFENCEI): Delete;
> >  (MASK_ZIHINTNTL):Ditto;
> >  (MASK_ZIHINTPAUSE):  Ditto;
> >  (TARGET_ZICSR):  Ditto;
> >  (TARGET_ZIFENCEI):   Ditto;
> >  (TARGET_ZIHINTNTL):  Ditto;
> >  (TARGET_ZIHINTPAUSE):Ditto;
> >  (MASK_ZAWRS):Ditto;
> >  (TARGET_ZAWRS):  Ditto;
> >  (MASK_ZBA):  Ditto;
> >  (MASK_ZBB):  Ditto;
> >  (MASK_ZBC):  Ditto;
> >  (MASK_ZBS):  Ditto;
> >  (TARGET_ZBA):Ditto;
> >  (TARGET_ZBB):Ditto;
> >  (TARGET_ZBC):Ditto;
> >  (TARGET_ZBS):Ditto;
> >  (MASK_ZFINX):Ditto;
> >  (MASK_ZDINX):Ditto;
> >  (MASK_ZHINX):Ditto;
> >  (MASK_ZHINXMIN): Ditto;
> >  (TARGET_ZFINX):  Ditto;
> >  (TARGET_ZDINX):  Ditto;
> >  (TARGET_ZHINX):  Ditto;
> >  (TARGET_ZHINXMIN):   Ditto;
> >  (MASK_ZBKB): Ditto;
> >  (MASK_ZBKC): Ditto;
> >  (MASK_ZBKX): Ditto;
> >  (MASK_ZKNE): Ditto;
> >  (MASK_ZKND): Ditto;
> >  (MASK_ZKNH): Ditto;
> >  (MASK_ZKR):  Ditto;
> >  (MASK_ZKSED):Ditto;
> >  (MASK_ZKSH): Ditto;
> >  (MASK_ZKT):  Ditto;
> >  (TARGET_ZBKB):   Ditto;
> >  (TARGET_ZBKC):   Ditto;
> >  (TARGET_ZBKX):   Ditto;
> >  (TARGET_ZKNE):   Ditto;
> >  (TARGET_ZKND):   Ditto;
> >  (TARGET_ZKNH):   Ditto;
> >  (TARGET_ZKR):Ditto;
> >  (TARGET_ZKSED):  Ditto;
> >  (TARGET_ZKSH):   Ditto;
> >  (TARGET_ZKT):Ditto;
> >  (MASK_ZTSO): Ditto;
> >  (TARGET_ZTSO):   Ditto;
> >  (MASK_VECTOR_ELEN_32):   Ditto;
> >  (MASK_VECTOR_ELEN_64):   Ditto;
> >  (MASK_VECTOR_ELEN_FP_32):Ditto;
> >  (MASK_VECTOR_ELEN_FP_64):Ditto;
> >  (MASK_VECTOR_ELEN_FP_16):Ditto;
> >  (TARGET_VECTOR_ELEN_32): Ditto;
> >  (TARGET_VECTOR_ELEN_64): Ditto;
> >  (TARGET_VECTOR_ELEN_FP_32):Ditto;
> >  (TARGET_VECTOR_ELEN_FP_64):Ditto;
> >  (TARGET_VECTOR_ELEN_FP_16):Ditto;
> >   (MASK_ZVBB):   Ditto;
> >  (MASK_ZVBC):   Ditto;
> >  (TARGET_ZVBB): Ditto;
> >  (TARGET_ZVBC): Ditto;
> >  (MASK_ZVKG):   Ditto;
> >  (MASK_ZVKNED): Ditto;
> >  (MASK_ZVKNHA): Ditto;
> >  (MASK_ZVKNHB): Ditto;
> >  (MASK_ZVKSED): Ditto;
> >  (MASK_ZVKSH):  Ditto;
> >  (MASK_ZVKN):   Ditto;
> >  (MASK_ZVKNC):  Ditto;
> >  (MASK_ZVKNG):  Ditto;
> >  (MASK_ZVKS):   Ditto;
> >  (MASK_ZVKSC):  Ditto;
> >  (MASK_ZVKSG):  Ditto;
> >  (MASK_ZVKT):   Ditto;
> >  (TARGET_ZVKG): Ditto;
> >  (TARGET_ZVKNED):   Ditto;
> >  (TARGET_ZVKNHA):   Ditto;
> >  (TARGET_ZVKNHB):   Ditto;
> >  (TARGET_ZVKSED):   Ditto;
> >  (TARGET_ZVKSH):Ditto;
> >  (TARGET_ZVKN): Ditto;
> >  (TARGET_ZVKNC):Ditto;
> >  (TARGET_ZVKNG):Ditto;
> >  (TARGET_ZVKS): Ditto;
> >  (TARGET_ZVKSC):Ditto;
> >  (TARGET_ZVKSG):Ditto;
> >  (TARGET_ZVKT): Ditto;
> >  (MASK_ZVL32B): Ditto;
> >  (MASK_ZVL64B): Ditto;
> >  (MASK_ZVL128B):Ditto;
> >  (MASK_ZVL256B):Ditto;
> >  (MASK_ZVL512B):Ditto;
> >  (MASK_ZVL1024B):   Ditto;
> >  (MASK_ZVL2048B):   Ditto;
> >  (MASK_ZVL4096B):   Ditto;
> >  (MASK_ZVL8192B):   Ditto;
> >  (MASK_ZVL16384B):  Ditto;
> >  (MASK_ZVL32768B):  Ditto;
> >  (MASK_ZVL65536B): 

Re: [PATCH v2] C, ObjC: Add -Wunterminated-string-initialization

2023-10-01 Thread Alejandro Colomar
On Sun, Oct 01, 2023 at 09:37:59AM +0200, Martin Uecker wrote:
> 
> (I shortened the recipient list)
> 
> Am Sonntag, dem 01.10.2023 um 02:55 +0200 schrieb Alejandro Colomar:
> 
> > > 
> ...
> > I ran the tests, and get some unexpected failure.  I used dg-warning,
> > but maybe I used it wrong?  Here's the output:
> > 
> > ```
> > output is:
> > /home/alx/src/gnu/gcc/wustr/gcc/testsuite/gcc.dg/Wunterminated-string-initialization.c:5:14:
> >  warning: initializer-string for array of 'char' is too long 
> > [-Wunterminated-string-initi
> > alization]
> > 
> > FAIL: gcc.dg/Wunterminated-string-initialization.c  (test for warnings, 
> > line 5)
> > ```
> > 
> > And here's the test:
> > 
> > ```
> > /* { dg-do compile } */
> > /* { dg-options "-Wunterminated-string-initialization" } */
> > 
> > char a1[] = "a";
> > char a2[1] = "a";   /* { dg-warning "unterminated char sequence" } */
> > char a3[2] = "a";
> > ```
> > 
> > Why isn't it expecting the warning?
> 
> Because the text does not match the actual output above?

Makes sense.

Here's the output after a fix (which I'll send soon as a new revision):

```
output is:
/home/alx/src/gnu/gcc/wustr/gcc/testsuite/gcc.dg/Wunterminated-string-initialization.c:5:14:
 warning: initializer-string for array of 'char' is too long 
[-Wunterminated-string-initialization]

```
and

```
=== gcc Summary ===

# of expected passes2
```

The only thing that concerns me a little bit is that I don't see any
PASS (or XFAIL).

> You should see an additional FAIL for an excess warning.

Yep, I did.

Cheers,
Alex

> 
> Martin
> 
> 
> 
> 


signature.asc
Description: PGP signature


[PATCH v3] C, ObjC: Add -Wunterminated-string-initialization

2023-10-01 Thread Alejandro Colomar
From: Alejandro Colomar 

Warn about the following:

char  s[3] = "foo";

Initializing a char array with a string literal of the same length as
the size of the array is usually a mistake.  Rarely is the case where
one wants to create a non-terminated character sequence from a string
literal.

In some cases, for writing faster code, one may want to use arrays
instead of pointers, since that removes the need for storing an array of
pointers apart from the strings themselves.

char  *log_levels[]   = { "info", "warning", "err" };
vs.
char  log_levels[][7] = { "info", "warning", "err" };

This forces the programmer to specify a size, which might change if a
new entry is later added.  Having no way to enforce null termination is
very dangerous, however, so it is useful to have a warning for this, so
that the compiler can make sure that the programmer didn't make any
mistakes.  This warning catches the bug above, so that the programmer
will be able to fix it and write:

char  log_levels[][8] = { "info", "warning", "err" };

This warning already existed as part of -Wc++-compat, but this patch
allows enabling it separately.  It is also included in -Wextra, since
it may not always be desired (when unterminated character sequences are
wanted), but it's likely to be desired in most cases.

Link: 
Link: 
Link: 

Acked-by: Doug McIlroy 
Cc: "G. Branden Robinson" 
Cc: Ralph Corderoy 
Cc: Dave Kemper 
Cc: Larry McVoy 
Cc: Andrew Pinski 
Cc: Jonathan Wakely 
Cc: Andrew Clayton 
Cc: Martin Uecker 
Cc: David Malcolm 
Signed-off-by: Alejandro Colomar 
---

v3:

-  Fix dg-warning message in the testsuite.

 gcc/c-family/c.opt | 4 
 gcc/c/c-typeck.cc  | 6 +++---
 gcc/testsuite/gcc.dg/Wunterminated-string-initialization.c | 6 ++
 3 files changed, 13 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/Wunterminated-string-initialization.c

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 44b9c862c14..e8f6b836836 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -1407,6 +1407,10 @@ Wunsuffixed-float-constants
 C ObjC Var(warn_unsuffixed_float_constants) Warning
 Warn about unsuffixed float constants.
 
+Wunterminated-string-initialization
+C ObjC Var(warn_unterminated_string_initialization) Warning LangEnabledBy(C 
ObjC,Wextra || Wc++-compat)
+Warn about character arrays initialized as unterminated character sequences by 
a string literal.
+
 Wunused
 C ObjC C++ ObjC++ LangEnabledBy(C ObjC C++ ObjC++,Wall)
 ; documented in common.opt
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index e55e887da14..7df9de819ed 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -8399,11 +8399,11 @@ digest_init (location_t init_loc, tree type, tree init, 
tree origtype,
pedwarn_init (init_loc, 0,
  ("initializer-string for array of %qT "
   "is too long"), typ1);
- else if (warn_cxx_compat
+ else if (warn_unterminated_string_initialization
   && compare_tree_int (TYPE_SIZE_UNIT (type), len) < 0)
-   warning_at (init_loc, OPT_Wc___compat,
+   warning_at (init_loc, OPT_Wunterminated_string_initialization,
("initializer-string for array of %qT "
-"is too long for C++"), typ1);
+"is too long"), typ1);
  if (compare_tree_int (TYPE_SIZE_UNIT (type), len) < 0)
{
  unsigned HOST_WIDE_INT size
diff --git a/gcc/testsuite/gcc.dg/Wunterminated-string-initialization.c 
b/gcc/testsuite/gcc.dg/Wunterminated-string-initialization.c
new file mode 100644
index 000..13d5dbc6640
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wunterminated-string-initialization.c
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+/* { dg-options "-Wunterminated-string-initialization" } */
+
+char a1[] = "a";
+char a2[1] = "a";  /* { dg-warning "initializer-string for array of 'char' 
is too long" } */
+char a3[2] = "a";
-- 
2.40.1



[PATCH v4] C, ObjC: Add -Wunterminated-string-initialization

2023-10-01 Thread Alejandro Colomar
Warn about the following:

char  s[3] = "foo";

Initializing a char array with a string literal of the same length as
the size of the array is usually a mistake.  Rarely is the case where
one wants to create a non-terminated character sequence from a string
literal.

In some cases, for writing faster code, one may want to use arrays
instead of pointers, since that removes the need for storing an array of
pointers apart from the strings themselves.

char  *log_levels[]   = { "info", "warning", "err" };
vs.
char  log_levels[][7] = { "info", "warning", "err" };

This forces the programmer to specify a size, which might change if a
new entry is later added.  Having no way to enforce null termination is
very dangerous, however, so it is useful to have a warning for this, so
that the compiler can make sure that the programmer didn't make any
mistakes.  This warning catches the bug above, so that the programmer
will be able to fix it and write:

char  log_levels[][8] = { "info", "warning", "err" };

This warning already existed as part of -Wc++-compat, but this patch
allows enabling it separately.  It is also included in -Wextra, since
it may not always be desired (when unterminated character sequences are
wanted), but it's likely to be desired in most cases.

Link: 
Link: 
Link: 

Acked-by: Doug McIlroy 
Cc: "G. Branden Robinson" 
Cc: Ralph Corderoy 
Cc: Dave Kemper 
Cc: Larry McVoy 
Cc: Andrew Pinski 
Cc: Jonathan Wakely 
Cc: Andrew Clayton 
Cc: Martin Uecker 
Cc: David Malcolm 
Signed-off-by: Alejandro Colomar 
---

v4:

-  Fix From: address

 gcc/c-family/c.opt | 4 
 gcc/c/c-typeck.cc  | 6 +++---
 gcc/testsuite/gcc.dg/Wunterminated-string-initialization.c | 6 ++
 3 files changed, 13 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/Wunterminated-string-initialization.c

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 44b9c862c14..e8f6b836836 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -1407,6 +1407,10 @@ Wunsuffixed-float-constants
 C ObjC Var(warn_unsuffixed_float_constants) Warning
 Warn about unsuffixed float constants.
 
+Wunterminated-string-initialization
+C ObjC Var(warn_unterminated_string_initialization) Warning LangEnabledBy(C 
ObjC,Wextra || Wc++-compat)
+Warn about character arrays initialized as unterminated character sequences by 
a string literal.
+
 Wunused
 C ObjC C++ ObjC++ LangEnabledBy(C ObjC C++ ObjC++,Wall)
 ; documented in common.opt
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index e55e887da14..7df9de819ed 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -8399,11 +8399,11 @@ digest_init (location_t init_loc, tree type, tree init, 
tree origtype,
pedwarn_init (init_loc, 0,
  ("initializer-string for array of %qT "
   "is too long"), typ1);
- else if (warn_cxx_compat
+ else if (warn_unterminated_string_initialization
   && compare_tree_int (TYPE_SIZE_UNIT (type), len) < 0)
-   warning_at (init_loc, OPT_Wc___compat,
+   warning_at (init_loc, OPT_Wunterminated_string_initialization,
("initializer-string for array of %qT "
-"is too long for C++"), typ1);
+"is too long"), typ1);
  if (compare_tree_int (TYPE_SIZE_UNIT (type), len) < 0)
{
  unsigned HOST_WIDE_INT size
diff --git a/gcc/testsuite/gcc.dg/Wunterminated-string-initialization.c 
b/gcc/testsuite/gcc.dg/Wunterminated-string-initialization.c
new file mode 100644
index 000..13d5dbc6640
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wunterminated-string-initialization.c
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+/* { dg-options "-Wunterminated-string-initialization" } */
+
+char a1[] = "a";
+char a2[1] = "a";  /* { dg-warning "initializer-string for array of 'char' 
is too long" } */
+char a3[2] = "a";
-- 
2.40.1



Re: [PATCH] rtl-optimization/110939 Really fix narrow comparison of memory and constant

2023-10-01 Thread Stefan Schulze Frielinghaus
On Fri, Sep 29, 2023 at 01:01:57PM -0600, Jeff Law wrote:
> 
> 
> On 8/10/23 07:04, Stefan Schulze Frielinghaus via Gcc-patches wrote:
> > In the former fix in commit 41ef5a34161356817807be3a2e51fbdbe575ae85 I
> > completely missed the fact that the normal form of a generated constant for 
> > a
> > mode with fewer bits than in HOST_WIDE_INT is a sign extended version of the
> > actual constant.  This even holds true for unsigned constants.
> > 
> > Fixed by masking out the upper bits for the incoming constant and sign
> > extending the resulting unsigned constant.
> > 
> > Bootstrapped and regtested on x64 and s390x.  Ok for mainline?
> > 
> [ snip]
> 
> > 
> > gcc/ChangeLog:
> > 
> > * combine.cc (simplify_compare_const): Properly handle unsigned
> > constants while narrowing comparison of memory and constants.
> OK.
> 
> 
> > ---
> > @@ -12051,15 +12052,15 @@ simplify_compare_const (enum rtx_code code, 
> > machine_mode mode,
> > HOST_WIDE_INT_PRINT_HEX ") to (MEM %s "
> > HOST_WIDE_INT_PRINT_HEX ").\n", GET_MODE_NAME (int_mode),
> > GET_MODE_NAME (narrow_mode_iter), GET_RTX_NAME (code),
> > -   (unsigned HOST_WIDE_INT)const_op, GET_RTX_NAME (adjusted_code),
> > -   n);
> > +   (unsigned HOST_WIDE_INT) const_op & GET_MODE_MASK (int_mode),
> > +   GET_RTX_NAME (adjusted_code), n);
> > }
> >   poly_int64 offset = (BYTES_BIG_ENDIAN
> >? 0
> >: (GET_MODE_SIZE (int_mode)
> >   - GET_MODE_SIZE (narrow_mode_iter)));
> >   *pop0 = adjust_address_nv (op0, narrow_mode_iter, offset);
> > - *pop1 = GEN_INT (n);
> > + *pop1 = gen_int_mode (n, narrow_mode_iter);
> >   return adjusted_code;
> FWIW, I should definitely have caught this hunk earlier -- we've gone the
> rounds in this same space (GEN_INT vs gen_int_mode) elsewhere.
> 
> Again, sorry for the long wait.
> 
> jeff

No worries at all.  At least I have learned something new :)

Thanks Jeff and Eric for clarification.  This matches with my intuition,
now, so I've pushed the patch.

Cheers,
Stefan


RE: [ARC PATCH] Use rlc r0, 0 to implement scc_ltu (i.e. carry_flag ? 1 : 0)

2023-10-01 Thread Claudiu Zissulescu
I'll add it to our nightly. Just to be sure 😊 I’ll let you know asap it's 
status.

Roger, you can always use Synopsys free nsim simulator which you can find it on 
Synopsys website.

Thanks,
Claudiu


-Original Message-
From: Jeff Law  
Sent: Saturday, September 30, 2023 1:02 AM
To: Roger Sayle ; Claudiu Zissulescu 

Cc: gcc-patches@gcc.gnu.org
Subject: Re: [ARC PATCH] Use rlc r0, 0 to implement scc_ltu (i.e. carry_flag ? 
1 : 0)



On 9/29/23 15:11, Roger Sayle wrote:
> 
> Hi Claudiu,
>> The patch looks sane. Have you run dejagnu test suite?
> 
> I've not yet managed to set up an emulator or compile the entire 
> toolchain, so my dejagnu results are only useful for catching 
> (serious) problems in the compile only tests:
> 
>  === gcc Summary ===
> 
> # of expected passes91875
> # of unexpected failures23768
> # of unexpected successes   23
> # of expected failures  1038
> # of unresolved testcases   19490
> # of unsupported tests  3819
> /home/roger/GCC/arc-linux/gcc/xgcc  version 14.0.0 20230828 
> (experimental)
> (GCC)
> 
> If someone could double check there are no issues on real hardware 
> that would be great.  I'm not sure if ARC is one of the targets 
> covered by Jeff Law's compile farm?
It is :-)  Runs daily, about 4:30 am UTC.  So if the bits go in we'd have data 
within 24hrs.


Jeff



Re: [PATCH] rtl-optimization/110939 Really fix narrow comparison of memory and constant

2023-10-01 Thread Jeff Law




On 10/1/23 08:26, Stefan Schulze Frielinghaus wrote:


FWIW, I should definitely have caught this hunk earlier -- we've gone the
rounds in this same space (GEN_INT vs gen_int_mode) elsewhere.

Again, sorry for the long wait.

jeff


No worries at all.  At least I have learned something new :)

Thanks Jeff and Eric for clarification.  This matches with my intuition,
now, so I've pushed the patch.
BTW, in a completely different context I need to do some testing on the 
alpha port, which hasn't bootstrapped in a couple months.  I'd been 
assuming the failure was completely due to ongoing changes I'm making in 
the infrastructure I used to bootstrap QEMU emulated systems.


As it turns out, the infrastructure changes and this minor combine issue 
were both playing a role!


Jeff


[PATCH v5] C, ObjC: Add -Wunterminated-string-initialization

2023-10-01 Thread Alejandro Colomar
Warn about the following:

char  s[3] = "foo";

Initializing a char array with a string literal of the same length as
the size of the array is usually a mistake.  Rarely is the case where
one wants to create a non-terminated character sequence from a string
literal.

In some cases, for writing faster code, one may want to use arrays
instead of pointers, since that removes the need for storing an array of
pointers apart from the strings themselves.

char  *log_levels[]   = { "info", "warning", "err" };
vs.
char  log_levels[][7] = { "info", "warning", "err" };

This forces the programmer to specify a size, which might change if a
new entry is later added.  Having no way to enforce null termination is
very dangerous, however, so it is useful to have a warning for this, so
that the compiler can make sure that the programmer didn't make any
mistakes.  This warning catches the bug above, so that the programmer
will be able to fix it and write:

char  log_levels[][8] = { "info", "warning", "err" };

This warning already existed as part of -Wc++-compat, but this patch
allows enabling it separately.  It is also included in -Wextra, since
it may not always be desired (when unterminated character sequences are
wanted), but it's likely to be desired in most cases.

Since Wc++-compat now includes this warning, the test has to be modified
to expect the text of the new warning too, in .

Link: 
Link: 
Link: 

Acked-by: Doug McIlroy 
Cc: "G. Branden Robinson" 
Cc: Ralph Corderoy 
Cc: Dave Kemper 
Cc: Larry McVoy 
Cc: Andrew Pinski 
Cc: Jonathan Wakely 
Cc: Andrew Clayton 
Cc: Martin Uecker 
Cc: David Malcolm 
Signed-off-by: Alejandro Colomar 
---

v5:

-  Fix existing C++-compat tests.  [reported by ]


 gcc/c-family/c.opt | 4 
 gcc/c/c-typeck.cc  | 6 +++---
 gcc/testsuite/gcc.dg/Wcxx-compat-14.c  | 2 +-
 gcc/testsuite/gcc.dg/Wunterminated-string-initialization.c | 6 ++
 4 files changed, 14 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/Wunterminated-string-initialization.c

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 44b9c862c14..e8f6b836836 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -1407,6 +1407,10 @@ Wunsuffixed-float-constants
 C ObjC Var(warn_unsuffixed_float_constants) Warning
 Warn about unsuffixed float constants.
 
+Wunterminated-string-initialization
+C ObjC Var(warn_unterminated_string_initialization) Warning LangEnabledBy(C 
ObjC,Wextra || Wc++-compat)
+Warn about character arrays initialized as unterminated character sequences by 
a string literal.
+
 Wunused
 C ObjC C++ ObjC++ LangEnabledBy(C ObjC C++ ObjC++,Wall)
 ; documented in common.opt
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index e55e887da14..7df9de819ed 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -8399,11 +8399,11 @@ digest_init (location_t init_loc, tree type, tree init, 
tree origtype,
pedwarn_init (init_loc, 0,
  ("initializer-string for array of %qT "
   "is too long"), typ1);
- else if (warn_cxx_compat
+ else if (warn_unterminated_string_initialization
   && compare_tree_int (TYPE_SIZE_UNIT (type), len) < 0)
-   warning_at (init_loc, OPT_Wc___compat,
+   warning_at (init_loc, OPT_Wunterminated_string_initialization,
("initializer-string for array of %qT "
-"is too long for C++"), typ1);
+"is too long"), typ1);
  if (compare_tree_int (TYPE_SIZE_UNIT (type), len) < 0)
{
  unsigned HOST_WIDE_INT size
diff --git a/gcc/testsuite/gcc.dg/Wcxx-compat-14.c 
b/gcc/testsuite/gcc.dg/Wcxx-compat-14.c
index 23783711be6..6df0ee197cc 100644
--- a/gcc/testsuite/gcc.dg/Wcxx-compat-14.c
+++ b/gcc/testsuite/gcc.dg/Wcxx-compat-14.c
@@ -2,5 +2,5 @@
 /* { dg-options "-Wc++-compat" } */
 
 char a1[] = "a";
-char a2[1] = "a";  /* { dg-warning "C\[+\]\[+\]" } */
+char a2[1] = "a";  /* { dg-warning "initializer-string for array of 'char' 
is too long" } */
 char a3[2] = "a";
diff --git a/gcc/testsuite/gcc.dg/Wunterminated-string-initialization.c 
b/gcc/testsuite/gcc.dg/Wunterminated-string-initialization.c
new file mode 100644
index 000..13d5dbc6640
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wunterminated-string-initialization.c
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+/* { dg-options "-Wunterminated-string-initialization" } */
+
+char a1[] = "a";
+char a2[1] = "a";  /* { dg-warning "initializer-string for array of 'char' 
is too long" } */
+char a3[2] = "a";
-- 
2.40.1



[COMMITTED/13] Fix PR 110386: backprop vs ABSU_EXPR

2023-10-01 Thread Andrew Pinski
From: Andrew Pinski 

The issue here is that when backprop tries to go
and strip sign ops, it skips over ABSU_EXPR but
ABSU_EXPR not only does an ABS, it also changes the
type to unsigned.
Since strip_sign_op_1 is only supposed to strip off
sign changing operands and not ones that change types,
removing ABSU_EXPR here is correct. We don't handle
nop conversions so this does cause any missed optimizations either.

Committed to the GCC 13 branch after bootstrapped and
tested on x86_64-linux-gnu with no regressions.

PR tree-optimization/110386

gcc/ChangeLog:

* gimple-ssa-backprop.cc (strip_sign_op_1): Remove ABSU_EXPR.

gcc/testsuite/ChangeLog:

* gcc.c-torture/compile/pr110386-1.c: New test.
* gcc.c-torture/compile/pr110386-2.c: New test.

(cherry picked from commit 2bbac12ea7bd8a3eef5382e1b13f6019df4ec03f)
---
 gcc/gimple-ssa-backprop.cc   |  1 -
 gcc/testsuite/gcc.c-torture/compile/pr110386-1.c |  9 +
 gcc/testsuite/gcc.c-torture/compile/pr110386-2.c | 11 +++
 3 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr110386-1.c
 create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr110386-2.c

diff --git a/gcc/gimple-ssa-backprop.cc b/gcc/gimple-ssa-backprop.cc
index 65a65590017..dcb15ed4f61 100644
--- a/gcc/gimple-ssa-backprop.cc
+++ b/gcc/gimple-ssa-backprop.cc
@@ -694,7 +694,6 @@ strip_sign_op_1 (tree rhs)
 switch (gimple_assign_rhs_code (assign))
   {
   case ABS_EXPR:
-  case ABSU_EXPR:
   case NEGATE_EXPR:
return gimple_assign_rhs1 (assign);
 
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr110386-1.c 
b/gcc/testsuite/gcc.c-torture/compile/pr110386-1.c
new file mode 100644
index 000..4fcc977ad16
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr110386-1.c
@@ -0,0 +1,9 @@
+
+int f(int a)
+{
+int c = c < 0 ? c : -c;
+c = -c;
+unsigned b =  c;
+unsigned t = b*a;
+return t*t;
+}
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr110386-2.c 
b/gcc/testsuite/gcc.c-torture/compile/pr110386-2.c
new file mode 100644
index 000..c60e1b6994b
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr110386-2.c
@@ -0,0 +1,11 @@
+/* { dg-do compile { target i?86-*-* x86_64-*-* } } */
+/* { dg-options "-mavx" } */
+
+#include 
+
+__m128i do_stuff(__m128i XMM0) {
+   __m128i ABS0 = _mm_abs_epi32(XMM0);
+   __m128i MUL0 = _mm_mullo_epi32(ABS0, XMM0);
+   __m128i MUL1 = _mm_mullo_epi32(MUL0, MUL0);
+   return MUL1;
+}
-- 
2.39.3



[PATCH v2] ipa-utils: avoid uninitialized probabilities on ICF [PR111559]

2023-10-01 Thread Sergei Trofimovich
From: Sergei Trofimovich 

r14-3459-g0c78240fd7d519 "Check that passes do not forget to define profile"
exposed check failures in cases when gcc produces uninitialized profile
probabilities. In case of PR/111559 uninitialized profile is generated
by edges executed 0 times reported by IPA profile:

$ gcc -O2 -fprofile-generate pr111559.c -o b -fopt-info
$ ./b
$ gcc -O2 -fprofile-use -fprofile-correction pr111559.c -o b -fopt-info

pr111559.c: In function 'rule1':
pr111559.c:6:13: error: probability of edge 3->4 not initialized
6 | static void rule1(void) { if (p) edge(); }
  | ^
during GIMPLE pass: fixup_cfg
pr111559.c:6:13: internal compiler error: verify_flow_info failed

The change conservatively ignores updates with uninitialized values and
uses initially assigned probabilities (`always` probability in case of
the example).

PR ipa/111283
PR gcov-profile/111559

gcc/
* ipa-utils.cc (ipa_merge_profiles): Avoid producing
uninitialized probabilities when merging counters with zero
denominators.

gcc/testsuite/
* gcc.dg/tree-prof/pr111559.c: New test.
---
 gcc/ipa-utils.cc  |  6 +-
 gcc/testsuite/gcc.dg/tree-prof/pr111559.c | 16 
 2 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-prof/pr111559.c

diff --git a/gcc/ipa-utils.cc b/gcc/ipa-utils.cc
index 956c6294fd7..7c53ae9dd45 100644
--- a/gcc/ipa-utils.cc
+++ b/gcc/ipa-utils.cc
@@ -651,13 +651,17 @@ ipa_merge_profiles (struct cgraph_node *dst,
{
  edge srce = EDGE_SUCC (srcbb, i);
  edge dste = EDGE_SUCC (dstbb, i);
- dste->probability = 
+ profile_probability merged =
dste->probability * dstbb->count.ipa ().probability_in
 (dstbb->count.ipa ()
  + srccount.ipa ())
+ srce->probability * srcbb->count.ipa ().probability_in
 (dstbb->count.ipa ()
  + srccount.ipa ());
+ /* We produce uninitialized probabilities when
+denominator is zero: https://gcc.gnu.org/PR111559.  */
+ if (merged.initialized_p ())
+   dste->probability = merged;
}
  dstbb->count = dstbb->count.ipa () + srccount.ipa ();
}
diff --git a/gcc/testsuite/gcc.dg/tree-prof/pr111559.c 
b/gcc/testsuite/gcc.dg/tree-prof/pr111559.c
new file mode 100644
index 000..43202c6c888
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-prof/pr111559.c
@@ -0,0 +1,16 @@
+/* { dg-options "-O2" } */
+
+__attribute__((noipa)) static void edge(void) {}
+
+int p = 0;
+
+__attribute__((noinline))
+static void rule1(void) { if (p) edge(); }
+
+__attribute__((noinline))
+static void rule1_same(void) { if (p) edge(); }
+
+__attribute__((noipa)) int main(void) {
+rule1();
+rule1_same();
+}
-- 
2.42.0



Re: [Fortran, Patch, Coarray, PR 37336] Fix crash in finalizer when derived type coarray is already freed.

2023-10-01 Thread Paul Richard Thomas
Hi Andre,

All is well that ends well! Thanks for working on this.

Regards

Paul

On Sat, 30 Sept 2023 at 14:16, Andre Vehreschild  wrote:
>
> Hi all,
>
> back porting to gcc-13 unfortunately caused a regression due to
> gfc_deallocate_with_status() having a different parameter count. This is fixed
> as obvious by 874b895fffd921659b37dc05bc94eea48e9a0157.
>
> Sorry for breaking gfortran-13. I still don't know why it checkout fine on my
> system in the beginning. I must have done something wrong.
>
> Please accept my apologies and regards,
> Andre
>
> On Fri, 29 Sep 2023 15:13:56 +0200
> Andre Vehreschild via Fortran  wrote:
>
> > Hi Paul,
> >
> > thanks. Commit to trunk as a680274616ec6b26ccfdcee400ed7f54e341d40c
> > and backported to gcc-13 as d9b3269bdccac2db9200303494c4e82f2aeb7bbc
> >
> > Thanks for the fast review.
> >
> > Regards,
> >   Andre
> >
> > On Fri, 29 Sep 2023 13:38:57 +0100
> > Paul Richard Thomas  wrote:
> >
> > > Hi Andre,
> > >
> > > Yes indeed - it's fine for trunk and, I would suggest, 13-branch.
> > >
> > > Cheers
> > >
> > > Paul
> > >
> > > On Fri, 29 Sept 2023 at 11:01, Andre Vehreschild  wrote:
> > > >
> > > > Hi Paul,
> > > >
> > > > thanks for the quick review. I've added a testcase with a module and a
> > > > finalizer in the derived type. This also is no problem.
> > > >
> > > > Regtests ok on x86_64_linux_gnu/f37. Ok for trunk?
> > > >
> > > > Regards,
> > > > Andre
> > > >
> > > > On Thu, 28 Sep 2023 19:21:12 +0100
> > > > Paul Richard Thomas  wrote:
> > > >
> > > > > Hi Andre,
> > > > >
> > > > > The patch looks fine to me. Since you mention it in the comment, is it
> > > > > worth declaring the derived type 'foo' in a module and giving it a
> > > > > final routine?
> > > > >
> > > > > Thanks for the patch.
> > > > >
> > > > > Paul
> > > > >
> > > > > On Thu, 28 Sept 2023 at 13:45, Andre Vehreschild via Fortran
> > > > >  wrote:
> > > > > >
> > > > > > Hi all,
> > > > > >
> > > > > > attached patch fixes a crash in coarray programs when an allocatable
> > > > > > derived typed coarray was freed explicitly. The generated cleanup 
> > > > > > code
> > > > > > did not take into account, that the coarray may have been 
> > > > > > deallocated
> > > > > > already. The patch fixes this by moving the statements accessing
> > > > > > components inside the derived type into the block guard by its
> > > > > > allocated check.
> > > > > >
> > > > > > Regtested ok on f37/x86_64. Ok for master?
> > > > > >
> > > > > > Regards,
> > > > > > Andre
> > > > > > --
> > > > > > Andre Vehreschild * Email: vehre ad gmx dot de
> > > >
> > > >
> > > > --
> > > > Andre Vehreschild * Email: vehre ad gmx dot de
> >
> >
> > --
> > Andre Vehreschild * Email: vehre ad gmx dot de
>
>
> --
> Andre Vehreschild * Email: vehre ad gmx dot de


[WIP 1/4] openacc: Rename OMP_CLAUSE_TILE to OMP_CLAUSE_OACC_TILE

2023-10-01 Thread Sandra Loosemore
From: Frederik Harwath 

OMP_CLAUSE_TILE will be used for the OpenMP 5.1 loop transformation
construct "omp tile".

gcc/ChangeLog:

* tree-core.h (enum omp_clause_code): Rename OMP_CLAUSE_TILE.
* tree.h (OMP_CLAUSE_TILE_LIST): Rename to ...
(OMP_CLAUSE_OACC_TILE_LIST): ... this.
(OMP_CLAUSE_TILE_ITERVAR): Rename to ...
(OMP_CLAUSE_OACC_TILE_ITERVAR): ... this.
(OMP_CLAUSE_TILE_COUNT): Rename to ...
(OMP_CLAUSE_OACC_TILE_COUNT): this.
* gimplify.cc (gimplify_scan_omp_clauses): Adjust to renamings.
(gimplify_adjust_omp_clauses): Likewise.
(gimplify_omp_for): Likewise.
* omp-general.cc (omp_extract_for_data): Likewise.
* omp-low.cc (scan_sharing_clauses): Likewise.
(lower_oacc_head_mark): Likewise.
* tree-nested.cc (convert_nonlocal_omp_clauses): Likewise.
(convert_local_omp_clauses): Likewise.
* tree-pretty-print.cc (dump_omp_clause): Likewise.
* tree.cc: Likewise.

gcc/c-family/ChangeLog:

* c-omp.cc (c_oacc_split_loop_clauses): Adjust to renamings.

gcc/c/ChangeLog:

* c-parser.cc (c_parser_omp_clause_collapse): Adjust to renamings.
(c_parser_oacc_clause_tile): Likewise.
(c_parser_omp_for_loop): Likewise.
* c-typeck.cc (c_finish_omp_clauses): Likewise.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_oacc_clause_tile): Adjust to renamings.
(cp_parser_omp_clause_collapse): Likewise.
(cp_parser_omp_for_loop): Likewise.
* pt.cc (tsubst_omp_clauses): Likewise.
* semantics.cc (finish_omp_clauses): Likewise.
(finish_omp_for): Likewise.

gcc/fortran/ChangeLog:

* openmp.cc (enum omp_mask2): Adjust to renamings.
(gfc_match_omp_clauses): Likewise.
* trans-openmp.cc (gfc_trans_omp_clauses): Likewise.
---
 gcc/c-family/c-omp.cc   |  2 +-
 gcc/c/c-parser.cc   | 12 ++--
 gcc/c/c-typeck.cc   |  2 +-
 gcc/cp/parser.cc| 12 ++--
 gcc/cp/pt.cc|  2 +-
 gcc/cp/semantics.cc |  8 
 gcc/fortran/openmp.cc   |  6 +++---
 gcc/fortran/trans-openmp.cc |  4 ++--
 gcc/gimplify.cc |  8 
 gcc/omp-general.cc  |  8 
 gcc/omp-low.cc  |  6 +++---
 gcc/tree-core.h |  2 +-
 gcc/tree-nested.cc  |  4 ++--
 gcc/tree-pretty-print.cc|  4 ++--
 gcc/tree.cc |  2 +-
 gcc/tree.h  | 12 ++--
 16 files changed, 47 insertions(+), 47 deletions(-)

diff --git a/gcc/c-family/c-omp.cc b/gcc/c-family/c-omp.cc
index 95b6c1e623f..5de3b77c450 100644
--- a/gcc/c-family/c-omp.cc
+++ b/gcc/c-family/c-omp.cc
@@ -1899,7 +1899,7 @@ c_oacc_split_loop_clauses (tree clauses, tree 
*not_loop_clauses,
 {
  /* Loop clauses.  */
case OMP_CLAUSE_COLLAPSE:
-   case OMP_CLAUSE_TILE:
+   case OMP_CLAUSE_OACC_TILE:
case OMP_CLAUSE_GANG:
case OMP_CLAUSE_WORKER:
case OMP_CLAUSE_VECTOR:
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 0d468b86bd8..e6342d2188d 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -14658,7 +14658,7 @@ c_parser_omp_clause_collapse (c_parser *parser, tree 
list)
   location_t loc;
 
   check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
-  check_no_duplicate_clause (list, OMP_CLAUSE_TILE, "tile");
+  check_no_duplicate_clause (list, OMP_CLAUSE_OACC_TILE, "tile");
 
   loc = c_parser_peek_token (parser)->location;
   matching_parens parens;
@@ -15842,7 +15842,7 @@ c_parser_oacc_clause_tile (c_parser *parser, tree list)
   location_t loc;
   tree tile = NULL_TREE;
 
-  check_no_duplicate_clause (list, OMP_CLAUSE_TILE, "tile");
+  check_no_duplicate_clause (list, OMP_CLAUSE_OACC_TILE, "tile");
   check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
 
   loc = c_parser_peek_token (parser)->location;
@@ -15894,9 +15894,9 @@ c_parser_oacc_clause_tile (c_parser *parser, tree list)
   /* Consume the trailing ')'.  */
   c_parser_consume_token (parser);
 
-  c = build_omp_clause (loc, OMP_CLAUSE_TILE);
+  c = build_omp_clause (loc, OMP_CLAUSE_OACC_TILE);
   tile = nreverse (tile);
-  OMP_CLAUSE_TILE_LIST (c) = tile;
+  OMP_CLAUSE_OACC_TILE_LIST (c) = tile;
   OMP_CLAUSE_CHAIN (c) = list;
   return c;
 }
@@ -21137,10 +21137,10 @@ c_parser_omp_for_loop (location_t loc, c_parser 
*parser, enum tree_code code,
   for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
   collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl));
-else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_TILE)
+else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_OACC_TILE)
   {
tiling = true;
-   collapse = list_length (OMP_CLAUSE_TILE_LIST (cl));
+   collapse = list_length (OMP_CLAUSE_OACC_TILE_LIST (cl));
   }
 else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_ORDERED
 && OMP_CLAUSE_ORDERE

[WIP 0/4] OpenMP: support for loop transformations

2023-10-01 Thread Sandra Loosemore
This series of patches is an update of Frederik's previous loop
transformation patch set, previously posted here:

https://gcc.gnu.org/pipermail/gcc-patches/2023-March/614564.html

that has been updated to resolve conflicts with my set of
imperfectly-nested loops patches and other changes on mainline since
March.  It does not address Jakub's code review concerns that these
patches are lowering the transformations too late, and that this needs
to be done in the front ends instead; the purpose of this iteration of
the patch set is to provide a baseline for doing that rewrite.

I used the version of Frederik's patches that were committed
to the OG13 branch as the basis for this work, along with several
follow-up bug fixes, some glue and additional test cases I had added
on OG13 with my own imperfectly-nested loops patches there, the
support for C++ attribute syntax that I had later put on OG13 (which
required resolving some conflicts with different changes on mainline),
etc.  The specific OG13 commits that were on my merge list were:

ea770a4a9f6 openmp: Add Fortran support for "omp unroll" directive
c17983cd052 openmp: Add C/C++ support for "omp unroll" directive
5e11b7ffc84 openacc: Rename OMP_CLAUSE_TILE to OMP_CLAUSE_OACC_TILE
c6f772b089d openmp: Add Fortran support for "omp tile"
5b9c9f10892 openmp: Add C/C++ support for "omp tile"
5c71451f714 openmp: Add Fortran support for loop transformations on inner loops
3baddf440b7 openmp: Add C/C++ support for loop transformations on inner loops
c89addc938d openmp: Fix loop transformation tests
94a75fb12e6 openmp: Fix initialization for 'unroll full'
8adfa43a19e openmp: Fix diagnostic message for "omp unroll"
e59a5a62eb5 openmp: Fix number of iterations computation for "omp unroll full"
62e64a55d3f OpenMP: Handle loop transformation clauses in nested functions
09623de2186 OpenMP: C support for imperfectly-nested loops
546b3460346 OpenMP: C++ support for imperfectly-nested loops
bf38eb98eaf OpenMP: New c/c++ testcases for imperfectly-nested loops
4b17c1a010b OpenMP: Refactor and tidy Fortran front-end code for loop 
transformations
e10b1be8777 OpenMP: Fortran support for imperfectly nested loops
ff563b2c8dd OpenMP: C++ attribute syntax fixes/testcases for loop 
transformations

Because there were so many incremental changes I've reorganized
Frederik's patch set into a smaller set of consolidated changes, and
written new changelogs.

-Sandra

Frederik Harwath (4):
  openacc: Rename OMP_CLAUSE_TILE to OMP_CLAUSE_OACC_TILE
  OpenMP: Language-independent parts of loop transform support.
  OpenMP: Fortran front-end support for loop transforms.
  OpenMP: C and C++ front-end support for loop transforms.

 gcc/Makefile.in   |1 +
 gcc/c-family/c-gimplify.cc|1 +
 gcc/c-family/c-omp.cc |   12 +-
 gcc/c-family/c-pragma.cc  |2 +
 gcc/c-family/c-pragma.h   |7 +-
 gcc/c/c-parser.cc |  527 -
 gcc/c/c-typeck.cc |   10 +-
 gcc/cp/cp-gimplify.cc |3 +
 gcc/cp/parser.cc  |  541 -
 gcc/cp/pt.cc  |   15 +-
 gcc/cp/semantics.cc   |  103 +-
 gcc/doc/invoke.texi   |9 +
 gcc/fortran/dump-parse-tree.cc|   28 +
 gcc/fortran/gfortran.h|   12 +-
 gcc/fortran/match.h   |2 +
 gcc/fortran/openmp.cc |  736 +--
 gcc/fortran/parse.cc  |   48 +
 gcc/fortran/resolve.cc|6 +
 gcc/fortran/st.cc |2 +
 gcc/fortran/trans-openmp.cc   |  186 +-
 gcc/fortran/trans.cc  |2 +
 gcc/gimple-pretty-print.cc|6 +
 gcc/gimple.h  |1 +
 gcc/gimplify.cc   |   73 +-
 gcc/omp-general.cc|   22 +-
 gcc/omp-general.h |1 +
 gcc/omp-low.cc|6 +-
 gcc/omp-transform-loops.cc| 1815 +
 gcc/params.opt|8 +
 gcc/passes.def|1 +
 .../c-c++-common/gomp/imperfect-attributes.c  |   18 +-
 .../loop-transforms/imperfect-loop-nest.c |   11 +
 .../gomp/loop-transforms/tile-1.c |  160 ++
 .../gomp/loop-transforms/tile-2.c |  179 ++
 .../gomp/loop-transforms/tile-3.c |  109 +
 .../gomp/loop-transforms/tile-4.c |  322 +++
 .../gomp/loop-transforms/tile-5.c |  150 ++
 .../gomp/loop-transforms/tile-6.c |   34 +
 .../gomp/loop-transforms/tile-7.c |   31 +
 .../gomp/loop-transforms/tile-8.c |   40 +
 .../gomp/loop-transforms

[WIP 2/4] OpenMP: Language-independent parts of loop transform support.

2023-10-01 Thread Sandra Loosemore
From: Frederik Harwath 

This patch adds support for the OMP_LOOP_TRANS tree node, internal
OpenMP clauses representing loop transformations, and the
omp_transform_loops pass to lower them.

gcc/ChangeLog:

* Makefile.in (OBJS): Add omp-transform-loops.o.
* gimple-pretty-print.cc (dump_gimple_omp_for): Handle
GF_OMP_FOR_KIND_TRANSFORM_LOOP.
* gimple.h (enum gf_mask): Add GF_FOR_KIND_TRANSFORM_LOOP.
* gimplify.cc (is_gimple_stmt): Add OMP_LOOP_TRANS.
(gimplify_scan_omp_clauses): Handle loop transform clauses.
(gimplify_adjust_omp_clauses): Likewise.
(omp_for_drop_tile_clauses): New function.
(gimplify_omp_for): Call omp_for_drop_tile_clauses.  Handle
OMP_LOOP_TRANS and loop transform clauses.
(gimplify_omp_loop): Handle loop transform clauses.
(gimplify_expr): Handle OMP_LOOP_TRANS.
* omp-general.cc (omp_loop_transform_clause_p): New function.
* omp-general.h (omp_loop_transform_clause_p): Declare.
* omp-transform-loops.cc: New file.
* params.opt (omp-unroll-full-max-iterations): New.
(omp-unroll-default-factor): New.
* passes.def: Add pass_omp_transform_loops before pass_lower_omp.
* tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_UNROLL_FULL,
OMP_CLAUSE_UNROLL_NONE, OMP_CLAUSE_UNROLL_PARTIAL, and
OMP_CLAUSE_TILE.
* tree-nested.cc (convert_nonlocal_omp_clauses): Add support
for loop transform clauses.
(convert_local_omp_clauses): Likewise.
* tree-pass.h (make_pass_omp_transform_loops): Declare.
* tree-pretty-print.cc (dump_omp_clause): Add support for loop
transform clauses.
(dump_generic_node): Handle OMP_LOOP_TRANS.
* tree.cc (omp_clause_num_ops): Add entries for loop transforms.
(omp_clause_code_name): Likewise.
* tree.def (OMP_LOOP_TRANS): New.
* tree.h (OMP_CLAUSE_TRANSFORM_LEVEL): New.
(OMP_CLAUSE_UNROLL_PARTIAL_EXPR): New.
(OMP_CLAUSE_TILE_SIZES): New.
* doc/invoke.texi (Optimize Options): Document the new parameters.

Co-Authored-By: Sandra Loosemore 
---
 gcc/Makefile.in|1 +
 gcc/doc/invoke.texi|9 +
 gcc/gimple-pretty-print.cc |6 +
 gcc/gimple.h   |1 +
 gcc/gimplify.cc|   65 +-
 gcc/omp-general.cc |   14 +
 gcc/omp-general.h  |1 +
 gcc/omp-transform-loops.cc | 1815 
 gcc/params.opt |8 +
 gcc/passes.def |1 +
 gcc/tree-core.h|   12 +
 gcc/tree-nested.cc |   14 +
 gcc/tree-pass.h|1 +
 gcc/tree-pretty-print.cc   |   52 ++
 gcc/tree.cc|8 +
 gcc/tree.def   |6 +
 gcc/tree.h |   11 +
 17 files changed, 2024 insertions(+), 1 deletion(-)
 create mode 100644 gcc/omp-transform-loops.cc

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 9cc16268abf..767823e223b 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1582,6 +1582,7 @@ OBJS = \
omp-expand.o \
omp-general.o \
omp-low.o \
+   omp-transform-loops.o \
omp-oacc-kernels-decompose.o \
omp-oacc-neuter-broadcast.o \
omp-simd-clone.o \
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 4085fc90907..e904dc4b3c4 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -16470,6 +16470,15 @@ With @option{--param=openacc-privatization=quiet}, 
don't diagnose.
 This is the current default.
 With @option{--param=openacc-privatization=noisy}, do diagnose.
 
+@item omp-unroll-full-max-iterations
+The maximum number of iterations of a loop for which an OpenMP @samp{omp 
unroll}
+directive on the loop without a clause is turned into an
+@samp{omp unroll full}.
+
+@item omp-unroll-default-factor
+The unroll factor used for loops that have an OpenMP @samp{omp unroll partial}
+directive without an explicit unroll factor.
+
 @end table
 
 The following choices of @var{name} are available on AArch64 targets:
diff --git a/gcc/gimple-pretty-print.cc b/gcc/gimple-pretty-print.cc
index 320df9197b4..1548feea092 100644
--- a/gcc/gimple-pretty-print.cc
+++ b/gcc/gimple-pretty-print.cc
@@ -1474,6 +1474,9 @@ dump_gimple_omp_for (pretty_printer *buffer, const 
gomp_for *gs, int spc,
case GF_OMP_FOR_KIND_SIMD:
  kind = " simd";
  break;
+   case GF_OMP_FOR_KIND_TRANSFORM_LOOP:
+ kind = " unroll";
+ break;
default:
  gcc_unreachable ();
}
@@ -1511,6 +1514,9 @@ dump_gimple_omp_for (pretty_printer *buffer, const 
gomp_for *gs, int spc,
case GF_OMP_FOR_KIND_SIMD:
  pp_string (buffer, "#pragma omp simd");
  break;
+   case GF_OMP_FOR_KIND_TRANSFORM_LOOP:
+ pp_string (buffer, "#pragma omp loop_transform");
+ break;
default:
  gcc_unreachable ();
}
diff --git a/gcc/gimple.h b/gc

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

2023-10-01 Thread Andrew Pinski
From: Andrew Pinski 

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.

Committed to GCC 13 branch after bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

PR tree-optimization/111331
* 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.

(cherry picked from commit 30e6ee074588bacefd2dfe745b188bb20c81fe5e)
---
 .../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 
 4 files changed, 55 insertions(+), 4 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/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 a7ab6ce4ad9..c3d78d1400b 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -2270,7 +2270,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)
@@ -2301,7 +2301,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
@@ -2341,7 +2341,7 @@ minmax_replacement (basic_block cond_bb, basic_block 
middle_bb, basic_block alt_
 
  /* We need BOUND >= LARGER.  */
  if (!integer_nonzerop (fold_build2 (GE_EXPR, boolean_type_node,
- bound, larger)))
+ bound, arg_true)))
return false;
}
  else if (operand_equal_for_phi_arg_p (arg_true, smaller)
@@ -2368,7 +2368,7 @@ minmax_replacement (basic_block cond_bb, basic_block 
middle_bb, basic_block alt_
 
  /* We need BOUND <= SMALLER.  */
  if (!integer_nonzerop (fold_build2 (LE_EXPR, boolean_type_node,
- bound, smaller)))
+ bound, arg_true)))
return false;
}
  else
-- 
2.39.3



Re: [PATCH v6] RISC-V:Optimize the MASK opt generation

2023-10-01 Thread Gerald Pfeifer
On Sun, 1 Oct 2023, Kito Cheng wrote:
> Committed to trunk, thanks Feng :)

Hmm, my nightly FreeBSD 12 tester now fails as follows:

  nawk -f /scratch/tmp/gerald/GCC-HEAD/gcc/opt-functions.awk \
-f /scratch/tmp/gerald/GCC-HEAD/gcc/opt-read.awk \
-f /scratch/tmp/gerald/GCC-HEAD/gcc/opth-gen.awk \
   < optionlist > tmp-options.h
  nawk: syntax error at source line 67 source file 
/scratch/tmp/gerald/GCC-HEAD/gcc/opt-read.awk
  context is
>>>other_masks[var_index][ 
<<< n_other_mask[var_index]++] = name
  nawk: illegal statement at source line 67 source file 
  /scratch/tmp/gerald/GCC-HEAD/gcc/opt-read.awk
  nawk -f /scratch/tmp/gerald/GCC-HEAD/gcc/opt-functions.awk \
-f /scratch/tmp/gerald/GCC-HEAD/gcc/opt-read.awk \
   -f /scratch/tmp/gerald/GCC-HEAD/gcc/optc-save-gen.awk \
   -v header_name="config.h system.h coretypes.h tm.h" < optionlist \
   > options-save.cc
  nawk: syntax error at source line 386 source file 
  /scratch/tmp/gerald/GCC-HEAD/gcc/opth-gen.awk
  nawk: syntax error at source line 67 source file 
  /scratch/tmp/gerald/GCC-HEAD/gcc/opt-read.awk
  context is
>>>other_masks[var_index][ 
<<< n_other_mask[var_index]++] = name
  nawk: illegal statement at source line 67 source file 
  /scratch/tmp/gerald/GCC-HEAD/gcc/opt-read.awk
  gmake[3]: *** [Makefile:2477: s-options-h] Error 2

Gerald


Committed: Fix typo in add_options_for_riscv_v, add_options_for_riscv_zfh, add_options_for_riscv_d .

2023-10-01 Thread Joern Rennecke
Committed as obvious (RE doesn't compile without patch, and I know
what I meant when I wrote it).
commit 5f3da480e7541a9c29d655dccb2463fc5f3cf2c4
Author: Joern Rennecke 
Date:   Sun Oct 1 22:46:43 2023 +0100

Fix typo in add_options_for_riscv_v, add_options_for_riscv_zfh, 
add_options_for_riscv_d .

gcc/testsuite/
* lib/target-supports.exp (add_options_for_riscv_v):
Fix typo in first regexp.
(add_options_for_riscv_zfh): Likewise.
(add_options_for_riscv_d): Likewise.

diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp
index f3043b2af1b..64889fa6d34 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -2021,7 +2021,7 @@ proc riscv_get_arch { } {
 proc add_options_for_riscv_d { flags } {
 if { [lsearch $flags -march=*] >= 0 } {
# If there are multiple -march flags, we have to adjust all of them.
-   return [regsub -all -- 
{((?^|[[:space:]])-march=rv[[:digit:]]*[a-ce-rt-wy]*)d*} $flags \\1d ]
+   return [regsub -all -- 
{((?:^|[[:space:]])-march=rv[[:digit:]]*[a-ce-rt-wy]*)d*} $flags \\1d ]
 }
 if { [check_effective_target_riscv_d] } {
return "$flags"
@@ -2032,7 +2032,7 @@ proc add_options_for_riscv_d { flags } {
 proc add_options_for_riscv_v { flags } {
 if { [lsearch $flags -march=*] >= 0 } {
# If there are multiple -march flags, we have to adjust all of them.
-   return [regsub -all -- 
{((?^|[[:space:]])-march=rv[[:digit:]]*[a-rt-uwy]*)v*} $flags \\1v ]
+   return [regsub -all -- 
{((?:^|[[:space:]])-march=rv[[:digit:]]*[a-rt-uwy]*)v*} $flags \\1v ]
 }
 if { [check_effective_target_riscv_v] } {
return "$flags"
@@ -2043,8 +2043,8 @@ proc add_options_for_riscv_v { flags } {
 proc add_options_for_riscv_zfh { flags } {
 if { [lsearch $flags -march=*] >= 0 } {
# If there are multiple -march flags, we have to adjust all of them.
-   set flags [regsub -all -- {(?^|[[:space:]])-march=[[:alnum:]_.]*} 
$flags &_zfh ]
-   return [regsub -all -- 
{((?^|[[:space:]])-march=[[:alnum:]_.]*_zfh[[:alnum:]_.]*)_zfh} $flags \\1 ]
+   set flags [regsub -all -- {(?:^|[[:space:]])-march=[[:alnum:]_.]*} 
$flags &_zfh ]
+   return [regsub -all -- 
{((?:^|[[:space:]])-march=[[:alnum:]_.]*_zfh[[:alnum:]_.]*)_zfh} $flags \\1 ]
 }
 if { [check_effective_target_riscv_zfh] } {
return "$flags"


[PATCH] C/C++: add hints for strerror

2023-10-01 Thread Oskari Pirhonen
Add proper hints for implicit declaration of strerror.

The results could be confusing depending on the other included headers.
These example messages are from compiling a trivial program to print the
string for an errno value. It only includes stdio.h (cstdio for C++).

Before:
$ /tmp/gcc-master/bin/gcc test.c -o test_c
test.c: In function ‘main’:
test.c:4:20: warning: implicit declaration of function ‘strerror’; did you mean 
‘perror’? [-Wimplicit-function-declaration]
4 | printf("%s\n", strerror(0));
  |^~~~
  |perror

$ /tmp/gcc-master/bin/g++ test.cpp -o test_cpp
test.cpp: In function ‘int main()’:
test.cpp:4:20: error: ‘strerror’ was not declared in this scope; did you mean 
‘stderr’?
4 | printf("%s\n", strerror(0));
  |^~~~
  |stderr

After:
$ /tmp/gcc-known-headers/bin/gcc test.c -o test_c
test.c: In function ‘main’:
test.c:4:20: warning: implicit declaration of function ‘strerror’ 
[-Wimplicit-function-declaration]
4 | printf("%s\n", strerror(0));
  |^~~~
test.c:2:1: note: ‘strerror’ is defined in header ‘’; this is 
probably fixable by adding ‘#include ’
1 | #include 
  +++ |+#include 
2 |

$ /tmp/gcc-known-headers/bin/g++ test.cpp -o test_cpp
test.cpp: In function ‘int main()’:
test.cpp:4:20: error: ‘strerror’ was not declared in this scope
4 | printf("%s\n", strerror(0));
  |^~~~
test.cpp:2:1: note: ‘strerror’ is defined in header ‘’; this is 
probably fixable by adding ‘#include ’
1 | #include 
  +++ |+#include 
2 |

gcc/c-family/ChangeLog:

* known-headers.cc (get_stdlib_header_for_name): Add strerror.

gcc/testsuite/ChangeLog:

* g++.dg/spellcheck-stdlib.C: Add check for strerror.
* gcc.dg/spellcheck-stdlib-2.c: New test.

Signed-off-by: Oskari Pirhonen 
---
 gcc/c-family/known-headers.cc  | 1 +
 gcc/testsuite/g++.dg/spellcheck-stdlib.C   | 2 ++
 gcc/testsuite/gcc.dg/spellcheck-stdlib-2.c | 8 
 3 files changed, 11 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/spellcheck-stdlib-2.c

diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc
index 3484c867ca0..14855bd75c7 100644
--- a/gcc/c-family/known-headers.cc
+++ b/gcc/c-family/known-headers.cc
@@ -182,6 +182,7 @@ get_stdlib_header_for_name (const char *name, enum stdlib 
lib)
 {"strchr", {"", ""} },
 {"strcmp", {"", ""} },
 {"strcpy", {"", ""} },
+{"strerror", {"", ""} },
 {"strlen", {"", ""} },
 {"strncat", {"", ""} },
 {"strncmp", {"", ""} },
diff --git a/gcc/testsuite/g++.dg/spellcheck-stdlib.C 
b/gcc/testsuite/g++.dg/spellcheck-stdlib.C
index fd0f3a9b8c9..33718b8034e 100644
--- a/gcc/testsuite/g++.dg/spellcheck-stdlib.C
+++ b/gcc/testsuite/g++.dg/spellcheck-stdlib.C
@@ -104,6 +104,8 @@ void test_cstring (char *dest, char *src)
   // { dg-message "'#include '" "" { target *-*-* } .-1 }
   strcpy(dest, "test"); // { dg-error "was not declared" }
   // { dg-message "'#include '" "" { target *-*-* } .-1 }
+  strerror(0); // { dg-error "was not declared" }
+  // { dg-message "'#include '" "" { target *-*-* } .-1 }
   strlen("test"); // { dg-error "was not declared" }
   // { dg-message "'#include '" "" { target *-*-* } .-1 }
   strncat(dest, "test", 3); // { dg-error "was not declared" }
diff --git a/gcc/testsuite/gcc.dg/spellcheck-stdlib-2.c 
b/gcc/testsuite/gcc.dg/spellcheck-stdlib-2.c
new file mode 100644
index 000..61c17f350cb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/spellcheck-stdlib-2.c
@@ -0,0 +1,8 @@
+/* { dg-options "-Wimplicit-function-declaration" } */
+
+/* Missing .  */
+void test_string_h (void)
+{
+  strerror (0); /* { dg-warning "implicit declaration of function 'strerror'" 
} */
+  /* { dg-message "'strerror' is defined in header ''" "" { target 
*-*-* } .-1 } */
+}
-- 
2.41.0



[RISC-V]: Re: cpymem for RISCV with v extension

2023-10-01 Thread Joern Rennecke
On Tue, 15 Aug 2023 at 15:06, Jeff Law  wrote:
 >
> On 8/15/23 03:16, juzhe.zh...@rivai.ai wrote:
> > The new  patch looks reasonable to me now. Thanks for fixing it.
> >
> > Could you append testcase after finishing test infrastructure ?
> > I prefer this patch with testcase after infrastructure.
> So let's call this an ACK, but ask that Joern not commit until the
> testsuite bits are in place.

Beyond the adding of tests, the patch needed some changes because of the
Refactoring of emit_{vlmax,nonvlmax}_xxx functions .
Attached is the committed version.
commit 9464e72bcc9123b619215af8cfef491772a3ebd9
Author: Joern Rennecke 
Date:   Mon Oct 2 03:16:09 2023 +0100

cpymem for RISC-V with v extension

gcc/
* config/riscv/riscv-protos.h (riscv_vector::expand_block_move):
Declare.
* config/riscv/riscv-v.cc (riscv_vector::expand_block_move):
New function.
* config/riscv/riscv.md (cpymemsi): Use 
riscv_vector::expand_block_move.
Change to ..
(cpymem) .. this.

gcc/testsuite/
* gcc.target/riscv/rvv/base/cpymem-1.c: New test.
* gcc.target/riscv/rvv/base/cpymem-2.c: Likewise.

Co-Authored-By: Juzhe-Zhong 

diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h
index af5baf37e6a..43426a5326b 100644
--- a/gcc/config/riscv/riscv-protos.h
+++ b/gcc/config/riscv/riscv-protos.h
@@ -492,6 +492,7 @@ bool slide1_sew64_helper (int, machine_mode, machine_mode,
  machine_mode, rtx *);
 rtx gen_avl_for_scalar_move (rtx);
 void expand_tuple_move (rtx *);
+bool expand_block_move (rtx, rtx, rtx);
 machine_mode preferred_simd_mode (scalar_mode);
 machine_mode get_mask_mode (machine_mode);
 void expand_vec_series (rtx, rtx, rtx);
diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc
index 097457562bd..29e138e1da2 100644
--- a/gcc/config/riscv/riscv-v.cc
+++ b/gcc/config/riscv/riscv-v.cc
@@ -49,6 +49,7 @@
 #include "tm-constrs.h"
 #include "rtx-vector-builder.h"
 #include "targhooks.h"
+#include "predict.h"
 
 using namespace riscv_vector;
 
@@ -1991,6 +1992,206 @@ expand_tuple_move (rtx *ops)
 }
 }
 
+/* Used by cpymemsi in riscv.md .  */
+
+bool
+expand_block_move (rtx dst_in, rtx src_in, rtx length_in)
+{
+  /*
+memcpy:
+   mv a3, a0   # Copy destination
+loop:
+   vsetvli t0, a2, e8, m8, ta, ma  # Vectors of 8b
+   vle8.v v0, (a1) # Load bytes
+   add a1, a1, t0  # Bump pointer
+   sub a2, a2, t0  # Decrement count
+   vse8.v v0, (a3) # Store bytes
+   add a3, a3, t0  # Bump pointer
+   bnez a2, loop   # Any more?
+   ret # Return
+  */
+  if (!TARGET_VECTOR)
+return false;
+  HOST_WIDE_INT potential_ew
+= (MIN (MIN (MEM_ALIGN (src_in), MEM_ALIGN (dst_in)), BITS_PER_WORD)
+   / BITS_PER_UNIT);
+  machine_mode vmode = VOIDmode;
+  bool need_loop = true;
+  bool size_p = optimize_function_for_size_p (cfun);
+  rtx src, dst;
+  rtx end = gen_reg_rtx (Pmode);
+  rtx vec;
+  rtx length_rtx = length_in;
+
+  if (CONST_INT_P (length_in))
+{
+  HOST_WIDE_INT length = INTVAL (length_in);
+
+/* By using LMUL=8, we can copy as many bytes in one go as there
+   are bits in a vector register.  If the entire block thus fits,
+   we don't need a loop.  */
+if (length <= TARGET_MIN_VLEN)
+  {
+   need_loop = false;
+
+   /* If a single scalar load / store pair can do the job, leave it
+  to the scalar code to do that.  */
+   /* ??? If fast unaligned access is supported, the scalar code could
+  use suitably sized scalars irrespective of alignemnt.  If that
+  gets fixed, we have to adjust the test here.  */
+
+   if (pow2p_hwi (length) && length <= potential_ew)
+ return false;
+  }
+
+  /* Find the vector mode to use.  Using the largest possible element
+size is likely to give smaller constants, and thus potentially
+reducing code size.  However, if we need a loop, we need to update
+the pointers, and that is more complicated with a larger element
+size, unless we use an immediate, which prevents us from dynamically
+using the targets transfer size that the hart supports.  And then,
+unless we know the *exact* vector size of the hart, we'd need
+multiple vsetvli / branch statements, so it's not even a size win.
+If, in the future, we find an RISCV-V implementation that is slower
+for small element widths, we might allow larger element widths for
+loops too.  */
+  if (need_loop)
+   potential_ew = 1;
+  for (; potential_ew; potential_ew >>= 1)
+   {
+ scalar_int_mode elem_mode;
+ unsigned HOST_WIDE_INT bits = potential_ew * BITS_PER_UNIT;
+ unsign

Re: [PATCH v6] RISC-V:Optimize the MASK opt generation

2023-10-01 Thread Kito Cheng
Hi Gerald:

Thanks for reporting this issue, I just realized multidimensional
arrays are gawk extensions, could you try the attached patch to see if
it can resolve the issue?

On Mon, Oct 2, 2023 at 4:56 AM Gerald Pfeifer  wrote:
>
> On Sun, 1 Oct 2023, Kito Cheng wrote:
> > Committed to trunk, thanks Feng :)
>
> Hmm, my nightly FreeBSD 12 tester now fails as follows:
>
>   nawk -f /scratch/tmp/gerald/GCC-HEAD/gcc/opt-functions.awk \
> -f /scratch/tmp/gerald/GCC-HEAD/gcc/opt-read.awk \
> -f /scratch/tmp/gerald/GCC-HEAD/gcc/opth-gen.awk \
>< optionlist > tmp-options.h
>   nawk: syntax error at source line 67 source file
> /scratch/tmp/gerald/GCC-HEAD/gcc/opt-read.awk
>   context is
> >>>other_masks[var_index][
> <<< n_other_mask[var_index]++] = name
>   nawk: illegal statement at source line 67 source file
>   /scratch/tmp/gerald/GCC-HEAD/gcc/opt-read.awk
>   nawk -f /scratch/tmp/gerald/GCC-HEAD/gcc/opt-functions.awk \
> -f /scratch/tmp/gerald/GCC-HEAD/gcc/opt-read.awk \
>-f /scratch/tmp/gerald/GCC-HEAD/gcc/optc-save-gen.awk \
>-v header_name="config.h system.h coretypes.h tm.h" < optionlist \
>> options-save.cc
>   nawk: syntax error at source line 386 source file
>   /scratch/tmp/gerald/GCC-HEAD/gcc/opth-gen.awk
>   nawk: syntax error at source line 67 source file
>   /scratch/tmp/gerald/GCC-HEAD/gcc/opt-read.awk
>   context is
> >>>other_masks[var_index][
> <<< n_other_mask[var_index]++] = name
>   nawk: illegal statement at source line 67 source file
>   /scratch/tmp/gerald/GCC-HEAD/gcc/opt-read.awk
>   gmake[3]: *** [Makefile:2477: s-options-h] Error 2
>
> Gerald
From a2a621ed6a3eaf136e917d10f4970a6bf7240d5a Mon Sep 17 00:00:00 2001
From: Kito Cheng 
Date: Mon, 2 Oct 2023 10:50:42 +0800
Subject: [PATCH] options: Prevent multidimensional arrays

Multidimensional arrary is gawk extension, and we accidentally
introduced that in recent commit[1].

[1] https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=e4a4b8e983bac865eb435b11798e38d633b98942

gcc/ChangeLog:

	* opt-read.awk: Drop multidimensional arrays.
	* opth-gen.awk: Ditto.
---
 gcc/opt-read.awk | 2 +-
 gcc/opth-gen.awk | 8 
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/opt-read.awk b/gcc/opt-read.awk
index fcf92853957..b6b4c01888d 100644
--- a/gcc/opt-read.awk
+++ b/gcc/opt-read.awk
@@ -131,7 +131,7 @@ BEGIN {
 	{
 		target_vars[n_target_vars++] = target_var
 	}
-	other_masks[var_index][n_other_mask[var_index]++] = name
+	other_masks[var_index "," n_other_mask[var_index]++] = name
 }
 else
 {
diff --git a/gcc/opth-gen.awk b/gcc/opth-gen.awk
index 70ca3d37719..c4398be2f3a 100644
--- a/gcc/opth-gen.awk
+++ b/gcc/opth-gen.awk
@@ -412,9 +412,9 @@ for (i = 0; i < n_target_vars; i++)
 		continue
 	for (j = 0; j < n_other_mask[i]; j++)
 	{
-		print "#define MASK_" other_masks[i][j] " (1U << " other_masknum[i][""]++ ")"
+		print "#define MASK_" other_masks[i "," j] " (1U << " other_masknum[i]++ ")"
 	}
-	if (other_masknum[i][""] > 32)
+	if (other_masknum[i] > 32)
 		print "#error too many target masks for" extra_target_vars[i]
 }
 
@@ -437,8 +437,8 @@ for (i = 0; i < n_target_vars; i++)
 		continue
 	for (j = 0; j < n_other_mask[i]; j++)
 	{
-		print "#define TARGET_" other_masks[i][j] \
-		  " ((" target_vars[i] " & MASK_" other_masks[i][j] ") != 0)"
+		print "#define TARGET_" other_masks[i "," j] \
+		  " ((" target_vars[i] " & MASK_" other_masks[i "," j] ") != 0)"
 	}
 }
 print ""
-- 
2.40.1



Re: Improve -Wflex-array-member-not-at-end changes.html wording |Plus: and warning bug? (was: [V2][PATCH] gcc-14/changes.html: Deprecate a GCC C extension on flexible array members.)

2023-10-01 Thread Qing Zhao
Hi, Tobias,

Sorry for the late reply.

I has been on vacation after Cauldron, and will be back to work in the mid of 
Oct. will look at this issue at that time.

Qing

> On Sep 25, 2023, at 2:24 PM, Tobias Burnus  wrote:
> 
> Hi all,
> 
> I stumbled over this as I found the wording in the release notes rather 
> unclear.is.
> 
> 
> First, the following gives only a -pedantic warning and not a 
> -Wflex-array-member-not-at-end:
> 
>  struct t { int b; int x[]; };
>  struct q { int b; struct t a[2]; int c; };
> 
> warning: invalid use of structure with flexible array member [-Wpedantic]
> 
> If I remove the "[2]", it shows additionally:
>  warning: structure containing a flexible array member is not at the end of 
> another structure [-Wflex-array-member-not-at-end]
> 
> It seems as if it should print latter warning also inside the struct.
> 
> Qing? Joseph? Thoughts?
> 
> * * *
> 
> Secondly, if this is deprecated, shouldn't then the warning enabled by, e.g., 
> -Wall or made
> otherwise more prominent? (-std=?) - Currently, one either has to find the 
> new flag or use
> -pedantic.
> 
> Or is this not really regarded as deprecated? But then (IMHO) we should not 
> really claim so and just
> add the warning without deprecation.
> 
> BTW; clang-15 prints the -Wgnu-variable-sized-type-not-at-end warning by 
> default.
> 
> Joseph, all: Thoughts?
> 
> * * *
> 
> Cross ref: The patch adding the new warning is r14-2197-g070a6bf0bdc6761
> https://gcc.gnu.org/pipermail/gcc-cvs/2023-June/385730.html (cf. previously 
> in this thread)
> 
> 
> * * *
> 
> Regarding the changes.html wording:
> 
> On 07.08.23 16:22, Qing Zhao via Gcc-patches wrote:
> 
>> Comparing to the 1st version, the only change is to address Richard's
>> comment on refering a warning option for diagnosing deprecated behavior.
> ...
>> +++ b/htdocs/gcc-14/changes.html
>> @@ -30,7 +30,18 @@ a work-in-progress.
>>  
>>  Caveats
>>  
>> -  ...
>> +  C:
>> +  Support for the GCC extension, a structure containing a C99 flexible 
>> array
>> +  member, or a union containing such a structure, is not the last field 
>> of
>> +  another structure, is deprecated. Refer to
>> +  https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html";>
>> +  Zero Length Arrays.
> 
> ...
> 
> I find the first sentence difficult to read. What do you think of the 
> following?
> (It is hard to come up with some good wording.)
> 
> --- a/htdocs/gcc-14/changes.html
> +++ b/htdocs/gcc-14/changes.html
> @@ -31,9 +31,10 @@ a work-in-progress.
> Caveats
> 
>   C:
> -  Support for the GCC extension, a structure containing a C99 flexible 
> array
> -  member, or a union containing such a structure, is not the last field 
> of
> -  another structure, is deprecated. Refer to
> +  Support for the GCC extension that a structure containing a C99 
> flexible
> +  array (and any union containing a member of such structure) can be a
> +  member of a structure has been deprecated for the case that it is not
> +  the last member. Refer to
>   https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html";>
>   Zero Length Arrays.
>   Any code relying on this extension should be modifed to ensure that
> 
> 
> Tobias
> 
> PS:  C17 has:
> "A structure or union shall not contain a member with incomplete or function 
> type (hence, a structure
> shall not contain an instance of itself, but may contain a pointer to an 
> instance of itself), except that
> the last member of a structure with more than one named member may have 
> incomplete array type;
> such a structure (and any union containing, possibly recursively, a member 
> that is such a structure)
> shall not be a member of a structure or an element of an array."
> 
> -
> 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



Re: [PATCH v6] RISC-V:Optimize the MASK opt generation

2023-10-01 Thread Jan-Benedict Glaw
On Mon, 2023-10-02 10:55:25 +0800, Kito Cheng  wrote:
> Hi Gerald:
> 
> Thanks for reporting this issue, I just realized multidimensional
> arrays are gawk extensions, could you try the attached patch to see if
> it can resolve the issue?

With your new patch, it works for me again using `mawk` (cf.
http://toolchain.lug-owl.de/laminar/jobs/gcc-local/75), but please
also keep using TABs in opt-read.awk ("if (target_var)").

MfG, JBG

-- 


signature.asc
Description: PGP signature


[pushed] Fix profiledbootstrap poly_int fallout [PR111642]

2023-10-01 Thread Richard Sandiford
rtl-tests.cc and simplify-rtx.cc used partial specialisation
to try to restrict the NUM_POLY_INT_COEFFS>1 tests without
resorting to preprocessor tests.  That now triggers an error
in some configurations, since the NUM_POLY_INT_COEFFS>1 tests
used the global poly_int64, whose definition does not depend
on the template parameter.

This patch uses local types that do depend on the template parameter.

Tested using profiledbootstrap and bootstrap4 on x86_64-linux-gnu,
both of which failed for me for unrelated reasons later.  But Sergei
confirms in the PR that the patch does fix the bug.  Pushed as obvious.

Richard


gcc/
PR bootstrap/111642
* rtl-tests.cc (const_poly_int_tests::run): Use a local
poly_int64 typedef.
* simplify-rtx.cc (simplify_const_poly_int_tests::run): Likewise.
---
 gcc/rtl-tests.cc| 1 +
 gcc/simplify-rtx.cc | 1 +
 2 files changed, 2 insertions(+)

diff --git a/gcc/rtl-tests.cc b/gcc/rtl-tests.cc
index ae8669419b6..96656c54a48 100644
--- a/gcc/rtl-tests.cc
+++ b/gcc/rtl-tests.cc
@@ -246,6 +246,7 @@ template
 void
 const_poly_int_tests::run ()
 {
+  using poly_int64 = poly_int;
   rtx x1 = gen_int_mode (poly_int64 (1, 1), QImode);
   rtx x255 = gen_int_mode (poly_int64 (1, 255), QImode);
 
diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc
index 170406aa28b..bd9443dbcc2 100644
--- a/gcc/simplify-rtx.cc
+++ b/gcc/simplify-rtx.cc
@@ -8689,6 +8689,7 @@ template
 void
 simplify_const_poly_int_tests::run ()
 {
+  using poly_int64 = poly_int;
   rtx x1 = gen_int_mode (poly_int64 (1, 1), QImode);
   rtx x2 = gen_int_mode (poly_int64 (-80, 127), QImode);
   rtx x3 = gen_int_mode (poly_int64 (-79, -128), QImode);
-- 
2.25.1