Patch ping (Re: [PATCH] middle-end, i386: Pattern recognize add/subtract with carry [PR79173])

2023-06-13 Thread Jakub Jelinek via Gcc-patches
Hi!

On Tue, Jun 06, 2023 at 11:42:07PM +0200, Jakub Jelinek via Gcc-patches wrote:
> The following patch introduces {add,sub}c5_optab and pattern recognizes
> various forms of add with carry and subtract with carry/borrow, see
> pr79173-{1,2,3,4,5,6}.c tests on what is matched.
> Primarily forms with 2 __builtin_add_overflow or __builtin_sub_overflow
> calls per limb (with just one for the least significant one), for
> add with carry even when it is hand written in C (for subtraction
> reassoc seems to change it too much so that the pattern recognition
> doesn't work).  __builtin_{add,sub}_overflow are standardized in C23
> under ckd_{add,sub} names, so it isn't any longer a GNU only extension.
> 
> Note, clang has for these has (IMHO badly designed)
> __builtin_{add,sub}c{b,s,,l,ll} builtins which don't add/subtract just
> a single bit of carry, but basically add 3 unsigned values or
> subtract 2 unsigned values from one, and result in carry out of 0, 1, or 2
> because of that.  If we wanted to introduce those for clang compatibility,
> we could and lower them early to just two __builtin_{add,sub}_overflow
> calls and let the pattern matching in this patch recognize it later.
> 
> I've added expanders for this on ix86 and in addition to that
> added various peephole2s to make sure we get nice (and small) code
> for the common cases.  I think there are other PRs which request that
> e.g. for the _{addcarry,subborrow}_u{32,64} intrinsics, which the patch
> also improves.

I'd like to ping this patch.

Thanks.

Jakub



Re: [PATCH v2] [PR96339] Optimise svlast[ab]

2023-06-13 Thread Tejas Belagod via Gcc-patches



From: Richard Sandiford 
Date: Monday, June 12, 2023 at 2:15 PM
To: Tejas Belagod 
Cc: gcc-patches@gcc.gnu.org , Tejas Belagod 

Subject: Re: [PATCH v2] [PR96339] Optimise svlast[ab]
Tejas Belagod  writes:
> From: Tejas Belagod 
>
>   This PR optimizes an SVE intrinsics sequence where
> svlasta (svptrue_pat_b8 (SV_VL1), x)
>   a scalar is selected based on a constant predicate and a variable vector.
>   This sequence is optimized to return the correspoding element of a NEON
>   vector. For eg.
> svlasta (svptrue_pat_b8 (SV_VL1), x)
>   returns
> umovw0, v0.b[1]
>   Likewise,
> svlastb (svptrue_pat_b8 (SV_VL1), x)
>   returns
>  umovw0, v0.b[0]
>   This optimization only works provided the constant predicate maps to a range
>   that is within the bounds of a 128-bit NEON register.
>
> gcc/ChangeLog:
>
>PR target/96339
>* config/aarch64/aarch64-sve-builtins-base.cc (svlast_impl::fold): 
> Fold sve
>calls that have a constant input predicate vector.
>(svlast_impl::is_lasta): Query to check if intrinsic is svlasta.
>(svlast_impl::is_lastb): Query to check if intrinsic is svlastb.
>(svlast_impl::vect_all_same): Check if all vector elements are equal.
>
> gcc/testsuite/ChangeLog:
>
>PR target/96339
>* gcc.target/aarch64/sve/acle/general-c/svlast.c: New.
>* gcc.target/aarch64/sve/acle/general-c/svlast128_run.c: New.
>* gcc.target/aarch64/sve/acle/general-c/svlast256_run.c: New.
>* gcc.target/aarch64/sve/pcs/return_4.c (caller_bf16): Fix asm
>to expect optimized code for function body.
>* gcc.target/aarch64/sve/pcs/return_4_128.c (caller_bf16): Likewise.
>* gcc.target/aarch64/sve/pcs/return_4_256.c (caller_bf16): Likewise.
>* gcc.target/aarch64/sve/pcs/return_4_512.c (caller_bf16): Likewise.
>* gcc.target/aarch64/sve/pcs/return_4_1024.c (caller_bf16): Likewise.
>* gcc.target/aarch64/sve/pcs/return_4_2048.c (caller_bf16): Likewise.
>* gcc.target/aarch64/sve/pcs/return_5.c (caller_bf16): Likewise.
>* gcc.target/aarch64/sve/pcs/return_5_128.c (caller_bf16): Likewise.
>* gcc.target/aarch64/sve/pcs/return_5_256.c (caller_bf16): Likewise.
>* gcc.target/aarch64/sve/pcs/return_5_512.c (caller_bf16): Likewise.
>* gcc.target/aarch64/sve/pcs/return_5_1024.c (caller_bf16): Likewise.
>* gcc.target/aarch64/sve/pcs/return_5_2048.c (caller_bf16): Likewise.

OK, thanks.

Applied on master, thanks.

Tejas.


Richard


[PATCH v1] RISC-V: Fix one typo in full-vec-movel test

2023-06-13 Thread Pan Li via Gcc-patches
From: Pan Li 

This patch would like to fix one typo when checking assembly of
full-vec-movel.

Signed-off-by: Pan Li 

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vls-vlmax/full-vec-move1.c:
Adjust dg-do to comiple for asm checking.
---
 .../gcc.target/riscv/rvv/autovec/vls-vlmax/full-vec-move1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/full-vec-move1.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/full-vec-move1.c
index c1119cddee7..c32c31ecd69 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/full-vec-move1.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/full-vec-move1.c
@@ -1,4 +1,4 @@
-/* { dg-do run { target { riscv_vector } } } */
+/* { dg-do compile } */
 /* { dg-additional-options "-std=c99 -O3 -march=rv64gcv_zvl128b 
-fno-vect-cost-model --param=riscv-autovec-preference=fixed-vlmax" } */
 
 #include 
-- 
2.34.1



Re: [PATCH v1] RISC-V: Fix one typo in full-vec-movel test

2023-06-13 Thread Robin Dapp via Gcc-patches
> This patch would like to fix one typo when checking assembly of
> full-vec-movel.

OK.  (I actually intended to commit this myself adding some more
comments to the iterator change as well as fix the tests, but well...)

Regards
 Robin


Re: Re: [PATCH v1] RISC-V: Fix one typo in full-vec-movel test

2023-06-13 Thread juzhe.zh...@rivai.ai
Oh. Sorry. Since I want to commit my patch so I asked Pan to commit your test 
as well.
I think you can resend a fix of this testcase and drop this patch.



juzhe.zh...@rivai.ai
 
From: Robin Dapp
Date: 2023-06-13 15:20
To: pan2.li; gcc-patches
CC: rdapp.gcc; juzhe.zhong; jeffreyalaw; yanzhang.wang; kito.cheng
Subject: Re: [PATCH v1] RISC-V: Fix one typo in full-vec-movel test
> This patch would like to fix one typo when checking assembly of
> full-vec-movel.
 
OK.  (I actually intended to commit this myself adding some more
comments to the iterator change as well as fix the tests, but well...)
 
Regards
Robin
 


Re: [PATCH v1] RISC-V: Fix one typo in full-vec-movel test

2023-06-13 Thread Robin Dapp via Gcc-patches
> Oh. Sorry. Since I want to commit my patch so I asked Pan to commit
> your test as well. I think you can resend a fix of this testcase and
> drop this patch.

No problem, will fix it another time.  Pan can just go ahead with this
fix now, no need to wait for a maintainer, it's obvious enough.

Thanks
 Robin


RE: [PATCH v1] RISC-V: Fix one typo in full-vec-movel test

2023-06-13 Thread Li, Pan2 via Gcc-patches
Committed, thanks Robin and Juzhe.

Pan

-Original Message-
From: Robin Dapp  
Sent: Tuesday, June 13, 2023 3:24 PM
To: juzhe.zh...@rivai.ai; Li, Pan2 ; gcc-patches 

Cc: rdapp@gmail.com; jeffreyalaw ; Wang, Yanzhang 
; kito.cheng 
Subject: Re: [PATCH v1] RISC-V: Fix one typo in full-vec-movel test

> Oh. Sorry. Since I want to commit my patch so I asked Pan to commit 
> your test as well. I think you can resend a fix of this testcase and 
> drop this patch.

No problem, will fix it another time.  Pan can just go ahead with this fix now, 
no need to wait for a maintainer, it's obvious enough.

Thanks
 Robin


[COMMITTED] ada: Remove explicit decoration of wrapper created in freezing

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Piotr Trojanek 

We create wrapper functions associated with inherited functions with
controlling results which are not overridden during freezing. We partly
decorated them explicitly, even though they would be fully decorated
later anyway.

This early decoration didn't work as expected, because flag
In_Private_Part that is read by Override_Dispatching_Operation it not
set reliably while freezing (as explained in the comment of
Is_Private_Declaration). In effect, we were getting a circularity
between Alias and Overridden_Operation, which was causing GNATprove to
loop infinitely.

Apparently the cleanest fix is to not decorate the wrapper with an early
call to Override_Dispatching_Operation.

gcc/ada/

* exp_ch3.adb (Make_Controlling_Function_Wrappers): Remove early
decoration.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_ch3.adb | 2 --
 1 file changed, 2 deletions(-)

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index f8c99470dd7..91dcfa0f643 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -11140,8 +11140,6 @@ package body Exp_Ch3 is
 --  is a wrapper's body in order to get check suppression right.
 
 Set_Corresponding_Spec (Func_Body, Func_Id);
-
-Override_Dispatching_Operation (Tag_Typ, Subp, New_Op => Func_Id);
  end if;
 
   <>
-- 
2.40.0



[COMMITTED] ada: Simplify appending to a newly created list

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Piotr Trojanek 

Code cleanup; semantics is unaffected.

gcc/ada/

* exp_disp.adb (Make_Disp_Asynchronous_Select_Spec): Use a single call
to New_List.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_disp.adb | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/exp_disp.adb b/gcc/ada/exp_disp.adb
index 494ead7c144..9381ceee60c 100644
--- a/gcc/ada/exp_disp.adb
+++ b/gcc/ada/exp_disp.adb
@@ -2755,7 +2755,7 @@ package body Exp_Disp is
   Def_Id : constant Entity_Id  :=
  Make_Defining_Identifier (Loc,
Name_uDisp_Asynchronous_Select);
-  Params : constant List_Id:= New_List;
+  Params : List_Id;
 
begin
   pragma Assert (not Restriction_Active (No_Dispatching_Calls));
@@ -2770,7 +2770,7 @@ package body Exp_Disp is
 
   Set_Warnings_Off (B_Id);
 
-  Append_List_To (Params, New_List (
+  Params := New_List (
 
 Make_Parameter_Specification (Loc,
   Defining_Identifier => Make_Defining_Identifier (Loc, Name_uT),
@@ -2795,7 +2795,7 @@ package body Exp_Disp is
 Make_Parameter_Specification (Loc,
   Defining_Identifier => Make_Defining_Identifier (Loc, Name_uF),
   Parameter_Type  => New_Occurrence_Of (Standard_Boolean, Loc),
-  Out_Present => True)));
+  Out_Present => True));
 
   return
 Make_Procedure_Specification (Loc,
-- 
2.40.0



[COMMITTED] ada: Fix expansion of aggregates with controlled components

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Eric Botcazou 

The expansion is incorrect in the case where the initialization expression
of a component is a conditional expression that has a function call as one
of its dependent expressions, leading to a wrong order of initialization,
adjustment and finalization.

gcc/ada/

* exp_aggr.adb (Initialize_Component): Perform immediate expansion
of the initialization expression if it is a conditional expression
and the component type is controlled.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_aggr.adb | 102 +--
 1 file changed, 99 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index e5b2cedb954..8c6c9f97429 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -8444,8 +8444,104 @@ package body Exp_Aggr is
   Comp  : Node_Id;
   Comp_Typ  : Entity_Id;
   Init_Expr : Node_Id;
-  Stmts : List_Id) is
+  Stmts : List_Id)
+   is
+  Init_Expr_Q : constant Node_Id:= Unqualify (Init_Expr);
+  Loc : constant Source_Ptr := Sloc (N);
+
begin
+  --  If the initialization expression of a component with controlled type
+  --  is a conditional expression that has a function call as one of its
+  --  dependent expressions, then we need to expand it immediately, so as
+  --  to trigger the special processing for function calls with controlled
+  --  type below and avoid a wrong order of initialization, adjustment and
+  --  finalization in the context of aggregates. For the sake of uniformity
+  --  we perform this expansion for all conditional expressions.
+
+  if Nkind (Init_Expr_Q) = N_If_Expression
+and then Present (Comp_Typ)
+and then Needs_Finalization (Comp_Typ)
+  then
+ declare
+Cond   : constant Node_Id := First (Expressions (Init_Expr_Q));
+Thenx  : constant Node_Id := Next (Cond);
+Elsex  : constant Node_Id := Next (Thenx);
+Then_Stmts : constant List_Id := New_List;
+Else_Stmts : constant List_Id := New_List;
+
+If_Stmt : Node_Id;
+
+ begin
+Initialize_Component
+  (N => N,
+   Comp  => Comp,
+   Comp_Typ  => Comp_Typ,
+   Init_Expr => Thenx,
+   Stmts => Then_Stmts);
+
+Initialize_Component
+  (N => N,
+   Comp  => Comp,
+   Comp_Typ  => Comp_Typ,
+   Init_Expr => Elsex,
+   Stmts => Else_Stmts);
+
+If_Stmt :=
+  Make_Implicit_If_Statement (N,
+Condition   => Relocate_Node (Cond),
+Then_Statements => Then_Stmts,
+Else_Statements => Else_Stmts);
+
+Set_From_Conditional_Expression (If_Stmt);
+Append_To (Stmts, If_Stmt);
+ end;
+
+  elsif Nkind (Init_Expr_Q) = N_Case_Expression
+and then Present (Comp_Typ)
+and then Needs_Finalization (Comp_Typ)
+  then
+ declare
+Alt   : Node_Id;
+Alt_Stmts : List_Id;
+Case_Stmt : Node_Id;
+
+ begin
+Case_Stmt :=
+   Make_Case_Statement (Loc,
+ Expression   =>
+   Relocate_Node (Expression (Init_Expr_Q)),
+ Alternatives => New_List);
+
+Alt := First (Alternatives (Init_Expr_Q));
+while Present (Alt) loop
+   declare
+  Alt_Expr : constant Node_Id:= Expression (Alt);
+  Alt_Loc  : constant Source_Ptr := Sloc (Alt_Expr);
+
+   begin
+  Alt_Stmts := New_List;
+
+  Initialize_Component
+(N => N,
+ Comp  => Comp,
+ Comp_Typ  => Comp_Typ,
+ Init_Expr => Alt_Expr,
+ Stmts => Alt_Stmts);
+
+  Append_To
+(Alternatives (Case_Stmt),
+ Make_Case_Statement_Alternative (Alt_Loc,
+ Discrete_Choices => Discrete_Choices (Alt),
+ Statements   => Alt_Stmts));
+   end;
+
+   Next (Alt);
+end loop;
+
+Set_From_Conditional_Expression (Case_Stmt);
+Append_To (Stmts, Case_Stmt);
+ end;
+
   --  Handle an initialization expression of a controlled type in
   --  case it denotes a function call. In general such a scenario
   --  will produce a transient scope, but this will lead to wrong
@@ -8477,9 +8573,9 @@ package body Exp_Aggr is
   --Adjust (Comp);
   --Finalize (Res);
 
-  if Present (Comp_Typ)
+  elsif Nkind (Init_Expr_Q) /= N_Aggregate
+and then Present (Comp_Typ)
 and then Need

[COMMITTED] ada: Factor out tag assignments from type in expander

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Eric Botcazou 

They are performed in a few different places during expansion.

gcc/ada/

* exp_util.ads (Make_Tag_Assignment_From_Type): Declare.
* exp_util.adb (Make_Tag_Assignment_From_Type): New function.
* exp_aggr.adb (Build_Record_Aggr_Code): Call the above function.
(Initialize_Simple_Component): Likewise.
* exp_ch3.adb (Build_Record_Init_Proc.Build_Assignment): Likewise.
(Build_Record_Init_Proc.Build_Init_Procedure ): Likewise.
(Make_Tag_Assignment): Likewise.  Rename local variable and call
Unqualify to go through qualified expressions.
* exp_ch4.adb (Expand_Allocator_Expression): Likewise.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_aggr.adb | 47 -
 gcc/ada/exp_ch3.adb  | 72 +---
 gcc/ada/exp_ch4.adb  | 28 ++---
 gcc/ada/exp_util.adb | 27 +
 gcc/ada/exp_util.ads |  7 +
 5 files changed, 57 insertions(+), 124 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 8c6c9f97429..c145d79f482 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -3095,22 +3095,9 @@ package body Exp_Aggr is
 
if Tagged_Type_Expansion then
   Instr :=
-Make_OK_Assignment_Statement (Loc,
-  Name   =>
-Make_Selected_Component (Loc,
-  Prefix=> New_Copy_Tree (Target),
-  Selector_Name =>
-New_Occurrence_Of
-  (First_Tag_Component (Base_Type (Typ)), Loc)),
-
-  Expression =>
-Unchecked_Convert_To (RTE (RE_Tag),
-  New_Occurrence_Of
-(Node (First_Elmt
-   (Access_Disp_Table (Base_Type (Typ,
- Loc)));
+Make_Tag_Assignment_From_Type
+  (Loc, New_Copy_Tree (Target), Base_Type (Typ));
 
-  Set_Assignment_OK (Name (Instr));
   Append_To (Assign, Instr);
 
   --  Ada 2005 (AI-251): If tagged type has progenitors we must
@@ -3629,19 +3616,8 @@ package body Exp_Aggr is
 
   elsif Is_Tagged_Type (Typ) and then Tagged_Type_Expansion then
  Instr :=
-   Make_OK_Assignment_Statement (Loc,
- Name =>
-   Make_Selected_Component (Loc,
- Prefix => New_Copy_Tree (Target),
- Selector_Name =>
-   New_Occurrence_Of
- (First_Tag_Component (Base_Type (Typ)), Loc)),
-
- Expression =>
-   Unchecked_Convert_To (RTE (RE_Tag),
- New_Occurrence_Of
-   (Node (First_Elmt (Access_Disp_Table (Base_Type (Typ,
-Loc)));
+   Make_Tag_Assignment_From_Type
+ (Loc, New_Copy_Tree (Target), Base_Type (Typ));
 
  Append_To (L, Instr);
 
@@ -8761,19 +8737,8 @@ package body Exp_Aggr is
 and then Is_Tagged_Type (Comp_Typ)
   then
  Append_To (Blk_Stmts,
-   Make_OK_Assignment_Statement (Loc,
- Name   =>
-   Make_Selected_Component (Loc,
- Prefix=> New_Copy_Tree (Comp),
- Selector_Name =>
-   New_Occurrence_Of
- (First_Tag_Component (Full_Typ), Loc)),
-
- Expression =>
-   Unchecked_Convert_To (RTE (RE_Tag),
- New_Occurrence_Of
-   (Node (First_Elmt (Access_Disp_Table (Full_Typ))),
-Loc;
+   Make_Tag_Assignment_From_Type
+ (Loc, New_Copy_Tree (Comp), Full_Typ));
   end if;
 
   --  Adjust the component. In the case of an array aggregate, controlled
diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index 91dcfa0f643..fbedc16ddd0 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -2150,21 +2150,10 @@ package body Exp_Ch3 is
and then Nkind (Exp_Q) /= N_Raise_Expression
  then
 Append_To (Res,
-  Make_Assignment_Statement (Default_Loc,
-Name   =>
-  Make_Selected_Component (Default_Loc,
-Prefix=>
-  New_Copy_Tree (Lhs, New_Scope => Proc_Id),
-Selector_Name =>
-  New_Occurrence_Of
-(First_Tag_Component (Typ), Default_Loc)),
-
-Expression =>
-  Unchecked_Convert_To (RTE (RE_Tag),
-New_Occurrence_Of
-  (Node (First_Elmt (Access_Disp_Table (Underlying_Type
- (Typ,
-   Default_Loc;
+  Make_Tag_Assignment_From_T

[COMMITTED] ada: Tune style in detection of writable function actuals

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Piotr Trojanek 

Cleanup; semantics is unaffected.

gcc/ada/

* sem_util.adb (Check_Function_Writable_Actuals): Tune style; use
subtype name to detect membership test nodes.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_util.adb | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index a75ebf5d7b1..237bbd3987c 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -2899,6 +2899,10 @@ package body Sem_Util is
function Get_Record_Part (N : Node_Id) return Node_Id;
--  Return the record part of this record type definition
 
+   -
+   -- Get_Record_Part --
+   -
+
function Get_Record_Part (N : Node_Id) return Node_Id is
   Type_Def : constant Node_Id := Type_Definition (N);
begin
@@ -3293,9 +3297,7 @@ package body Sem_Util is
   & "in unspecified order",
   Node (Elmt_2));
 
-when N_In
-   | N_Not_In
-=>
+when N_Membership_Test =>
Error_Msg_N
  ("value may be affected by call in other "
   & "alternative because they are evaluated "
@@ -3307,7 +3309,7 @@ package body Sem_Util is
  ("value of actual may be affected by call in "
   & "other actual because they are evaluated "
   & "in unspecified order",
-   Node (Elmt_2));
+  Node (Elmt_2));
  end case;
   end if;
 
-- 
2.40.0



[COMMITTED] ada: Factor common processing in expansion of aggregates

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Eric Botcazou 

The final processing at the component level of array aggregates and record
aggregates is very similar, so this factors out the common processing into
three new library-level subprograms.

There should be no functional changes, but the expanded code may be changed
in the case of controlled components of array aggregates not covered by a
multiple choice: the previous expansion used to place new declarations prior
to the aggregate in this case and that is no longer the case, i.e. they are
always placed right before the initialization of the component (as was done
for all controlled components of record aggregates and controlled components
of array aggregates covered by a multiple choice).

gcc/ada/

* exp_aggr.adb (Initialize_Component): New procedure factored out
from the processing of array and record aggregates.
(Initialize_Controlled_Component): Likewise.
(Initialize_Simple_Component): Likewise.
(Build_Array_Aggr_Code.Gen_Assign): Remove In_Loop parameter.
Call Initialize_Component to initialize the component.
(Initialize_Array_Component): Delete.
(Initialize_Ctrl_Array_Component): Likewise.
(Build_Array_Aggr_Code): Adjust calls to Gen_Assign.
(Build_Record_Aggr_Code): Call Initialize_Simple_Component or
Initialize_Component to initialize the component.
(Initialize_Ctrl_Record_Component): Delete.
(Initialize_Record_Component): Likewise.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_aggr.adb | 1000 +++---
 1 file changed, 360 insertions(+), 640 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 270d3bb8d66..e5b2cedb954 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -105,6 +105,36 @@ package body Exp_Aggr is
--  N is an aggregate (record or array). Checks the presence of default
--  initialization (<>) in any component (Ada 2005: AI-287).
 
+   procedure Initialize_Component
+ (N : Node_Id;
+  Comp  : Node_Id;
+  Comp_Typ  : Entity_Id;
+  Init_Expr : Node_Id;
+  Stmts : List_Id);
+   --  Perform the initialization of component Comp with expected type Comp_Typ
+   --  of aggregate N. Init_Expr denotes the initialization expression of the
+   --  component. All generated code is added to Stmts.
+
+   procedure Initialize_Controlled_Component
+ (N : Node_Id;
+  Comp  : Node_Id;
+  Comp_Typ  : Entity_Id;
+  Init_Expr : Node_Id;
+  Stmts : List_Id);
+   --  Perform the initialization of controlled component Comp with expected
+   --  type Comp_Typ of aggregate N. Init_Expr denotes the initialization
+   --  expression of the component. All generated code is added to Stmts.
+
+   procedure Initialize_Simple_Component
+ (N : Node_Id;
+  Comp  : Node_Id;
+  Comp_Typ  : Node_Id;
+  Init_Expr : Node_Id;
+  Stmts : List_Id);
+--  Perform the initialization of simple component Comp with expected
+--  type Comp_Typ of aggregate N. Init_Expr denotes the initialization
+--  expression of the component. All generated code is added to Stmts.
+
function Is_CCG_Supported_Aggregate (N : Node_Id) return Boolean;
--  Return True if aggregate N is located in a context supported by the
--  CCG backend; False otherwise.
@@ -1081,16 +,14 @@ package body Exp_Aggr is
 
   function Gen_Assign
 (Ind : Node_Id;
- Expr: Node_Id;
- In_Loop : Boolean := False) return List_Id;
+ Expr: Node_Id) return List_Id;
   --  Ind must be a side-effect-free expression. If the input aggregate N
   --  to Build_Loop contains no subaggregates, then this function returns
   --  the assignment statement:
   --
   -- Into (Indexes, Ind) := Expr;
   --
-  --  Otherwise we call Build_Code recursively. Flag In_Loop should be set
-  --  when the assignment appears within a generated loop.
+  --  Otherwise we call Build_Code recursively.
   --
   --  Ada 2005 (AI-287): In case of default initialized component, Expr
   --  is empty and we generate a call to the corresponding IP subprogram.
@@ -1310,35 +1338,13 @@ package body Exp_Aggr is
 
   function Gen_Assign
 (Ind : Node_Id;
- Expr: Node_Id;
- In_Loop : Boolean := False) return List_Id
+ Expr: Node_Id) return List_Id
is
  function Add_Loop_Actions (Lis : List_Id) return List_Id;
  --  Collect insert_actions generated in the construction of a loop,
  --  and prepend them to the sequence of assignments to complete the
  --  eventual body of the loop.
 
- procedure Initialize_Array_Component
-   (Arr_Comp  : Node_Id;
-Comp_Typ  : Node_Id;
-Init_Expr : Node_Id;
-Stmts : List_Id);
- --  Perform the in

[COMMITTED] ada: Add No_Elaboration_Code_All pragma to System.Storage_Elements

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Daniel King 

Allows System.Storage_Elements to be used in units that
have the No_Elaboration_Code_All restriction.

gcc/ada/

* libgnat/s-stoele.ads: Add No_Elaboration_Code_All pragma.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/libgnat/s-stoele.ads | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/ada/libgnat/s-stoele.ads b/gcc/ada/libgnat/s-stoele.ads
index 3262d0329c3..7de150dab59 100644
--- a/gcc/ada/libgnat/s-stoele.ads
+++ b/gcc/ada/libgnat/s-stoele.ads
@@ -43,6 +43,9 @@ package System.Storage_Elements is
--  this unit Pure instead of Preelaborable; see RM 13.7.1(15). In Ada 2005,
--  this is Pure in any case (AI-362).
 
+   pragma No_Elaboration_Code_All;
+   --  Allow the use of that restriction in units that WITH this unit
+
pragma Annotate (GNATprove, Always_Return, Storage_Elements);
 
type Storage_Offset is range -Memory_Size / 2 .. Memory_Size / 2 - 1;
-- 
2.40.0



[COMMITTED] ada: Cleanup expansion of locally handled exception handlers

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Piotr Trojanek 

Code cleanup related to handling exceptions in GNATprove; semantics is
unaffected.

gcc/ada/

* exp_ch11.ads (Find_Local_Handler): Fix typo in comment.
* exp_ch11.adb (Find_Local_Handler): Remove redundant check for the
Exception_Handler list being present; use membership test to eliminate
local object LCN; fold nested IF statements. Remove useless ELSIF
condition.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_ch11.adb | 124 +++
 gcc/ada/exp_ch11.ads |   2 +-
 2 files changed, 55 insertions(+), 71 deletions(-)

diff --git a/gcc/ada/exp_ch11.adb b/gcc/ada/exp_ch11.adb
index 753412eab16..da02eb9bfb2 100644
--- a/gcc/ada/exp_ch11.adb
+++ b/gcc/ada/exp_ch11.adb
@@ -1803,95 +1803,79 @@ package body Exp_Ch11 is
  --  Test for handled sequence of statements with at least one
  --  exception handler which might be the one we are looking for.
 
- elsif Nkind (P) = N_Handled_Sequence_Of_Statements
-   and then Present (Exception_Handlers (P))
- then
---  Before we proceed we need to check if the node N is covered
---  by the statement part of P rather than one of its exception
---  handlers (an exception handler obviously does not cover its
---  own statements).
-
---  This test is more delicate than might be thought. It is not
---  just a matter of checking the Statements (P), because the node
---  might be waiting to be wrapped in a transient scope, in which
---  case it will end up in the block statements, even though it
---  is not there now.
-
-if Is_List_Member (N) then
-   declare
-  LCN : constant List_Id := List_Containing (N);
+ --  We need to check if the node N is covered by the statement part of
+ --  P rather than one of its exception handlers (an exception handler
+ --  obviously does not cover its own statements).
 
-   begin
-  if LCN = Statements (P)
-   or else
- LCN = SSE.Actions_To_Be_Wrapped (Before)
-   or else
- LCN = SSE.Actions_To_Be_Wrapped (After)
-   or else
- LCN = SSE.Actions_To_Be_Wrapped (Cleanup)
-  then
- --  Loop through exception handlers
+ --  This test is more delicate than might be thought. It is not just
+ --  a matter of checking the Statements (P), because the node might be
+ --  waiting to be wrapped in a transient scope, in which case it will
+ --  end up in the block statements, even though it is not there now.
 
- H := First (Exception_Handlers (P));
- while Present (H) loop
+ elsif Nkind (P) = N_Handled_Sequence_Of_Statements
+   and then Is_List_Member (N)
+   and then List_Containing (N) in Statements (P)
+ | SSE.Actions_To_Be_Wrapped (Before)
+ | SSE.Actions_To_Be_Wrapped (After)
+ | SSE.Actions_To_Be_Wrapped (Cleanup)
+ then
+--  Loop through exception handlers
 
---  Guard against other constructs appearing in the
---  list of exception handlers.
+H := First (Exception_Handlers (P));
+while Present (H) loop
 
-if Nkind (H) = N_Exception_Handler then
+   --  Guard against other constructs appearing in the list of
+   --  exception handlers.
 
-   --  Loop through choices in one handler
+   if Nkind (H) = N_Exception_Handler then
 
-   C := First (Exception_Choices (H));
-   while Present (C) loop
+  --  Loop through choices in one handler
 
-  --  Deal with others case
+  C := First (Exception_Choices (H));
+  while Present (C) loop
 
-  if Nkind (C) = N_Others_Choice then
+ --  Deal with others case
 
- --  Matching others handler, but we need
- --  to ensure there is no choice parameter.
- --  If there is, then we don't have a local
- --  handler after all (since we do not allow
- --  choice parameters for local handlers).
+ if Nkind (C) = N_Others_Choice then
 
- if No (Choice_Parameter (H)) then
-return H;
- else
- 

[COMMITTED] ada: Small housekeeping work in expansion of extension aggregates

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Eric Botcazou 

This avoids repeatedly calling Unqualify on the same node, removes a dead
call to Generate_Finalization_Actions, a redundant setting of Assignment_OK
and reuses a local variable more consistently.  No functional changes.

gcc/ada/

* exp_aggr.adb (Build_Record_Aggr_Code): Add new variable Ancestor_Q
to store the result of Unqualify on Ancestor.  Remove the dead call
to Generate_Finalization_Actions in the case of another aggregate as
ancestor part.  Remove the redundant setting of Assignment_OK.  Use
Init_Typ in lieu of Etype (Ancestor) more consistently.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_aggr.adb | 36 +++-
 1 file changed, 15 insertions(+), 21 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 15230571123..dcbf2c4981d 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -2907,12 +2907,14 @@ package body Exp_Aggr is
 
   if Nkind (N) = N_Extension_Aggregate then
  declare
-Ancestor : constant Node_Id := Ancestor_Part (N);
+Ancestor   : constant Node_Id := Ancestor_Part (N);
+Ancestor_Q : constant Node_Id := Unqualify (Ancestor);
+
 Adj_Call : Node_Id;
 Assign   : List_Id;
 
  begin
---  If the ancestor part is a subtype mark "T", we generate
+--  If the ancestor part is a subtype mark T, we generate
 
 -- init-proc (T (tmp));  if T is constrained and
 -- init-proc (S (tmp));  where S applies an appropriate
@@ -3036,28 +3038,22 @@ package body Exp_Aggr is
 --  qualified).
 
 elsif Is_Limited_Type (Etype (Ancestor))
-  and then Nkind (Unqualify (Ancestor)) in
- N_Aggregate | N_Extension_Aggregate
+  and then Nkind (Ancestor_Q) in N_Aggregate
+   | N_Extension_Aggregate
 then
-   --  Set up finalization data for enclosing record, because
-   --  controlled subcomponents of the ancestor part will be
-   --  attached to it.
-
-   Generate_Finalization_Actions;
-
Append_List_To (L,
   Build_Record_Aggr_Code
-(N   => Unqualify (Ancestor),
- Typ => Etype (Unqualify (Ancestor)),
+(N   => Ancestor_Q,
+ Typ => Etype (Ancestor_Q),
  Lhs => Target));
 
---  If the ancestor part is an expression "E", we generate
+--  If the ancestor part is an expression E of type T, we generate
 
 -- T (tmp) := E;
 
 --  In Ada 2005, this includes the case of a (possibly qualified)
---  limited function call. The assignment will turn into a
---  build-in-place function call (for further details, see
+--  limited function call. The assignment will later be turned into
+--  a build-in-place function call (for further details, see
 --  Make_Build_In_Place_Call_In_Assignment).
 
 else
@@ -3067,15 +3063,13 @@ package body Exp_Aggr is
--  If the ancestor part is an aggregate, force its full
--  expansion, which was delayed.
 
-   if Nkind (Unqualify (Ancestor)) in
-N_Aggregate | N_Extension_Aggregate
+   if Nkind (Ancestor_Q) in N_Aggregate | N_Extension_Aggregate
then
   Set_Analyzed (Ancestor, False);
   Set_Analyzed (Expression (Ancestor), False);
end if;
 
Ref := Convert_To (Init_Typ, New_Copy_Tree (Target));
-   Set_Assignment_OK (Ref);
 
--  Make the assignment without usual controlled actions, since
--  we only want to Adjust afterwards, but not to Finalize
@@ -3112,14 +3106,14 @@ package body Exp_Aggr is
 
--  Call Adjust manually
 
-   if Needs_Finalization (Etype (Ancestor))
- and then not Is_Limited_Type (Etype (Ancestor))
+   if Needs_Finalization (Init_Typ)
+ and then not Is_Limited_Type (Init_Typ)
  and then not Is_Build_In_Place_Function_Call (Ancestor)
then
   Adj_Call :=
 Make_Adjust_Call
   (Obj_Ref => New_Copy_Tree (Ref),
-   Typ => Etype (Ancestor));
+   Typ => Init_Typ);
 
   --  Guard against a missing [Deep_]Adjust when the ancestor
   --  type was not properly frozen.
-- 
2.40.0



[COMMITTED] ada: Fix wrong expansion of limited extension aggregate

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Eric Botcazou 

This happens when the ancestor part is itself an aggregate: in this case,
the tag of the extension aggregate is wrongly set to that of the ancestor.

gcc/ada/

* exp_aggr.adb (Build_Record_Aggr_Code): In the case of an extension
aggregate of a limited type whose ancestor part is an aggregate, do
not skip the final code assigning the tag of the extension.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_aggr.adb | 2 --
 1 file changed, 2 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index c145d79f482..15230571123 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -3039,8 +3039,6 @@ package body Exp_Aggr is
   and then Nkind (Unqualify (Ancestor)) in
  N_Aggregate | N_Extension_Aggregate
 then
-   Ancestor_Is_Expression := True;
-
--  Set up finalization data for enclosing record, because
--  controlled subcomponents of the ancestor part will be
--  attached to it.
-- 
2.40.0



[COMMITTED] ada: Cleanup finding of locally handled exception handlers

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Piotr Trojanek 

Code cleanup related to handling exceptions in GNATprove; semantics is
unaffected.

gcc/ada/

* exp_ch11.adb (Find_Local_Handler): Replace guard against other
constructs appearing in the list of exception handlers with iteration
using First_Non_Pragma/Next_Non_Pragma.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_ch11.adb | 68 +---
 1 file changed, 33 insertions(+), 35 deletions(-)

diff --git a/gcc/ada/exp_ch11.adb b/gcc/ada/exp_ch11.adb
index da02eb9bfb2..db85c7efa6e 100644
--- a/gcc/ada/exp_ch11.adb
+++ b/gcc/ada/exp_ch11.adb
@@ -1819,62 +1819,60 @@ package body Exp_Ch11 is
  | SSE.Actions_To_Be_Wrapped (After)
  | SSE.Actions_To_Be_Wrapped (Cleanup)
  then
---  Loop through exception handlers
+--  Loop through exception handlers and guard against pragmas
+--  appearing among them.
 
-H := First (Exception_Handlers (P));
+H := First_Non_Pragma (Exception_Handlers (P));
 while Present (H) loop
 
--  Guard against other constructs appearing in the list of
--  exception handlers.
 
-   if Nkind (H) = N_Exception_Handler then
+   --  Loop through choices in one handler
 
-  --  Loop through choices in one handler
+   C := First (Exception_Choices (H));
+   while Present (C) loop
 
-  C := First (Exception_Choices (H));
-  while Present (C) loop
+  --  Deal with others case
 
- --  Deal with others case
+  if Nkind (C) = N_Others_Choice then
 
- if Nkind (C) = N_Others_Choice then
+ --  Matching others handler, but we need to ensure there
+ --  is no choice parameter. If there is, then we don't
+ --  have a local handler after all (since we do not allow
+ --  choice parameters for local handlers).
 
---  Matching others handler, but we need to ensure
---  there is no choice parameter. If there is, then we
---  don't have a local handler after all (since we do
---  not allow choice parameters for local handlers).
-
-if No (Choice_Parameter (H)) then
-   return H;
-else
-   return Empty;
-end if;
+ if No (Choice_Parameter (H)) then
+return H;
+ else
+return Empty;
+ end if;
 
- --  If not others must be entity name
+  --  If not others must be entity name
 
- else
-pragma Assert (Is_Entity_Name (C));
-pragma Assert (Present (Entity (C)));
+  else
+ pragma Assert (Is_Entity_Name (C));
+ pragma Assert (Present (Entity (C)));
 
---  Get exception being handled, dealing with renaming
+ --  Get exception being handled, dealing with renaming
 
-EHandle := Get_Renamed_Entity (Entity (C));
+ EHandle := Get_Renamed_Entity (Entity (C));
 
---  If match, then check choice parameter
+ --  If match, then check choice parameter
 
-if ERaise = EHandle then
-   if No (Choice_Parameter (H)) then
-  return H;
-   else
-  return Empty;
-   end if;
+ if ERaise = EHandle then
+if No (Choice_Parameter (H)) then
+   return H;
+else
+   return Empty;
 end if;
  end if;
+  end if;
 
- Next (C);
-  end loop;
-   end if;
+  Next (C);
+   end loop;
 
-   Next (H);
+   Next_Non_Pragma (H);
 end loop;
  end if;
 
-- 
2.40.0



[COMMITTED] ada: Remove obsolete code in Analyze_Assignment

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Eric Botcazou 

This code was dealing with build-in-place calls for nonlimited types, but
they no longer exist since Is_Build_In_Place_Result_Type => Is_Limited_View.

gcc/ada/

* sem_ch5.adb (Analyze_Assignment): Turn Rhs into a constant and
remove calls to the following subprograms.
(Transform_BIP_Assignment): Delete.
(Should_Transform_BIP_Assignment): Likewise.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_ch5.adb | 156 +---
 1 file changed, 1 insertion(+), 155 deletions(-)

diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb
index 99a57573a87..f9174869a26 100644
--- a/gcc/ada/sem_ch5.adb
+++ b/gcc/ada/sem_ch5.adb
@@ -113,7 +113,7 @@ package body Sem_Ch5 is
 
procedure Analyze_Assignment (N : Node_Id) is
   Lhs : constant Node_Id := Name (N);
-  Rhs : Node_Id  := Expression (N);
+  Rhs : constant Node_Id := Expression (N);
 
   procedure Diagnose_Non_Variable_Lhs (N : Node_Id);
   --  N is the node for the left hand side of an assignment, and it is not
@@ -137,27 +137,6 @@ package body Sem_Ch5 is
   --  nominal subtype. This procedure is used to deal with cases where the
   --  nominal subtype must be replaced by the actual subtype.
 
-  procedure Transform_BIP_Assignment (Typ : Entity_Id);
-  function Should_Transform_BIP_Assignment
-(Typ : Entity_Id) return Boolean;
-  --  If the right-hand side of an assignment statement is a build-in-place
-  --  call we cannot build in place, so we insert a temp initialized with
-  --  the call, and transform the assignment statement to copy the temp.
-  --  Transform_BIP_Assignment does the transformation, and
-  --  Should_Transform_BIP_Assignment determines whether we should.
-  --  The same goes for qualified expressions and conversions whose
-  --  operand is such a call.
-  --
-  --  This is only for nonlimited types; assignment statements are illegal
-  --  for limited types, but are generated internally for aggregates and
-  --  init procs. These limited-type are not really assignment statements
-  --  -- conceptually, they are initializations, so should not be
-  --  transformed.
-  --
-  --  Similarly, for nonlimited types, aggregates and init procs generate
-  --  assignment statements that are really initializations. These are
-  --  marked No_Ctrl_Actions.
-
   function Within_Function return Boolean;
   --  Determine whether the current scope is a function or appears within
   --  one.
@@ -354,87 +333,6 @@ package body Sem_Ch5 is
  end if;
   end Set_Assignment_Type;
 
-  -
-  -- Should_Transform_BIP_Assignment --
-  -
-
-  function Should_Transform_BIP_Assignment
-(Typ : Entity_Id) return Boolean
-  is
-  begin
- if Expander_Active
-   and then not Is_Limited_View (Typ)
-   and then Is_Build_In_Place_Result_Type (Typ)
-   and then not No_Ctrl_Actions (N)
- then
---  This function is called early, before name resolution is
---  complete, so we have to deal with things that might turn into
---  function calls later. N_Function_Call and N_Op nodes are the
---  obvious case. An N_Identifier or N_Expanded_Name is a
---  parameterless function call if it denotes a function.
---  Finally, an attribute reference can be a function call.
-
-declare
-   Unqual_Rhs : constant Node_Id := Unqual_Conv (Rhs);
-begin
-   case Nkind (Unqual_Rhs) is
-  when N_Function_Call
- | N_Op
-  =>
- return True;
-
-  when N_Expanded_Name
- | N_Identifier
-  =>
- return
-   Ekind (Entity (Unqual_Rhs)) in E_Function | E_Operator;
-
-  --  T'Input will turn into a call whose result type is T
-
-  when N_Attribute_Reference =>
- return Attribute_Name (Unqual_Rhs) = Name_Input;
-
-  when others =>
- return False;
-   end case;
-end;
- else
-return False;
- end if;
-  end Should_Transform_BIP_Assignment;
-
-  --
-  -- Transform_BIP_Assignment --
-  --
-
-  procedure Transform_BIP_Assignment (Typ : Entity_Id) is
-
- --  Tranform "X : [constant] T := F (...);" into:
- --
- -- Temp : constant T := F (...);
- -- X := Temp;
-
- Loc  : constant Source_Ptr := Sloc (N);
- Def_Id   : constant Entity_Id  := Make_Temporary (Loc, 'Y', Rhs);
- Obj_De

[COMMITTED] ada: Fix internal error on imported function with post-condition

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Eric Botcazou 

The problem, which is also present for an expression function, is that the
function is invoked in the initializing expression of a variable declared
in the same declarative part as the function, which causes the freezing of
its artificial body before the post-condition is analyzed on its spec.

gcc/ada/

* contracts.adb (Analyze_Entry_Or_Subprogram_Body_Contract): For a
subprogram body that has no contracts and does not come from source,
make sure that contracts on its corresponding spec are analyzed, if
any, before expanding them.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/contracts.adb | 16 
 1 file changed, 16 insertions(+)

diff --git a/gcc/ada/contracts.adb b/gcc/ada/contracts.adb
index 7625abf9554..ae9e07ffc16 100644
--- a/gcc/ada/contracts.adb
+++ b/gcc/ada/contracts.adb
@@ -598,6 +598,22 @@ package body Contracts is
  else
 Set_Analyzed (Items);
  end if;
+
+  --  When this is a subprogram body not coming from source, for example an
+  --  expression function, it does not cause freezing of previous contracts
+  --  (see Analyze_Subprogram_Body_Helper), in particular not of those on
+  --  its spec if it exists. In this case make sure they have been properly
+  --  analyzed before being expanded below, as we may be invoked during the
+  --  freezing of the subprogram in the middle of its enclosing declarative
+  --  part because the declarative part contains e.g. the declaration of a
+  --  variable initialized by means of a call to the subprogram.
+
+  elsif Nkind (Body_Decl) = N_Subprogram_Body
+and then not Comes_From_Source (Original_Node (Body_Decl))
+and then Present (Corresponding_Spec (Body_Decl))
+and then Present (Contract (Corresponding_Spec (Body_Decl)))
+  then
+ Analyze_Entry_Or_Subprogram_Contract (Corresponding_Spec (Body_Decl));
   end if;
 
   --  Due to the timing of contract analysis, delayed pragmas may be
-- 
2.40.0



[COMMITTED] ada: Remove wrong comment about expansion of exceptions for GNATprove

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Piotr Trojanek 

Code cleanup related to handling exceptions in GNATprove.

gcc/ada/

* exp_ch11.adb (Expand_N_Raise_Statement): Expansion of raise statements
never happens in GNATprove mode.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_ch11.adb | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/gcc/ada/exp_ch11.adb b/gcc/ada/exp_ch11.adb
index db85c7efa6e..53f0753cdce 100644
--- a/gcc/ada/exp_ch11.adb
+++ b/gcc/ada/exp_ch11.adb
@@ -1592,10 +1592,8 @@ package body Exp_Ch11 is
 
   else
  --  Bypass expansion to a run-time call when back-end exception
- --  handling is active, unless the target is CodePeer or GNATprove.
- --  In CodePeer, raising an exception is treated as an error, while in
- --  GNATprove all code with exceptions falls outside the subset of
- --  code which can be formally analyzed.
+ --  handling is active, unless the target is CodePeer, where
+ --  raising an exception is treated as an error.
 
  if not CodePeer_Mode then
 return;
@@ -1604,7 +1602,7 @@ package body Exp_Ch11 is
  --  Find innermost enclosing exception handler (there must be one,
  --  since the semantics has already verified that this raise statement
  --  is valid, and a raise with no arguments is only permitted in the
- --  context of an exception handler.
+ --  context of an exception handler).
 
  Ehand := Parent (N);
  while Nkind (Ehand) /= N_Exception_Handler loop
-- 
2.40.0



[COMMITTED] ada: Remove unreferenced routine Is_Inherited_Operation_For_Type

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Piotr Trojanek 

Remove routine that is no referenced after deconstructing of restriction
SPARK_05.

gcc/ada/

* sem_util.ads (Is_Inherited_Operation_For_Type): Remove spec.
* sem_util.adb (Is_Inherited_Operation_For_Type): Remove body.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_util.adb | 15 ---
 gcc/ada/sem_util.ads |  6 --
 2 files changed, 21 deletions(-)

diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 237bbd3987c..c736bc34bb1 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -17582,21 +17582,6 @@ package body Sem_Util is
   and then Is_Derived_Type (Etype (E)));
end Is_Inherited_Operation;
 
-   -
-   -- Is_Inherited_Operation_For_Type --
-   -
-
-   function Is_Inherited_Operation_For_Type
- (E   : Entity_Id;
-  Typ : Entity_Id) return Boolean
-   is
-   begin
-  --  Check that the operation has been created by the type declaration
-
-  return Is_Inherited_Operation (E)
-and then Defining_Identifier (Parent (E)) = Typ;
-   end Is_Inherited_Operation_For_Type;
-
--
-- Is_Inlinable_Expression_Function --
--
diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads
index 2a2dbdc2bdd..539ebebafcb 100644
--- a/gcc/ada/sem_util.ads
+++ b/gcc/ada/sem_util.ads
@@ -2088,12 +2088,6 @@ package Sem_Util is
--  E is a subprogram. Return True is E is an implicit operation inherited
--  by a derived type declaration.
 
-   function Is_Inherited_Operation_For_Type
- (E   : Entity_Id;
-  Typ : Entity_Id) return Boolean;
-   --  E is a subprogram. Return True is E is an implicit operation inherited
-   --  by the derived type declaration for type Typ.
-
function Is_Inlinable_Expression_Function (Subp : Entity_Id) return Boolean;
--  Return True if Subp is an expression function that fulfills all the
--  following requirements for inlining:
-- 
2.40.0



[COMMITTED] ada: Fix exception raised on invalid contract in generic package

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Eric Botcazou 

This lets the compiler give a proper error message instead.

gcc/ada/

* contracts.adb (Contract_Error): New exception.
(Add_Contract_Item): Raise Contract_Error instead of Program_Error.
(Add_Generic_Contract_Pragma): Deal with Contract_Error.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/contracts.adb | 31 +--
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/gcc/ada/contracts.adb b/gcc/ada/contracts.adb
index ae9e07ffc16..19073d1e4d8 100644
--- a/gcc/ada/contracts.adb
+++ b/gcc/ada/contracts.adb
@@ -62,6 +62,11 @@ with Warnsw; use Warnsw;
 
 package body Contracts is
 
+   Contract_Error : exception;
+   --  This exception is raised by Add_Contract_Item when it is invoked on an
+   --  invalid pragma. Note that clients of the package must filter them out
+   --  before invoking Add_Contract_Item, so it should not escape the package.
+
procedure Analyze_Package_Instantiation_Contract (Inst_Id : Entity_Id);
--  Analyze all delayed pragmas chained on the contract of package
--  instantiation Inst_Id as if they appear at the end of a declarative
@@ -198,7 +203,7 @@ package body Contracts is
  --  The pragma is not a proper contract item
 
  else
-raise Program_Error;
+raise Contract_Error;
  end if;
 
   --  Entry bodies, the applicable pragmas are:
@@ -216,7 +221,7 @@ package body Contracts is
  --  The pragma is not a proper contract item
 
  else
-raise Program_Error;
+raise Contract_Error;
  end if;
 
   --  Entry or subprogram declarations, the applicable pragmas are:
@@ -268,7 +273,7 @@ package body Contracts is
  --  The pragma is not a proper contract item
 
  else
-raise Program_Error;
+raise Contract_Error;
  end if;
 
   --  Packages or instantiations, the applicable pragmas are:
@@ -292,7 +297,7 @@ package body Contracts is
  --  The pragma is not a proper contract item
 
  else
-raise Program_Error;
+raise Contract_Error;
  end if;
 
   --  Package bodies, the applicable pragmas are:
@@ -305,7 +310,7 @@ package body Contracts is
  --  The pragma is not a proper contract item
 
  else
-raise Program_Error;
+raise Contract_Error;
  end if;
 
   --  The four volatility refinement pragmas are ok for all types.
@@ -343,7 +348,7 @@ package body Contracts is
 
--  The pragma is not a proper contract item
 
-   raise Program_Error;
+   raise Contract_Error;
 end if;
  end;
 
@@ -367,7 +372,7 @@ package body Contracts is
  --  The pragma is not a proper contract item
 
  else
-raise Program_Error;
+raise Contract_Error;
  end if;
 
   --  Task bodies, the applicable pragmas are:
@@ -381,7 +386,7 @@ package body Contracts is
  --  The pragma is not a proper contract item
 
  else
-raise Program_Error;
+raise Contract_Error;
  end if;
 
   --  Task units, the applicable pragmas are:
@@ -416,11 +421,11 @@ package body Contracts is
  --  The pragma is not a proper contract item
 
  else
-raise Program_Error;
+raise Contract_Error;
  end if;
 
   else
- raise Program_Error;
+ raise Contract_Error;
   end if;
end Add_Contract_Item;
 
@@ -2225,6 +2230,12 @@ package body Contracts is
  else
 Add_Contract_Item (Prag, Templ_Id);
  end if;
+
+  exception
+ --  We do not stop the compilation at this point in the case of an
+ --  invalid pragma because it will be properly diagnosed afterward.
+
+ when Contract_Error => null;
   end Add_Generic_Contract_Pragma;
 
   --  Local variables
-- 
2.40.0



[COMMITTED] ada: Add missing ss_mark/ss_release in quantified expressions

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Bob Duff 

If a quantified expression says "for all ... of F(...)"
where F(...) is a function call that returns on the secondary
stack, we need to clean up the secondary stack. This patch
adds the required ss_mark/ss_release in that case.

gcc/ada/

* exp_ch4.adb
(Expand_N_Quantified_Expression): Detect the secondary-stack
case, and find the innermost scope where we should mark/release,
and Set_Uses_Sec_Stack on that. Skip intermediate blocks and loops
that are part of expansion.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_ch4.adb | 26 ++
 1 file changed, 26 insertions(+)

diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index fdaeb50512f..7b6e997e3e7 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -6,6 +6,32 @@ package body Exp_Ch4 is
  Freeze_Before (P, Etype (Var));
   end;
 
+  --  For an expression of the form "for all/some X of F(...) => ...",
+  --  where F(...) is a function call that returns on the secondary stack,
+  --  we need to mark an enclosing scope as Uses_Sec_Stack. We must do
+  --  this before expansion, which can obscure the tree. Note that we
+  --  might be inside another quantified expression. Skip blocks and
+  --  loops that were generated by expansion.
+
+  if Present (Iterator_Specification (N))
+and then Nkind (Name (Iterator_Specification (N))) = N_Function_Call
+and then Needs_Secondary_Stack
+   (Etype (Name (Iterator_Specification (N
+  then
+ declare
+Source_Scope : Entity_Id := Current_Scope;
+ begin
+while Ekind (Source_Scope) in E_Block | E_Loop
+  and then not Comes_From_Source (Source_Scope)
+loop
+   Source_Scope := Scope (Source_Scope);
+end loop;
+
+Set_Uses_Sec_Stack (Source_Scope);
+Check_Restriction (No_Secondary_Stack, N);
+ end;
+  end if;
+
   --  Create the declaration of the flag which tracks the status of the
   --  quantified expression. Generate:
 
-- 
2.40.0



[COMMITTED] ada: Use ghost predicate in standard library

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Yannick Moy 

In preparation for attribute Initialized to become ghost, use aspect
Ghost_Predicate instead of Predicate in unit Ada.Strings.Superbounded
of the standard library.

gcc/ada/

* libgnat/a-strsup.ads: Change predicate aspect.
* sem_ch13.adb (Add_Predicate): Fix for first predicate.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/libgnat/a-strsup.ads | 2 +-
 gcc/ada/sem_ch13.adb | 6 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/libgnat/a-strsup.ads b/gcc/ada/libgnat/a-strsup.ads
index 7a8a2bac996..2e0cd98f8d4 100644
--- a/gcc/ada/libgnat/a-strsup.ads
+++ b/gcc/ada/libgnat/a-strsup.ads
@@ -69,7 +69,7 @@ package Ada.Strings.Superbounded with SPARK_Mode is
   --  Leaving it out is more efficient.
end record
with
- Predicate =>
+ Ghost_Predicate =>
Current_Length <= Max_Length
  and then Data (1 .. Current_Length)'Initialized,
  Put_Image => Put_Image;
diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index 32771f06d76..2b8b64aa392 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -10101,9 +10101,13 @@ package body Sem_Ch13 is
  --  Start of processing for Add_Predicate
 
  begin
---  A ghost predicate is checked only when Ghost mode is enabled
+--  A ghost predicate is checked only when Ghost mode is enabled.
+--  Add a condition for the presence of a predicate to be recorded,
+--  which is needed to generate the corresponding predicate
+--  function.
 
 if Is_Ignored_Ghost_Pragma (Prag) then
+   Add_Condition (New_Occurrence_Of (Standard_True, Sloc (Prag)));
return;
 end if;
 
-- 
2.40.0



[COMMITTED] ada: Streamline expansion of controlled actions for aggregates

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Eric Botcazou 

This changes the strategy used to expand controlled actions for array and
record aggregates so as to make it simpler and more robust.

The current strategy is to set the No_Ctrl_Actions flag on the assignments
generated during the expansion of aggregate, as done during the expansion
of initialization procedures, and to generate the adjustments of the LHS
manually in the same list of actions, before sending the entire list for
analysis and expansion.  The problem is that, when the RHS also requires
controlled actions, the No_Ctrl_Actions flag prevents transient scopes
from being created around the assignments, with the end result that the
actions are "naturally" generated between the assignments and adjustments
of the LHS, causing premature finalization of the RHS.  In order to counter
that, the controlled actions of the RHS must also be generated manually
during the expansion of the aggregates, after blocking normal processing
e.g. by means of the No_Side_Effect_Removal flag.  This means that, for
a more complex RHS, this strategy generates a wrong order of controlled
actions by default, until specifically adjusted.

The new strategy is to reuse the standard machinery as much as possible,
disabling only the part that is not needed for the assignments generated
during the expansion of aggregates, namely the finalization of the LHS;
in other words, the adjustment of the LHS is left entirely to the standard
machinery and the creation of transient scopes is no longer blocked, which
gives a correct order of controlled actions by default.  It is implemented
by means of a No_Finalize_Actions flag present on the assignments generated
during the expansion.

It is mostly straightforward, modulo the following hitch: the assignments
are now analyzed and expanded by the common expander, which in the case of
controlled assignments analyzes the final rewriting with all checks off,
which in particular disables elaboration checks for the calls to the Adjust
primitives; now these checks are necessary in the case where an aggregate
is the initialization expression of an object declared before the body of
the Adjust primitive is seen.  Hence the use of an existing trick, namely
Suppress/Unsuppress blocks, around the assignments.

gcc/ada/

* gen_il-fields.ads (Opt_Field_Enum): Add No_Finalize_Actions and
remove No_Side_Effect_Removal.
* gen_il-gen-gen_nodes.adb (N_Function_Call): Remove semantic flag
No_Side_Effect_Removal
(N_Assignment_Statement): Add semantic flag No_Finalize_Actions.
* sinfo.ads (No_Ctrl_Actions): Adjust comment.
(No_Finalize_Actions): New flag on assignment statements.
(No_Side_Effect_Removal): Delete.
* exp_aggr.adb (Build_Record_Aggr_Code): Remove obsolete comment and
Ancestor_Is_Expression variable.  In the case of an extension, do
not generate a call to Adjust manually, call Set_No_Finalize_Actions
instead.  Do not set the tags, replace call to Make_Unsuppress_Block
by Make_Suppress_Block and remove useless assertions.
In the general case, call Initialize_Component.
(Initialize_Controlled_Component): Delete.
(Initialize_Simple_Component): Delete.
(Initialize_Component): Do the low-level processing, but do not
generate a call to Adjust manually, call Set_No_Finalize_Actions.
(Process_Transient_Component): Delete.
(Process_Transient_Component_Completion): Likewise.
* exp_ch5.adb (Expand_Assign_Array): Deal with No_Finalize_Actions.
(Expand_Assign_Array_Loop): Likewise.
(Expand_N_Assignment_Statement): Likewise.
(Make_Tag_Ctrl_Assignment): Likewise.
* exp_util.adb (Remove_Side_Effects): Do not test the
No_Side_Effect_Removal flag.
* sem_prag.adb (Process_Suppress_Unsuppress): Give the warning in
SPARK mode only for pragma Suppress.
* tbuild.ads (Make_Suppress_Block): New declaration.
(Make_Unsuppress_Block): Adjust comment.
* tbuild.adb (Make_Suppress_Block): New procedure.
(Make_Unsuppress_Block): Unsuppress instead of suppressing.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_aggr.adb | 740 ++-
 gcc/ada/exp_ch5.adb  |  55 ++-
 gcc/ada/exp_util.adb |   8 -
 gcc/ada/gen_il-fields.ads|   2 +-
 gcc/ada/gen_il-gen-gen_nodes.adb |   4 +-
 gcc/ada/sem_prag.adb |   5 +-
 gcc/ada/sinfo.ads|  31 +-
 gcc/ada/tbuild.adb   |  36 +-
 gcc/ada/tbuild.ads   |  11 +-
 9 files changed, 142 insertions(+), 750 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index dcbf2c4981d..fb5f404922f 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -106,33 +106,13 @@ package body Exp_Aggr is
--  initialization (<>) in any component (Ada 2005: AI-287).
 
procedure Initiali

[COMMITTED] ada: Skip elaboration checks for abstract subprograms on derived types

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Piotr Trojanek 

Elaboration checks skip abstract subprogram declarations, which have no
body that could be examined. Now these checks also skip abstract
subprograms of a derived type, which have no body either.

gcc/ada/

* sem_elab.adb (Check_Overriding_Primitive): Prevent Corresponding_Body
to be called with entity of an abstract subprogram.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_elab.adb | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/sem_elab.adb b/gcc/ada/sem_elab.adb
index 1e18b987863..dc81e47da9e 100644
--- a/gcc/ada/sem_elab.adb
+++ b/gcc/ada/sem_elab.adb
@@ -15263,10 +15263,13 @@ package body Sem_Elab is
 --  Nothing to do for predefined primitives because they are
 --  artifacts of tagged type expansion and cannot override source
 --  primitives. Nothing to do as well for inherited primitives, as
---  the check concerns overriding ones.
+--  the check concerns overriding ones. Finally, nothing to do for
+--  abstract subprograms, because they have no body that could be
+--  examined.
 
 if Is_Predefined_Dispatching_Operation (Prim)
   or else not Is_Overriding_Subprogram (Prim)
+  or else Is_Abstract_Subprogram (Prim)
 then
return;
 end if;
-- 
2.40.0



[COMMITTED] ada: Mark attribute Initialized as ghost code

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Yannick Moy 

Implement the SPARK RM change that defines attribute Initialized
as being ghost, i.e. only allowed where a ghost entity would be allowed.

gcc/ada/

* ghost.adb (Check_Ghost_Context): Allow absence of Ghost_Id
for attribute. Update error message to mention Ghost_Predicate.
(Is_Ghost_Attribute_Reference): New query.
* ghost.ads (Is_Ghost_Attribute_Reference): New query.
* sem_attr.adb (Resolve_Attribute): Check ghost context for ghost
attributes.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/ghost.adb| 15 ++-
 gcc/ada/ghost.ads|  4 
 gcc/ada/sem_attr.adb |  7 +++
 3 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/ghost.adb b/gcc/ada/ghost.adb
index ee98126de81..6cf87ce29b1 100644
--- a/gcc/ada/ghost.adb
+++ b/gcc/ada/ghost.adb
@@ -655,7 +655,9 @@ package body Ghost is
   --  declaration and at the point of use match.
 
   if Is_OK_Ghost_Context (Ghost_Ref) then
- Check_Ghost_Policy (Ghost_Id, Ghost_Ref);
+ if Present (Ghost_Id) then
+Check_Ghost_Policy (Ghost_Id, Ghost_Ref);
+ end if;
 
   --  Otherwise the Ghost entity appears in a non-Ghost context and affects
   --  its behavior or value (SPARK RM 6.9(10,11)).
@@ -673,6 +675,7 @@ package body Ghost is
Ghost_Ref);
 Error_Msg_N
   ("\either make the type ghost "
+   & "or use a Ghost_Predicate "
& "or use a type invariant on a private type", Ghost_Ref);
  end if;
   end if;
@@ -1194,6 +1197,16 @@ package body Ghost is
   return False;
end Is_Ghost_Assignment;
 
+   --
+   -- Is_Ghost_Attribute_Reference --
+   --
+
+   function Is_Ghost_Attribute_Reference (N : Node_Id) return Boolean is
+   begin
+  return Nkind (N) = N_Attribute_Reference
+and then Attribute_Name (N) = Name_Initialized;
+   end Is_Ghost_Attribute_Reference;
+
--
-- Is_Ghost_Declaration --
--
diff --git a/gcc/ada/ghost.ads b/gcc/ada/ghost.ads
index 1532117955e..663e70cffe2 100644
--- a/gcc/ada/ghost.ads
+++ b/gcc/ada/ghost.ads
@@ -111,6 +111,10 @@ package Ghost is
--  Determine whether arbitrary node N denotes an assignment statement whose
--  target is a Ghost entity.
 
+   function Is_Ghost_Attribute_Reference (N : Node_Id) return Boolean;
+   --  Determine whether arbitrary node N denotes an attribute reference which
+   --  denotes a Ghost attribute.
+
function Is_Ghost_Declaration (N : Node_Id) return Boolean;
--  Determine whether arbitrary node N denotes a declaration which defines
--  a Ghost entity.
diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
index f5ee275e23f..24f57ac43ff 100644
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -41,6 +41,7 @@ with Exp_Dist;   use Exp_Dist;
 with Exp_Util;   use Exp_Util;
 with Expander;   use Expander;
 with Freeze; use Freeze;
+with Ghost;  use Ghost;
 with Gnatvsn;use Gnatvsn;
 with Itypes; use Itypes;
 with Lib;use Lib;
@@ -11068,6 +11069,12 @@ package body Sem_Attr is
  Set_Etype (N, Typ);
   end if;
 
+  --  A Ghost attribute must appear in a specific context
+
+  if Is_Ghost_Attribute_Reference (N) then
+ Check_Ghost_Context (Empty, N);
+  end if;
+
   --  Remaining processing depends on attribute
 
   case Attr_Id is
-- 
2.40.0



[COMMITTED] ada: Implement new aspect Always_Terminates for SPARK

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Piotr Trojanek 

This patch allows subprograms to be annotated with aspect
Always_Terminates that requires a boolean expression. When this
expression evaluates to True, the subprogram is required to terminate or
raise an exception, but not loop infinitely.

This aspect is only meant to be used by GNATprove and it has no
meaningful run-time semantics: either the annotated subprogram
terminates and then the aspect expression doesn't matter, or the
subprogram loops infinitely and there is nothing we can do. (We could
also evaluate the aspect expression just to detect run-time errors in
the expression itself, but this can be implemented later, after a
backend support for the aspect is added to GNATprove.)

Implementation of this aspect is heavily based on the implementation of
Subprogram_Variant, which in turn is heavily based on the implementation
of Contract_Cases. Since the new aspect is not yet expanded, there is no
corresponding assertion kind that would control the expansion.

gcc/ada/

* aspects.ads (Aspect_Id): Add new aspect.
(Implementation_Defined_Aspect): New aspect is
implementation-defined.
(Aspect_Argument): New aspect has an expression argument.
(Is_Representation_Aspect): New aspect is not a representation
aspect.
(Aspect_Names): Link new aspect identifier with a name.
(Aspect_Delay): New aspect is never delayed.
* contracts.adb (Expand_Subprogram_Contract): Mention new aspect
in comment.
(Add_Contract_Item): Attach pragma corresponding to the new aspect
to contract items.
(Analyze_Entry_Or_Subprogram_Contract): Analyze pragma
corresponding to the new aspect that appears with subprogram spec.
(Analyze_Subprogram_Body_Stub_Contract): Expand pragma
corresponding to the new aspect.
* contracts.ads
(Add_Contract_Item, Analyze_Entry_Or_Subprogram_Contract)
(Analyze_Entry_Or_Subprogram_Body_Contract)
(Analyze_Subprogram_Body_Stub_Contract): Mention new aspect in
comment.
* einfo-utils.adb (Get_Pragma): Return pragma attached to
contract.
* einfo-utils.ads (Get_Pragma): Mention new contract in comment.
* exp_prag.adb (Expand_Pragma_Always_Terminates): Placeholder for
possibly expanding new aspect.
* exp_prag.ads (Expand_Pragma_Always_Terminates): Dedicated
routine for expansion of the new aspect.
* inline.adb (Remove_Aspects_And_Pragmas): Remove aspect from
inlined bodies.
* par-prag.adb (Prag): Postpone checking of the pragma until
analysis.
* sem_ch12.adb: Mention new aspect in explanation of handling
contracts on generic units.
* sem_ch13.adb (Analyze_Aspect_Specifications): Convert new aspect
into a corresponding pragma.
(Check_Aspect_At_Freeze_Point): Don't expect new aspect.
* sem_prag.adb (Analyze_Always_Terminates_In_Decl_Part): Analyze
pragma corresponding to the new aspect.
(Analyze_Pragma): Handle pragma corresponding to the new aspect.
(Is_Non_Significant_Pragma_Reference): Handle references appearing
within new aspect.
* sem_prag.ads (Aspect_Specifying_Pragma): New aspect can be
emulated with a pragma.
(Assertion_Expression_Pragma): New aspect has an assertion
expression.
(Pragma_Significant_To_Subprograms): New aspect is significant to
subprograms.
(Analyze_Always_Terminates_In_Decl_Part): Add spec for routine
that analyses new aspect.
(Find_Related_Declaration_Or_Body): Mention new aspect in comment.
* sem_util.adb (Is_Subprogram_Contract_Annotation): New aspect is
a subprogram contract annotation.
* sem_util.ads (Is_Subprogram_Contract_Annotation): Mention new
aspect in comment.
* sinfo.ads (Is_Generic_Contract_Pragma): New pragma is a generic
contract.
(Contract): Explain attaching new pragma to subprogram contract.
* snames.ads-tmpl (Name_Always_Terminates): New name for the new
contract.
(Pragma_Always_Terminates): New pragma identifier.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/aspects.ads |   6 ++
 gcc/ada/contracts.adb   |  29 --
 gcc/ada/contracts.ads   |   4 +
 gcc/ada/einfo-utils.adb |   1 +
 gcc/ada/einfo-utils.ads |   1 +
 gcc/ada/exp_prag.adb|  10 ++
 gcc/ada/exp_prag.ads|   4 +
 gcc/ada/inline.adb  |   4 +-
 gcc/ada/par-prag.adb|   1 +
 gcc/ada/sem_ch12.adb|   7 +-
 gcc/ada/sem_ch13.adb|  30 --
 gcc/ada/sem_prag.adb| 199 
 gcc/ada/sem_prag.ads|  15 ++-
 gcc/ada/sem_util.adb|   3 +-
 gcc/ada/sem_util.ads|   1 +
 gcc/ada/sinfo.ads   |   2 +
 gcc/ada/snames.ads-tmpl |   2 +
 17 files changed, 295 insertions(+), 24 deletions(-)

diff --git a/gcc/ada/aspects.ads b/gcc/ada/a

[COMMITTED] ada: Fix spurious error on call to function returning private in generic

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Eric Botcazou 

The spurious error is given on a call to a parameterless function returning
a private type, present in the body of a generic construct both declared and
instantiated in the presence of the full view of the type, because this full
view is not properly restored for the instantiation.

This is supposed to be handled by the Has_Private_View mechanism, but it is
bypassed here because the call to the parameterless function is first parsed
as a simple identifier before being later analyzed as a function call.

Fixing this first issue uncovered another one, whereby the Has_Private_View
flag was not properly set on an operator returning a private type that ends
up being later resolved as a function call.

Finally a small loophole in Eval_Attribute exposed by the change also needs
to be plugged.

gcc/ada/

* sem_attr.adb (Eval_Attribute): Add more exceptions to the early
return for a prefix which is a nonfrozen generic actual type.
* sem_ch12.adb (Copy_Generic_Node): Also check private views in the
case of an entity name or operator analyzed as a function call.
(Set_Global_Type): Make it a child of Save_Global_References.
(Save_References_In_Operator): In the case where the operator has
been turned into a function call, call Set_Global_Type on the entity
if it is global.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_attr.adb |   8 ++-
 gcc/ada/sem_ch12.adb | 113 ++-
 2 files changed, 63 insertions(+), 58 deletions(-)

diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
index 24f57ac43ff..dc06435e7b0 100644
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -8437,9 +8437,13 @@ package body Sem_Attr is
 --  However, the attribute Unconstrained_Array must be evaluated,
 --  since it is documented to be a static attribute (and can for
 --  example appear in a Compile_Time_Warning pragma). The frozen
---  status of the type does not affect its evaluation.
+--  status of the type does not affect its evaluation. Likewise
+--  for attributes intended to be used with generic definitions.
 
-and then Id /= Attribute_Unconstrained_Array
+and then Id not in Attribute_Unconstrained_Array
+|  Attribute_Has_Access_Values
+|  Attribute_Has_Discriminants
+|  Attribute_Has_Tagged_Values
   then
  return;
   end if;
diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index 2562d1a0812..0ef894e153b 100644
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -8178,6 +8178,7 @@ package body Sem_Ch12 is
 and then Is_Entity_Name (Name (Assoc))
   then
  Set_Entity (New_N, Entity (Name (Assoc)));
+ Check_Private_View (N);
 
   elsif Nkind (Assoc) in N_Entity
 and then (Expander_Active
@@ -15716,6 +15717,13 @@ package body Sem_Ch12 is
   --  This is the recursive procedure that does the work, once the
   --  enclosing generic scope has been established.
 
+  procedure Set_Global_Type (N : Node_Id; N2 : Node_Id);
+  --  If the type of N2 is global to the generic unit, save the type in
+  --  the generic node. Just as we perform name capture for explicit
+  --  references within the generic, we must capture the global types
+  --  of local entities because they may participate in resolution in
+  --  the instance.
+
   ---
   -- Is_Global --
   ---
@@ -15909,67 +15917,12 @@ package body Sem_Ch12 is
   --
 
   procedure Reset_Entity (N : Node_Id) is
- procedure Set_Global_Type (N : Node_Id; N2 : Node_Id);
- --  If the type of N2 is global to the generic unit, save the type in
- --  the generic node. Just as we perform name capture for explicit
- --  references within the generic, we must capture the global types
- --  of local entities because they may participate in resolution in
- --  the instance.
-
  function Top_Ancestor (E : Entity_Id) return Entity_Id;
  --  Find the ultimate ancestor of the current unit. If it is not a
  --  generic unit, then the name of the current unit in the prefix of
  --  an expanded name must be replaced with its generic homonym to
  --  ensure that it will be properly resolved in an instance.
 
- -
- -- Set_Global_Type --
- -
-
- procedure Set_Global_Type (N : Node_Id; N2 : Node_Id) is
-Typ : constant Entity_Id := Etype (N2);
-
- begin
-Set_Etype (N, Typ);
-
---  If the entity of N is not the associated node, this is a
---  nested generic and it has an associated node as well, whose

[COMMITTED] ada: Disable inlining in potentially unevaluated contexts

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Piotr Trojanek 

Instead of explicitly disabling inlining in quantified expressions,
(which happen to be only preanalysed) and then disabling inlining in
potentially unevaluated contexts that are fully analysed (which happen
to include quantified expressions), we now simply disable inlining in
all potentially unevaluated contexts, regardless of the full analysis
mode.

This also disables inlining in iterated component associations, which
can be both preanalysed or fully analysed depending on their expression,
but nevertheless are potentially unevaluated.

gcc/ada/

* sem_res.adb (Resolve_Call): Replace early call to
In_Quantified_Expression with a call to Is_Potentially_Unevaluated that
was only done when Full_Analysis is true.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_res.adb | 21 ++---
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
index c2a4bcb58cd..41787f3d2bc 100644
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -7290,14 +7290,14 @@ package body Sem_Res is
Cannot_Inline
  ("cannot inline & (in default expression)?", N, Nam_UA);
 
---  Calls cannot be inlined inside quantified expressions, which
---  are left in expression form for GNATprove. Since these
---  expressions are only preanalyzed, we need to detect the failure
---  to inline outside of the case for Full_Analysis below.
+--  Calls cannot be inlined inside potentially unevaluated
+--  expressions, as this would create complex actions inside
+--  expressions, that are not handled by GNATprove.
 
-elsif In_Quantified_Expression (N) then
+elsif Is_Potentially_Unevaluated (N) then
Cannot_Inline
- ("cannot inline & (in quantified expression)?", N, Nam_UA);
+  ("cannot inline & (in potentially unevaluated context)?",
+   N, Nam_UA);
 
 --  Inlining should not be performed during preanalysis
 
@@ -7365,15 +7365,6 @@ package body Sem_Res is
elsif No (Body_To_Inline (Nam_Decl)) then
   null;
 
-   --  Calls cannot be inlined inside potentially unevaluated
-   --  expressions, as this would create complex actions inside
-   --  expressions, that are not handled by GNATprove.
-
-   elsif Is_Potentially_Unevaluated (N) then
-  Cannot_Inline
-("cannot inline & (in potentially unevaluated context)?",
- N, Nam_UA);
-
--  Calls cannot be inlined inside the conditions of while
--  loops, as this would create complex actions inside
--  the condition, that are not handled by GNATprove.
-- 
2.40.0



[COMMITTED] ada: Fix iterated component initialization

2023-06-13 Thread Marc Poulhiès via Gcc-patches
The call to Resolve_Aggr_Expr may leave references to temporary entities
used to check for the construct legality and meant to be removed.

Using Preanalyze_And_Resolve correctly guarantees that there is no
visible occurrence of such entities.

gcc/ada/

* sem_aggr.adb (Resolve_Iterated_Component_Association): Call
Preanalyze_And_Resolve instead of Resolve_Aggr_Expr except for
aggregate.

Co-authored-by: Ed Schonberg 

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_aggr.adb | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb
index 3b2d0347b41..843606ab4a1 100644
--- a/gcc/ada/sem_aggr.adb
+++ b/gcc/ada/sem_aggr.adb
@@ -1862,9 +1862,14 @@ package body Sem_Aggr is
 
  Expr := Expression (N);
 
- Expander_Mode_Save_And_Set (False);
- Dummy := Resolve_Aggr_Expr (Expr, Single_Elmt => False);
- Expander_Mode_Restore;
+ if Nkind (Expr) = N_Aggregate then
+--  If the expression is an aggregate, this is a multidimensional
+--  aggregate where the component type must be propagated downward.
+
+Dummy := Resolve_Aggr_Expr (Expr, Single_Elmt => False);
+ else
+Preanalyze_And_Resolve (Expr, Component_Typ);
+ end if;
 
  if Operating_Mode /= Check_Semantics then
 Remove_References (Expr);
-- 
2.40.0



[COMMITTED] ada: Recognize iterated_component_association as potentially unevaluated

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Piotr Trojanek 

Routine Is_Potentially_Unevaluated was written for Ada 2012, but now we
use it for Ada 2022 as well, so it must recognize iterated component
associations (which were added by Ada 2022) as an array component
association.

gcc/ada/

* sem_util.adb (Is_Potentially_Unevaluated): Recognize iterated
component association as potentially unevaluated.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_util.adb | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index b82978ba99e..23668f1bec5 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -19566,7 +19566,8 @@ package body Sem_Util is
  elsif Nkind (Par) = N_Quantified_Expression then
 return Expr = Condition (Par);
 
- elsif Nkind (Par) = N_Component_Association
+ elsif Nkind (Par) in N_Component_Association
+| N_Iterated_Component_Association
and then Expr = Expression (Par)
and then Nkind (Parent (Par))
   in N_Aggregate | N_Delta_Aggregate | N_Extension_Aggregate
@@ -19708,10 +19709,15 @@ package body Sem_Util is
  then
 return True;
 
- --  For component associations continue climbing; it may be part of
- --  an array aggregate.
+ --  For component associations continue climbing; it may be part of an
+ --  array aggregate. For iterated component association we know that
+ --  it belongs to an array aggreate, but only its expression is
+ --  potentially unevaluated, not discrete choice list or iterator
+ --  specification.
 
- elsif Nkind (Par) = N_Component_Association then
+ elsif Nkind (Par) in N_Component_Association
+| N_Iterated_Component_Association
+ then
 null;
 
  --  If the context is not an expression, or if is the result of
-- 
2.40.0



[COMMITTED] ada: Recognize iterated_component_association as repeatedly evaluated

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Piotr Trojanek 

As iterated_component_association is an array_component_association
(because of a grammar rule Ada 2022 RM 4.3.3(5/5)), its expression is
repeatedly evaluated (because of Ada 2022 RM 6.1.1(22.14/5)).

With this patch we will now get errors for both conjuncts in this code,
which have semantically equivalent array aggregates that use an ordinary
component association and iterated component association.

  procedure Iter (S : String)
with Post => String'(for J in 1 .. 3 => S (S'First)'Old) =
 String'( 1 .. 3 => S (S'First)'Old);

gcc/ada/

* sem_util.adb (Is_Repeatedly_Evaluated): Recognize iterated component
association as repeatedly evaluated.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_util.adb | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 23668f1bec5..3fd3eb45f33 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -30768,7 +30768,8 @@ package body Sem_Util is
   --array_component_association or of
   --a container_element_associatiation.
 
-  if Nkind (Par) = N_Component_Association
+  if Nkind (Par) in N_Component_Association
+  | N_Iterated_Component_Association
 and then Trailer = Expression (Par)
   then
  --  determine whether Par is part of an array aggregate
-- 
2.40.0



[COMMITTED] ada: Fix another case of missing Has_Private_View flag

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Eric Botcazou 

It occurs for the case of a function call first parsed as an identifier.

gcc/ada/

* sem_ch12.adb (Save_References_In_Identifier): In the case where
the identifier has been turned into a function call by analysis,
call Set_Global_Type on the entity if it is global.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_ch12.adb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index 0ef894e153b..a38ab284ce7 100644
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -16526,7 +16526,7 @@ package body Sem_Ch12 is
   E := Entity (Name (N2));
 
   if Present (E) and then Is_Global (E) then
- Set_Etype (N, Etype (N2));
+ Set_Global_Type (N, N2);
   else
  Set_Associated_Node (N, Empty);
  Set_Etype (N, Empty);
-- 
2.40.0



[COMMITTED] ada: Fix decoration of iterated component association for GNATprove

2023-06-13 Thread Marc Poulhiès via Gcc-patches
From: Piotr Trojanek 

This patch is an alternative solution for a recent fix in analysis of
iterated component association.

To recap, if the iterated expression is an aggregate, we want to
propagate the component type downward with a call to Resolve_Aggr_Expr;
otherwise we want this expression to be only preanalysed (since the
association might need to be repeatedly evaluated), but also we need to
apply predicate and range checks to the expression itself (these are
required for GNATprove).

It turns out that Resolve_Aggr_Expr already knows how to deal with a
nested aggregate and also works for GNATprove, where it both preanalyzes
the expression and applies necessary checks.

In other words, expression of the iterated component association is now
resolved just like expression of an ordinary array aggregate.

gcc/ada/

* sem_aggr.adb (Resolve_Iterated_Component_Association): Simply resolve
the expression.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_aggr.adb | 9 +
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb
index 843606ab4a1..c6063c78bf6 100644
--- a/gcc/ada/sem_aggr.adb
+++ b/gcc/ada/sem_aggr.adb
@@ -1862,14 +1862,7 @@ package body Sem_Aggr is
 
  Expr := Expression (N);
 
- if Nkind (Expr) = N_Aggregate then
---  If the expression is an aggregate, this is a multidimensional
---  aggregate where the component type must be propagated downward.
-
-Dummy := Resolve_Aggr_Expr (Expr, Single_Elmt => False);
- else
-Preanalyze_And_Resolve (Expr, Component_Typ);
- end if;
+ Dummy := Resolve_Aggr_Expr (Expr, Single_Elmt => False);
 
  if Operating_Mode /= Check_Semantics then
 Remove_References (Expr);
-- 
2.40.0



[PATCH, committed] testsuite: Check int128 effective target for pr109932-{1,2}.c [PR110230]

2023-06-13 Thread Kewen.Lin via Gcc-patches
Hi,

This patch is to make newly added test cases pr109932-{1,2}.c
check int128 effective target to avoid unsupported type error
on 32-bit.  I did hit this failure during testing and fixed
it, but made a stupid mistake not updating the local formatted
patch which was actually out of date.

Pushed as obvious in r14-1776-g16eb9d69079d76.

BR,
Kewen
-
PR testsuite/110230
PR target/109932

gcc/testsuite/ChangeLog:

* gcc.target/powerpc/pr109932-1.c: Adjust with int128 effective target.
* gcc.target/powerpc/pr109932-2.c: Ditto.
---
 gcc/testsuite/gcc.target/powerpc/pr109932-1.c | 1 +
 gcc/testsuite/gcc.target/powerpc/pr109932-2.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/gcc/testsuite/gcc.target/powerpc/pr109932-1.c 
b/gcc/testsuite/gcc.target/powerpc/pr109932-1.c
index 3e3f9eaa65e..374d9f60618 100644
--- a/gcc/testsuite/gcc.target/powerpc/pr109932-1.c
+++ b/gcc/testsuite/gcc.target/powerpc/pr109932-1.c
@@ -1,3 +1,4 @@
+/* { dg-require-effective-target int128 } */
 /* { dg-require-effective-target powerpc_altivec_ok } */
 /* { dg-options "-maltivec -mno-vsx" } */

diff --git a/gcc/testsuite/gcc.target/powerpc/pr109932-2.c 
b/gcc/testsuite/gcc.target/powerpc/pr109932-2.c
index 3e3f9eaa65e..374d9f60618 100644
--- a/gcc/testsuite/gcc.target/powerpc/pr109932-2.c
+++ b/gcc/testsuite/gcc.target/powerpc/pr109932-2.c
@@ -1,3 +1,4 @@
+/* { dg-require-effective-target int128 } */
 /* { dg-require-effective-target powerpc_altivec_ok } */
 /* { dg-options "-maltivec -mno-vsx" } */

--
2.34.1


[PATCH 1/2] Missed opportunity to use [SU]ABD

2023-06-13 Thread Oluwatamilore Adebayo via Gcc-patches
From: oluade01 

This adds a recognition pattern for the non-widening
absolute difference (ABD).

gcc/ChangeLog:

* doc/md.texi (sabd, uabd): Document them.
* internal-fn.def (ABD): Use new optab.
* optabs.def (sabd_optab, uabd_optab): New optabs,
* tree-vect-patterns.cc (vect_recog_absolute_difference):
Recognize the following idiom abs (a - b).
(vect_recog_sad_pattern): Refactor to use
vect_recog_absolute_difference.
(vect_recog_abd_pattern): Use patterns found by
vect_recog_absolute_difference to build a new ABD
internal call.
---
 gcc/doc/md.texi   |  10 ++
 gcc/internal-fn.def   |   3 +
 gcc/optabs.def|   2 +
 gcc/tree-vect-patterns.cc | 245 +-
 4 files changed, 230 insertions(+), 30 deletions(-)

diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi
index 
6a435eb44610960513e9739ac9ac1e8a27182c10..e11b10d2fca11016232921bc85e47975f700e6c6
 100644
--- a/gcc/doc/md.texi
+++ b/gcc/doc/md.texi
@@ -5787,6 +5787,16 @@ Other shift and rotate instructions, analogous to the
 Vector shift and rotate instructions that take vectors as operand 2
 instead of a scalar type.
 
+@cindex @code{uabd@var{m}} instruction pattern
+@cindex @code{sabd@var{m}} instruction pattern
+@item @samp{uabd@var{m}}, @samp{sabd@var{m}}
+Signed and unsigned absolute difference instructions.  These
+instructions find the difference between operands 1 and 2
+then return the absolute value.  A C code equivalent would be:
+@smallexample
+op0 = op1 > op2 ? op1 - op2 : op2 - op1;
+@end smallexample
+
 @cindex @code{avg@var{m}3_floor} instruction pattern
 @cindex @code{uavg@var{m}3_floor} instruction pattern
 @item @samp{avg@var{m}3_floor}
diff --git a/gcc/internal-fn.def b/gcc/internal-fn.def
index 
3ac9d82aace322bd8ef108596e5583daa18c76e3..116965f4830cec8f60642ff011a86b6562e2c509
 100644
--- a/gcc/internal-fn.def
+++ b/gcc/internal-fn.def
@@ -191,6 +191,9 @@ DEF_INTERNAL_OPTAB_FN (FMS, ECF_CONST, fms, ternary)
 DEF_INTERNAL_OPTAB_FN (FNMA, ECF_CONST, fnma, ternary)
 DEF_INTERNAL_OPTAB_FN (FNMS, ECF_CONST, fnms, ternary)
 
+DEF_INTERNAL_SIGNED_OPTAB_FN (ABD, ECF_CONST | ECF_NOTHROW, first,
+ sabd, uabd, binary)
+
 DEF_INTERNAL_SIGNED_OPTAB_FN (AVG_FLOOR, ECF_CONST | ECF_NOTHROW, first,
  savg_floor, uavg_floor, binary)
 DEF_INTERNAL_SIGNED_OPTAB_FN (AVG_CEIL, ECF_CONST | ECF_NOTHROW, first,
diff --git a/gcc/optabs.def b/gcc/optabs.def
index 
6c064ff4993620067d38742a0bfe0a3efb511069..35b835a6ac56d72417dac8ddfd77a8a7e2475e65
 100644
--- a/gcc/optabs.def
+++ b/gcc/optabs.def
@@ -359,6 +359,8 @@ OPTAB_D (mask_fold_left_plus_optab, 
"mask_fold_left_plus_$a")
 OPTAB_D (extract_last_optab, "extract_last_$a")
 OPTAB_D (fold_extract_last_optab, "fold_extract_last_$a")
 
+OPTAB_D (uabd_optab, "uabd$a3")
+OPTAB_D (sabd_optab, "sabd$a3")
 OPTAB_D (savg_floor_optab, "avg$a3_floor")
 OPTAB_D (uavg_floor_optab, "uavg$a3_floor")
 OPTAB_D (savg_ceil_optab, "avg$a3_ceil")
diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index 
dc102c919352a0328cf86eabceb3a38c41a7e4fd..4b63febc33e90b3caa854404a241afb2f09d755e
 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -782,6 +782,86 @@ vect_split_statement (vec_info *vinfo, stmt_vec_info 
stmt2_info, tree new_rhs,
 }
 }
 
+/* Look for the following pattern
+   X = x[i]
+   Y = y[i]
+   DIFF = X - Y
+   DAD = ABS_EXPR
+
+   ABS_STMT should point to a statement of code ABS_EXPR or ABSU_EXPR.
+   HALF_TYPE and UNPROM will be set should the statement be found to
+   be a widened operation.
+   DIFF_STMT will be set to the MINUS_EXPR
+   statement that precedes the ABS_STMT unless vect_widened_op_tree
+   succeeds.
+ */
+static bool
+vect_recog_absolute_difference (vec_info *vinfo, gassign *abs_stmt,
+   tree *half_type,
+   vect_unpromoted_value unprom[2],
+   gassign **diff_stmt)
+{
+  if (!abs_stmt)
+return false;
+
+  /* FORNOW.  Can continue analyzing the def-use chain when this stmt in a phi
+ inside the loop (in case we are analyzing an outer-loop).  */
+  enum tree_code code = gimple_assign_rhs_code (abs_stmt);
+  if (code != ABS_EXPR && code != ABSU_EXPR)
+return false;
+
+  tree abs_oprnd = gimple_assign_rhs1 (abs_stmt);
+  tree abs_type = TREE_TYPE (abs_oprnd);
+  if (!abs_oprnd)
+return false;
+  if (!ANY_INTEGRAL_TYPE_P (abs_type)
+  || TYPE_OVERFLOW_WRAPS (abs_type)
+  || TYPE_UNSIGNED (abs_type))
+return false;
+
+  /* Peel off conversions from the ABS input.  This can involve sign
+ changes (e.g. from an unsigned subtraction to a signed ABS input)
+ or signed promotion, but it can't include unsigned promotion.
+ (Note that ABS of an unsigned promotion should have been folded
+ away before now anyway.)  */
+  vect_unpromoted_value unprom_d

[PATCH 2/2] AArch64: New RTL for ABD

2023-06-13 Thread Oluwatamilore Adebayo via Gcc-patches
From: oluade01 

This patch adds new RTL and tests for sabd and uabd

PR tree-optimization/109156

gcc/ChangeLog:

* config/aarch64/aarch64-simd-builtins.def (sabd, uabd):
Change the mode to 3.
* config/aarch64/aarch64-simd.md (aarch64_abd):
Rename to abd3.
* config/aarch64/aarch64-sve.md (abd_3): Rename
to abd3.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/abd.h: New file.
* gcc.target/aarch64/abd_2.c: New test.
* gcc.target/aarch64/abd_3.c: New test.
* gcc.target/aarch64/abd_4.c: New test.
* gcc.target/aarch64/abd_none_2.c: New test.
* gcc.target/aarch64/abd_none_3.c: New test.
* gcc.target/aarch64/abd_none_4.c: New test.
* gcc.target/aarch64/abd_run_1.c: New test.
* gcc.target/aarch64/sve/abd_1.c: New test.
* gcc.target/aarch64/sve/abd_none_1.c: New test.
* gcc.target/aarch64/sve/abd_2.c: New test.
* gcc.target/aarch64/sve/abd_none_2.c: New test.
---
 gcc/config/aarch64/aarch64-simd.md| 12 +++
 gcc/config/aarch64/aarch64-sve.md |  4 +-
 gcc/testsuite/gcc.target/aarch64/abd.h| 68 ++
 gcc/testsuite/gcc.target/aarch64/abd_2.c  | 35 +++
 gcc/testsuite/gcc.target/aarch64/abd_3.c  | 36 +++
 gcc/testsuite/gcc.target/aarch64/abd_4.c  | 30 ++
 gcc/testsuite/gcc.target/aarch64/abd_none_2.c | 14 +++
 gcc/testsuite/gcc.target/aarch64/abd_none_3.c | 14 +++
 gcc/testsuite/gcc.target/aarch64/abd_none_4.c | 22 +
 gcc/testsuite/gcc.target/aarch64/abd_run_1.c  | 93 +++
 gcc/testsuite/gcc.target/aarch64/sve/abd_1.c  | 35 +++
 gcc/testsuite/gcc.target/aarch64/sve/abd_2.c  | 29 ++
 .../gcc.target/aarch64/sve/abd_none_1.c   | 13 +++
 .../gcc.target/aarch64/sve/abd_none_2.c   | 21 +
 14 files changed, 424 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/aarch64/abd.h
 create mode 100644 gcc/testsuite/gcc.target/aarch64/abd_2.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/abd_3.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/abd_4.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/abd_none_2.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/abd_none_3.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/abd_none_4.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/abd_run_1.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/abd_1.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/abd_2.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/abd_none_1.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/abd_none_2.c

diff --git a/gcc/config/aarch64/aarch64-simd.md 
b/gcc/config/aarch64/aarch64-simd.md
index 
a567f016b354c0f0542e58e7b51c0be739882d65..bf90202ba2ad3f62f2020486d21256f083effb07
 100644
--- a/gcc/config/aarch64/aarch64-simd.md
+++ b/gcc/config/aarch64/aarch64-simd.md
@@ -910,6 +910,18 @@ (define_insn "aarch64_abd"
   [(set_attr "type" "neon_abd")]
 )
 
+(define_expand "abd3"
+  [(match_operand:VDQ_BHSI 0 "register_operand")
+   (USMAX:VDQ_BHSI
+ (match_operand:VDQ_BHSI 1 "register_operand")
+ (match_operand:VDQ_BHSI 2 "register_operand"))]
+  "TARGET_SIMD"
+  {
+emit_insn (gen_aarch64_abd (operands[0], operands[1], 
operands[2]));
+DONE;
+  }
+)
+
 (define_insn "aarch64_abdl"
   [(set (match_operand: 0 "register_operand" "=w")
(zero_extend:
diff --git a/gcc/config/aarch64/aarch64-sve.md 
b/gcc/config/aarch64/aarch64-sve.md
index 
2898b85376b831c2728b806e0f2079086345f1fe..2de651a1989c6b36272dd78a8744c700ebc75c1a
 100644
--- a/gcc/config/aarch64/aarch64-sve.md
+++ b/gcc/config/aarch64/aarch64-sve.md
@@ -4001,7 +4001,7 @@ (define_insn_and_rewrite "*aarch64_adr_shift_uxtw"
 ;; -
 
 ;; Unpredicated integer absolute difference.
-(define_expand "abd_3"
+(define_expand "abd3"
   [(use (match_operand:SVE_I 0 "register_operand"))
(USMAX:SVE_I
  (match_operand:SVE_I 1 "register_operand")
@@ -6973,7 +6973,7 @@ (define_expand "sad"
   {
 rtx ones = force_reg (mode, CONST1_RTX (mode));
 rtx diff = gen_reg_rtx (mode);
-emit_insn (gen_abd_3 (diff, operands[1], operands[2]));
+emit_insn (gen_abd3 (diff, operands[1], operands[2]));
 emit_insn (gen_udot_prod (operands[0], diff, ones, operands[3]));
 DONE;
   }
diff --git a/gcc/testsuite/gcc.target/aarch64/abd.h 
b/gcc/testsuite/gcc.target/aarch64/abd.h
new file mode 100644
index 
..b95fd908d91d9e576e4d76638844e22deb50a006
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/abd.h
@@ -0,0 +1,68 @@
+#ifdef ABD_IDIOM
+
+#define TEST1(S, TYPE) \
+__attribute__((noipa)) \
+void fn_##S##_##TYPE (S TYPE * restrict a, \
+ S TYPE * restrict b,  \
+ S TYPE * restrict out) {  \
+  for (int i = 0; i < N; i++

Re: [PATCH v1] rs6000: Update powerpc test fold-vec-extract-int.p8.c

2023-06-13 Thread Kewen.Lin via Gcc-patches
Hi,

on 2023/5/19 15:40, Ajit Agarwal via Gcc-patches wrote:
> Hello All:
> 
> Update powerpc tests for both le and be endian with extra removal of zero 
> extension and sign extension.
> with default ree pass for rs6000 target.

Nice! 

> 
> Bootstrapped and regtested on powerpc64-linux-gnu.
> 
> Thanks & Regards
> Ajit
> 
> rs6000: Update powerpc test fold-vec-extract-int.p8.c

May be better to start with "testsuite:" or "testsuite, rs6000:".

> 
> Update powerpc tests with extra zero_extend removal with default ree pass.
> 
> 2023-05-19  Ajit Kumar Agarwal  

Since there is an upstream bug tracking this, could you add one PR
marker like:

PR testsuite/109880

OK for trunk with the PR marker added, thanks!

BR,
Kewen

> 
> gcc/testsuite/ChangeLog:
> 
>   * gcc.target/powerpc/fold-vec-extract-int.p8.c: Update test.
> ---
>  gcc/testsuite/gcc.target/powerpc/fold-vec-extract-int.p8.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-extract-int.p8.c 
> b/gcc/testsuite/gcc.target/powerpc/fold-vec-extract-int.p8.c
> index 75eaf25943b..f5f953320d8 100644
> --- a/gcc/testsuite/gcc.target/powerpc/fold-vec-extract-int.p8.c
> +++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-extract-int.p8.c
> @@ -13,8 +13,8 @@
>  
>  /* { dg-final { scan-assembler-times {\mvspltw\M} 3 { target lp64 } } } */
>  /* { dg-final { scan-assembler-times {\mmfvsrwz\M} 3 { target lp64 } } } */
> -/* { dg-final { scan-assembler-times {\mrldicl\M} 7 { target { le } } } } */
> -/* { dg-final { scan-assembler-times {\mrldicl\M} 4 { target { lp64 && be } 
> } } } */
> +/* { dg-final { scan-assembler-times {\mrldicl\M} 5 { target { le } } } } */
> +/* { dg-final { scan-assembler-times {\mrldicl\M} 2 { target { lp64 && be } 
> } } } */
>  /* { dg-final { scan-assembler-times {\msubfic\M} 3 { target { le } } } } */
>  /* { dg-final { scan-assembler-times {\msldi\M} 3  { target lp64 } } } */
>  /* { dg-final { scan-assembler-times {\mmtvsrd\M} 3 { target lp64 } } } */



Re: Patch ping (Re: [PATCH] middle-end, i386: Pattern recognize add/subtract with carry [PR79173])

2023-06-13 Thread Uros Bizjak via Gcc-patches
On Tue, Jun 13, 2023 at 9:06 AM Jakub Jelinek  wrote:
>
> Hi!
>
> On Tue, Jun 06, 2023 at 11:42:07PM +0200, Jakub Jelinek via Gcc-patches wrote:
> > The following patch introduces {add,sub}c5_optab and pattern recognizes
> > various forms of add with carry and subtract with carry/borrow, see
> > pr79173-{1,2,3,4,5,6}.c tests on what is matched.
> > Primarily forms with 2 __builtin_add_overflow or __builtin_sub_overflow
> > calls per limb (with just one for the least significant one), for
> > add with carry even when it is hand written in C (for subtraction
> > reassoc seems to change it too much so that the pattern recognition
> > doesn't work).  __builtin_{add,sub}_overflow are standardized in C23
> > under ckd_{add,sub} names, so it isn't any longer a GNU only extension.
> >
> > Note, clang has for these has (IMHO badly designed)
> > __builtin_{add,sub}c{b,s,,l,ll} builtins which don't add/subtract just
> > a single bit of carry, but basically add 3 unsigned values or
> > subtract 2 unsigned values from one, and result in carry out of 0, 1, or 2
> > because of that.  If we wanted to introduce those for clang compatibility,
> > we could and lower them early to just two __builtin_{add,sub}_overflow
> > calls and let the pattern matching in this patch recognize it later.
> >
> > I've added expanders for this on ix86 and in addition to that
> > added various peephole2s to make sure we get nice (and small) code
> > for the common cases.  I think there are other PRs which request that
> > e.g. for the _{addcarry,subborrow}_u{32,64} intrinsics, which the patch
> > also improves.
>
> I'd like to ping this patch.

I briefly went over the x86 part (LGTM), but please get a middle-end
approval first.

Thanks,
Uros.

>
> Thanks.
>
> Jakub
>


[committed] [PATCH v1] rs6000: Update powerpc test fold-vec-extract-int.p8.c

2023-06-13 Thread Ajit Agarwal via Gcc-patches
commit 17714c08e9013b51cf8d04ac39f844d355c923f2 (HEAD -> master, origin/master, 
origin/HEAD)
Author: “Ajit Kumar Agarwal” 
Date:   Fri May 19 02:30:44 2023 -0500

testsuite: Update powerpc test fold-vec-extract-int.p8.c

Update powerpc tests with extra zero_extend removal with default ree pass.

2023-06-13  Ajit Kumar Agarwal  

gcc/testsuite/ChangeLog:

PR testsuite/109880
* gcc.target/powerpc/fold-vec-extract-int.p8.c: Update test.

On 13/06/23 1:58 pm, Kewen.Lin wrote:
> PR testsuite/109880


Re: [PATCH] Add MinGW option -mcrtdll= for choosing C RunTime DLL library

2023-06-13 Thread LIU Hao via Gcc-patches

在 2023/6/13 14:29, Pali Rohár 写道:

Of course, just I'm not sure where to put the new paragraph. At the
beginning? Or after the text? What do you think?


Maybe just in front of 'This option is available for MinGW targets.' Also you 
may reword it as you like.



--
Best regards,
LIU Hao



OpenPGP_signature
Description: OpenPGP digital signature


Re: [PATCH] middle-end, i386: Pattern recognize add/subtract with carry [PR79173]

2023-06-13 Thread Richard Biener via Gcc-patches
On Tue, 6 Jun 2023, Jakub Jelinek wrote:

> Hi!
> 
> The following patch introduces {add,sub}c5_optab and pattern recognizes
> various forms of add with carry and subtract with carry/borrow, see
> pr79173-{1,2,3,4,5,6}.c tests on what is matched.
> Primarily forms with 2 __builtin_add_overflow or __builtin_sub_overflow
> calls per limb (with just one for the least significant one), for
> add with carry even when it is hand written in C (for subtraction
> reassoc seems to change it too much so that the pattern recognition
> doesn't work).  __builtin_{add,sub}_overflow are standardized in C23
> under ckd_{add,sub} names, so it isn't any longer a GNU only extension.
> 
> Note, clang has for these has (IMHO badly designed)
> __builtin_{add,sub}c{b,s,,l,ll} builtins which don't add/subtract just
> a single bit of carry, but basically add 3 unsigned values or
> subtract 2 unsigned values from one, and result in carry out of 0, 1, or 2
> because of that.  If we wanted to introduce those for clang compatibility,
> we could and lower them early to just two __builtin_{add,sub}_overflow
> calls and let the pattern matching in this patch recognize it later.
> 
> I've added expanders for this on ix86 and in addition to that
> added various peephole2s to make sure we get nice (and small) code
> for the common cases.  I think there are other PRs which request that
> e.g. for the _{addcarry,subborrow}_u{32,64} intrinsics, which the patch
> also improves.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> Would be nice if support for these optabs was added to many other targets,
> arm/aarch64 and powerpc* certainly have such instructions, I'd expect
> in fact that most targets do.
> 
> The _BitInt support I'm working on will also need this to emit reasonable
> code.
> 
> 2023-06-06  Jakub Jelinek  
> 
>   PR middle-end/79173
>   * internal-fn.def (ADDC, SUBC): New internal functions.
>   * internal-fn.cc (expand_ADDC, expand_SUBC): New functions.
>   (commutative_ternary_fn_p): Return true also for IFN_ADDC.
>   * optabs.def (addc5_optab, subc5_optab): New optabs.
>   * tree-ssa-math-opts.cc (match_addc_subc): New function.
>   (math_opts_dom_walker::after_dom_children): Call match_addc_subc
>   for PLUS_EXPR, MINUS_EXPR, BIT_IOR_EXPR and BIT_XOR_EXPR unless
>   other optimizations have been successful for those.
>   * gimple-fold.cc (gimple_fold_call): Handle IFN_ADDC and IFN_SUBC.
>   * gimple-range-fold.cc (adjust_imagpart_expr): Likewise.
>   * tree-ssa-dce.cc (eliminate_unnecessary_stmts): Likewise.
>   * doc/md.texi (addc5, subc5): Document new named
>   patterns.
>   * config/i386/i386.md (subborrow): Add alternative with
>   memory destination.
>   (addc5, subc5): New define_expand patterns.
>   (*sub_3, @add3_carry, addcarry, @sub3_carry,
>   subborrow, *add3_cc_overflow_1): Add define_peephole2
>   TARGET_READ_MODIFY_WRITE/-Os patterns to prefer using memory
>   destination in these patterns.
> 
>   * gcc.target/i386/pr79173-1.c: New test.
>   * gcc.target/i386/pr79173-2.c: New test.
>   * gcc.target/i386/pr79173-3.c: New test.
>   * gcc.target/i386/pr79173-4.c: New test.
>   * gcc.target/i386/pr79173-5.c: New test.
>   * gcc.target/i386/pr79173-6.c: New test.
>   * gcc.target/i386/pr79173-7.c: New test.
>   * gcc.target/i386/pr79173-8.c: New test.
>   * gcc.target/i386/pr79173-9.c: New test.
>   * gcc.target/i386/pr79173-10.c: New test.
> 
> --- gcc/internal-fn.def.jj2023-06-05 10:38:06.670333685 +0200
> +++ gcc/internal-fn.def   2023-06-05 11:40:50.672212265 +0200
> @@ -381,6 +381,8 @@ DEF_INTERNAL_FN (ASAN_POISON_USE, ECF_LE
>  DEF_INTERNAL_FN (ADD_OVERFLOW, ECF_CONST | ECF_LEAF | ECF_NOTHROW, NULL)
>  DEF_INTERNAL_FN (SUB_OVERFLOW, ECF_CONST | ECF_LEAF | ECF_NOTHROW, NULL)
>  DEF_INTERNAL_FN (MUL_OVERFLOW, ECF_CONST | ECF_LEAF | ECF_NOTHROW, NULL)
> +DEF_INTERNAL_FN (ADDC, ECF_CONST | ECF_LEAF | ECF_NOTHROW, NULL)
> +DEF_INTERNAL_FN (SUBC, ECF_CONST | ECF_LEAF | ECF_NOTHROW, NULL)
>  DEF_INTERNAL_FN (TSAN_FUNC_EXIT, ECF_NOVOPS | ECF_LEAF | ECF_NOTHROW, NULL)
>  DEF_INTERNAL_FN (VA_ARG, ECF_NOTHROW | ECF_LEAF, NULL)
>  DEF_INTERNAL_FN (VEC_CONVERT, ECF_CONST | ECF_LEAF | ECF_NOTHROW, NULL)
> --- gcc/internal-fn.cc.jj 2023-05-15 19:12:24.080780016 +0200
> +++ gcc/internal-fn.cc2023-06-06 09:38:46.333871169 +0200
> @@ -2722,6 +2722,44 @@ expand_MUL_OVERFLOW (internal_fn, gcall
>expand_arith_overflow (MULT_EXPR, stmt);
>  }
>  
> +/* Expand ADDC STMT.  */
> +
> +static void
> +expand_ADDC (internal_fn ifn, gcall *stmt)
> +{
> +  tree lhs = gimple_call_lhs (stmt);
> +  tree arg1 = gimple_call_arg (stmt, 0);
> +  tree arg2 = gimple_call_arg (stmt, 1);
> +  tree arg3 = gimple_call_arg (stmt, 2);
> +  tree type = TREE_TYPE (arg1);
> +  machine_mode mode = TYPE_MODE (type);
> +  insn_code icode = optab_handler (ifn == IFN_ADDC
> +   

[PATCH] Fix disambiguation against .MASK_LOAD

2023-06-13 Thread Richard Biener via Gcc-patches
Alias analysis was treating .MASK_LOAD as storing a full vector
which means we disambiguate against decls of smaller than vector size.
This complements the previous patch handling .MASK_STORE and fixes
runtime execution FAILs of gfortran.dg/matmul_3.f90 and
gfortran.dg/inline_sum_2.f90 when using AVX512 with full masked loop
vectorization on Zen4.

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

* tree-ssa-alias.cc (ref_maybe_used_by_call_p_1): For
.MASK_LOAD and friends set the size of the access to unknown.
---
 gcc/tree-ssa-alias.cc | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-ssa-alias.cc b/gcc/tree-ssa-alias.cc
index b5476e8b41e..e1bc04b82ba 100644
--- a/gcc/tree-ssa-alias.cc
+++ b/gcc/tree-ssa-alias.cc
@@ -2829,6 +2829,9 @@ ref_maybe_used_by_call_p_1 (gcall *call, ao_ref *ref, 
bool tbaa_p)
  ao_ref_init_from_ptr_and_size (&rhs_ref,
 gimple_call_arg (call, 0),
 TYPE_SIZE_UNIT (TREE_TYPE (lhs)));
+ /* We cannot make this a known-size access since otherwise
+we disambiguate against refs to decls that are smaller.  */
+ rhs_ref.size = -1;
  rhs_ref.ref_alias_set = rhs_ref.base_alias_set
= tbaa_p ? get_deref_alias_set (TREE_TYPE
(gimple_call_arg (call, 1))) : 0;
@@ -3073,7 +3076,7 @@ call_may_clobber_ref_p_1 (gcall *call, ao_ref *ref, bool 
tbaa_p)
  ao_ref_init_from_ptr_and_size (&lhs_ref, gimple_call_arg (call, 0),
 TYPE_SIZE_UNIT (TREE_TYPE (rhs)));
  /* We cannot make this a known-size access since otherwise
-we disambiguate against stores to decls that are smaller.  */
+we disambiguate against refs to decls that are smaller.  */
  lhs_ref.size = -1;
  lhs_ref.ref_alias_set = lhs_ref.base_alias_set
= tbaa_p ? get_deref_alias_set
-- 
2.35.3


[PATCH] middle-end/110232 - fix native interpret of vector

2023-06-13 Thread Richard Biener via Gcc-patches
The following fixes native interpretation of a buffer as boolean
vector with bit-precision elements such as AVX512 vectors.  The
check whether the buffer covers the whole vector was broken for
bit-precision elements and the following instead implements it
based on the vector type size.

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

PR middle-end/110232
* fold-const.cc (native_interpret_vector): Use TYPE_SIZE_UNIT
to check whether the buffer covers the whole vector.

* gcc.target/i386/pr110232.c: New testcase.
---
 gcc/fold-const.cc| 11 ---
 gcc/testsuite/gcc.target/i386/pr110232.c | 12 
 2 files changed, 16 insertions(+), 7 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr110232.c

diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 84b0d06b819..9ea055d4523 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -8796,16 +8796,13 @@ native_interpret_vector_part (tree type, const unsigned 
char *bytes,
 static tree
 native_interpret_vector (tree type, const unsigned char *ptr, unsigned int len)
 {
-  tree etype;
-  unsigned int size;
-  unsigned HOST_WIDE_INT count;
+  unsigned HOST_WIDE_INT size;
 
-  etype = TREE_TYPE (type);
-  size = GET_MODE_SIZE (SCALAR_TYPE_MODE (etype));
-  if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&count)
-  || size * count > len)
+  if (!tree_to_poly_uint64 (TYPE_SIZE_UNIT (type)).is_constant (&size)
+  || size > len)
 return NULL_TREE;
 
+  unsigned HOST_WIDE_INT count = TYPE_VECTOR_SUBPARTS (type).to_constant ();
   return native_interpret_vector_part (type, ptr, len, count, 1);
 }
 
diff --git a/gcc/testsuite/gcc.target/i386/pr110232.c 
b/gcc/testsuite/gcc.target/i386/pr110232.c
new file mode 100644
index 000..43b74b15e00
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr110232.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -march=znver4 --param vect-partial-vector-usage=2 
-fno-vect-cost-model -fdump-tree-vect" } */
+
+int a[4096];
+
+void foo ()
+{
+  for (int i = 1; i < 4095; ++i)
+a[i] = 42;
+}
+
+/* { dg-final { scan-tree-dump-not "VIEW_CONVERT_EXPR" "vect" } } */
-- 
2.35.3


Re: [PATCH] c, c++: Accept __builtin_classify_type (typename)

2023-06-13 Thread Jason Merrill via Gcc-patches

On 6/12/23 15:57, Jakub Jelinek wrote:

Hi!

As mentioned in my stdckdint.h mail, __builtin_classify_type has
a problem that argument promotion (the argument is passed to ...
prototyped builtin function) means that certain type classes will
simply never appear.
I think it is too late to change how it behaves, lots of code in the
wild might rely on the current behavior.

So, the following patch adds option to use a typename rather than
expression as the operand to the builtin, making it behave similarly
to sizeof, typeof or say the clang _Generic extension where the
first argument can be there not just expression, but also typename.

I think we have other prior art here, e.g. __builtin_va_arg also
expects typename.

I've added this to both C and C++, because it would be weird if it
supported it only in C and not in C++.

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

2023-06-12  Jakub Jelinek  

gcc/
* builtins.h (type_to_class): Declare.
* builtins.cc (type_to_class): No longer static.  Return
int rather than enum.
* doc/extend.texi (__builtin_classify_type): Document.
gcc/c/
* c-parser.cc (c_parser_postfix_expression_after_primary): Parse
__builtin_classify_type call with typename as argument.
gcc/cp/
* parser.cc (cp_parser_postfix_expression): Parse
__builtin_classify_type call with typename as argument.
* pt.cc (tsubst_copy_and_build): Handle __builtin_classify_type
with dependent typename as argument.
gcc/testsuite/
* c-c++-common/builtin-classify-type-1.c: New test.
* g++.dg/ext/builtin-classify-type-1.C: New test.
* g++.dg/ext/builtin-classify-type-2.C: New test.
* gcc.dg/builtin-classify-type-1.c: New test.

--- gcc/builtins.h.jj   2023-01-03 00:20:34.856089856 +0100
+++ gcc/builtins.h  2023-06-12 09:35:20.841902572 +0200
@@ -156,5 +156,6 @@ extern internal_fn associated_internal_f
  extern internal_fn replacement_internal_fn (gcall *);
  
  extern bool builtin_with_linkage_p (tree);

+extern int type_to_class (tree);
  
  #endif /* GCC_BUILTINS_H */

--- gcc/builtins.cc.jj  2023-05-20 15:31:09.03352 +0200
+++ gcc/builtins.cc 2023-06-12 09:35:31.709751296 +0200
@@ -113,7 +113,6 @@ static rtx expand_builtin_apply_args (vo
  static rtx expand_builtin_apply_args_1 (void);
  static rtx expand_builtin_apply (rtx, rtx, rtx);
  static void expand_builtin_return (rtx);
-static enum type_class type_to_class (tree);
  static rtx expand_builtin_classify_type (tree);
  static rtx expand_builtin_mathfn_3 (tree, rtx, rtx);
  static rtx expand_builtin_mathfn_ternary (tree, rtx, rtx);
@@ -1852,7 +1851,7 @@ expand_builtin_return (rtx result)
  
  /* Used by expand_builtin_classify_type and fold_builtin_classify_type.  */
  
-static enum type_class

+int
  type_to_class (tree type)
  {
switch (TREE_CODE (type))
--- gcc/doc/extend.texi.jj  2023-06-10 19:58:26.197478291 +0200
+++ gcc/doc/extend.texi 2023-06-12 18:06:24.629413024 +0200
@@ -14354,6 +14354,30 @@ need not be a constant.  @xref{Object Si
  description of the function.
  @enddefbuiltin
  
+@defbuiltin{int __builtin_classify_type (@var{arg})}

+@defbuiltinx{int __builtin_classify_type (@var{type})}
+The @code{__builtin_classify_type} returns a small integer with a category
+of @var{arg} argument's type, like void type, integer type, enumeral type,
+boolean type, pointer type, reference type, offset type, real type, complex
+type, function type, method type, record type, union type, array type,
+string type, etc.  When the argument is an expression, for
+backwards compatibility reason the argument is promoted like arguments
+passed to @code{...} in varargs function, so some classes are never returned
+in certain languages.  Alternatively, the argument of the builtin-in
+function can be a typename, such as the @code{typeof} specifier.
+
+@smallexample
+int a[2];
+__builtin_classify_type (a) == __builtin_classify_type (int[5]);
+__builtin_classify_type (a) == __builtin_classify_type (void*);
+__builtin_classify_type (typeof (a)) == __builtin_classify_type (int[5]);
+@end smallexample
+
+The first comparison will never be true, as @var{a} is implicitly converted
+to pointer.  The last two comparisons will be true as they classify
+pointers in the second case and arrays in the last case.
+@enddefbuiltin
+
  @defbuiltin{double __builtin_huge_val (void)}
  Returns a positive infinity, if supported by the floating-point format,
  else @code{DBL_MAX}.  This function is suitable for implementing the
--- gcc/c/c-parser.cc.jj2023-06-10 19:22:15.577205685 +0200
+++ gcc/c/c-parser.cc   2023-06-12 17:32:31.007413019 +0200
@@ -11213,6 +11213,32 @@ c_parser_postfix_expression_after_primar
literal_zero_mask = 0;
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
  exprlist = NULL;
+   else if (TREE_CODE (expr.value) == FUNCTION_DECL
+&& fndecl_built_

[PATCHv3, rs6000] Add two peephole2 patterns for mr. insn

2023-06-13 Thread HAO CHEN GUI via Gcc-patches
Hi,
  This patch adds two peephole2 patterns which help convert certain insn
sequences to "mr." instruction. These insn sequences can't be combined in
combine pass.

  Compared to last version, it changes the new mode iterator name from "Q"
to "WORD".

  Bootstrapped and tested on powerpc64-linux BE and LE with no regressions.

Thanks
Gui Haochen

ChangeLog
rs6000: Add two peephole patterns for "mr." insn

When investigating the issue mentioned in PR87871#c30 - if compare
and move pattern benefits before RA, I checked the assembly generated
for SPEC2017 and found that certain insn sequences aren't converted to
"mr." instructions.
Following two sequence are never to be combined to "mr." pattern as
there is no register link between them. This patch adds two peephole2
patterns to convert them to "mr." instructions.

cmp 0,3,0
mr 4,3

mr 4,3
cmp 0,3,0

The patch also creates a new mode iterator which decided by
TARGET_POWERPC64.  This mode iterator is used in "mr." and its split
pattern.  The original P iterator is wrong when -m32/-mpowerpc64 is set.
In this situation, the "mr." should compares the whole 64-bit register
with 0 other than the low 32-bit one.

gcc/
* config/rs6000/rs6000.md (peephole2 for compare_and_move): New.
(peephole2 for move_and_compare): New.
(mode_iterator WORD): New.  Set the mode to SI/DImode by
TARGET_POWERPC64.
(*mov_internal2): Change the mode iterator from P to WORD.
(split pattern for compare_and_move): Likewise.

gcc/testsuite/
* gcc.dg/rtl/powerpc/move_compare_peephole_32.c: New.
* gcc.dg/rtl/powerpc/move_compare_peephole_64.c: New.


patch.diff
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index b0db8ae508d..1f0fe85b9b5 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -491,6 +491,7 @@ (define_mode_iterator SDI [SI DI])
 ; The size of a pointer.  Also, the size of the value that a record-condition
 ; (one with a '.') will compare; and the size used for arithmetic carries.
 (define_mode_iterator P [(SI "TARGET_32BIT") (DI "TARGET_64BIT")])
+(define_mode_iterator WORD [(SI "!TARGET_POWERPC64") (DI "TARGET_POWERPC64")])

 ; Iterator to add PTImode along with TImode (TImode can go in VSX registers,
 ; PTImode is GPR only)
@@ -7879,9 +7880,9 @@ (define_split

 (define_insn "*mov_internal2"
   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
-   (compare:CC (match_operand:P 1 "gpc_reg_operand" "0,r,r")
+   (compare:CC (match_operand:WORD 1 "gpc_reg_operand" "0,r,r")
(const_int 0)))
-   (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
+   (set (match_operand:WORD 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
   ""
   "@
cmpi %2,%0,0
@@ -7891,11 +7892,41 @@ (define_insn "*mov_internal2"
(set_attr "dot" "yes")
(set_attr "length" "4,4,8")])

+(define_peephole2
+  [(set (match_operand:CC 2 "cc_reg_operand" "")
+   (compare:CC (match_operand:WORD 1 "int_reg_operand" "")
+   (const_int 0)))
+   (set (match_operand:WORD 0 "int_reg_operand" "")
+   (match_dup 1))]
+  "!cc_reg_not_cr0_operand (operands[2], CCmode)"
+  [(parallel [(set (match_operand:CC 2 "cc_reg_operand" "=x")
+  (compare:CC (match_operand:WORD 1 "int_reg_operand" "r")
+  (const_int 0)))
+ (set (match_operand:WORD 0 "int_reg_operand" "=r")
+  (match_dup 1))])]
+  ""
+)
+
+(define_peephole2
+  [(set (match_operand:WORD 0 "int_reg_operand" "")
+   (match_operand:WORD 1 "int_reg_operand" ""))
+   (set (match_operand:CC 2 "cc_reg_operand" "")
+   (compare:CC (match_dup 1)
+   (const_int 0)))]
+  "!cc_reg_not_cr0_operand (operands[2], CCmode)"
+  [(parallel [(set (match_operand:CC 2 "cc_reg_operand" "=x")
+  (compare:CC (match_operand:GPR 1 "int_reg_operand" "r")
+  (const_int 0)))
+ (set (match_operand:WORD 0 "int_reg_operand" "=r")
+  (match_dup 1))])]
+  ""
+)
+
 (define_split
   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand")
-   (compare:CC (match_operand:P 1 "gpc_reg_operand")
+   (compare:CC (match_operand:WORD 1 "gpc_reg_operand")
(const_int 0)))
-   (set (match_operand:P 0 "gpc_reg_operand") (match_dup 1))]
+   (set (match_operand:WORD 0 "gpc_reg_operand") (match_dup 1))]
   "reload_completed"
   [(set (match_dup 0) (match_dup 1))
(set (match_dup 2)
diff --git a/gcc/testsuite/gcc.dg/rtl/powerpc/move_compare_peephole_32.c 
b/gcc/testsuite/gcc.dg/rtl/powerpc/move_compare_peephole_32.c
new file mode 100644
index 000..29234dea7c7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/rtl/powerpc/move_compare_peephole_32.c
@@ -0,0 +1,60 @@
+/* { dg-do compile { target powerpc*-*-* } } */
+/* { dg-skip-if "" { has_arch_ppc64 } } */
+/* { dg-options "-O2 -mregnames" } */
+
+/* Following instruction sequence is found in assembly of
+   Perl_block_start, whic

[PATCH][committed] aarch64: Extend -mtp= arguments

2023-06-13 Thread Kyrylo Tkachov via Gcc-patches
Hi all,

After discussing the -mtp= option with Arm's LLVM developers we'd like to extend
the functionality of the option somewhat.
First of all, there is another TPIDR register that can be used to read the 
thread pointer:
TPIDRRO_EL0 (which can also be accessed by AArch32 under another name) so it 
makes sense
to add -mtp=tpidrr0_el0. This makes the existing arguments el0, el1, el2, el3 
somewhat
inconsistent in their naming so this patch introduces the more "full" names
tpidr_el0, tpidr_el1, tpidr_el2, tpidr_el3 and makes the above short names 
alias of these new ones.
Long story short, we preserve backwards compatibility and add a new TPIDR 
register to access through
-mtp that wasn't available previously.
There is more relevant discussion of the options at 
https://reviews.llvm.org/D152433 if you're interested.

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

gcc/ChangeLog:

PR target/108779
* config/aarch64/aarch64-opts.h (enum aarch64_tp_reg): Add
AARCH64_TPIDRRO_EL0 value.
* config/aarch64/aarch64.cc (aarch64_output_load_tp):
* config/aarch64/aarch64.opt (tpidr_el0, tpidr_el1, tpidr_el2,
tpidr_el3, tpidrro_el3): New accepted values to -mtp=.
* doc/invoke.texi (AArch64 Options): Document new -mtp= options.

gcc/testsuite/ChangeLog:

PR target/108779
* gcc.target/aarch64/mtp_5.c: New test.
* gcc.target/aarch64/mtp_6.c: New test.
* gcc.target/aarch64/mtp_7.c: New test.
* gcc.target/aarch64/mtp_8.c: New test.
* gcc.target/aarch64/mtp_9.c: New test.


mtp-a64.patch
Description: mtp-a64.patch


[PATCH] RISC-V: Add more SLP tests

2023-06-13 Thread juzhe . zhong
From: Juzhe-Zhong 

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/partial/slp-10.c: New test.
* gcc.target/riscv/rvv/autovec/partial/slp-11.c: New test.
* gcc.target/riscv/rvv/autovec/partial/slp_run-10.c: New test.
* gcc.target/riscv/rvv/autovec/partial/slp_run-11.c: New test.

---
 .../riscv/rvv/autovec/partial/slp-10.c| 30 ++
 .../riscv/rvv/autovec/partial/slp-11.c| 31 +++
 .../riscv/rvv/autovec/partial/slp_run-10.c| 30 ++
 .../riscv/rvv/autovec/partial/slp_run-11.c| 30 ++
 4 files changed, 121 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-10.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-11.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp_run-10.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp_run-11.c

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-10.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-10.c
new file mode 100644
index 000..b33e85c5be2
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-10.c
@@ -0,0 +1,30 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-march=rv32gcv -mabi=ilp32d --param 
riscv-autovec-preference=scalable -fno-vect-cost-model 
-fdump-tree-optimized-details" } */
+
+#include 
+
+#define VEC_PERM(TYPE) 
\
+  TYPE __attribute__ ((noinline, noclone)) 
\
+  vec_slp_##TYPE (TYPE *restrict a, int n) 
\
+  {
\
+for (int i = 0; i < n; ++i)
\
+  {
\
+   a[i * 2] += 10;\
+   a[i * 2 + 1] += 17;\
+  }
\
+  }
+
+#define TEST_ALL(T)
\
+  T (int8_t)   
\
+  T (uint8_t)  
\
+  T (int16_t)  
\
+  T (uint16_t) 
\
+  T (int32_t)  
\
+  T (uint32_t) 
\
+  T (int64_t)  
\
+  T (uint64_t)
+
+TEST_ALL (VEC_PERM)
+
+/* { dg-final { scan-tree-dump-times "{ 10, 17, ... }" 8 "optimized" } } */
+
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-11.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-11.c
new file mode 100644
index 000..c62eced99f9
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-11.c
@@ -0,0 +1,31 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-march=rv32gcv -mabi=ilp32d --param 
riscv-autovec-preference=scalable -fno-vect-cost-model 
-fdump-tree-optimized-details" } */
+
+#include 
+
+#define VEC_PERM(TYPE) 
\
+  TYPE __attribute__ ((noinline, noclone)) 
\
+  vec_slp_##TYPE (TYPE *restrict a, int n) 
\
+  {
\
+for (int i = 0; i < n; ++i)
\
+  {
\
+   a[i * 4] += 41;\
+   a[i * 4 + 1] += 25;\
+   a[i * 4 + 2] += 31;\
+   a[i * 4 + 3] += 62;\
+  }
\
+  }
+
+#define TEST_ALL(T)
\
+  T (int8_t)   
\
+  T (uint8_t)  
\
+  T (int16_t)  
\
+  T (uint16_t) 
\
+  T (int32_t)  
\
+  T (uint32_t) 
\
+  T (int64_t) 

[PATCH][committed] arm: Extend -mtp= arguments

2023-06-13 Thread Kyrylo Tkachov via Gcc-patches
Hi all,

After discussing the -mtp= option with Arm's LLVM developers we'd like to extend
the functionality of the option somewhat.
There are actually 3 system registers that can be accessed for the thread 
pointer
in aarch32: tpidrurw, tpidruro, tpidrprw.  They are all read through the CP15 
co-processor
mechanism. The current -mtp=cp15 option reads the tpidruro register.
This patch extends -mtp to allow for the above three explicit tpidr names and
keeps -mtp=cp15 as an alias of -mtp=tpidruro for backwards compatibility.

There is more relevant discussion of the options at 
https://reviews.llvm.org/D152433 if you're interested.

Bootstrapped and tested on arm-none-linux-gnueabihf.
Pushing to trunk.
Thanks,
Kyrill

gcc/ChangeLog:

* config/arm/arm-opts.h (enum arm_tp_type): Remove TP_CP15.
Add TP_TPIDRURW, TP_TPIDRURO, TP_TPIDRPRW values.
* config/arm/arm-protos.h (arm_output_load_tpidr): Declare prototype.
* config/arm/arm.cc (arm_option_reconfigure_globals): Replace TP_CP15
with TP_TPIDRURO.
(arm_output_load_tpidr): Define.
* config/arm/arm.h (TARGET_HARD_TP): Define in terms of TARGET_SOFT_TP.
* config/arm/arm.md (load_tp_hard): Call arm_output_load_tpidr to output
assembly.
(reload_tp_hard): Likewise.
* config/arm/arm.opt (tpidrurw, tpidruro, tpidrprw): New values for
arm_tp_type.
* doc/invoke.texi (Arm Options, mtp): Document new values.

gcc/testsuite/ChangeLog:

* gcc.target/arm/mtp.c: New test.
* gcc.target/arm/mtp_1.c: New test.
* gcc.target/arm/mtp_2.c: New test.
* gcc.target/arm/mtp_3.c: New test.
* gcc.target/arm/mtp_4.c: New test.


mtp-arm.patch
Description: mtp-arm.patch


Re: [PATCH 4/4] rs6000: build constant via li/lis;rldic

2023-06-13 Thread Jiufu Guo via Gcc-patches


Hi David,

Thanks for your valuable comments!

David Edelsohn  writes:
>  
> On Wed, Jun 7, 2023 at 9:56 PM Jiufu Guo  wrote:
>
>  Hi,
>
>  This patch checks if a constant is possible to be built by "li;rldic".
>  We only need to take care of "negative li", other forms do not need to check.
>  For example, "negative lis" is just a "negative li" with an additional shift.
>
>  Bootstrap and regtest pass on ppc64{,le}.
>  Is this ok for trunk?
>
>  BR,
>  Jeff (Jiufu)
>
>  gcc/ChangeLog:
>
>  * config/rs6000/rs6000.cc (can_be_built_by_li_and_rldic): New 
> function.
>  (rs6000_emit_set_long_const): Call can_be_built_by_li_and_rldic.
>
> This is okay.
>
> Do you have any measurement of how expensive it is to test all of these 
> additional methods to generate a constant?  How much does this affect the
> compile time?

Yeap, Thanks for this very good question!
This patch is mostly using bitwise operations and if-conditions,
it would be expected not expensive.

Testcases were checked.  For example:
A case with ~1000 constants: most of them hit this feature.
With this feature, the compiling time is slightly faster.

0m1.985s(without patch) vs. 0m1.874s(with patch)
(note:D rs6000_emit_set_long_const does not occur in hot perf
functions.  So, the tricky time saving would not directly cause
by this feature.)

A case with ~1000 constants:(most are not hit by this feature)
0m2.493s(without patch) vs. 0m2.558s(with patch).

For runtime, actually, with the patch, it seems there is no visible
improvement in SPEC2017.  While I still feel this patch is
doing the right thing: use fewer instructions to build the constant.

BR,
Jeff (Jiufu Guo)

>
> Thanks, David
>
>  
>  
>  gcc/testsuite/ChangeLog:
>
>  * gcc.target/powerpc/const-build.c: Add more tests.
>  ---
>   gcc/config/rs6000/rs6000.cc   | 61 ++-
>   .../gcc.target/powerpc/const-build.c  | 28 +
>   2 files changed, 88 insertions(+), 1 deletion(-)
>
>  diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
>  index 2a3fa733b45..cd04b6b5c82 100644
>  --- a/gcc/config/rs6000/rs6000.cc
>  +++ b/gcc/config/rs6000/rs6000.cc
>  @@ -10387,6 +10387,64 @@ can_be_built_by_li_lis_and_rldicr (HOST_WIDE_INT c, 
> int *shift,
> return false;
>   }
>
>  +/* Check if value C can be built by 2 instructions: one is 'li', another is
>  +   rldic.
>  +
>  +   If so, *SHIFT is set to the 'shift' operand of rldic; and *MASK is set
>  +   to the mask value about the 'mb' operand of rldic; and return true.
>  +   Return false otherwise.  */
>  +
>  +static bool
>  +can_be_built_by_li_and_rldic (HOST_WIDE_INT c, int *shift, HOST_WIDE_INT 
> *mask)
>  +{
>  +  /* There are 49 successive ones in the negative value of 'li'.  */
>  +  int ones = 49;
>  +
>  +  /* 1..1xx1..1: negative value of li --> 0..01..1xx0..0:
>  + right bits are shifted as 0's, and left 1's(and x's) are cleaned.  */
>  +  int tz = ctz_hwi (c);
>  +  int lz = clz_hwi (c);
>  +  int middle_ones = clz_hwi (~(c << lz));
>  +  if (tz + lz + middle_ones >= ones)
>  +{
>  +  *mask = ((1LL << (HOST_BITS_PER_WIDE_INT - tz - lz)) - 1LL) << tz;
>  +  *shift = tz;
>  +  return true;
>  +}
>  +
>  +  /* 1..1xx1..1 --> 1..1xx0..01..1: some 1's(following x's) are cleaned. */
>  +  int leading_ones = clz_hwi (~c);
>  +  int tailing_ones = ctz_hwi (~c);
>  +  int middle_zeros = ctz_hwi (c >> tailing_ones);
>  +  if (leading_ones + tailing_ones + middle_zeros >= ones)
>  +{
>  +  *mask = ~(((1ULL << middle_zeros) - 1ULL) << tailing_ones);
>  +  *shift = tailing_ones + middle_zeros;
>  +  return true;
>  +}
>  +
>  +  /* xx1..1xx: --> xx0..01..1xx: some 1's(following x's) are cleaned. */
>  +  /* Get the position for the first bit of successive 1.
>  + The 24th bit would be in successive 0 or 1.  */
>  +  HOST_WIDE_INT low_mask = (1LL << 24) - 1LL;
>  +  int pos_first_1 = ((c & (low_mask + 1)) == 0)
>  + ? clz_hwi (c & low_mask)
>  + : HOST_BITS_PER_WIDE_INT - ctz_hwi (~(c | low_mask));
>  +  middle_ones = clz_hwi (~c << pos_first_1);
>  +  middle_zeros = ctz_hwi (c >> (HOST_BITS_PER_WIDE_INT - pos_first_1));
>  +  if (pos_first_1 < HOST_BITS_PER_WIDE_INT
>  +  && middle_ones + middle_zeros < HOST_BITS_PER_WIDE_INT
>  +  && middle_ones + middle_zeros >= ones)
>  +{
>  +  *mask = ~(((1ULL << middle_zeros) - 1LL)
>  +   << (HOST_BITS_PER_WIDE_INT - pos_first_1));
>  +  *shift = HOST_BITS_PER_WIDE_INT - pos_first_1 + middle_zeros;
>  +  return true;
>  +}
>  +
>  +  return false;
>  +}
>  +
>   /* Subroutine of rs6000_emit_set_const, handling PowerPC64 DImode.
>  Output insns to set DEST equal to the constant C as a series of
>  lis, ori and shl instructions.  */
>  @@ -10435,7 +10493,8 @@ rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT 
> c)
>   }
> else if (can_be_built_by_li_lis_and_rotldi (c, &shift, &ma

[PATCH] RISC-V: Fix bug of VLA SLP auto-vectorization

2023-06-13 Thread juzhe . zhong
From: Juzhe-Zhong 

Sorry for producing bugs in the previous VLA SLP patch.

Consider this following permutation:
_85 = VEC_PERM_EXPR <{ 99, 17, ... }, { 11, 80, ... }, { 0, POLY_INT_CST [4, 
4], 1, POLY_INT_CST [5, 4], 2, POLY_INT_CST [6, 4], ... }>;

The correct result should be:
_85 = { 99, 11, 17, 80, ... }

However, I did wrong in the previous patch.

Code sequence before this patch:

set mask = { 0, 1, 0, 1, ... }
set v0 = { 99, 17, 99, 17, ... }
set v1 = { 11, 80, 11, 80, ... }
set index = viota (mask) = { 0, 0, 1, 1, 2, 2, ... }
set result = vrgather_mu (v0, v1, index, mask) = { 99, 11, 99, 80 }
The result is incorrect.

After this patch:

set mask = { 0, 1, 0, 1, ... }
set index = viota (mask) = { 0, 0, 1, 1, 2, 2, ... }
set v0 = vrgather ({ 99, 17, 99, 17, ... }, index) = { 99, 99, 17, 17, ... }
set v1 = { 11, 80, 11, 80, ... }
set result = vrgather_mu (v0, v1, index, mask) = { 99, 11, 17, 80 }
The result is what we expected.

This issue was discovered in the test I appended in this patch with 
--param=riscv-autovec-lmul=2.

gcc/ChangeLog:

* config/riscv/riscv-v.cc (emit_vlmax_decompress_insn): Fix bug.
(shuffle_decompress_patterns): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/partial/slp-12.c: New test.
* gcc.target/riscv/rvv/autovec/partial/slp_run-12.c: New test.

---
 gcc/config/riscv/riscv-v.cc   |  8 ++---
 .../riscv/rvv/autovec/partial/slp-12.c| 33 +++
 .../riscv/rvv/autovec/partial/slp_run-12.c| 30 +
 3 files changed, 67 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-12.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp_run-12.c

diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc
index 3ce2eb7f2ad..d797326d736 100644
--- a/gcc/config/riscv/riscv-v.cc
+++ b/gcc/config/riscv/riscv-v.cc
@@ -866,7 +866,7 @@ emit_vlmax_masked_gather_mu_insn (rtx target, rtx op, rtx 
sel, rtx mask)
  e q r d c b v a  # v11 destination after vrgather using viota.m under mask
 */
 static void
-emit_vlmax_decompress_insn (rtx target, rtx op, rtx mask)
+emit_vlmax_decompress_insn (rtx target, rtx op0, rtx op1, rtx mask)
 {
   machine_mode data_mode = GET_MODE (target);
   machine_mode sel_mode = related_int_vector_mode (data_mode).require ();
@@ -876,7 +876,8 @@ emit_vlmax_decompress_insn (rtx target, rtx op, rtx mask)
   rtx sel = gen_reg_rtx (sel_mode);
   rtx iota_ops[] = {sel, mask};
   emit_vlmax_insn (code_for_pred_iota (sel_mode), RVV_UNOP, iota_ops);
-  emit_vlmax_masked_gather_mu_insn (target, op, sel, mask);
+  emit_vlmax_gather_insn (target, op0, sel);
+  emit_vlmax_masked_gather_mu_insn (target, op1, sel, mask);
 }
 
 /* Emit merge instruction.  */
@@ -2444,8 +2445,7 @@ shuffle_decompress_patterns (struct expand_vec_perm_d *d)
   rtx const_vec = gen_const_vector_dup (sel_mode, 1);
   rtx mask = gen_reg_rtx (mask_mode);
   expand_vec_cmp (mask, EQ, vid_repeat, const_vec);
-  emit_move_insn (d->target, op0);
-  emit_vlmax_decompress_insn (d->target, op1, mask);
+  emit_vlmax_decompress_insn (d->target, op0, op1, mask);
   return true;
 }
 
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-12.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-12.c
new file mode 100644
index 000..4131fd71a74
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-12.c
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-march=rv32gcv -mabi=ilp32d --param 
riscv-autovec-preference=scalable -fno-vect-cost-model" } */
+
+#include 
+
+#define VEC_PERM(TYPE) 
\
+  TYPE __attribute__ ((noinline, noclone)) 
\
+  vec_slp_##TYPE (TYPE *restrict a, int n) 
\
+  {
\
+for (int i = 0; i < n; ++i)
\
+  {
\
+   a[i * 8] += 99;\
+   a[i * 8 + 1] += 11;\
+   a[i * 8 + 2] += 17;\
+   a[i * 8 + 3] += 80;\
+   a[i * 8 + 4] += 63;\
+   a[i * 8 + 5] += 37;\
+   a[i * 8 + 6] += 24;\
+   a[i * 8 + 7] += 81;\
+  }
\
+  }
+
+#define TEST_ALL(T)
\
+  T (int8

[committed] libgomp/testsuite: Add requires-unified-addr-1.{c,f90} [PR109837]

2023-06-13 Thread Tobias Burnus

Add a testcase for "omp requires unified_address" as we hadn't one.

The feature itself worked since the beginning (hardware + implementation
wise); that the devices report 'omp requires unified_address' as
supported is newer: for nvptx since r13-3460-g131d18e928a3ea and for GCN
since r14-1584-gf1af7d65ff64fe (a week ago).

The test assumes (→ dg-output) that all offload devices support
unified_address; this implies: if an offloading device is available, it
also remains available after adding the unified-address requirement.
Goal: ensure that we don't end up with only host fallback.

Unified address implies: Pointer size is the same such that no
'is_device_ptr' is required to convert an opaque pointer, it also
permits to do device-pointer pointer arithmetic on the host. This
testcase also assumes that 'int' / 'integer' has the same size on host
and device. (If not: good luck with offloading in general!)

The test also makes the sound assumption that derived-type component
pointers are passed through with the derived-type itself such that the
pointer address remains well defined. In terms of the standard, it would
have an undefined association status.

Committed as Rev. r14-1783-gd5c58ad1ebaff9

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 d5c58ad1ebaff924c2546df074174cffb128feb8
Author: Tobias Burnus 
Date:   Tue Jun 13 11:27:47 2023 +0200

libgomp/testsuite: Add requires-unified-addr-1.{c,f90} [PR109837]

Add a testcase for 'omp requires unified_address' that is currently supported
by all devices but was not tested for.

libgomp/

PR libgomp/109837
* testsuite/libgomp.c-c++-common/requires-unified-addr-1.c: New test.
* testsuite/libgomp.fortran/requires-unified-addr-1.f90: New test.
---
 .../libgomp.c-c++-common/requires-unified-addr-1.c |  74 ++
 .../libgomp.fortran/requires-unified-addr-1.f90| 111 +
 2 files changed, 185 insertions(+)

diff --git a/libgomp/testsuite/libgomp.c-c++-common/requires-unified-addr-1.c b/libgomp/testsuite/libgomp.c-c++-common/requires-unified-addr-1.c
new file mode 100644
index 000..bff0a6b31ab
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c-c++-common/requires-unified-addr-1.c
@@ -0,0 +1,74 @@
+/* PR libgomp/109837 */
+
+#include 
+#include 
+#include 
+#include 
+
+#pragma omp requires unified_address
+
+#define N 15
+
+void
+test_device (int dev)
+{
+  struct st {
+int *ptr;
+int n;
+  };
+  struct st s;
+
+  s.n = 10;
+  s.ptr = (int *) omp_target_alloc (sizeof (int)*s.n, dev);
+  int *ptr1 = (int *) omp_target_alloc (sizeof (int)*N, dev);
+  assert (s.ptr != NULL);
+  assert (ptr1 != NULL);
+
+  int q[4] = {1,2,3,4};
+  int *qptr;
+  #pragma omp target enter data map(q) device(device_num: dev)
+  #pragma omp target data use_device_addr(q) device(device_num: dev)
+qptr = q;
+
+  #pragma omp target map(to:s) device(device_num: dev)
+  for (int i = 0; i < s.n; i++)
+s.ptr[i] = 23*i;
+
+  int *ptr2 = &s.ptr[3];
+
+  #pragma omp target firstprivate(qptr) map(tofrom:ptr2) device(device_num: dev)
+  for (int i = 0; i < 4; i++)
+*(qptr++) = ptr2[i];
+
+  #pragma omp target exit data map(q) device(device_num: dev)
+  for (int i = 0; i < 4; i++)
+q[i] = 23 * (i+3);
+
+  #pragma omp target map(to: ptr1) device(device_num: dev)
+  for (int i = 0; i < N; i++)
+ptr1[i] = 11*i;
+
+  int *ptr3 = (int *) malloc (sizeof (int)*N);
+  assert (0 == omp_target_memcpy(ptr3, ptr1, N * sizeof(int), 0, 0,
+ omp_get_initial_device(), dev));
+  for (int i = 0; i < N; i++)
+assert (ptr3[i] == 11*i);
+
+  free (ptr3);
+  omp_target_free (ptr1, dev);
+  omp_target_free (s.ptr, dev);
+}
+
+int
+main()
+{
+  int ntgts = omp_get_num_devices();
+  if (ntgts)
+fprintf (stderr, "Offloading devices exist\n");  /* { dg-output "Offloading devices exist(\n|\r\n|\r)" { target offload_device } } */
+  else
+fprintf (stderr, "Only host fallback\n");/* { dg-output "Only host fallback(\n|\r\n|\r)" { target { ! offload_device } } } */
+
+  for (int i = 0; i <= ntgts; i++)
+test_device (i);
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.fortran/requires-unified-addr-1.f90 b/libgomp/testsuite/libgomp.fortran/requires-unified-addr-1.f90
new file mode 100644
index 000..f5a5adf093b
--- /dev/null
+++ b/libgomp/testsuite/libgomp.fortran/requires-unified-addr-1.f90
@@ -0,0 +1,111 @@
+! PR libgomp/109837
+
+program main
+  use iso_c_binding
+  use iso_fortran_env
+  use omp_lib
+  implicit none (external, type)
+  !$omp requires unified_address
+
+  integer(c_intptr_t), parameter :: N = 15
+  integer :: i, ntgts
+
+  ntgts = omp_get_num_devices();
+  if (ntgts > 0) then
+write (ERROR_UNIT, '(a)') "Offloading devices e

Re: [PATCH] RISC-V: Add more SLP tests

2023-06-13 Thread Robin Dapp via Gcc-patches
Hi Juzhe,

as the tests are mostly directly from aarch64's testsuite I would
advise comments on where they were taken from as well as a TODO that
they should become common tests for a specific target selector
(vect_scalable_supported or something).

How about some assembly checks for the non-run tests?

Regards
 Robin



[PATCH v2 0/3] c++: Track lifetimes in constant evaluation [PR70331,...]

2023-06-13 Thread Nathaniel Shead via Gcc-patches
(Another) ping. I also have some more changes on top of this patch set
as well if this looks good as it is.

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

Thanks!

On Wed, Mar 29, 2023 at 01:32:55PM +1100, Nathaniel Shead wrote:
> This is an update of the patch series at
> https://gcc.gnu.org/pipermail/gcc-patches/2023-March/614759.html
> 
> The main change is modifying the first patch to store the "expired" flag
> in the C++-specific lang_decl_base struct instead of tree_decl_common.
> The second and third patches to improve diagnostic locations are
> otherwise unchanged.
> 
> Bootstrapped and regression tested on x86_64 linux.
> 
> Nathaniel
> 
> ---
> 
> Nathaniel Shead (3):
>   c++: Track lifetimes in constant evaluation [PR70331,PR96630,PR98675]
>   c++: Improve constexpr error for dangling local variables
>   c++: Improve location information in constexpr evaluation
> 
>  gcc/cp/constexpr.cc   | 152 --
>  gcc/cp/cp-tree.h  |  10 +-
>  gcc/cp/module.cc  |   2 +
>  gcc/cp/semantics.cc   |   5 +-
>  gcc/cp/typeck.cc  |   5 +-
>  gcc/testsuite/g++.dg/cpp0x/constexpr-48089.C  |  10 +-
>  gcc/testsuite/g++.dg/cpp0x/constexpr-diag3.C  |   2 +-
>  gcc/testsuite/g++.dg/cpp0x/constexpr-ice20.C  |   2 +-
>  gcc/testsuite/g++.dg/cpp1y/constexpr-89481.C  |   3 +-
>  .../g++.dg/cpp1y/constexpr-lifetime1.C|  14 ++
>  .../g++.dg/cpp1y/constexpr-lifetime2.C|  20 +++
>  .../g++.dg/cpp1y/constexpr-lifetime3.C|  13 ++
>  .../g++.dg/cpp1y/constexpr-lifetime4.C|  11 ++
>  .../g++.dg/cpp1y/constexpr-lifetime5.C|  11 ++
>  gcc/testsuite/g++.dg/cpp1y/constexpr-union5.C |   4 +-
>  gcc/testsuite/g++.dg/cpp1y/pr68180.C  |   4 +-
>  .../g++.dg/cpp1z/constexpr-lambda6.C  |   4 +-
>  gcc/testsuite/g++.dg/cpp2a/bit-cast11.C   |  10 +-
>  gcc/testsuite/g++.dg/cpp2a/bit-cast12.C   |  10 +-
>  gcc/testsuite/g++.dg/cpp2a/bit-cast14.C   |  14 +-
>  gcc/testsuite/g++.dg/cpp2a/constexpr-98122.C  |   4 +-
>  .../g++.dg/cpp2a/constexpr-dynamic17.C|   5 +-
>  gcc/testsuite/g++.dg/cpp2a/constexpr-init1.C  |   5 +-
>  gcc/testsuite/g++.dg/cpp2a/constexpr-new12.C  |   6 +-
>  gcc/testsuite/g++.dg/cpp2a/constexpr-new3.C   |  10 +-
>  gcc/testsuite/g++.dg/ext/constexpr-vla2.C |   4 +-
>  gcc/testsuite/g++.dg/ext/constexpr-vla3.C |   4 +-
>  gcc/testsuite/g++.dg/ubsan/pr63956.C  |   4 +-
>  .../g++.dg/warn/Wreturn-local-addr-6.C|   3 -
>  .../25_algorithms/equal/constexpr_neg.cc  |   7 +-
>  30 files changed, 246 insertions(+), 112 deletions(-)
>  create mode 100644 gcc/testsuite/g++.dg/cpp1y/constexpr-lifetime1.C
>  create mode 100644 gcc/testsuite/g++.dg/cpp1y/constexpr-lifetime2.C
>  create mode 100644 gcc/testsuite/g++.dg/cpp1y/constexpr-lifetime3.C
>  create mode 100644 gcc/testsuite/g++.dg/cpp1y/constexpr-lifetime4.C
>  create mode 100644 gcc/testsuite/g++.dg/cpp1y/constexpr-lifetime5.C
> 
> -- 
> 2.34.1
> 


[PATCH] c++: Report invalid id-expression in decltype [PR100482]

2023-06-13 Thread Nathaniel Shead via Gcc-patches
(Another) ping.

On Sun, Apr 30, 2023 at 12:00:05PM +1000, Nathaniel Shead wrote:
> This patch ensures that any errors raised by finish_id_expression when
> parsing a decltype expression are properly reported, rather than
> potentially going ignored and causing invalid code to be accepted.
> 
> We can also now remove the separate check for templates without args as
> this is also checked for in finish_id_expression.
> 
>   PR 100482
> 
> gcc/cp/ChangeLog:
> 
>   * parser.cc (cp_parser_decltype_expr): Report errors raised by
>   finish_id_expression.
> 
> gcc/testsuite/ChangeLog:
> 
>   * g++.dg/pr100482.C: New test.
> 
> Signed-off-by: Nathaniel Shead 
> ---
>  gcc/cp/parser.cc| 22 +++---
>  gcc/testsuite/g++.dg/pr100482.C | 11 +++
>  2 files changed, 22 insertions(+), 11 deletions(-)
>  create mode 100644 gcc/testsuite/g++.dg/pr100482.C
> 
> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
> index e5f032f2330..20ebcdc3cfd 100644
> --- a/gcc/cp/parser.cc
> +++ b/gcc/cp/parser.cc
> @@ -16508,10 +16508,6 @@ cp_parser_decltype_expr (cp_parser *parser,
>   expr = cp_parser_lookup_name_simple (parser, expr,
>id_expr_start_token->location);
>  
> -  if (expr && TREE_CODE (expr) == TEMPLATE_DECL)
> - /* A template without args is not a complete id-expression.  */
> - expr = error_mark_node;
> -
>if (expr
>&& expr != error_mark_node
>&& TREE_CODE (expr) != TYPE_DECL
> @@ -16532,13 +16528,17 @@ cp_parser_decltype_expr (cp_parser *parser,
> &error_msg,
>  id_expr_start_token->location));
>  
> -  if (expr == error_mark_node)
> -/* We found an id-expression, but it was something that we
> -   should not have found. This is an error, not something
> -   we can recover from, so note that we found an
> -   id-expression and we'll recover as gracefully as
> -   possible.  */
> -id_expression_or_member_access_p = true;
> +   if (error_msg)
> + {
> +   /* We found an id-expression, but it was something that we
> +  should not have found. This is an error, not something
> +  we can recover from, so report the error we found and
> +  we'll recover as gracefully as possible.  */
> +   cp_parser_parse_definitely (parser);
> +   cp_parser_error (parser, error_msg);
> +   id_expression_or_member_access_p = true;
> +   return error_mark_node;
> + }
>  }
>  
>if (expr
> diff --git a/gcc/testsuite/g++.dg/pr100482.C b/gcc/testsuite/g++.dg/pr100482.C
> new file mode 100644
> index 000..dcf6722fda5
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/pr100482.C
> @@ -0,0 +1,11 @@
> +// { dg-do compile { target c++11 } }
> +
> +namespace N {}
> +decltype(std) x;   // { dg-error "expected primary-expression" }
> +
> +struct S {};
> +decltype(S) y;  // { dg-error "argument to .decltype. must be an expression" 
> }
> +
> +template 
> +struct U {};
> +decltype(U) z;  // { dg-error "missing template arguments" }
> -- 
> 2.40.0
> 


[PATCH] c++: Fix ICE with parameter pack of decltype(auto) [PR103497]

2023-06-13 Thread Nathaniel Shead via Gcc-patches
(Another) ping.

https://gcc.gnu.org/pipermail/gcc-patches/2023-April/616465.html

On Sat, Apr 22, 2023 at 04:25:13PM +1000, Nathaniel Shead wrote:
> Bootstrapped and tested on x86_64-pc-linux-gnu.
> 
> -- 8< --
> 
> This patch raises an error early when the decltype(auto) specifier is
> used as a parameter of a function. This prevents any issues with an
> unexpected tree type later on when performing the call.
> 
>   PR 103497
> 
> gcc/cp/ChangeLog:
> 
>   * parser.cc (cp_parser_simple_type_specifier): Add check for
>   decltype(auto) as function parameter.
> 
> gcc/testsuite/ChangeLog:
> 
>   * g++.dg/pr103497.C: New test.
> 
> Signed-off-by: Nathaniel Shead 
> ---
>  gcc/cp/parser.cc| 10 ++
>  gcc/testsuite/g++.dg/pr103497.C |  7 +++
>  2 files changed, 17 insertions(+)
>  create mode 100644 gcc/testsuite/g++.dg/pr103497.C
> 
> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
> index e5f032f2330..1415e07e152 100644
> --- a/gcc/cp/parser.cc
> +++ b/gcc/cp/parser.cc
> @@ -19884,6 +19884,16 @@ cp_parser_simple_type_specifier (cp_parser* parser,
>&& cp_lexer_peek_nth_token (parser->lexer, 2)->type != CPP_SCOPE)
>  {
>type = saved_checks_value (token->u.tree_check_value);
> +  /* Within a function parameter declaration, decltype(auto) is always an
> +  error.  */
> +  if (parser->auto_is_implicit_function_template_parm_p
> +   && TREE_CODE (type) == TEMPLATE_TYPE_PARM
> +   && AUTO_IS_DECLTYPE (type))
> + {
> +   error_at (token->location,
> + "cannot declare a parameter with %");
> +   type = error_mark_node;
> + }
>if (decl_specs)
>   {
> cp_parser_set_decl_spec_type (decl_specs, type,
> diff --git a/gcc/testsuite/g++.dg/pr103497.C b/gcc/testsuite/g++.dg/pr103497.C
> new file mode 100644
> index 000..bcd421c2907
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/pr103497.C
> @@ -0,0 +1,7 @@
> +// { dg-do compile { target c++14 } }
> +
> +void foo(decltype(auto)... args);  // { dg-error "parameter with 
> .decltype.auto..|no parameter packs" }
> +
> +int main() {
> +  foo();
> +}
> -- 
> 2.34.1
> 


Re: Re: [PATCH] RISC-V: Add more SLP tests

2023-06-13 Thread juzhe.zh...@rivai.ai
>> as the tests are mostly directly from aarch64's testsuite I would
>> advise comments on where they were taken from as well as a TODO that
>> they should become common tests for a specific target selector
>> (vect_scalable_supported or something).

Ok.

 
>> (How about some assembly checks for the non-run tests?
No, I tried. I can't add assembly check in the tests since we are SLP using 
different LMUL.
Different LMUL will end up with different SLP style and their instructions are 
quite different.
Unless we can have assembly check with predicate recognizing LMUL=M1/M2/M4/M8



juzhe.zh...@rivai.ai
 
From: Robin Dapp
Date: 2023-06-13 18:08
To: juzhe.zhong; gcc-patches
CC: rdapp.gcc; kito.cheng; kito.cheng; palmer; palmer; jeffreyalaw
Subject: Re: [PATCH] RISC-V: Add more SLP tests
Hi Juzhe,
 
as the tests are mostly directly from aarch64's testsuite I would
advise comments on where they were taken from as well as a TODO that
they should become common tests for a specific target selector
(vect_scalable_supported or something).
 
How about some assembly checks for the non-run tests?
 
Regards
Robin
 
 


[PATCH V2] RISC-V: Add more SLP tests

2023-06-13 Thread juzhe . zhong
From: Juzhe-Zhong 

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/partial/slp-10.c: New test.
* gcc.target/riscv/rvv/autovec/partial/slp-11.c: New test.
* gcc.target/riscv/rvv/autovec/partial/slp_run-10.c: New test.
* gcc.target/riscv/rvv/autovec/partial/slp_run-11.c: New test.

---
 .../riscv/rvv/autovec/partial/slp-10.c| 32 ++
 .../riscv/rvv/autovec/partial/slp-11.c| 33 +++
 .../riscv/rvv/autovec/partial/slp_run-10.c| 33 +++
 .../riscv/rvv/autovec/partial/slp_run-11.c| 33 +++
 4 files changed, 131 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-10.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-11.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp_run-10.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp_run-11.c

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-10.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-10.c
new file mode 100644
index 000..c5215611e53
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-10.c
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-march=rv32gcv -mabi=ilp32d --param 
riscv-autovec-preference=scalable -fno-vect-cost-model 
-fdump-tree-optimized-details" } */
+
+#include 
+
+#define VEC_PERM(TYPE) 
\
+  TYPE __attribute__ ((noinline, noclone)) 
\
+  vec_slp_##TYPE (TYPE *restrict a, int n) 
\
+  {
\
+for (int i = 0; i < n; ++i)
\
+  {
\
+   a[i * 2] += 10;\
+   a[i * 2 + 1] += 17;\
+  }
\
+  }
+
+#define TEST_ALL(T)
\
+  T (int8_t)   
\
+  T (uint8_t)  
\
+  T (int16_t)  
\
+  T (uint16_t) 
\
+  T (int32_t)  
\
+  T (uint32_t) 
\
+  T (int64_t)  
\
+  T (uint64_t)
+
+TEST_ALL (VEC_PERM)
+
+/* { dg-final { scan-tree-dump-times "{ 10, 17, ... }" 8 "optimized" } } */
+/* This testcase is from aarch64 and floating-point operations are removed.
+   TODO: We will add floating-point operations back and make them as common 
test in the future.  */
+
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-11.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-11.c
new file mode 100644
index 000..ccb5ab6831d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-11.c
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-march=rv32gcv -mabi=ilp32d --param 
riscv-autovec-preference=scalable -fno-vect-cost-model 
-fdump-tree-optimized-details" } */
+
+#include 
+
+#define VEC_PERM(TYPE) 
\
+  TYPE __attribute__ ((noinline, noclone)) 
\
+  vec_slp_##TYPE (TYPE *restrict a, int n) 
\
+  {
\
+for (int i = 0; i < n; ++i)
\
+  {
\
+   a[i * 4] += 41;\
+   a[i * 4 + 1] += 25;\
+   a[i * 4 + 2] += 31;\
+   a[i * 4 + 3] += 62;\
+  }
\
+  }
+
+#define TEST_ALL(T)
\
+  T (int8_t)   
\
+  T (uint8_t)  
\
+  T (int16_t)  
\
+  T (uint16_t) 
\
+  T (int32_

[ping] Add 'libgomp.{, oacc-}fortran/fortran-torture_execute_math.f90'

2023-06-13 Thread Thomas Schwinge
Hi!

On 2023-06-05T14:18:48+0200, I wrote:
> OK to push the attached
> "Add 'libgomp.{,oacc-}fortran/fortran-torture_execute_math.f90'"?

Ping.


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 0d5095d8cd2d68113890a39a7fdb649198e576c1 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Fri, 2 Jun 2023 23:11:00 +0200
Subject: [PATCH] Add
 'libgomp.{,oacc-}fortran/fortran-torture_execute_math.f90'

	gcc/testsuite/
	* gfortran.fortran-torture/execute/math.f90: Enhance for optional
	OpenACC, OpenMP 'target' usage.
	libgomp/
	* testsuite/libgomp.fortran/fortran-torture_execute_math.f90: New.
	* testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90:
	Likewise.
---
 .../gfortran.fortran-torture/execute/math.f90 | 23 +--
 .../fortran-torture_execute_math.f90  |  4 
 .../fortran-torture_execute_math.f90  |  5 
 3 files changed, 30 insertions(+), 2 deletions(-)
 create mode 100644 libgomp/testsuite/libgomp.fortran/fortran-torture_execute_math.f90
 create mode 100644 libgomp/testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90

diff --git a/gcc/testsuite/gfortran.fortran-torture/execute/math.f90 b/gcc/testsuite/gfortran.fortran-torture/execute/math.f90
index 17cc78f7a10..e71f669304f 100644
--- a/gcc/testsuite/gfortran.fortran-torture/execute/math.f90
+++ b/gcc/testsuite/gfortran.fortran-torture/execute/math.f90
@@ -1,9 +1,14 @@
 ! Program to test mathematical intrinsics
+
+! See also 'libgomp/testsuite/libgomp.fortran/fortran-torture_execute_math.f90'; thus the '!$omp' directives.
+! See also 'libgomp/testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90'; thus the '!$acc' directives.
+
 subroutine dotest (n, val4, val8, known)
implicit none
real(kind=4) val4, known
real(kind=8) val8
integer n
+   !$acc routine seq
 
if (abs (val4 - known) .gt. 0.001) STOP 1
if (abs (real (val8, kind=4) - known) .gt. 0.001) STOP 2
@@ -14,17 +19,20 @@ subroutine dotestc (n, val4, val8, known)
complex(kind=4) val4, known
complex(kind=8) val8
integer n
+   !$acc routine seq
+
if (abs (val4 - known) .gt. 0.001) STOP 3
if (abs (cmplx (val8, kind=4) - known) .gt. 0.001) STOP 4
 end subroutine
 
-program testmath
+subroutine testmath
implicit none
real(kind=4) r, two4, half4
real(kind=8) q, two8, half8
complex(kind=4) cr
complex(kind=8) cq
external dotest, dotestc
+   !$acc routine seq
 
two4 = 2.0
two8 = 2.0_8
@@ -96,5 +104,16 @@ program testmath
cq = log ((-1.0_8, -1.0_8))
call dotestc (21, cr, cq, (0.3466, -2.3562))
 
-end program
+end subroutine
 
+program main
+   implicit none
+   external testmath
+
+   !$acc serial
+   !$omp target
+   call testmath
+   !$acc end serial
+   !$omp end target
+
+end program
diff --git a/libgomp/testsuite/libgomp.fortran/fortran-torture_execute_math.f90 b/libgomp/testsuite/libgomp.fortran/fortran-torture_execute_math.f90
new file mode 100644
index 000..3348a0bb3ad
--- /dev/null
+++ b/libgomp/testsuite/libgomp.fortran/fortran-torture_execute_math.f90
@@ -0,0 +1,4 @@
+! { dg-do run }
+! { dg-additional-options -foffload-options=-lm }
+
+include '../../../gcc/testsuite/gfortran.fortran-torture/execute/math.f90'
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90 b/libgomp/testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90
new file mode 100644
index 000..1b2ac440762
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90
@@ -0,0 +1,5 @@
+! { dg-do run }
+!TODO { dg-prune-output {using 'vector_length \(32\)', ignoring 1} }
+! { dg-additional-options -foffload-options=-lm }
+
+include '../../../gcc/testsuite/gfortran.fortran-torture/execute/math.f90'
-- 
2.34.1



[ping] driver: Forward '-lgfortran', '-lm' to offloading compilation

2023-06-13 Thread Thomas Schwinge
Hi!

On 2023-06-05T14:25:18+0200, I wrote:
> OK to push the attached
> "driver: Forward '-lgfortran', '-lm' to offloading compilation"?
> (We didn't have a PR open for that, or did we?)

Ping.


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 5d3cb866cad3bbcf47c5e66825e5710e86cc017e Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Mon, 5 Jun 2023 11:26:37 +0200
Subject: [PATCH] driver: Forward '-lgfortran', '-lm' to offloading compilation

..., so that users don't manually need to specify
'-foffload-options=-lgfortran', '-foffload-options=-lm' in addition to
'-lgfortran', '-lm' (specified manually, or implicitly by the driver).

	gcc/
	* gcc.cc (driver_handle_option): Forward host '-lgfortran', '-lm'
	to offloading compilation.
	* config/gcn/mkoffload.cc (main): Adjust.
	* config/nvptx/mkoffload.cc (main): Likewise.
	* doc/invoke.texi (foffload-options): Update example.
	libgomp/
	* testsuite/libgomp.fortran/fortran.exp (lang_link_flags): Don't
	set.
	* testsuite/libgomp.oacc-fortran/fortran.exp (lang_link_flags):
	Likewise.
	* testsuite/libgomp.c/simd-math-1.c: Remove
	'-foffload-options=-lm'.
	* testsuite/libgomp.fortran/fortran-torture_execute_math.f90:
	Likewise.
	* testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90:
	Likewise.
---
 gcc/config/gcn/mkoffload.cc   | 12 
 gcc/config/nvptx/mkoffload.cc | 12 
 gcc/doc/invoke.texi   |  5 +-
 gcc/gcc.cc| 56 +++
 libgomp/testsuite/libgomp.c/simd-math-1.c |  1 -
 .../fortran-torture_execute_math.f90  |  1 -
 libgomp/testsuite/libgomp.fortran/fortran.exp |  2 -
 .../fortran-torture_execute_math.f90  |  1 -
 .../libgomp.oacc-fortran/fortran.exp  |  2 -
 9 files changed, 82 insertions(+), 10 deletions(-)

diff --git a/gcc/config/gcn/mkoffload.cc b/gcc/config/gcn/mkoffload.cc
index 988c12318fd..8b608bf024e 100644
--- a/gcc/config/gcn/mkoffload.cc
+++ b/gcc/config/gcn/mkoffload.cc
@@ -946,6 +946,18 @@ main (int argc, char **argv)
   else if (startswith (argv[i], STR))
 	gcn_stack_size = atoi (argv[i] + strlen (STR));
 #undef STR
+  /* Translate host into offloading libraries.  */
+  else if (strcmp (argv[i], "-l_GCC_gfortran") == 0
+	   || strcmp (argv[i], "-l_GCC_m") == 0)
+	{
+	  /* Elide '_GCC_'.  */
+	  size_t i_dst = strlen ("-l");
+	  size_t i_src = strlen ("-l_GCC_");
+	  char c;
+	  do
+	c = argv[i][i_dst++] = argv[i][i_src++];
+	  while (c != '\0');
+	}
 }
 
   if (!(fopenacc ^ fopenmp))
diff --git a/gcc/config/nvptx/mkoffload.cc b/gcc/config/nvptx/mkoffload.cc
index 6cdea45cffe..aaea9fb320d 100644
--- a/gcc/config/nvptx/mkoffload.cc
+++ b/gcc/config/nvptx/mkoffload.cc
@@ -649,6 +649,18 @@ main (int argc, char **argv)
   else if (strcmp (argv[i], "-dumpbase") == 0
 	   && i + 1 < argc)
 	dumppfx = argv[++i];
+  /* Translate host into offloading libraries.  */
+  else if (strcmp (argv[i], "-l_GCC_gfortran") == 0
+	   || strcmp (argv[i], "-l_GCC_m") == 0)
+	{
+	  /* Elide '_GCC_'.  */
+	  size_t i_dst = strlen ("-l");
+	  size_t i_src = strlen ("-l_GCC_");
+	  char c;
+	  do
+	c = argv[i][i_dst++] = argv[i][i_src++];
+	  while (c != '\0');
+	}
 }
   if (!(fopenacc ^ fopenmp))
 fatal_error (input_location, "either %<-fopenacc%> or %<-fopenmp%> "
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index d2d639c92d4..7b3a2a74459 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -2716,9 +2716,8 @@ the @option{-foffload-options=@var{target-list}=@var{options}} form.  The
 Typical command lines are
 
 @smallexample
--foffload-options=-lgfortran -foffload-options=-lm
--foffload-options="-lgfortran -lm" -foffload-options=nvptx-none=-latomic
--foffload-options=amdgcn-amdhsa=-march=gfx906 -foffload-options=-lm
+-foffload-options='-fno-math-errno -ffinite-math-only' -foffload-options=nvptx-none=-latomic
+-foffload-options=amdgcn-amdhsa=-march=gfx906 -foffload-options=-O3
 @end smallexample
 
 @opindex fopenacc
diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index 2ccca00d603..15995206856 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -47,6 +47,9 @@ compilation is specified by a string called a "spec".  */
 #include "opts-jobserver.h"
 #include "common/common-target.h"
 
+#ifndef MATH_LIBRARY
+#define MATH_LIBRARY "m"
+#endif
 
 
 /* Manage the manipulation of env vars.
@@ -4117,6 +4120,48 @@ next_item:
 }
 }
 
+/* Forward certain options to offloading compilation.  */
+
+static void
+forward_offload_option (size_t opt_index, const char *arg, bool validated)
+{
+  switch (opt_index)
+{
+case OPT_l:
+  /* Use a '_GCC_' prefix and standard name ('-l_GCC_m' irrespective of the
+	 host's 'MATH_LIBRARY', for exa

[PATCH] RISC-V: Remove duplicate `#include "riscv-vector-switch.def"`

2023-06-13 Thread Lehua Ding
Hi,

This patch remove the duplicate `#include "riscv-vector-switch.def"` statement
and add #undef for ENTRY and TUPLE_ENTRY macros later.

Best,
Lehua

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

diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc
index e1b85a5af91f..09c2abcbc623 100644
--- a/gcc/config/riscv/riscv-v.cc
+++ b/gcc/config/riscv/riscv-v.cc
@@ -1210,7 +1210,6 @@ struct mode_vtype_group
   ratio_for_min_vlen64[MODE##mode] = RATIO_FOR_MIN_VLEN64; 
\
   vlmul_for_for_vlen128[MODE##mode] = VLMUL_FOR_MIN_VLEN128;   
\
   ratio_for_for_vlen128[MODE##mode] = RATIO_FOR_MIN_VLEN128;
-#include "riscv-vector-switch.def"
 #define TUPLE_ENTRY(MODE, REQUIREMENT, SUBPART_MODE, NF, VLMUL_FOR_MIN_VLEN32, 
\
RATIO_FOR_MIN_VLEN32, VLMUL_FOR_MIN_VLEN64,\
RATIO_FOR_MIN_VLEN64, VLMUL_FOR_MIN_VLEN128,   \
@@ -1224,6 +1223,8 @@ struct mode_vtype_group
   vlmul_for_for_vlen128[MODE##mode] = VLMUL_FOR_MIN_VLEN128;   
\
   ratio_for_for_vlen128[MODE##mode] = RATIO_FOR_MIN_VLEN128;
 #include "riscv-vector-switch.def"
+#undef ENTRY
+#undef TUPLE_ENTRY
   }
 };
 
-- 
2.36.3



Re: [PATCH] RISC-V: Remove duplicate `#include "riscv-vector-switch.def"`

2023-06-13 Thread juzhe.zh...@rivai.ai
Send V2 patch with changelog.

Thanks.


juzhe.zh...@rivai.ai
 
From: Lehua Ding
Date: 2023-06-13 18:53
To: gcc-patches; juzhe.zhong
Subject: [PATCH] RISC-V: Remove duplicate `#include "riscv-vector-switch.def"`
Hi,
 
This patch remove the duplicate `#include "riscv-vector-switch.def"` statement
and add #undef for ENTRY and TUPLE_ENTRY macros later.
 
Best,
Lehua
 
---
gcc/config/riscv/riscv-v.cc | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
 
diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc
index e1b85a5af91f..09c2abcbc623 100644
--- a/gcc/config/riscv/riscv-v.cc
+++ b/gcc/config/riscv/riscv-v.cc
@@ -1210,7 +1210,6 @@ struct mode_vtype_group
   ratio_for_min_vlen64[MODE##mode] = RATIO_FOR_MIN_VLEN64; 
\
   vlmul_for_for_vlen128[MODE##mode] = VLMUL_FOR_MIN_VLEN128;   
\
   ratio_for_for_vlen128[MODE##mode] = RATIO_FOR_MIN_VLEN128;
-#include "riscv-vector-switch.def"
#define TUPLE_ENTRY(MODE, REQUIREMENT, SUBPART_MODE, NF, VLMUL_FOR_MIN_VLEN32, \
RATIO_FOR_MIN_VLEN32, VLMUL_FOR_MIN_VLEN64,\
RATIO_FOR_MIN_VLEN64, VLMUL_FOR_MIN_VLEN128,   \
@@ -1224,6 +1223,8 @@ struct mode_vtype_group
   vlmul_for_for_vlen128[MODE##mode] = VLMUL_FOR_MIN_VLEN128;   
\
   ratio_for_for_vlen128[MODE##mode] = RATIO_FOR_MIN_VLEN128;
#include "riscv-vector-switch.def"
+#undef ENTRY
+#undef TUPLE_ENTRY
   }
};
-- 
2.36.3
 


[PATCH V2] RISC-V: Remove duplicate `#include "riscv-vector-switch.def"`

2023-06-13 Thread Lehua Ding
Hi,

This patch remove the duplicate `#include "riscv-vector-switch.def"` statement
and add #undef for ENTRY and TUPLE_ENTRY macros later.

Best,
Lehua

gcc/ChangeLog:

* config/riscv/riscv-v.cc (struct mode_vtype_group): Remove duplicate 
#include.
(ENTRY): Undef.
(TUPLE_ENTRY): Undef.

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

diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc
index e1b85a5af91f..09c2abcbc623 100644
--- a/gcc/config/riscv/riscv-v.cc
+++ b/gcc/config/riscv/riscv-v.cc
@@ -1210,7 +1210,6 @@ struct mode_vtype_group
   ratio_for_min_vlen64[MODE##mode] = RATIO_FOR_MIN_VLEN64; 
\
   vlmul_for_for_vlen128[MODE##mode] = VLMUL_FOR_MIN_VLEN128;   
\
   ratio_for_for_vlen128[MODE##mode] = RATIO_FOR_MIN_VLEN128;
-#include "riscv-vector-switch.def"
 #define TUPLE_ENTRY(MODE, REQUIREMENT, SUBPART_MODE, NF, VLMUL_FOR_MIN_VLEN32, 
\
RATIO_FOR_MIN_VLEN32, VLMUL_FOR_MIN_VLEN64,\
RATIO_FOR_MIN_VLEN64, VLMUL_FOR_MIN_VLEN128,   \
@@ -1224,6 +1223,8 @@ struct mode_vtype_group
   vlmul_for_for_vlen128[MODE##mode] = VLMUL_FOR_MIN_VLEN128;   
\
   ratio_for_for_vlen128[MODE##mode] = RATIO_FOR_MIN_VLEN128;
 #include "riscv-vector-switch.def"
+#undef ENTRY
+#undef TUPLE_ENTRY
   }
 };
 
-- 
2.36.3



Re: [PATCH V2] RISC-V: Remove duplicate `#include "riscv-vector-switch.def"`

2023-06-13 Thread juzhe.zh...@rivai.ai
LGTM. 
Thanks.
Will merge it soon.


juzhe.zh...@rivai.ai
 
From: Lehua Ding
Date: 2023-06-13 18:59
To: gcc-patches; juzhe.zhong
Subject: [PATCH V2] RISC-V: Remove duplicate `#include 
"riscv-vector-switch.def"`
Hi,
 
This patch remove the duplicate `#include "riscv-vector-switch.def"` statement
and add #undef for ENTRY and TUPLE_ENTRY macros later.
 
Best,
Lehua
 
gcc/ChangeLog:
 
* config/riscv/riscv-v.cc (struct mode_vtype_group): Remove duplicate 
#include.
(ENTRY): Undef.
(TUPLE_ENTRY): Undef.
 
---
gcc/config/riscv/riscv-v.cc | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
 
diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc
index e1b85a5af91f..09c2abcbc623 100644
--- a/gcc/config/riscv/riscv-v.cc
+++ b/gcc/config/riscv/riscv-v.cc
@@ -1210,7 +1210,6 @@ struct mode_vtype_group
   ratio_for_min_vlen64[MODE##mode] = RATIO_FOR_MIN_VLEN64; 
\
   vlmul_for_for_vlen128[MODE##mode] = VLMUL_FOR_MIN_VLEN128;   
\
   ratio_for_for_vlen128[MODE##mode] = RATIO_FOR_MIN_VLEN128;
-#include "riscv-vector-switch.def"
#define TUPLE_ENTRY(MODE, REQUIREMENT, SUBPART_MODE, NF, VLMUL_FOR_MIN_VLEN32, \
RATIO_FOR_MIN_VLEN32, VLMUL_FOR_MIN_VLEN64,\
RATIO_FOR_MIN_VLEN64, VLMUL_FOR_MIN_VLEN128,   \
@@ -1224,6 +1223,8 @@ struct mode_vtype_group
   vlmul_for_for_vlen128[MODE##mode] = VLMUL_FOR_MIN_VLEN128;   
\
   ratio_for_for_vlen128[MODE##mode] = RATIO_FOR_MIN_VLEN128;
#include "riscv-vector-switch.def"
+#undef ENTRY
+#undef TUPLE_ENTRY
   }
};
-- 
2.36.3
 


Re: [PATCH V2] RISC-V: Remove duplicate `#include "riscv-vector-switch.def"`

2023-06-13 Thread Lehua Ding
> LGTM. 
> Thanks.
> Will merge it soon.


Thank you for such a prompt reply.
 
  

Re: [PATCH] New finish_compare_by_pieces target hook (for x86).

2023-06-13 Thread Richard Biener via Gcc-patches
On Mon, Jun 12, 2023 at 4:04 PM Roger Sayle  wrote:
>
>
> The following simple test case, from PR 104610, shows that memcmp () == 0
> can result in some bizarre code sequences on x86.
>
> int foo(char *a)
> {
> static const char t[] = "0123456789012345678901234567890";
> return __builtin_memcmp(a, &t[0], sizeof(t)) == 0;
> }
>
> with -O2 currently contains both:
> xorl%eax, %eax
> xorl$1, %eax
> and also
> movl$1, %eax
> xorl$1, %eax
>
> Changing the return type of foo to _Bool results in the equally
> bizarre:
> xorl%eax, %eax
> testl   %eax, %eax
> sete%al
> and also
> movl$1, %eax
> testl   %eax, %eax
> sete%al
>
> All these sequences set the result to a constant, but this optimization
> opportunity only occurs very late during compilation, by basic block
> duplication in the 322r.bbro pass, too late for CSE or peephole2 to
> do anything about it.  The problem is that the idiom expanded by
> compare_by_pieces for __builtin_memcmp_eq contains basic blocks that
> can't easily be optimized by if-conversion due to the multiple
> incoming edges on the fail block.
>
> In summary, compare_by_pieces generates code that looks like:
>
> if (x[0] != y[0]) goto fail_label;
> if (x[1] != y[1]) goto fail_label;
> ...
> if (x[n] != y[n]) goto fail_label;
> result = 1;
> goto end_label;
> fail_label:
> result = 0;
> end_label:
>
> In theory, the RTL if-conversion pass could be enhanced to tackle
> arbitrarily complex if-then-else graphs, but the solution proposed
> here is to allow suitable targets to perform if-conversion during
> compare_by_pieces.  The x86, for example, can take advantage that
> all of the above comparisons set and test the zero flag (ZF), which
> can then be used in combination with sete.  Hence compare_by_pieces
> could instead generate:
>
> if (x[0] != y[0]) goto fail_label;
> if (x[1] != y[1]) goto fail_label;
> ...
> if (x[n] != y[n]) goto fail_label;
> fail_label:
> sete result
>
> which requires one less basic block, and the redundant conditional
> branch to a label immediately after is cleaned up by GCC's existing
> RTL optimizations.
>
> For the test case above, where -O2 -msse4 previously generated:
>
> foo:movdqu  (%rdi), %xmm0
> pxor.LC0(%rip), %xmm0
> ptest   %xmm0, %xmm0
> je  .L5
> .L2:movl$1, %eax
> xorl$1, %eax
> ret
> .L5:movdqu  16(%rdi), %xmm0
> pxor.LC1(%rip), %xmm0
> ptest   %xmm0, %xmm0
> jne .L2
> xorl%eax, %eax
> xorl$1, %eax
> ret
>
> we now generate:
>
> foo:movdqu  (%rdi), %xmm0
> pxor.LC0(%rip), %xmm0
> ptest   %xmm0, %xmm0
> jne .L2
> movdqu  16(%rdi), %xmm0
> pxor.LC1(%rip), %xmm0
> ptest   %xmm0, %xmm0
> .L2:sete%al
> movzbl  %al, %eax
> ret
>
> Using a target hook allows the large amount of intelligence already in
> compare_by_pieces to be re-used by the i386 backend, but this can also
> help other backends with condition flags where the equality result can
> be materialized.
>
> This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
> and make -k check, both with and without --target_board=unix{-m32}
> with no new failures.  Ok for mainline?

What's the guarantee that the zero flag is appropriately set on all
edges incoming now and forever?  Does this require target specific
knowledge on how do_compare_rtx_and_jump is emitting RTL?

Do you see matching this in ifcvt to be unreasonable?  I'm thinking
of "reducing" the incoming edges pairwise without actually looking
at the ifcvt code.

Thanks,
Richard.

>
> 2023-06-12  Roger Sayle  
>
> gcc/ChangeLog
> * config/i386/i386.cc (ix86_finish_compare_by_pieces): New
> function to provide a backend specific implementation.
> (TARGET_FINISH_COMPARE_BY_PIECES): Use the above function.
>
> * doc/tm.texi.in (TARGET_FINISH_COMPARE_BY_PIECES): New @hook.
> * doc/tm.texi: Regenerate.
>
> * expr.cc (compare_by_pieces): Call finish_compare_by_pieces in
> targetm to finalize the RTL expansion.  Move the current
> implementation to a default target hook.
> * target.def (finish_compare_by_pieces): New target hook to allow
> compare_by_pieces to be customized by the target.
> * targhooks.cc (default_finish_compare_by_pieces): Default
> implementation moved here from expr.cc's compare_by_pieces.
> * targhooks.h (default_finish_compare_by_pieces): Prototype.
>
> gcc/testsuite/ChangeLog
> * gcc.target/i386/pieces-memcmp-1.c: New test case.
>
>
> Thanks in advance,
> Roger
> --
>


Re: [ping] Add 'libgomp.{,oacc-}fortran/fortran-torture_execute_math.f90'

2023-06-13 Thread Tobias Burnus

On 13.06.23 12:42, Thomas Schwinge wrote:

On 2023-06-05T14:18:48+0200, I wrote:

OK to push the attached
"Add 'libgomp.{,oacc-}fortran/fortran-torture_execute_math.f90'"?


Subject: [PATCH] Add
  'libgomp.{,oacc-}fortran/fortran-torture_execute_math.f90'

  gcc/testsuite/
  * gfortran.fortran-torture/execute/math.f90: Enhance for optional
  OpenACC, OpenMP 'target' usage.


I think it is more readable with a linebreak here and with "OpenACC
'serial' and OpenMP ..." instead of "OpenACC, OpenMP".

What I would like to see a hint somewhere in the commit log that the
libgomp files include the gfortran.fortran-torture file. I don't care
whether you add the hint before the changelog items as free text – or in
the bullet above (e.g. "as it is included in libgomp/testsuite") – or
after "New." in the following bullet list.


  libgomp/
  * testsuite/libgomp.fortran/fortran-torture_execute_math.f90: New.
  * testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90:
  Likewise.



---
  .../gfortran.fortran-torture/execute/math.f90 | 23 +--
  .../fortran-torture_execute_math.f90  |  4 
  .../fortran-torture_execute_math.f90  |  5 
  3 files changed, 30 insertions(+), 2 deletions(-)
  create mode 100644 
libgomp/testsuite/libgomp.fortran/fortran-torture_execute_math.f90
  create mode 100644 
libgomp/testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90

diff --git a/gcc/testsuite/gfortran.fortran-torture/execute/math.f90 
b/gcc/testsuite/gfortran.fortran-torture/execute/math.f90
index 17cc78f7a10..e71f669304f 100644
--- a/gcc/testsuite/gfortran.fortran-torture/execute/math.f90
+++ b/gcc/testsuite/gfortran.fortran-torture/execute/math.f90
@@ -1,9 +1,14 @@
  ! Program to test mathematical intrinsics
+
+! See also 
'libgomp/testsuite/libgomp.fortran/fortran-torture_execute_math.f90'; thus the 
'!$omp' directives.
+! See also 
'libgomp/testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90'; thus 
the '!$acc' directives.


Likewise here: it is not completely obvious that this file is 'include'd
by the other testcases.

Maybe add a line "! This file is also included in:" and remove the "See
also" or some creative variant of it.

Minor remark: The OpenMP part is OK, but strict reading of the spec
requires an "omp declare target' if a subroutine is in a different
compilation unit. And according the glossary, that's the case here. In
practice, it also works without as it is in the same translation unit.
(compilation unit = for C/C++: translation unit, for Fortran:
subprogram). I think the HPE/Cray compiler will complain, but maybe only
when used with modules and not with subroutine subprograms. (As many
compilers write a .mod file for modules, a late change of attributes can
be more problematic.)

Otherwise LGTM.

Tobias

PS: I assume that you have check it with both with an in-build-tree and
an in-install-tree testsuite run.


+
  subroutine dotest (n, val4, val8, known)
 implicit none
 real(kind=4) val4, known
 real(kind=8) val8
 integer n
+   !$acc routine seq

 if (abs (val4 - known) .gt. 0.001) STOP 1
 if (abs (real (val8, kind=4) - known) .gt. 0.001) STOP 2
@@ -14,17 +19,20 @@ subroutine dotestc (n, val4, val8, known)
 complex(kind=4) val4, known
 complex(kind=8) val8
 integer n
+   !$acc routine seq
+
 if (abs (val4 - known) .gt. 0.001) STOP 3
 if (abs (cmplx (val8, kind=4) - known) .gt. 0.001) STOP 4
  end subroutine

-program testmath
+subroutine testmath
 implicit none
 real(kind=4) r, two4, half4
 real(kind=8) q, two8, half8
 complex(kind=4) cr
 complex(kind=8) cq
 external dotest, dotestc
+   !$acc routine seq

 two4 = 2.0
 two8 = 2.0_8
@@ -96,5 +104,16 @@ program testmath
 cq = log ((-1.0_8, -1.0_8))
 call dotestc (21, cr, cq, (0.3466, -2.3562))

-end program
+end subroutine

+program main
+   implicit none
+   external testmath
+
+   !$acc serial
+   !$omp target
+   call testmath
+   !$acc end serial
+   !$omp end target
+
+end program
diff --git a/libgomp/testsuite/libgomp.fortran/fortran-torture_execute_math.f90 
b/libgomp/testsuite/libgomp.fortran/fortran-torture_execute_math.f90
new file mode 100644
index 000..3348a0bb3ad
--- /dev/null
+++ b/libgomp/testsuite/libgomp.fortran/fortran-torture_execute_math.f90
@@ -0,0 +1,4 @@
+! { dg-do run }
+! { dg-additional-options -foffload-options=-lm }
+
+include '../../../gcc/testsuite/gfortran.fortran-torture/execute/math.f90'
diff --git 
a/libgomp/testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90 
b/libgomp/testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90
new file mode 100644
index 000..1b2ac440762
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90
@@ -0,0 +1,5 @@
+! { dg-do run }
+!TODO { dg-prune-output {using 'vector_length \(32\)', ignoring 1} }
+! { dg-additional-options -foffload-options=-lm }
+
+inc

Re: [PATCH] middle-end, i386: Pattern recognize add/subtract with carry [PR79173]

2023-06-13 Thread Jakub Jelinek via Gcc-patches
On Tue, Jun 13, 2023 at 08:40:36AM +, Richard Biener wrote:
> I suspect re-association can wreck things even more here.  I have
> to say the matching code is very hard to follow, not sure if
> splitting out a function matching
> 
>_22 = .{ADD,SUB}_OVERFLOW (_6, _5);
>_23 = REALPART_EXPR <_22>;
>_24 = IMAGPART_EXPR <_22>;
> 
> from _23 and _24 would help?

I've outlined 3 most often used sequences of statements or checks
into 3 helper functions, hope that helps.

> > +  while (TREE_CODE (rhs[0]) == SSA_NAME && !rhs[3])
> > +   {
> > + gimple *g = SSA_NAME_DEF_STMT (rhs[0]);
> > + if (has_single_use (rhs[0])
> > + && is_gimple_assign (g)
> > + && (gimple_assign_rhs_code (g) == code
> > + || (code == MINUS_EXPR
> > + && gimple_assign_rhs_code (g) == PLUS_EXPR
> > + && TREE_CODE (gimple_assign_rhs2 (g)) == INTEGER_CST)))
> > +   {
> > + rhs[0] = gimple_assign_rhs1 (g);
> > + tree &r = rhs[2] ? rhs[3] : rhs[2];
> > + r = gimple_assign_rhs2 (g);
> > + if (gimple_assign_rhs_code (g) != code)
> > +   r = fold_build1 (NEGATE_EXPR, TREE_TYPE (r), r);
> 
> Can you use const_unop here?  In fact both will not reliably
> negate all constants (ick), so maybe we want a force_const_negate ()?

It is unsigned type NEGATE_EXPR of INTEGER_CST, so I think it should
work.  That said, changed it to const_unop and am just giving up on it
as if it wasn't a PLUS_EXPR with INTEGER_CST addend if const_unop doesn't
simplify.

> > + else if (addc_subc)
> > +   {
> > + if (!integer_zerop (arg2))
> > +   ;
> > + /* x = y + 0 + 0; x = y - 0 - 0; */
> > + else if (integer_zerop (arg1))
> > +   result = arg0;
> > + /* x = 0 + y + 0; */
> > + else if (subcode != MINUS_EXPR && integer_zerop (arg0))
> > +   result = arg1;
> > + /* x = y - y - 0; */
> > + else if (subcode == MINUS_EXPR
> > +  && operand_equal_p (arg0, arg1, 0))
> > +   result = integer_zero_node;
> > +   }
> 
> So this all performs simplifications but also constant folding.  In
> particular the match.pd re-simplification will invoke fold_const_call
> on all-constant argument function calls but does not do extra folding
> on partially constant arg cases but instead relies on patterns here.
> 
> Can you add all-constant arg handling to fold_const_call and
> consider moving cases like y + 0 + 0 to match.pd?

The reason I've done this here is that this is the spot where all other
similar internal functions are handled, be it the ubsan ones
- IFN_UBSAN_CHECK_{ADD,SUB,MUL}, or __builtin_*_overflow ones
- IFN_{ADD,SUB,MUL}_OVERFLOW, or these 2 new ones.  The code handles
there 2 constant arguments as well as various patterns that can be
simplified and has code to clean it up later, build a COMPLEX_CST,
or COMPLEX_EXPR etc. as needed.  So, I think we want to handle those
elsewhere, we should do it for all of those functions, but then
probably incrementally.

> > +@cindex @code{addc@var{m}5} instruction pattern
> > +@item @samp{addc@var{m}5}
> > +Adds operands 2, 3 and 4 (where the last operand is guaranteed to have
> > +only values 0 or 1) together, sets operand 0 to the result of the
> > +addition of the 3 operands and sets operand 1 to 1 iff there was no
> > +overflow on the unsigned additions, and to 0 otherwise.  So, it is
> > +an addition with carry in (operand 4) and carry out (operand 1).
> > +All operands have the same mode.
> 
> operand 1 set to 1 for no overflow sounds weird when specifying it
> as carry out - can you double check?

Fixed.

> > +@cindex @code{subc@var{m}5} instruction pattern
> > +@item @samp{subc@var{m}5}
> > +Similarly to @samp{addc@var{m}5}, except subtracts operands 3 and 4
> > +from operand 2 instead of adding them.  So, it is
> > +a subtraction with carry/borrow in (operand 4) and carry/borrow out
> > +(operand 1).  All operands have the same mode.
> > +
> 
> I wonder if we want to name them uaddc and usubc?  Or is this supposed
> to be simply the twos-complement "carry"?  I think the docs should
> say so then (note we do have uaddv and addv).

Makes sense, I've actually renamed even the internal functions etc.

Here is only lightly tested patch with everything but gimple-fold.cc
changed.

2023-06-13  Jakub Jelinek  

PR middle-end/79173
* internal-fn.def (UADDC, USUBC): New internal functions.
* internal-fn.cc (expand_UADDC, expand_USUBC): New functions.
(commutative_ternary_fn_p): Return true also for IFN_UADDC.
* optabs.def (uaddc5_optab, usubc5_optab): New optabs.
* tree-ssa-math-opts.cc (uaddc_cast, uaddc_ne0, uaddc_is_cplxpart,
match_uaddc_usubc): New functions.
(math_opts_dom_walker::after_dom_children): Call match_uaddc_usubc
for PLUS_EXPR, MINUS_EXPR, BIT_IOR_EXPR and BIT_XOR_EXPR unless
other optimizations have been succe

RE: [PATCH v5] RISC-V: Add vector psabi checking.

2023-06-13 Thread Li, Pan2 via Gcc-patches
Committed v6 with riscv.exp and rvv.exp passed, thanks Kito.

Pan

-Original Message-
From: Li, Pan2 
Sent: Monday, June 12, 2023 8:49 PM
To: Kito Cheng ; Wang, Yanzhang 
Cc: gcc-patches@gcc.gnu.org; juzhe.zh...@rivai.ai
Subject: RE: [PATCH v5] RISC-V: Add vector psabi checking.

Sure thing, will commit it after all riscv.exp rvv.exp pass.

Pan

-Original Message-
From: Kito Cheng  
Sent: Monday, June 12, 2023 8:43 PM
To: Wang, Yanzhang 
Cc: gcc-patches@gcc.gnu.org; juzhe.zh...@rivai.ai; Li, Pan2 
Subject: Re: [PATCH v5] RISC-V: Add vector psabi checking.

Hi Yan-Zhang:

OK with one minor, go ahead IF the regression is clean.

Hi Pan:

Could you help to verify this patch and commit if the regression is clean?

thanks :)

> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/rvv.exp 
> b/gcc/testsuite/gcc.target/riscv/rvv/rvv.exp
> index 5e69235a268..ad79d0e9a8d 100644
> --- a/gcc/testsuite/gcc.target/riscv/rvv/rvv.exp
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/rvv.exp
> @@ -43,7 +43,7 @@ dg-init
>  # Main loop.
>  set CFLAGS "$DEFAULT_CFLAGS -march=$gcc_march -mabi=$gcc_mabi -O3"

Add -Wno-psabi here rather than below, and also add it for
g++.target/riscv/rvv/rvv.exp

>  dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/base/*.\[cS\]]] \
> -   "" $CFLAGS
> +   "-Wno-psabi" $CFLAGS
>  gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/vsetvl/*.\[cS\]]] \
> "" $CFLAGS
>  dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/autovec/*.\[cS\]]] \


[PATCH V3] RISC-V: Add more SLP tests

2023-06-13 Thread juzhe . zhong
From: Juzhe-Zhong 

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/partial/slp-10.c: New test.
* gcc.target/riscv/rvv/autovec/partial/slp-11.c: New test.
* gcc.target/riscv/rvv/autovec/partial/slp-13.c: New test.
* gcc.target/riscv/rvv/autovec/partial/slp-14.c: New test.
* gcc.target/riscv/rvv/autovec/partial/slp-15.c: New test.
* gcc.target/riscv/rvv/autovec/partial/slp_run-10.c: New test.
* gcc.target/riscv/rvv/autovec/partial/slp_run-11.c: New test.
* gcc.target/riscv/rvv/autovec/partial/slp_run-13.c: New test.
* gcc.target/riscv/rvv/autovec/partial/slp_run-14.c: New test.
* gcc.target/riscv/rvv/autovec/partial/slp_run-15.c: New test.

---
 .../riscv/rvv/autovec/partial/slp-10.c| 32 +++
 .../riscv/rvv/autovec/partial/slp-11.c| 33 +++
 .../riscv/rvv/autovec/partial/slp-13.c| 34 +++
 .../riscv/rvv/autovec/partial/slp-14.c| 33 +++
 .../riscv/rvv/autovec/partial/slp-15.c| 35 
 .../riscv/rvv/autovec/partial/slp_run-10.c| 33 +++
 .../riscv/rvv/autovec/partial/slp_run-11.c| 33 +++
 .../riscv/rvv/autovec/partial/slp_run-13.c| 47 +++
 .../riscv/rvv/autovec/partial/slp_run-14.c| 57 +++
 .../riscv/rvv/autovec/partial/slp_run-15.c| 56 ++
 10 files changed, 393 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-10.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-11.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-13.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-14.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-15.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp_run-10.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp_run-11.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp_run-13.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp_run-14.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp_run-15.c

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-10.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-10.c
new file mode 100644
index 000..c5215611e53
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-10.c
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-march=rv32gcv -mabi=ilp32d --param 
riscv-autovec-preference=scalable -fno-vect-cost-model 
-fdump-tree-optimized-details" } */
+
+#include 
+
+#define VEC_PERM(TYPE) 
\
+  TYPE __attribute__ ((noinline, noclone)) 
\
+  vec_slp_##TYPE (TYPE *restrict a, int n) 
\
+  {
\
+for (int i = 0; i < n; ++i)
\
+  {
\
+   a[i * 2] += 10;\
+   a[i * 2 + 1] += 17;\
+  }
\
+  }
+
+#define TEST_ALL(T)
\
+  T (int8_t)   
\
+  T (uint8_t)  
\
+  T (int16_t)  
\
+  T (uint16_t) 
\
+  T (int32_t)  
\
+  T (uint32_t) 
\
+  T (int64_t)  
\
+  T (uint64_t)
+
+TEST_ALL (VEC_PERM)
+
+/* { dg-final { scan-tree-dump-times "{ 10, 17, ... }" 8 "optimized" } } */
+/* This testcase is from aarch64 and floating-point operations are removed.
+   TODO: We will add floating-point operations back and make them as common 
test in the future.  */
+
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-11.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-11.c
new file mode 100644
index 000..ccb5ab6831d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-11.c
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-march=rv32gcv -mabi=ilp32d --param 
riscv-autovec-preference=scalable -fno-vect-cost-model 
-fdump-tree-optimized-details" } */
+
+#include 
+
+#define VEC_PERM(TYPE) 

Re: [PATCH V3] RISC-V: Add more SLP tests

2023-06-13 Thread Robin Dapp via Gcc-patches
Hi Juzhe,

thanks, works for me as is.  I just hope somebody is going to take on the task
of making different LMUL SLP variants "scannable" at some point because
it would definitely increase our test coverage with these tests. (Or split
the tests manually and not iterate over LMUL)

Regards
 Robin


[pushed] c++: mutable temps in rodata

2023-06-13 Thread Jason Merrill via Gcc-patches
Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

If the type of a temporary has mutable members, we can't set TREE_READONLY
on the VAR_DECL; this is parallel to the check in
cp_apply_type_quals_to_decl.

gcc/cp/ChangeLog:

* tree.cc (build_target_expr): Check TYPE_HAS_MUTABLE_P.

gcc/testsuite/ChangeLog:

* g++.dg/tree-ssa/initlist-opt6.C: New test.
---
 gcc/cp/tree.cc|  1 +
 gcc/testsuite/g++.dg/tree-ssa/initlist-opt6.C | 18 ++
 2 files changed, 19 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/tree-ssa/initlist-opt6.C

diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
index 751c9adeb62..799183dc646 100644
--- a/gcc/cp/tree.cc
+++ b/gcc/cp/tree.cc
@@ -522,6 +522,7 @@ build_target_expr (tree decl, tree value, tsubst_flags_t 
complain)
   if (CP_TYPE_CONST_NON_VOLATILE_P (type)
   && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
   && !VOID_TYPE_P (TREE_TYPE (value))
+  && !TYPE_HAS_MUTABLE_P (type)
   && reduced_constant_expression_p (value))
 TREE_READONLY (decl) = true;
 
diff --git a/gcc/testsuite/g++.dg/tree-ssa/initlist-opt6.C 
b/gcc/testsuite/g++.dg/tree-ssa/initlist-opt6.C
new file mode 100644
index 000..ea1bf5d935e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/tree-ssa/initlist-opt6.C
@@ -0,0 +1,18 @@
+// { dg-do compile { target c++11 } }
+// { dg-additional-options -fdump-tree-gimple }
+// { dg-final { scan-tree-dump-not {static const struct S} "gimple" } }
+
+// Test that mutable prevents putting this init-list array in rodata.
+
+#include 
+
+struct S {
+constexpr S(int i) : i(i) {}
+mutable int i;
+};
+
+void f(std::initializer_list);
+
+int main() {
+f({1,2,3});
+}

base-commit: d438b67e005bf8fc9e4af26410bf69816c30e969
-- 
2.31.1



Re: [PATCH] RISC-V: Fix bug of VLA SLP auto-vectorization

2023-06-13 Thread Robin Dapp via Gcc-patches
Hi Juzhe,

LGTM.  You could also add the aarch64 test disclaimer here again,
but no need for a V2. 

Regards
 Robin


Re: Re: [PATCH V3] RISC-V: Add more SLP tests

2023-06-13 Thread juzhe.zh...@rivai.ai
Ok. After floating-point binary. I will do floating-point ternary.
I think you do conversion next (widen floating point, float to int, int to 
float).

It seems that we almost done  most of the part autovec patterns in RISC-V port.
What else we can do? My second middle-end patch (LEN_MASK _* load/store) is 
blocked which is prerequisite for reduction
if you understand how reduction works.
 
Maybe next you could find the way to optimize vv->vx ?

Thanks.


juzhe.zh...@rivai.ai
 
From: Robin Dapp
Date: 2023-06-13 20:00
To: juzhe.zhong; gcc-patches
CC: rdapp.gcc; kito.cheng; kito.cheng; palmer; palmer; jeffreyalaw
Subject: Re: [PATCH V3] RISC-V: Add more SLP tests
Hi Juzhe,
 
thanks, works for me as is.  I just hope somebody is going to take on the task
of making different LMUL SLP variants "scannable" at some point because
it would definitely increase our test coverage with these tests. (Or split
the tests manually and not iterate over LMUL)
 
Regards
Robin
 


[PATCH] Fix memory leak in loop header copying

2023-06-13 Thread Richard Biener via Gcc-patches


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

* tree-ssa-loop-ch.cc (ch_base::copy_headers): Free loop BBs.
---
 gcc/tree-ssa-loop-ch.cc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/tree-ssa-loop-ch.cc b/gcc/tree-ssa-loop-ch.cc
index 7fdef3bb11a..22252bee135 100644
--- a/gcc/tree-ssa-loop-ch.cc
+++ b/gcc/tree-ssa-loop-ch.cc
@@ -642,6 +642,7 @@ ch_base::copy_headers (function *fun)
   if (stmt_can_terminate_bb_p (gsi_stmt (bsi)))
 precise = false;
   }
+ free (bbs);
}
   if (precise
  && get_max_loop_iterations_int (loop) == 1)
-- 
2.35.3


[PATCH] rs6000: replace '(const_int 0)' to 'unspec:BLK [(const_int 0)]' for stack_tie

2023-06-13 Thread Jiufu Guo via Gcc-patches
Hi,

For stack_tie, currently below insn is generated:
(insn 15 14 16 3 (parallel [
 (set (mem/c:BLK (reg/f:DI 1 1) [1  A8])
 (const_int 0 [0]))
 ]) "/home/guojiufu/temp/gdb.c":13:3 922 {stack_tie}
  (nil))

It is "set (mem/c:BLK (reg/f:DI 1 1) (const_int 0 [0])".  This maybe
looks like "a memory block is zerored", while actually stack_tie
may be more like a placeholder, and does not generate any thing.

To avoid potential misunderstand, "UNPSEC:BLK [(const_int 0)].." could
be used here.

Compare with previous version, this addes ChangeLog and removes
const_anchor parts.
https://gcc.gnu.org/pipermail/gcc-patches/2023-June/621356.html.

Bootstrap®test pass on ppc64{,le}.
Is this ok for trunk?

BR,
Jeff (Jiufu Guo)

gcc/ChangeLog:

* config/rs6000/predicates.md (tie_operand): Update to match new
stack_tie pattern.
* config/rs6000/rs6000-logue.cc (rs6000_emit_stack_tie): Update to
use the new stack_tie pattern.
* config/rs6000/rs6000.md (UNSPEC_TIE): New UNSPEC.
(restore_stack_block): Update to use the new stack_tie pattern.
(restore_stack_nonlocal): Likewise.
(stack_tie): Update pattern to use UNSPEC_TIE.
(stack_restore_tie): Likewise.  

---
 gcc/config/rs6000/predicates.md   | 11 +++
 gcc/config/rs6000/rs6000-logue.cc |  4 +++-
 gcc/config/rs6000/rs6000.md   | 14 ++
 4 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md
index a16ee30f0c0..4748cb37ce8 100644
--- a/gcc/config/rs6000/predicates.md
+++ b/gcc/config/rs6000/predicates.md
@@ -1854,10 +1854,13 @@ (define_predicate "stmw_operation"
 (define_predicate "tie_operand"
   (match_code "parallel")
 {
-  return (GET_CODE (XVECEXP (op, 0, 0)) == SET
- && MEM_P (XEXP (XVECEXP (op, 0, 0), 0))
- && GET_MODE (XEXP (XVECEXP (op, 0, 0), 0)) == BLKmode
- && XEXP (XVECEXP (op, 0, 0), 1) == const0_rtx);
+  rtx set = XVECEXP (op, 0, 0);
+  return (GET_CODE (set) == SET
+ && MEM_P (SET_DEST (set))
+ && GET_MODE (SET_DEST (set)) == BLKmode
+ && GET_CODE (SET_SRC (set)) == UNSPEC
+ && XINT (SET_SRC (set), 1) == UNSPEC_TIE
+ && XVECEXP (SET_SRC (set), 0, 0) == const0_rtx);
 })
 
 ;; Match a small code model toc reference (or medium and large
diff --git a/gcc/config/rs6000/rs6000-logue.cc 
b/gcc/config/rs6000/rs6000-logue.cc
index bc6b153b59f..b99f43a8282 100644
--- a/gcc/config/rs6000/rs6000-logue.cc
+++ b/gcc/config/rs6000/rs6000-logue.cc
@@ -1463,7 +1463,9 @@ rs6000_emit_stack_tie (rtx fp, bool hard_frame_needed)
   while (--i >= 0)
 {
   rtx mem = gen_frame_mem (BLKmode, regs[i]);
-  RTVEC_ELT (p, i) = gen_rtx_SET (mem, const0_rtx);
+  RTVEC_ELT (p, i)
+   = gen_rtx_SET (mem, gen_rtx_UNSPEC (BLKmode, gen_rtvec (1, const0_rtx),
+   UNSPEC_TIE));
 }
 
   emit_insn (gen_stack_tie (gen_rtx_PARALLEL (VOIDmode, p)));
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index b0db8ae508d..fdcf8347812 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -158,6 +158,7 @@ (define_c_enum "unspec"
UNSPEC_HASHCHK
UNSPEC_XXSPLTIDP_CONST
UNSPEC_XXSPLTIW_CONST
+   UNSPEC_TIE
   ])
 
 ;;
@@ -10828,7 +10829,9 @@ (define_expand "restore_stack_block"
   operands[4] = gen_frame_mem (Pmode, operands[1]);
   p = rtvec_alloc (1);
   RTVEC_ELT (p, 0) = gen_rtx_SET (gen_frame_mem (BLKmode, operands[0]),
- const0_rtx);
+ gen_rtx_UNSPEC (BLKmode,
+ gen_rtvec (1, const0_rtx),
+ UNSPEC_TIE));
   operands[5] = gen_rtx_PARALLEL (VOIDmode, p);
 })
 
@@ -10866,7 +10869,9 @@ (define_expand "restore_stack_nonlocal"
   operands[5] = gen_frame_mem (Pmode, operands[3]);
   p = rtvec_alloc (1);
   RTVEC_ELT (p, 0) = gen_rtx_SET (gen_frame_mem (BLKmode, operands[0]),
- const0_rtx);
+ gen_rtx_UNSPEC (BLKmode,
+ gen_rtvec (1, const0_rtx),
+ UNSPEC_TIE));
   operands[6] = gen_rtx_PARALLEL (VOIDmode, p);
 })
 
@@ -13898,7 +13903,8 @@ (define_insn "*save_fpregs__r1"
 ; not be moved over loads from or stores to stack memory.
 (define_insn "stack_tie"
   [(match_parallel 0 "tie_operand"
-  [(set (mem:BLK (reg 1)) (const_int 0))])]
+  [(set (mem:BLK (reg 1))
+   (unspec:BLK [(const_int 0)] UNSPEC_TIE))])]
   ""
   ""
   [(set_attr "length" "0")])
@@ -13910,7 +13916,7 @@ (define_insn "stack_restore_tie"
   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
(plus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
 (match_operand:SI 2 "reg_or_cint_

Re: [PATCH] rs6000: replace '(const_int 0)' to 'unspec:BLK [(const_int 0)]' for stack_tie

2023-06-13 Thread Xi Ruoyao via Gcc-patches
On Tue, 2023-06-13 at 20:23 +0800, Jiufu Guo via Gcc-patches wrote:

> Compare with previous version, this addes ChangeLog and removes
> const_anchor parts.
> https://gcc.gnu.org/pipermail/gcc-patches/2023-June/621356.html.

[Off topic]

const_anchor is just broken now.  See
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104843 and the thread
beginning at
https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591470.html.  If
you want to use it for rs6000 I guess you need to fix it first...

To me const_anchor needs a complete rework but I don't want to spend my
time on it.

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


[PATCH] Add -Wmissing-variable-declarations [PR65213].

2023-06-13 Thread Hamza Mahfooz
Resolves:
PR c/65213 - Extend -Wmissing-declarations to variables [i.e. add
-Wmissing-variable-declarations]

gcc/c-family/ChangeLog:

PR c/65213
* c.opt (-Wmissing-variable-declarations): New option.

gcc/c/ChangeLog:

PR c/65213
* c-decl.cc (start_decl): Handle -Wmissing-variable-declarations

gcc/ChangeLog:

PR c/65213
* doc/invoke.texi (-Wmissing-variable-declarations): Document
new option.

gcc/testsuite/ChangeLog:

PR c/65213
* gcc.dg/Wmissing-variable-declarations.c: New test.

Signed-off-by: Hamza Mahfooz 
---
 gcc/c-family/c.opt|  4 +++
 gcc/c/c-decl.cc   | 10 +-
 gcc/doc/invoke.texi   | 11 +--
 .../gcc.dg/Wmissing-variable-declarations.c   | 33 +++
 4 files changed, 55 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/Wmissing-variable-declarations.c

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index cead1995561..42ad447f39b 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -1043,6 +1043,10 @@ Wmissing-prototypes
 C ObjC Var(warn_missing_prototypes) Warning
 Warn about global functions without prototypes.
 
+Wmissing-variable-declarations
+C ObjC Var(warn_missing_variable_declarations) Warning
+Warn about global variables without previous declarations.
+
 Wmudflap
 C ObjC C++ ObjC++ WarnRemoved
 
diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index 1af51c4acfc..8e276b2a846 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -5340,6 +5340,7 @@ start_decl (struct c_declarator *declarator, struct 
c_declspecs *declspecs,
location_t *lastloc /* = NULL */)
 {
   tree decl;
+  tree old_decl;
   tree tem;
   tree expr = NULL_TREE;
   enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
@@ -5360,7 +5361,9 @@ start_decl (struct c_declarator *declarator, struct 
c_declspecs *declspecs,
   if (!decl || decl == error_mark_node)
 return NULL_TREE;
 
-  if (tree lastdecl = lastloc ? lookup_last_decl (decl) : NULL_TREE)
+  old_decl = lookup_last_decl (decl);
+
+  if (tree lastdecl = lastloc ? old_decl : NULL_TREE)
 if (lastdecl != error_mark_node)
   *lastloc = DECL_SOURCE_LOCATION (lastdecl);
 
@@ -5372,6 +5375,11 @@ start_decl (struct c_declarator *declarator, struct 
c_declspecs *declspecs,
   && TREE_PUBLIC (decl))
 warning (OPT_Wmain, "%q+D is usually a function", decl);
 
+  if (warn_missing_variable_declarations && VAR_P (decl)
+  && !DECL_EXTERNAL (decl) && TREE_PUBLIC (decl) && old_decl == NULL_TREE)
+warning_at (DECL_SOURCE_LOCATION (decl), 
OPT_Wmissing_variable_declarations,
+   "no previous declaration for %qD", decl);
+
   if (initialized)
 /* Is it valid for this decl to have an initializer at all?
If not, set INITIALIZED to zero, which will indirectly
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 8fa3f9fae01..e9b51842234 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -496,8 +496,8 @@ Objective-C and Objective-C++ Dialects}.
 
 @item C and Objective-C-only Warning Options
 @gccoptlist{-Wbad-function-cast  -Wmissing-declarations
--Wmissing-parameter-type  -Wmissing-prototypes  -Wnested-externs
--Wold-style-declaration  -Wold-style-definition
+-Wmissing-parameter-type -Wmissing-prototypes -Wmissing-variable-declarations
+-Wnested-externs -Wold-style-declaration  -Wold-style-definition
 -Wstrict-prototypes  -Wtraditional  -Wtraditional-conversion
 -Wdeclaration-after-statement  -Wpointer-sign}
 
@@ -9565,6 +9565,13 @@ provide prototypes and a non-matching declaration 
declares an
 overload rather than conflict with an earlier declaration.
 Use @option{-Wmissing-declarations} to detect missing declarations in C++.
 
+@opindex Wmissing-variable-declarations
+@opindex Wno-missing-variable-declarations
+@item -Wmissing-variable-declarations @r{(C and Objective-C only)}
+Warn if a global variable is defined without a previous declaration.
+Use this option to detect global variables that do not have a matching
+extern declaration in a header file.
+
 @opindex Wmissing-declarations
 @opindex Wno-missing-declarations
 @item -Wmissing-declarations
diff --git a/gcc/testsuite/gcc.dg/Wmissing-variable-declarations.c 
b/gcc/testsuite/gcc.dg/Wmissing-variable-declarations.c
new file mode 100644
index 000..b292dbe8c22
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wmissing-variable-declarations.c
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-options "-Wmissing-variable-declarations" } */
+
+int b0; /* { dg-warning "no previous declaration for 'b0'" } */
+
+int b1 = 1; /* { dg-warning "no previous declaration for 'b1'" } */
+
+int b2; /* { dg-warning "no previous declaration for 'b2'" } */
+int b2 = 2; 
+
+struct {
+int g0;
+} b3; /* { dg-warning "no previous declaration for 'b3'" } */
+
+int b4; /* { dg-warning "no previous declaration for 'b4'" } */
+int b4 = 3;
+extern int b4;
+
+static 

Re: [PATCH V3] RISC-V: Add more SLP tests

2023-06-13 Thread Jeff Law via Gcc-patches




On 6/13/23 05:38, juzhe.zh...@rivai.ai wrote:

From: Juzhe-Zhong 

gcc/testsuite/ChangeLog:

 * gcc.target/riscv/rvv/autovec/partial/slp-10.c: New test.
 * gcc.target/riscv/rvv/autovec/partial/slp-11.c: New test.
 * gcc.target/riscv/rvv/autovec/partial/slp-13.c: New test.
 * gcc.target/riscv/rvv/autovec/partial/slp-14.c: New test.
 * gcc.target/riscv/rvv/autovec/partial/slp-15.c: New test.
 * gcc.target/riscv/rvv/autovec/partial/slp_run-10.c: New test.
 * gcc.target/riscv/rvv/autovec/partial/slp_run-11.c: New test.
 * gcc.target/riscv/rvv/autovec/partial/slp_run-13.c: New test.
 * gcc.target/riscv/rvv/autovec/partial/slp_run-14.c: New test.
 * gcc.target/riscv/rvv/autovec/partial/slp_run-15.c: New test.

---

OK
jeff



Re: [PATCH] RISC-V: Fix bug of VLA SLP auto-vectorization

2023-06-13 Thread Jeff Law via Gcc-patches




On 6/13/23 06:16, Robin Dapp wrote:

Hi Juzhe,

LGTM.  You could also add the aarch64 test disclaimer here again,
but no need for a V2.

Agreed.

jeff


Re: [PATCH 1/4] rs6000: build constant via li;rotldi

2023-06-13 Thread David Edelsohn via Gcc-patches
On Mon, Jun 12, 2023 at 11:30 PM Jiufu Guo  wrote:
>
>
> Hi David,
>
> David Edelsohn  writes:
> > On Wed, Jun 7, 2023 at 9:55 PM Jiufu Guo  wrote:
> >
> >  Hi,
> >
> >  This patch checks if a constant is possible to be rotated to/from a 
> > positive
> >  or negative value from "li". If so, we could use "li;rotldi" to build it.
> >
> >  Bootstrap and regtest pass on ppc64{,le}.
> >  Is this ok for trunk?
> >
> >  BR,
> >  Jeff (Jiufu)
> >
> >  gcc/ChangeLog:
> >
> >  * config/rs6000/rs6000.cc (can_be_rotated_to_positive_li): New 
> > function.
> >  (can_be_rotated_to_negative_li): New function.
> >  (can_be_built_by_li_and_rotldi): New function.
> >  (rs6000_emit_set_long_const): Call can_be_built_by_li_and_rotldi.
> >
> >  gcc/testsuite/ChangeLog:
> >
> >  * gcc.target/powerpc/const-build.c: New test.
> >  ---
> >   gcc/config/rs6000/rs6000.cc   | 64 +--
> >   .../gcc.target/powerpc/const-build.c  | 54 
> >   2 files changed, 112 insertions(+), 6 deletions(-)
> >   create mode 100644 gcc/testsuite/gcc.target/powerpc/const-build.c
> >
> >  diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
> >  index 42f49e4a56b..1dd0072350a 100644
> >  --- a/gcc/config/rs6000/rs6000.cc
> >  +++ b/gcc/config/rs6000/rs6000.cc
> >  @@ -10258,6 +10258,48 @@ rs6000_emit_set_const (rtx dest, rtx source)
> > return true;
> >   }
> >
> >  +/* Check if C can be rotated to a positive value which 'li' instruction
> >  +   is able to load.  If so, set *ROT to the number by which C is rotated,
> >  +   and return true.  Return false otherwise.  */
> >  +
> >  +static bool
> >  +can_be_rotated_to_positive_li (HOST_WIDE_INT c, int *rot)
> >  +{
> >  +  /* 49 leading zeros and 15 low bits on the positive value
> >  + generated by 'li' instruction.  */
> >  +  return can_be_rotated_to_lowbits (c, 15, rot);
> >  +}
> >  +
> >  +/* Like can_be_rotated_to_positive_li, but check the negative value of 
> > 'li'.  */
> >  +
> >  +static bool
> >  +can_be_rotated_to_negative_li (HOST_WIDE_INT c, int *rot)
> >  +{
> >  +  return can_be_rotated_to_lowbits (~c, 15, rot);
> >  +}
> >  +
> >  +/* Check if value C can be built by 2 instructions: one is 'li', another 
> > is
> >  +   rotldi.
> >  +
> >  +   If so, *SHIFT is set to the shift operand of rotldi(rldicl), and *MASK
> >  +   is set to -1, and return true.  Return false otherwise.  */
> >  +
> >
> > I look at this feature and it's good, but I don't fully understand the 
> > benefit of this level of abstraction.  Ideally all of the above functions 
> > would
> > be inlined.  They aren't reused.
> >
> >  +static bool
> >  +can_be_built_by_li_and_rotldi (HOST_WIDE_INT c, int *shift,
> >  +  HOST_WIDE_INT *mask)
> >  +{
> >  +  int n;
> >  +  if (can_be_rotated_to_positive_li (c, &n)
> >  +  || can_be_rotated_to_negative_li (c, &n))
> >
> > Why not
> >
> > /* Check if C or ~C can be rotated to a positive or negative value
> > which 'li' instruction is able to load.  */
> > if (can_be_rotated_to_lowbits (c, 15, &n)
> > || can_be_rotated_to_lowbits (~c, 15, &n))
>
>
> Thanks a lot for your review!!
>
> Your suggestions could also achieve my goal of using a new function:
> Using "can_be_rotated_to_positive_li" is just trying to get a
> straightforward name.  Like yours, the code's comments would also
> make it easy to understand.

I recognize that you are trying to be consistent with the other
functions that you add in later patches, but it feels like overkill in
abstraction to me.  Or maybe combine postive_li and negative_li into a
single function so that the abstraction serves a purpose other than a
tail call and creating an alias for a specific invocation of
can_be_rotated_to_lowbits.

Thanks, David

>
> BR,
> Jeff (Jiufu Guo)
> >
> > ...
> >
> > This is a style of software engineering, but it seems overkill to me when 
> > the function is a single line that tail calls another function.  Am I 
> > missing
> > something?
> >
> > The rest of this patch looks good.
> >
> > Thanks, David
> >
> >  +{
> >  +  *mask = HOST_WIDE_INT_M1;
> >  +  *shift = HOST_BITS_PER_WIDE_INT - n;
> >  +  return true;
> >  +}
> >  +
> >  +  return false;
> >  +}
> >  +
> >   /* Subroutine of rs6000_emit_set_const, handling PowerPC64 DImode.
> >  Output insns to set DEST equal to the constant C as a series of
> >  lis, ori and shl instructions.  */
> >  @@ -10266,15 +10308,14 @@ static void
> >   rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c)
> >   {
> > rtx temp;
> >  +  int shift;
> >  +  HOST_WIDE_INT mask;
> > HOST_WIDE_INT ud1, ud2, ud3, ud4;
> >
> > ud1 = c & 0x;
> >  -  c = c >> 16;
> >  -  ud2 = c & 0x;
> >  -  c = c >> 16;
> >  -  ud3 = c & 0x;
> >  -  c = c >> 16;
> >  -  ud4 = c & 0x;
> >  +  ud2 = (c >> 16) & 0x;
> >  +  ud3 = (c >> 32) & 0x;
> >  +  ud4 = (c >> 48) & 0xfff

Re: [PATCH] Fix note_defect3 function

2023-06-13 Thread Jeff Law via Gcc-patches




On 6/12/23 21:18, Akari Takahashi via Gcc-patches wrote:

Hello,

I've noticed an issue with the note_defect3 function and have prepared a
patch to fix it. The function is missing a return statement, which is
causing undefined behavior. This patch adds the missing return statement,
ensuring that the function returns the correct value.

Please consider applying this patch to correct the issue. Thank you.

Best regards,

Takahashi Akari
Thanks.  Reviewing that file it looks like it was just supposed to be 
used for the sh5/sh5media processor.  My recollection is those were 
never actually produced and support for them was removed from GCC some 
time ago.  This file was missed during that removal.


Rather than apply the patch, I think the better choice is to just remove 
the divtab.cc file unless someone has a real use for it.


Is there a particular reason you were investigating the divtab.cc file?

jeff


Ping * 2 : Fwd: [V9][PATCH 1/2] Handle component_ref to a structre/union field including flexible array member [PR101832]

2023-06-13 Thread Qing Zhao via Gcc-patches
Hi,

I’d like to ping this patch again for the Middle-end approval (on 
gcc/tree-object-size.cc change).
This is an important patch to Linux Kernel security. 

The patch has addressed all the comments and suggestions raised during the 
review process. 
The C FE, Doc changes has been approved.
Most of the Middle-end changes been reviewed by Richard Biener and have been 
updated based on his suggestions.

The only change that has not been reviewed is the simple change in 
gcc/tree-object-size.cc.  which is simple and straightforward.
Please review this change and let me know whether it’s okay for commit to trunk?

Thanks a lot!

Qing

> On Jun 5, 2023, at 11:12 AM, Qing Zhao via Gcc-patches 
>  wrote:
> 
> Ping on this patch.
> 
> The C FE and Doc changes has been approved.
> Please help to review and approve the Middle-end change.
> 
> Or provide guide on how to move this patch forward.
> 
> Thanks a lot for the help.
> 
> Qing
> 
> Begin forwarded message:
> 
> From: Qing Zhao mailto:qing.z...@oracle.com>>
> Subject: [V9][PATCH 1/2] Handle component_ref to a structre/union field 
> including flexible array member [PR101832]
> Date: May 30, 2023 at 2:30:28 PM EDT
> To: jos...@codesourcery.com, 
> richard.guent...@gmail.com, 
> ja...@redhat.com, 
> gcc-patches@gcc.gnu.org
> Cc: keesc...@chromium.org, 
> siddh...@gotplt.org, 
> uec...@tugraz.at, Qing Zhao 
> mailto:qing.z...@oracle.com>>
> 
> Richard or Jakub,
> 
> could you please review this patch and see whether it's Okay to commit?
> 
> thanks a lot.
> 
> Qing
> 
> ===
> 
> GCC extension accepts the case when a struct with a C99 flexible array member
> is embedded into another struct or union (possibly recursively) as the last
> field.
> __builtin_object_size should treat such struct as flexible size.
> 
> gcc/c/ChangeLog:
> 
> PR tree-optimization/101832
> * c-decl.cc (finish_struct): Set TYPE_INCLUDES_FLEXARRAY for
> struct/union type.
> 
> gcc/lto/ChangeLog:
> 
> PR tree-optimization/101832
> * lto-common.cc (compare_tree_sccs_1): Compare bit
> TYPE_NO_NAMED_ARGS_STDARG_P or TYPE_INCLUDES_FLEXARRAY properly
> for its corresponding type.
> 
> gcc/ChangeLog:
> 
> PR tree-optimization/101832
> * print-tree.cc (print_node): Print new bit 
> type_includes_flexarray.
> * tree-core.h (struct tree_type_common): Use bit no_named_args_stdarg_p
> as type_includes_flexarray for RECORD_TYPE or UNION_TYPE.
> * tree-object-size.cc (addr_object_size): Handle 
> structure/union type
> when it has flexible size.
> * tree-streamer-in.cc 
> (unpack_ts_type_common_value_fields): Stream
> in bit no_named_args_stdarg_p properly for its corresponding type.
> * tree-streamer-out.cc 
> (pack_ts_type_common_value_fields): Stream
> out bit no_named_args_stdarg_p properly for its corresponding type.
> * tree.h (TYPE_INCLUDES_FLEXARRAY): New macro TYPE_INCLUDES_FLEXARRAY.
> 
> gcc/testsuite/ChangeLog:
> 
> PR tree-optimization/101832
> * gcc.dg/builtin-object-size-pr101832.c: New test.
> 
> change TYPE_INCLUDES_FLEXARRAY to TYPE_INCLUDES_FLEXARRAY
> ---
> gcc/c/c-decl.cc   |  11 ++
> gcc/lto/lto-common.cc |   5 +-
> gcc/print-tree.cc |   5 +
> .../gcc.dg/builtin-object-size-pr101832.c | 134 ++
> gcc/tree-core.h   |   2 +
> gcc/tree-object-size.cc   |  
> 23 ++-
> gcc/tree-streamer-in.cc   |   
> 5 +-
> gcc/tree-streamer-out.cc  |  
>  5 +-
> gcc/tree.h|   7 +-
> 9 files changed, 192 insertions(+), 5 deletions(-)
> create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-pr101832.c
> 
> diff --git a/gcc/c/c-decl.cc 
> b/gcc/c/c-decl.cc
> index b5b491cf2da..0c718151f6d 100644
> --- a/gcc/c/c-decl.cc
> +++ b/gcc/c/c-decl.cc
> @@ -9282,6 +9282,17 @@ finish_struct (location_t loc, tree t, tree fieldlist, 
> tree attributes,
>  /* Set DECL_NOT_FLEXARRAY flag for FIELD_DECL x.  */
>  DECL_NOT_FLEXARRAY (x) = !is_flexible_array_member_p (is_last_field, x);
> 
> +  /* Set TYPE_INCLUDES_FLEXARRAY for the context of x, t.
> + when x is an array and is the last field.  */
> +  if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE)
> + TYPE_INCLUDES_FLEXARRAY (t)
> +  = is_last_field && flexible_array_member_type_p (TREE_TYPE (x));
> +  /* Recursively set TYPE_INCLUDES

RE: [PATCH] RISC-V: Fix bug of VLA SLP auto-vectorization

2023-06-13 Thread Li, Pan2 via Gcc-patches
Committed, thanks Jeff.

Pan

-Original Message-
From: Gcc-patches  On Behalf 
Of Jeff Law via Gcc-patches
Sent: Tuesday, June 13, 2023 9:30 PM
To: Robin Dapp ; juzhe.zh...@rivai.ai; 
gcc-patches@gcc.gnu.org
Cc: kito.ch...@gmail.com; kito.ch...@sifive.com; pal...@dabbelt.com; 
pal...@rivosinc.com
Subject: Re: [PATCH] RISC-V: Fix bug of VLA SLP auto-vectorization



On 6/13/23 06:16, Robin Dapp wrote:
> Hi Juzhe,
> 
> LGTM.  You could also add the aarch64 test disclaimer here again, but 
> no need for a V2.
Agreed.

jeff


RE: [PATCH V3] RISC-V: Add more SLP tests

2023-06-13 Thread Li, Pan2 via Gcc-patches
Committed, thanks Jeff.

Pan

-Original Message-
From: Gcc-patches  On Behalf 
Of Jeff Law via Gcc-patches
Sent: Tuesday, June 13, 2023 9:26 PM
To: juzhe.zh...@rivai.ai; gcc-patches@gcc.gnu.org
Cc: kito.ch...@gmail.com; kito.ch...@sifive.com; pal...@dabbelt.com; 
pal...@rivosinc.com; rdapp@gmail.com
Subject: Re: [PATCH V3] RISC-V: Add more SLP tests



On 6/13/23 05:38, juzhe.zh...@rivai.ai wrote:
> From: Juzhe-Zhong 
> 
> gcc/testsuite/ChangeLog:
> 
>  * gcc.target/riscv/rvv/autovec/partial/slp-10.c: New test.
>  * gcc.target/riscv/rvv/autovec/partial/slp-11.c: New test.
>  * gcc.target/riscv/rvv/autovec/partial/slp-13.c: New test.
>  * gcc.target/riscv/rvv/autovec/partial/slp-14.c: New test.
>  * gcc.target/riscv/rvv/autovec/partial/slp-15.c: New test.
>  * gcc.target/riscv/rvv/autovec/partial/slp_run-10.c: New test.
>  * gcc.target/riscv/rvv/autovec/partial/slp_run-11.c: New test.
>  * gcc.target/riscv/rvv/autovec/partial/slp_run-13.c: New test.
>  * gcc.target/riscv/rvv/autovec/partial/slp_run-14.c: New test.
>  * gcc.target/riscv/rvv/autovec/partial/slp_run-15.c: New test.
> 
> ---
OK
jeff



Re: [PATCH] RISC-V: Add comments of some functions

2023-06-13 Thread Jeff Law via Gcc-patches




On 6/12/23 20:26, juzhe.zh...@rivai.ai wrote:

From: Juzhe-Zhong 

gcc/ChangeLog:

 * config/riscv/riscv-v.cc (rvv_builder::single_step_npatterns_p): Add 
comment.
 (shuffle_generic_patterns): Ditto.
 (expand_vec_perm_const_1): Ditto.

OK.  Thanks!
jeff


Re: [PATCH V2] RISC-V: Support RVV VLA SLP auto-vectorization

2023-06-13 Thread Jeff Law via Gcc-patches




On 6/12/23 20:27, juzhe.zh...@rivai.ai wrote:

Ok.
https://gcc.gnu.org/pipermail/gcc-patches/2023-June/thread.html 


I have add comments as you suggested.
Thanks.  With those changes I think the main patch here (RVV VLA SLP 
auto-vectorization) is good to go.


jeff


Re: [PATCH] RISC-V: Implement vec_set and vec_extract.

2023-06-13 Thread Jeff Law via Gcc-patches




On 6/13/23 00:50, Robin Dapp wrote:

I suggest we implement vector calling convention even though it is not ratified 
yet.
We can allow calling convention to be enabled only when 
--param=riscv-autovec-preference=fixed-vlmax.
We have such issue:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110119 

if we don't have calling convention for fixed-vlmax.


Let's discuss this in the patchwork sync meeting later.
In fact I'd ask y'all start with this since my contribution would be 
minimal and I'll be in the car for the first ~30 minutes.


jeff


RE: [PATCH] RISC-V: Add comments of some functions

2023-06-13 Thread Li, Pan2 via Gcc-patches
Committed, thanks Jeff.

Pan

-Original Message-
From: Gcc-patches  On Behalf 
Of Jeff Law via Gcc-patches
Sent: Tuesday, June 13, 2023 10:06 PM
To: juzhe.zh...@rivai.ai; gcc-patches@gcc.gnu.org
Cc: kito.ch...@gmail.com; kito.ch...@sifive.com; pal...@dabbelt.com; 
pal...@rivosinc.com; rdapp@gmail.com
Subject: Re: [PATCH] RISC-V: Add comments of some functions



On 6/12/23 20:26, juzhe.zh...@rivai.ai wrote:
> From: Juzhe-Zhong 
> 
> gcc/ChangeLog:
> 
>  * config/riscv/riscv-v.cc (rvv_builder::single_step_npatterns_p): 
> Add comment.
>  (shuffle_generic_patterns): Ditto.
>  (expand_vec_perm_const_1): Ditto.
OK.  Thanks!
jeff


Re: [PATCH] modula2: Fix bootstrap

2023-06-13 Thread Jakub Jelinek via Gcc-patches
On Wed, Jun 07, 2023 at 09:42:22AM +0100, Andre Vieira (lists) wrote:
> I do need those includes and sorry I broke your bootstrap it didn't show up
> on my aarch64-unknown-linux-gnu bootstrap, I'm guessing the rules there were
> just run in a different order. Glad you were able to fix it :)

Unfortunately, it doesn't really work.
My x86_64-linux bootstrap today died again with:
In file included from ../../gcc/m2/gm2-gcc/gcc-consolidation.h:74,
 from ../../gcc/m2/gm2-lang.cc:24:
../../gcc/internal-fn.h:24:10: fatal error: insn-opinit.h: No such file or 
directory
   24 | #include "insn-opinit.h"
  |  ^~~
compilation terminated.
/home/jakub/src/gcc/obj36/./prev-gcc/xg++ 
-B/home/jakub/src/gcc/obj36/./prev-gcc/ -B/usr/local/x86_64-pc-linux-gnu/bin/ 
-nostdinc++ 
-B/home/jakub/src/gcc/obj36/prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs 
-B/home/jakub/src/gcc/obj36/prev-x86_64-pc-linux-gnu/libstdc++-v3/libsupc++/.libs
  
-I/home/jakub/src/gcc/obj36/prev-x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc-linux-gnu
  -I/home/jakub/src/gcc/obj36/prev-x86_64-pc-linux-gnu/libstdc++-v3/include  
-I/home/jakub/src/gcc/libstdc++-v3/libsupc++ 
-L/home/jakub/src/gcc/obj36/prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs 
-L/home/jakub/src/gcc/obj36/prev-x86_64-pc-linux-gnu/libstdc++-v3/libsupc++/.libs
  -fno-PIE -c -g   -g -O2 -fchecking=1 -DIN_GCC -fno-exceptions -fno-rtti 
-fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings 
-Wcast-qual  -fno-common  -DHAVE_CONFIG_H \
 -I. -Im2/gm2-gcc -I../../gcc -I../../gcc/m2/gm2-gcc 
-I../../gcc/../include  -I../../gcc/../libcpp/include -I../../gcc/../libcody  
-I../../gcc/../libdecnumber -I../../gcc/../libdecnumber/bid -I../libdecnumber 
-I../../gcc/../libbacktrace   -I. -Im2/gm2-gcc -I../../gcc 
-I../../gcc/m2/gm2-gcc -I../../gcc/../include  -I../../gcc/../libcpp/include 
-I../../gcc/../libcody  -I../../gcc/../libdecnumber 
-I../../gcc/../libdecnumber/bid -I../libdecnumber -I../../gcc/../libbacktrace  
../../gcc/m2/gm2-gcc/m2type.cc -o m2/gm2-gcc/m2type.o
make[3]: *** [../../gcc/m2/Make-lang.in:570: m2/gm2-lang.o] Error 1
make[3]: *** Waiting for unfinished jobs
errors.  Dunno what is going on.
I've tried
--- gcc/m2/Make-lang.in.jj  2023-06-07 15:56:07.112684198 +0200
+++ gcc/m2/Make-lang.in 2023-06-13 16:08:55.409364765 +0200
@@ -511,7 +511,7 @@ GM2_LIBS_BOOT = m2/gm2-compiler-boot
 m2/gm2-libs-boot/libgm2.a \
 $(GM2-BOOT-O)
 
-$(GM2_C_OBJS) : | $(generated_files)
+m2_OBJS = $(GM2_C_OBJS)
 
 cc1gm2$(exeext): m2/stage1/cc1gm2$(exeext) $(m2.prev)
cp -p $< $@

but that doesn't really work either, this time not just random bootstrap
breakages from time to time, but all the time.
Including GM2_C_OBJS in m2_OBJS is I think the right thing, but that
results in predefining IN_GCC_FRONTEND macro and we have e.g.

/* Front ends should never have to include middle-end headers.  Enforce
   this by poisoning the header double-include protection defines.  */
#ifdef IN_GCC_FRONTEND
#pragma GCC poison GCC_RTL_H GCC_EXCEPT_H GCC_EXPR_H
#endif

in system.h to make sure that FE sources don't include rtl.h, except.h,
expr.h.  But m2/gm2-gcc/gcc-consolidation.h includes tons of the RTL
headers, rtl.h, df.h (twice), except.h; why?
Also, seems one of GM2_C_OBJS is some special copy of stor-layout.cc
which really isn't a FE file and so needs the RTL-ish headers.

Jakub



RE: [PATCH] RISC-V: Remove duplicate `#include "riscv-vector-switch.def"`

2023-06-13 Thread Li, Pan2 via Gcc-patches
Committed, thanks Juzhe.

Pan

-Original Message-
From: Gcc-patches  On Behalf 
Of juzhe.zh...@rivai.ai
Sent: Tuesday, June 13, 2023 6:56 PM
To: 丁乐华 ; gcc-patches 
Subject: Re: [PATCH] RISC-V: Remove duplicate `#include 
"riscv-vector-switch.def"`

Send V2 patch with changelog.

Thanks.


juzhe.zh...@rivai.ai
 
From: Lehua Ding
Date: 2023-06-13 18:53
To: gcc-patches; juzhe.zhong
Subject: [PATCH] RISC-V: Remove duplicate `#include "riscv-vector-switch.def"` 
Hi,
 
This patch remove the duplicate `#include "riscv-vector-switch.def"` statement 
and add #undef for ENTRY and TUPLE_ENTRY macros later.
 
Best,
Lehua
 
---
gcc/config/riscv/riscv-v.cc | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
 
diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc index 
e1b85a5af91f..09c2abcbc623 100644
--- a/gcc/config/riscv/riscv-v.cc
+++ b/gcc/config/riscv/riscv-v.cc
@@ -1210,7 +1210,6 @@ struct mode_vtype_group
   ratio_for_min_vlen64[MODE##mode] = RATIO_FOR_MIN_VLEN64; 
\
   vlmul_for_for_vlen128[MODE##mode] = VLMUL_FOR_MIN_VLEN128;   
\
   ratio_for_for_vlen128[MODE##mode] = RATIO_FOR_MIN_VLEN128; -#include 
"riscv-vector-switch.def"
#define TUPLE_ENTRY(MODE, REQUIREMENT, SUBPART_MODE, NF, VLMUL_FOR_MIN_VLEN32, \
RATIO_FOR_MIN_VLEN32, VLMUL_FOR_MIN_VLEN64,\
RATIO_FOR_MIN_VLEN64, VLMUL_FOR_MIN_VLEN128,   \
@@ -1224,6 +1223,8 @@ struct mode_vtype_group
   vlmul_for_for_vlen128[MODE##mode] = VLMUL_FOR_MIN_VLEN128;   
\
   ratio_for_for_vlen128[MODE##mode] = RATIO_FOR_MIN_VLEN128; #include 
"riscv-vector-switch.def"
+#undef ENTRY
+#undef TUPLE_ENTRY
   }
};
--
2.36.3
 


Re: [RFC] Add stdckdint.h header for C23

2023-06-13 Thread Joseph Myers
On Tue, 13 Jun 2023, Jakub Jelinek via Gcc-patches wrote:

> There is always the possibility to have the header co-owned by both
> the compiler and C library, limits.h style.
> Just 
> #if __has_include_next()
> # include_next 
> #endif
> perhaps guarded with some macro at the end of the GCC version and
> do the same at the start of the glibc version again perhaps with some macro.
> And leave the compiler specific part to the compiler (perhaps with some
> fallback in the libc version if the compiler specific part is missing) and
> have the library related part be provided by the C library?

This seems a reasonable approach.  If the structure types do make it into 
future standard versions, we'd need to work out exactly where the division 
is between compiler and library header responsibilities (where those 
pieces involving structure types but not library functions go, for 
example).  For operations using structure types with overflow flag we'd 
need also to work out to what extent it's appropriate to implement those 
purely in the header with _Generic versus adding new built-in functions or 
extending what the existing ones can do.

> > > What I'm struggling with is enforcing the weird restrictions
> > > C23 imposes on these.
> > 
> > It's not clear all those restrictions need to be enforced - this 
> > definitely seems like a case of undefined behavior to provide useful 
> > extension space, where for various of those restrictions there are unique 
> > sensible semantics to provide if the types in question are supported.
> 
> So why does C2X say
> Recommended practice
> It is recommended to produce a diagnostic message if type2 or type3 are
> not suitable integer types, or if *result is not a modifiable lvalue of
> a suitable integer type.
> ?
> Or is it meant that a suitable integer type doesn't need to be necessarily
> one that is listed in the previous paragraph?
> Perhaps the checking could be guarded on #ifdef __STRICT_ANSI__, sure...

Diagnostics are better than doing something completely random - but making 
it conditional when there are sensible semantics also makes sense.

It seems likely a future standard version will support these operations 
for bit-precise types, at least.  (Bit-precise types are generally tricky 
for type-generic operations; there's no standard way to select on them 
with _Generic beyond listing individual types with specific widths, and no 
standard way to determine the width of the bit-precise type of an 
argument.  So implementing some type-generic operations for such types may 
need new language extensions, prompting WG14 caution about requiring such 
support - but this also makes support for such types in standard 
type-generic macros in headers particularly valuable, precisely because 
they can't be implemented purely in user code using standard language 
features.)

-- 
Joseph S. Myers
jos...@codesourcery.com


Re: [PATCH] ipa: Self-DCE of uses of removed call LHSs (PR 108007)

2023-06-13 Thread Martin Jambor
Ping.

Thanks,

Martin

On Fri, May 12 2023, Martin Jambor wrote:
> Hi,
>
> PR 108007 is another manifestation where we rely on DCE to clean-up
> after IPA-SRA and if the user explicitely switches DCE off, IPA-SRA
> can leave behind statements which are fed uninitialized values and
> trap, even though their results are themselves never used.
>
> I have already fixed this for unused parameters in callees, this bug
> shows that almost the same thing can happen for removed returns, on
> the side of callers.  This means that the issue has to be fixed
> elsewhere, in call redirection.  This patch adds a function which
> recursivewly looks for uses of operations fed specific SSA names and
> removes them all.
>
> That would have been easy if it wasn't for debug statements during
> tree-inline (from which call redirection is also invoked).  Debug
> statements are decoupled from the rest at this point and iterating
> over uses of SSAs does not bring them up.  During tree-inline they are
> handled especially at the end, I assume in order to make sure that
> relative ordering of UIDs are the same with and without debug info.
>
> This means that during tree-inline we need to make a hash of killed
> SSAs, that we already have in copy_body_data, available to the
> function making the purging.  So the patch duly does also that, making
> the interface slightly ugly.
>
> Bootstrapped and tested on x86_64-linux.  OK for master?  (I am not sure
> the problem is grave enough to warrant backporting to release branches
> but can do that as well if people think I should.)
>
> Thanks,
>
> Martin
>
>
> gcc/ChangeLog:
>
> 2023-05-11  Martin Jambor  
>
>   PR ipa/108007
>   * cgraph.h (cgraph_edge): Add a parameter to
>   redirect_call_stmt_to_callee.
>   * ipa-param-manipulation.h (ipa_param_adjustments): Added a
>   parameter to modify_call.
>   * cgraph.cc (cgraph_edge::redirect_call_stmt_to_callee): New
>   parameter killed_ssas, pass it to padjs->modify_call.
>   * ipa-param-manipulation.cc (purge_transitive_uses): New function.
>   (ipa_param_adjustments::modify_call): New parameter killed_ssas.
>   Instead of substitutin uses, invoke purge_transitive_uses.  If
>   hash of killed SSAs has not been provided, create a temporary one
>   and release SSAs that have been added to it.
>   * tree-inline.cc (redirect_all_calls): Create
>   id->killed_new_ssa_names earlier, pass it to edge redirection,
>   adjust a comment.
>   (copy_body): Release SSAs in id->killed_new_ssa_names.
>
> gcc/testsuite/ChangeLog:
>
> 2023-05-11  Martin Jambor  
>
>   PR ipa/108007
>   * gcc.dg/ipa/pr108007.c: New test.
> ---
>  gcc/cgraph.cc   | 10 +++-
>  gcc/cgraph.h|  9 ++-
>  gcc/ipa-param-manipulation.cc   | 85 +
>  gcc/ipa-param-manipulation.h|  3 +-
>  gcc/testsuite/gcc.dg/ipa/pr108007.c | 32 +++
>  gcc/tree-inline.cc  | 28 ++
>  6 files changed, 129 insertions(+), 38 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.dg/ipa/pr108007.c
>
> diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
> index e8f9bec8227..5e923bf0557 100644
> --- a/gcc/cgraph.cc
> +++ b/gcc/cgraph.cc
> @@ -1403,11 +1403,17 @@ cgraph_edge::redirect_callee (cgraph_node *n)
> speculative indirect call, remove "speculative" of the indirect call and
> also redirect stmt to it's final direct target.
>  
> +   When called from within tree-inline, KILLED_SSAs has to contain the 
> pointer
> +   to killed_new_ssa_names within the copy_body_data structure and SSAs
> +   discovered to be useless (if LHS is removed) will be added to it, 
> otherwise
> +   it needs to be NULL.
> +
> It is up to caller to iteratively transform each "speculative"
> direct call as appropriate.  */
>  
>  gimple *
> -cgraph_edge::redirect_call_stmt_to_callee (cgraph_edge *e)
> +cgraph_edge::redirect_call_stmt_to_callee (cgraph_edge *e,
> +hash_set  *killed_ssas)
>  {
>tree decl = gimple_call_fndecl (e->call_stmt);
>gcall *new_stmt;
> @@ -1527,7 +1533,7 @@ cgraph_edge::redirect_call_stmt_to_callee (cgraph_edge 
> *e)
>   remove_stmt_from_eh_lp (e->call_stmt);
>  
>tree old_fntype = gimple_call_fntype (e->call_stmt);
> -  new_stmt = padjs->modify_call (e, false);
> +  new_stmt = padjs->modify_call (e, false, killed_ssas);
>cgraph_node *origin = e->callee;
>while (origin->clone_of)
>   origin = origin->clone_of;
> diff --git a/gcc/cgraph.h b/gcc/cgraph.h
> index f5f54769eda..c1a3691b6f5 100644
> --- a/gcc/cgraph.h
> +++ b/gcc/cgraph.h
> @@ -1833,9 +1833,16 @@ public:
>   speculative indirect call, remove "speculative" of the indirect call and
>   also redirect stmt to it's final direct target.
>  
> + When called from within tree-inline, KILLED_SSAs has to contain the
> + pointer to killed_new_ssa_names within the cop

Re: [RFC] Add stdckdint.h header for C23

2023-06-13 Thread Jakub Jelinek via Gcc-patches
On Tue, Jun 13, 2023 at 03:10:48PM +, Joseph Myers wrote:
> > So why does C2X say
> > Recommended practice
> > It is recommended to produce a diagnostic message if type2 or type3 are
> > not suitable integer types, or if *result is not a modifiable lvalue of
> > a suitable integer type.
> > ?
> > Or is it meant that a suitable integer type doesn't need to be necessarily
> > one that is listed in the previous paragraph?
> > Perhaps the checking could be guarded on #ifdef __STRICT_ANSI__, sure...
> 
> Diagnostics are better than doing something completely random - but making 
> it conditional when there are sensible semantics also makes sense.
> 
> It seems likely a future standard version will support these operations 
> for bit-precise types, at least.  (Bit-precise types are generally tricky 
> for type-generic operations; there's no standard way to select on them 
> with _Generic beyond listing individual types with specific widths, and no 
> standard way to determine the width of the bit-precise type of an 
> argument.  So implementing some type-generic operations for such types may 
> need new language extensions, prompting WG14 caution about requiring such 
> support - but this also makes support for such types in standard 
> type-generic macros in headers particularly valuable, precisely because 
> they can't be implemented purely in user code using standard language 
> features.)

Yeah, having say __builtin_{clz,ctz,ffs,popcount,parity} variants which would
be typegeneric and would allow say any normal integral or _BitInt type
(or just unsigned versions thereof?) would be useful.  Even without _BitInt
we have the problem that we don't have builtins for __uint128_t.

One question is if we should keep them UB on zero input or hardcode some 
particular
behavior for clz/ctz.  The backend defaults might not be appropriate, I
think if we'd make it non-UB, using the precision of the type would be
reasonable, whatever it is (__builtin_clzb ((unsigned _BitInt(126)) 0)
might be 126 etc.).

Jakub



RE: [PATCH v2] machine descriptor: New compact syntax for insn and insn_split in Machine Descriptions.

2023-06-13 Thread Tamar Christina via Gcc-patches
Hi All,

Updated patch with feedback addressed.


Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.

Any feedback?

Thanks,
Tamar

gcc/ChangeLog:

* gensupport.cc (class conlist, add_constraints, add_attributes,
skip_spaces, expect_char, preprocess_compact_syntax,
parse_section_layout, parse_section, convert_syntax): New.
(process_rtx): Check for conversion.
* genoutput.cc (process_template): Check for unresolved iterators.
(class data): Add compact_syntax_p.
(gen_insn): Use it.
* gensupport.h (compact_syntax): New.
(hash-set.h): Include.

Co-Authored-By: Omar Tahir 

--- inline copy of patch ---

diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi
index 
6a435eb44610960513e9739ac9ac1e8a27182c10..3bd1bcbc8beda9bbaea71c65118ecfa2cdace335
 100644
--- a/gcc/doc/md.texi
+++ b/gcc/doc/md.texi
@@ -27,6 +27,7 @@ See the next chapter for information on the C header file.
 from such an insn.
 * Output Statement::For more generality, write C code to output
 the assembler code.
+* Compact Syntax::  Compact syntax for writing machine descriptors.
 * Predicates::  Controlling what kinds of operands can be used
 for an insn.
 * Constraints:: Fine-tuning operand selection.
@@ -713,6 +714,167 @@ you can use @samp{*} inside of a @samp{@@} 
multi-alternative template:
 @end group
 @end smallexample
 
+@node Compact Syntax
+@section Compact Syntax
+@cindex compact syntax
+
+When a @code{define_insn} or @code{define_insn_and_split} has multiple
+alternatives it may be beneficial to use the compact syntax when specifying
+alternatives.
+
+This syntax puts the constraints and attributes on the same horizontal line as
+the instruction assembly template.
+
+As an example
+
+@smallexample
+@group
+(define_insn_and_split ""
+  [(set (match_operand:SI 0 "nonimmediate_operand" "=r,k,r,r,r,r")
+   (match_operand:SI 1 "aarch64_mov_operand"  " r,r,k,M,n,Usv"))]
+  ""
+  "@@
+   mov\\t%w0, %w1
+   mov\\t%w0, %w1
+   mov\\t%w0, %w1
+   mov\\t%w0, %1
+   #
+   * return aarch64_output_sve_cnt_immediate ('cnt', '%x0', operands[1]);"
+  "&& true"
+   [(const_int 0)]
+  @{
+ aarch64_expand_mov_immediate (operands[0], operands[1]);
+ DONE;
+  @}
+  [(set_attr "type" "mov_reg,mov_reg,mov_reg,mov_imm,mov_imm,mov_imm")
+   (set_attr "arch"   "*,*,*,*,*,sve")
+   (set_attr "length" "4,4,4,4,*,  4")
+]
+)
+@end group
+@end smallexample
+
+can be better expressed as:
+
+@smallexample
+@group
+(define_insn_and_split ""
+  [(set (match_operand:SI 0 "nonimmediate_operand")
+   (match_operand:SI 1 "aarch64_mov_operand"))]
+  ""
+  @{@@ [cons: =0, 1; attrs: type, arch, length]
+ [r , r  ; mov_reg  , *   , 4] mov\t%w0, %w1
+ [k , r  ; mov_reg  , *   , 4] ^
+ [r , k  ; mov_reg  , *   , 4] ^
+ [r , M  ; mov_imm  , *   , 4] mov\t%w0, %1
+ [r , n  ; mov_imm  , *   , *] #
+ [r , Usv; mov_imm  , sve , 4] << aarch64_output_sve_cnt_immediate ("cnt", 
"%x0", operands[1]);
+  @}
+  "&& true"
+  [(const_int 0)]
+  @{
+aarch64_expand_mov_immediate (operands[0], operands[1]);
+DONE;
+  @}
+)
+@end group
+@end smallexample
+
+The syntax rules are as follows:
+@itemize @bullet
+@item
+Templates must start with @samp{@{@@} to use the new syntax.
+
+@item
+@samp{@{@@} is followed by a layout in parentheses which is @samp{cons:}
+followed by a comma-separated list of @code{match_operand}/@code{match_scratch}
+operand numbers, then a semicolon, followed by the same for attributes
+(@samp{attrs:}).  Operand modifiers can be placed in this section group as 
well.
+Both sections are optional (so you can use only @samp{cons}, or only
+@samp{attrs}, or both), and @samp{cons} must come before @samp{attrs} if
+present.
+
+@item
+Each alternative begins with any amount of whitespace.
+
+@item
+Following the whitespace is a comma-separated list of "constraints" and/or
+"attributes" within brackets @code{[]}, with sections separated by a semicolon.
+
+@item
+Should you want to copy the previous asm line, the symbol @code{^} can be used.
+This allows less copy pasting between alternative and reduces the number of
+lines to update on changes.
+
+@item
+When using C functions for output, the idiom @samp{* return @var{function};}
+can be replaced with the shorthand @samp{<< @var{function};}.
+
+@item
+Following the closing @samp{]} is any amount of whitespace, and then the actual
+asm output.
+
+@item
+Spaces are allowed in the list (they will simply be removed).
+
+@item
+All constraint alternatives should be specified.  For example, a list of
+of three blank alternatives should be written @samp{[,,]} rather than
+@samp{[]}.
+
+@item
+All attribute alternatives should be non-empty, with @samp{*}
+representing the default attribute value.  For example, a list of three
+default attribute values should be written @samp{[*,*,*]} rather than
+@samp{[]}.
+
+
+@item
+Within

Re: [ping] driver: Forward '-lgfortran', '-lm' to offloading compilation

2023-06-13 Thread Joseph Myers
On Tue, 13 Jun 2023, Thomas Schwinge wrote:

> Hi!
> 
> On 2023-06-05T14:25:18+0200, I wrote:
> > OK to push the attached
> > "driver: Forward '-lgfortran', '-lm' to offloading compilation"?
> > (We didn't have a PR open for that, or did we?)
> 
> Ping.

OK.

-- 
Joseph S. Myers
jos...@codesourcery.com


Re: [RFC] Add stdckdint.h header for C23

2023-06-13 Thread Joseph Myers
On Tue, 13 Jun 2023, Jakub Jelinek via Gcc-patches wrote:

> Yeah, having say __builtin_{clz,ctz,ffs,popcount,parity} variants which would
> be typegeneric and would allow say any normal integral or _BitInt type
> (or just unsigned versions thereof?) would be useful.  Even without _BitInt
> we have the problem that we don't have builtins for __uint128_t.
> 
> One question is if we should keep them UB on zero input or hardcode some 
> particular
> behavior for clz/ctz.  The backend defaults might not be appropriate, I
> think if we'd make it non-UB, using the precision of the type would be
> reasonable, whatever it is (__builtin_clzb ((unsigned _BitInt(126)) 0)
> might be 126 etc.).

FWIW the C2x stdbit.h operations all have defined semantics on special 
cases, except for the stdc_bit_ceil operations (where there's an NB 
comment on CD2 to be considered at next week's WG14 meeting requesting 
defined semantics there as well).  They're also all for unsigned 
arguments.  (Note there are also NB comments requesting removal of some of 
the operations as duplicates or near-duplicates of others.)

The stdbit.h header does seem naturally to be something for libc, given 
that (a) it has a lot of functions, not just type-generic macros, and (b) 
the type-generic macros are generally easy to implement (at least for the 
types supported in the standard) in a way that doesn't depend on any 
compiler extensions (or even on _Generic, many of them can be implemented 
just to call the function for unsigned long long).  It makes sense in due 
course for GCC to know the names there (after any get removed) as built-in 
functions, but mapping in a header to existing __builtin_* is generally 
easy until then.

-- 
Joseph S. Myers
jos...@codesourcery.com


[PATCH, OpenACC 2.7] Implement self clause for compute constructs

2023-06-13 Thread Chung-Lin Tang via Gcc-patches
Hi Thomas,
This patch implements the compiler side for the 'self' clause for compute 
constructs:
parallel, kernels, and serial.

As you know, the actual "local device" device type for libgomp is not yet 
implemented,
so the libgomp side is basically just a simple duplicate of what host-fallback 
is doing,
though everything else should be completed by this patch.

Tested on powerpc64le-linux/nvptx, x64_64-linux/amdgcn tests pending.
Is this okay for trunk?

Thanks,
Chung-Lin

2023-06-13  Chung-Lin Tang  

gcc/c/ChangeLog:

* c-parser.cc (c_parser_oacc_compute_clause_self): New function.
(c_parser_oacc_all_clauses): Add new 'bool compute_p = false'
parameter, add parsing of self clause when compute_p is true.
(OACC_KERNELS_CLAUSE_MASK): Add PRAGMA_OACC_CLAUSE_SELF.
(OACC_PARALLEL_CLAUSE_MASK): Likewise,
(OACC_SERIAL_CLAUSE_MASK): Likewise.
(c_parser_oacc_compute): Adjust call to c_parser_oacc_all_clauses to
set compute_p argument to true.
* c-typeck.cc (c_finish_omp_clauses): Add OMP_CLAUSE_SELF case.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_oacc_compute_clause_self): New function.
(cp_parser_oacc_all_clauses): Add new 'bool compute_p = false'
parameter, add parsing of self clause when compute_p is true.
(OACC_KERNELS_CLAUSE_MASK): Add PRAGMA_OACC_CLAUSE_SELF.
(OACC_PARALLEL_CLAUSE_MASK): Likewise,
(OACC_SERIAL_CLAUSE_MASK): Likewise.
(cp_parser_oacc_compute): Adjust call to c_parser_oacc_all_clauses to
set compute_p argument to true.
* pt.cc (tsubst_omp_clauses): Add OMP_CLAUSE_SELF case.
* c-typeck.cc (c_finish_omp_clauses): Add OMP_CLAUSE_SELF case, merged
with OMP_CLAUSE_IF case.

gcc/fortran/ChangeLog:

* gfortran.h (typedef struct gfc_omp_clauses): Add self_expr field.
* openmp.cc (enum omp_mask2): Add OMP_CLAUSE_SELF.
(gfc_match_omp_clauses): Add handling for OMP_CLAUSE_SELF.
(OACC_PARALLEL_CLAUSES): Add OMP_CLAUSE_SELF.
(OACC_KERNELS_CLAUSES): Likewise.
(OACC_SERIAL_CLAUSES): Likewise.
(resolve_omp_clauses): Add handling for omp_clauses->self_expr.
* trans-openmp.cc (gfc_trans_omp_clauses): Add handling of
clauses->self_expr and building of OMP_CLAUSE_SELF tree clause.
(gfc_split_omp_clauses): Add handling of self_expr field copy.

gcc/ChangeLog:

* gimplify.cc (gimplify_scan_omp_clauses): Add OMP_CLAUSE_SELF case.
(gimplify_adjust_omp_clauses): Likewise.
* omp-expand.cc (expand_omp_target): Add OMP_CLAUSE_SELF expansion code,
* omp-low.cc (scan_sharing_clauses): Add OMP_CLAUSE_SELF case.
* tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_SELF enum.
* tree-nested.cc (convert_nonlocal_omp_clauses): Add OMP_CLAUSE_SELF
case.
(convert_local_omp_clauses): Likewise.
* tree-pretty-print.cc (dump_omp_clause): Add OMP_CLAUSE_SELF case.
* tree.cc (omp_clause_num_ops): Add OMP_CLAUSE_SELF entry.
(omp_clause_code_name): Likewise.
* tree.h (OMP_CLAUSE_SELF_EXPR): New macro.

gcc/testsuite/ChangeLog:

* c-c++-common/goacc/self-clause-1.c: New test.
* c-c++-common/goacc/self-clause-2.c: New test.
* gfortran.dg/goacc/self.f95: New test.

include/ChangeLog:

* gomp-constants.h (GOACC_FLAG_LOCAL_DEVICE): New flag bit value.

libgomp/ChangeLog:

* oacc-parallel.c (GOACC_parallel_keyed): Add code to handle
GOACC_FLAG_LOCAL_DEVICE case.
* testsuite/libgomp.oacc-c-c++-common/self-1.c: New test.From 449883981c8e1f707b47ff8f8dd70049b9ffda82 Mon Sep 17 00:00:00 2001
From: Chung-Lin Tang 
Date: Tue, 13 Jun 2023 08:44:31 -0700
Subject: [PATCH] OpenACC 2.7: Implement self clause for compute constructs

This patch implements the 'self' clause for compute constructs: parallel,
kernels, and serial. This clause conditionally uses the local device
(the host mult-core CPU) as the executing device of the compute region.

The actual implementation of the "local device" device type inside libgomp
(presumably using pthreads) is still not yet completed, so the libgomp
side is still implemented the exact same as host-fallback mode. (so as of now,
it essentially behaves like the 'if' clause with the condition inverted)

gcc/c/ChangeLog:

* c-parser.cc (c_parser_oacc_compute_clause_self): New function.
(c_parser_oacc_all_clauses): Add new 'bool compute_p = false'
parameter, add parsing of self clause when compute_p is true.
(OACC_KERNELS_CLAUSE_MASK): Add PRAGMA_OACC_CLAUSE_SELF.
(OACC_PARALLEL_CLAUSE_MASK): Likewise,
(OACC_SERIAL_CLAUSE_MASK): Likewise.
(c_parser_oacc_compute): Adjust call to c_parser_oacc_all_clauses to
set compute_p argument to true.
* c-typeck.cc (c_finish_omp_clauses): Add OMP_CLAUSE_SELF case.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_oacc_compute_c

  1   2   >