[gcc(refs/users/meissner/heads/work169-tar)] Fix up TAR errors

2024-06-21 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:9ca952ceea056ad90a88cb664b400365e5556b4b

commit 9ca952ceea056ad90a88cb664b400365e5556b4b
Author: Michael Meissner 
Date:   Fri Jun 21 03:22:32 2024 -0400

Fix up TAR errors

2024-06-21  Michael Meissner  

* config/rs6000/rs6000.md (movcc_): Add alternatives to 
allowing
Cmode and floating point (under debug switches) back.  Add support 
for
the TAR register.
(movsf_hardfloat): Likewise.
(movsd_hardfloat): Likewise.
(mov_softfloat): Likewise.
(mov_hardfloat64): Likewise.
(mov_softfloat64): Likewise.
* lra-constraints.cc (lra_constraints): Change internal_error to
fatal_insn.

Diff:
---
 gcc/config/rs6000/rs6000.md | 117 +---
 gcc/lra-constraints.cc  |  13 +++--
 2 files changed, 78 insertions(+), 52 deletions(-)

diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index a42443ef0081..73aac467e74c 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -8120,9 +8120,9 @@
 
 (define_insn "*movcc_"
   [(set (match_operand:CC_any 0 "nonimmediate_operand"
-   "=y,x,?y,y,r,r,r,r,r,m")
+   "=y,x,?y,y,r,r,r,r, r,*c*l,r,m")
(match_operand:CC_any 1 "general_operand"
-   " y,r, r,O,x,y,r,I,m,r"))]
+   " y,r, r,O,x,y,r,I,*h,   r,m,r"))]
   "register_operand (operands[0], mode)
|| register_operand (operands[1], mode)"
   "@
@@ -8134,6 +8134,8 @@
mfcr %0%Q1\;rlwinm %0,%0,%f1,0xf000
mr %0,%1
li %0,%1
+   mf%1 %0
+   mt%0 %1
lwz%U1%X1 %0,%1
stw%U0%X0 %1,%0"
   [(set_attr_alternative "type"
@@ -8147,9 +8149,11 @@
(const_string "mfcrf") (const_string "mfcr"))
   (const_string "integer")
   (const_string "integer")
+  (const_string "mfjmpr")
+  (const_string "mtjmpr")
   (const_string "load")
   (const_string "store")])
-   (set_attr "length" "*,*,12,*,*,8,*,*,*,*")])
+   (set_attr "length" "*,*,12,*,*,8,*,*,*,*,*,*")])
 
 ;; For floating-point, we normally deal with the floating-point registers
 ;; unless -msoft-float is used.  The sole exception is that parameter passing
@@ -8200,17 +8204,17 @@
 ;;
 ;; LWZ  LFSLXSSP   LXSSPX STFS   STXSSP
 ;; STXSSPX  STWXXLXOR  LI FMRXSCPSGNDP
-;; MR   XXSPLTIDP
+;; MR   MT  MF   NOPXXSPLTIDP
 
 (define_insn "movsf_hardfloat"
   [(set (match_operand:SF 0 "nonimmediate_operand"
 "=!r,   f, v,  wa,m, wY,
  Z, m, wa, !r,f, wa,
- !r,wa")
+ !r,*wt*c*l,   !r, *h,wa")
(match_operand:SF 1 "input_operand"
 "m, m, wY, Z, f, v,
  wa,r, j,  j, f, wa,
- r, eP"))]
+ r, r, *h, 0, eP"))]
   "(register_operand (operands[0], SFmode)
|| register_operand (operands[1], SFmode))
&& TARGET_HARD_FLOAT
@@ -8230,29 +8234,32 @@
fmr %0,%1
xscpsgndp %x0,%x1,%x1
mr %0,%1
+   mt%0 %1
+   mf%1 %0
+   nop
#"
   [(set_attr "type"
"load,   fpload,fpload, fpload,fpstore,   fpstore,
 fpstore,store, veclogical, integer,   fpsimple,  fpsimple,
-*,  vecperm")
+*,  mtjmpr,mfjmpr, *, vecperm")
(set_attr "isa"
"*,  *, p9v,p8v,   *, p9v,
 p8v,*, *,  *, *, *,
-*,  p10")
+*,  *, *,  *, p10")
(set_attr "prefixed"
"*,  *, *,  *, *, *,
 *,  *, *,  *, *, *,
-*,  yes")])
+*,  *, *,  *, yes")])
 
 ;; LWZ  LFIWZX STWSTFIWX MTVSRWZMFVSRWZ
-;; FMR  MR
+;; FMR  MR MT%0   MF%1   NOP
 (define_insn "movsd_hardfloat"
   [(set (match_operand:SD 0 "nonimmediate_operand"
 "=!r,   d, m, ?Z,?d,?r,
- f, !r")
+ f, !r,*wt*c*l,   !r,*h")
(match_operand:SD 1 "input_operand"
 "m, ?Z,r, wx,r, d,
- f, r"))]
+ f, r, r, *h,0"))]
   "(register_operand (operands[0], SDmode)
|| register_operand (operands[1], SDmode))
&& TARGET_HARD_FLOAT"
@@ -8264,43 +8271,49 @@
mtvsrwz %x0,%1
mfvsrwz %0,%x1
fmr %0,%1
-   mr %0,%1"
+   mr %0,%1
+   mt

[gcc(refs/users/meissner/heads/work169-tar)] Add -mlrspr.

2024-06-21 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:9d922e12e93504f2c4e2622564a52fe8597e2934

commit 9d922e12e93504f2c4e2622564a52fe8597e2934
Author: Michael Meissner 
Date:   Fri Jun 21 03:26:03 2024 -0400

Add -mlrspr.

2024-06-21  Michael Meissner  

gcc/

* config/rs6000/rs6000.cc (rs6000_hard_regno_mode_ok_uncached): Add
support for -mlrspr.
* config/rs6000/rs6000.opt (-mlrspr): New debug option.

Diff:
---
 gcc/config/rs6000/rs6000.cc  | 4 +++-
 gcc/config/rs6000/rs6000.opt | 4 
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 2eaa88a6d633..ca5514510608 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -1949,7 +1949,9 @@ rs6000_hard_regno_mode_ok_uncached (int regno, 
machine_mode mode)
   return (!orig_complex_p && mode == SImode);
 
 case LR_REGNO:
-  return (!orig_complex_p && mode == Pmode);
+  if (!TARGET_LRSPR)
+   return (!orig_complex_p && mode == Pmode);
+  /* fall through.  */
 
 case CTR_REGNO:
 case TAR_REGNO:
diff --git a/gcc/config/rs6000/rs6000.opt b/gcc/config/rs6000/rs6000.opt
index f339e1bed39a..b4b6dc8fa9ca 100644
--- a/gcc/config/rs6000/rs6000.opt
+++ b/gcc/config/rs6000/rs6000.opt
@@ -666,6 +666,10 @@ mfpspr
 Target Undocumented Var(TARGET_FPSPR) Init(0)
 Allow (do not allow) floating point values to be in the CTR or TAR registers.
 
+mlrspr
+Target Undocumented Var(TARGET_LRSPR) Init(1)
+Treat (do not treat) the LR register like CTR/TAR in terms of what modes it 
can hold.
+
 ; Documented parameters
 
 -param=rs6000-vect-unroll-limit=


[gcc(refs/users/meissner/heads/work169-tar)] Update ChangeLog.*

2024-06-21 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:800d2947fa8297ea9871c59d520fc5e429d4263b

commit 800d2947fa8297ea9871c59d520fc5e429d4263b
Author: Michael Meissner 
Date:   Fri Jun 21 03:27:20 2024 -0400

Update ChangeLog.*

Diff:
---
 gcc/ChangeLog.tar | 29 +
 1 file changed, 29 insertions(+)

diff --git a/gcc/ChangeLog.tar b/gcc/ChangeLog.tar
index 21a1d759e9f4..c5b3554401df 100644
--- a/gcc/ChangeLog.tar
+++ b/gcc/ChangeLog.tar
@@ -1,3 +1,32 @@
+ Branch work169-tar, patch #204 
+
+Add -mlrspr.
+
+2024-06-21  Michael Meissner  
+
+gcc/
+
+   * config/rs6000/rs6000.cc (rs6000_hard_regno_mode_ok_uncached): Add
+   support for -mlrspr.
+   * config/rs6000/rs6000.opt (-mlrspr): New debug option.
+
+ Branch work169-tar, patch #203 
+
+Fix up TAR errors
+
+2024-06-21  Michael Meissner  
+
+   * config/rs6000/rs6000.md (movcc_): Add alternatives to allowing
+   Cmode and floating point (under debug switches) back.  Add support for
+   the TAR register.
+   (movsf_hardfloat): Likewise.
+   (movsd_hardfloat): Likewise.
+   (mov_softfloat): Likewise.
+   (mov_hardfloat64): Likewise.
+   (mov_softfloat64): Likewise.
+   * lra-constraints.cc (lra_constraints): Change internal_error to
+   fatal_insn.
+
  Branch work169-tar, patch #202 
 
 Add options for modes in SPR registers.


[gcc/aoliva/heads/testme] [testsuite] [arm] [vect] adjust mve-vshr test [PR113281]

2024-06-21 Thread Alexandre Oliva via Gcc-cvs
The branch 'aoliva/heads/testme' was updated to point to:

 7c42cd96b6bf... [testsuite] [arm] [vect] adjust mve-vshr test [PR113281]

It previously pointed to:

 d47e880e8b59... [testsuite] [arm] [vect] adjust mve-vshr test [PR113281]

Diff:

!!! WARNING: THE FOLLOWING COMMITS ARE NO LONGER ACCESSIBLE (LOST):
---

  d47e880... [testsuite] [arm] [vect] adjust mve-vshr test [PR113281]


Summary of changes (added commits):
---

  7c42cd9... [testsuite] [arm] [vect] adjust mve-vshr test [PR113281]


[gcc(refs/users/aoliva/heads/testme)] [testsuite] [arm] [vect] adjust mve-vshr test [PR113281]

2024-06-21 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:7c42cd96b6bffca9122910e170f6d6f264320ecb

commit 7c42cd96b6bffca9122910e170f6d6f264320ecb
Author: Alexandre Oliva 
Date:   Thu Jun 20 07:26:40 2024 -0300

[testsuite] [arm] [vect] adjust mve-vshr test [PR113281]

The test was too optimistic, alas.  We used to vectorize shifts
involving 8-bit and 16-bit integral types by clamping the shift count
at the highest in-range shift count, but that was not correct: such
narrow shifts expect integral promotion, so larger shift counts should
be accepted.  (int16_t)32768 >> (int16_t)16 must yield 0, not 1 (as
before the fix).

Unfortunately, in the gimple model of vector units, such large shift
counts wouldn't be well-defined, so we won't vectorize such shifts any
more, unless we can tell they're in range or undefined.

So the test that expected the incorrect clamping we no longer perform
needs to be adjusted.  Instead of nobbling the test, Richard Earnshaw
suggested annotating the test with the expected ranges so as to enable
the optimization.


Co-Authored-By: Richard Earnshaw 

for  gcc/testsuite/ChangeLog

PR tree-optimization/113281
* gcc.target/arm/simd/mve-vshr.c: Add expected ranges.

Diff:
---
 gcc/testsuite/gcc.target/arm/simd/mve-vshr.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/testsuite/gcc.target/arm/simd/mve-vshr.c 
b/gcc/testsuite/gcc.target/arm/simd/mve-vshr.c
index 8c7adef9ed8f..03078de49c65 100644
--- a/gcc/testsuite/gcc.target/arm/simd/mve-vshr.c
+++ b/gcc/testsuite/gcc.target/arm/simd/mve-vshr.c
@@ -9,6 +9,8 @@
   void test_ ## NAME ##_ ## SIGN ## BITS ## x ## NB (TYPE##BITS##_t * 
__restrict__ dest, TYPE##BITS##_t *a, TYPE##BITS##_t *b) { \
 int i; \
 for (i=0; i= (unsigned)(BITS))  \
+   __builtin_unreachable();\
   dest[i] = a[i] OP b[i];  \
 }  \
 }


[gcc r15-1509] ada: Spurious style error with mutiple square brackets

2024-06-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:3ebd803b861e1da85f08664915e3267f690ff611

commit r15-1509-g3ebd803b861e1da85f08664915e3267f690ff611
Author: Justin Squirek 
Date:   Thu May 9 20:16:24 2024 +

ada: Spurious style error with mutiple square brackets

This patch fixes a spurious error in the compiler when checking for style 
for
token separation where two square brackets are next to each other.

gcc/ada/

* csets.ads (Identifier_Char): New function - replacing table.
* csets.adb (Identifier_Char): Rename and move table for static 
values.
(Initialize): Remove dynamic calculations.
(Identifier_Char): New function to calculate dynamic values.
* opt.adb (Set_Config_Switches): Remove setting of Identifier_Char.

Diff:
---
 gcc/ada/csets.adb | 46 --
 gcc/ada/csets.ads | 14 +++---
 gcc/ada/opt.adb   |  3 ---
 3 files changed, 43 insertions(+), 20 deletions(-)

diff --git a/gcc/ada/csets.adb b/gcc/ada/csets.adb
index 7e5af3ffa171..54ebdb46b6cd 100644
--- a/gcc/ada/csets.adb
+++ b/gcc/ada/csets.adb
@@ -29,6 +29,12 @@ with System.WCh_Con; use System.WCh_Con;
 
 package body Csets is
 
+   Identifier_Char_Table : Char_Array_Flags;
+   --  This table contains all statically known characters which can appear in
+   --  identifiers, but excludes characters which need to be known dynamically,
+   --  for example like those that depend on the current Ada version which may
+   --  change from file to file.
+
X_80 : constant Character := Character'Val (16#80#);
X_81 : constant Character := Character'Val (16#81#);
X_82 : constant Character := Character'Val (16#82#);
@@ -1085,6 +1091,34 @@ package body Csets is
 
   others => ' ');
 
+   -
+   -- Identifier_Char --
+   -
+
+   function Identifier_Char (Item : Character) return Boolean is
+   begin
+  --  Handle explicit dynamic cases
+
+  case Item is
+
+ --  Add [ as an identifier character to deal with the brackets
+ --  notation for wide characters used in identifiers for versions up
+ --  to Ada 2012.
+
+ --  Note that if we are not allowing wide characters in identifiers,
+ --  then any use of this notation will be flagged as an error in
+ --  Scan_Identifier.
+
+ when '[' | ']' =>
+return Ada_Version < Ada_2022;
+
+ --  Otherwise, this is a static case - use the table
+
+ when others =>
+return Identifier_Char_Table (Item);
+  end case;
+   end Identifier_Char;
+

-- Initialize --

@@ -1144,24 +1178,16 @@ package body Csets is
   --  Build Identifier_Char table from used entries of Fold_Upper
 
   for J in Character loop
- Identifier_Char (J) := (Fold_Upper (J) /= ' ');
+ Identifier_Char_Table (J) := (Fold_Upper (J) /= ' ');
   end loop;
 
-  --  Add [ as an identifier character to deal with the brackets notation
-  --  for wide characters used in identifiers for versions up to Ada 2012.
-  --  Note that if we are not allowing wide characters in identifiers, then
-  --  any use of this notation will be flagged as an error in
-  --  Scan_Identifier.
-
-  Identifier_Char ('[') := Ada_Version < Ada_2022;
-
   --  Add entry for ESC if wide characters in use with a wide character
   --  encoding method active that uses the ESC code for encoding.
 
   if Identifier_Character_Set = 'w'
 and then Wide_Character_Encoding_Method in WC_ESC_Encoding_Method
   then
- Identifier_Char (ASCII.ESC) := True;
+ Identifier_Char_Table (ASCII.ESC) := True;
   end if;
end Initialize;
 
diff --git a/gcc/ada/csets.ads b/gcc/ada/csets.ads
index 9dc78ba10e87..f0930df47dbe 100644
--- a/gcc/ada/csets.ads
+++ b/gcc/ada/csets.ads
@@ -80,12 +80,12 @@ package Csets is
Fold_Lower : Translate_Table;
--  Table to fold upper case identifier letters to lower case
 
-   Identifier_Char : Char_Array_Flags;
-   --  This table has True entries for all characters that can legally appear
-   --  in identifiers, including digits, the underline character, all letters
-   --  including upper and lower case and extended letters (as controlled by
-   --  the setting of Opt.Identifier_Character_Set), left bracket for brackets
-   --  notation wide characters and also ESC if wide characters are permitted
-   --  in identifiers using escape sequences starting with ESC.
+   function Identifier_Char (Item : Character) return Boolean;
+   --  Return True for all characters that can legally appear in identifiers,
+   --  including digits, the underline character, all letters including upper
+   --  and lower case and extended letters (as controlled by the setting of
+   --  Opt.Identifier_Character_Set), left bracket for brackets notation wide
+   --  characters and also ESC if wide char

[gcc r15-1510] ada: Fix for Default_Component_Value with declare expressions

2024-06-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:a0546a36e007d1def02f5a575d1b4e2a08a66115

commit r15-1510-ga0546a36e007d1def02f5a575d1b4e2a08a66115
Author: Piotr Trojanek 
Date:   Thu May 16 10:59:31 2024 +0200

ada: Fix for Default_Component_Value with declare expressions

When the expression of aspect Default_Component_Value includes a declare
expression with current type instance, we attempted to recursively froze
that type, which itself caused an infinite recursion, because we didn't
properly manage the scope of declare expression.

This patch fixes both the detection of the current type instance and
analysis of the expression that caused recursive freezing.

gcc/ada/

* sem_attr.adb (In_Aspect_Specification): Use the standard
condition that works correctly with declare expressions.
* sem_ch13.adb (Analyze_Aspects_At_Freeze_Point): Replace
ordinary analysis with preanalysis of spec expressions.

Diff:
---
 gcc/ada/sem_attr.adb |  4 +++-
 gcc/ada/sem_ch13.adb | 12 ++--
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
index 72f5ab491759..d56c25a79cc8 100644
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -1843,7 +1843,9 @@ package body Sem_Attr is
if Nkind (P) = N_Aspect_Specification then
   return P_Type = Entity (P);
 
-   elsif Nkind (P) in N_Declaration then
+   --  Prevent the search from going too far
+
+   elsif Is_Body_Or_Package_Declaration (P) then
   return False;
end if;
 
diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index 4012932a6f21..a86f774018a3 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -1037,11 +1037,19 @@ package body Sem_Ch13 is
 
  Parent_Type : Entity_Id;
 
+ Save_In_Spec_Expression : constant Boolean := In_Spec_Expression;
+
   begin
  --  Ensure Expr is analyzed so that e.g. all types are properly
- --  resolved for Find_Type_Reference.
+ --  resolved for Find_Type_Reference. We preanalyze this expression
+ --  as a spec expression (to avoid recursive freezing), while skipping
+ --  resolution (to not fold type self-references, e.g. T'Last).
 
- Analyze (Expr);
+ In_Spec_Expression := True;
+
+ Preanalyze (Expr);
+
+ In_Spec_Expression := Save_In_Spec_Expression;
 
  --  A self-referential aspect is illegal if it forces freezing the
  --  entity before the corresponding aspect has been analyzed.


[gcc r15-1511] ada: Fix assertion failure on predicate involving access parameter

2024-06-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:c5aed359a563c48f616d58f708c398f8494d7731

commit r15-1511-gc5aed359a563c48f616d58f708c398f8494d7731
Author: Eric Botcazou 
Date:   Tue May 21 19:49:32 2024 +0200

ada: Fix assertion failure on predicate involving access parameter

The assertion fails because the Original_Node of the expression has no Etype
since its an unanalyzed identifier.

gcc/ada/

* accessibility.adb (Accessibility_Level): Apply the processing to
Expr when its Original_Node is an unanalyzed identifier.

Diff:
---
 gcc/ada/accessibility.adb | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/accessibility.adb b/gcc/ada/accessibility.adb
index da4d1d9ce2e2..298103377a7b 100644
--- a/gcc/ada/accessibility.adb
+++ b/gcc/ada/accessibility.adb
@@ -398,7 +398,7 @@ package body Accessibility is
 
   --  Local variables
 
-  E   : Node_Id := Original_Node (Expr);
+  E   : Node_Id;
   Pre : Node_Id;
 
--  Start of processing for Accessibility_Level
@@ -409,6 +409,17 @@ package body Accessibility is
 
   if Present (Param_Entity (Expr)) then
  E := Param_Entity (Expr);
+
+  --  Use the original node unless it is an unanalyzed identifier, as we
+  --  don't want to reason on unanalyzed expressions from predicates.
+
+  elsif Nkind (Original_Node (Expr)) /= N_Identifier
+or else Analyzed (Original_Node (Expr))
+  then
+ E := Original_Node (Expr);
+
+  else
+ E := Expr;
   end if;
 
   --  Extract the entity


[gcc r15-1512] ada: Predefined arithmetic operators incorrectly treated as directly visible

2024-06-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:244d02bb288a07f3252fc9ed38675b93a9a91225

commit r15-1512-g244d02bb288a07f3252fc9ed38675b93a9a91225
Author: Steve Baird 
Date:   Thu May 23 17:11:42 2024 -0700

ada: Predefined arithmetic operators incorrectly treated as directly visible

In some cases, a predefined operator (e.g., the "+" operator for an
integer type) is incorrectly treated as being directly visible when
it is not. This can lead to both accepting operator uses that should
be rejected and also to incorrectly rejecting legal constructs as ambiguous
(for example, an expression "Foo + 1" where Foo is an overloaded function 
and
the "+" operator is directly visible for the result type of only one of
the possible callees).

gcc/ada/

* sem_ch4.adb (Is_Effectively_Visible_Operator): A new function.
(Check_Arithmetic_Pair): In paths where Add_One_Interp was
previously called unconditionally, instead call only if
Is_Effectively_Visible_Operator returns True.
(Check_Boolean_Pair): Likewise.
(Find_Unary_Types): Likewise.

Diff:
---
 gcc/ada/sem_ch4.adb | 22 +-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
index 1175a34df218..dfeff02a011b 100644
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -270,6 +270,18 @@ package body Sem_Ch4 is
--  these aspects can be achieved without larger modifications to the
--  two-pass resolution algorithm.
 
+   function Is_Effectively_Visible_Operator
+ (N : Node_Id; Typ : Entity_Id) return Boolean
+   is (Is_Visible_Operator (N => N, Typ => Typ)
+ or else
+   --  test for a rewritten Foo."+" call
+   (N /= Original_Node (N)
+ and then Is_Effectively_Visible_Operator
+(N => Original_Node (N), Typ => Typ))
+ or else not Comes_From_Source (N));
+   --  Return True iff either Is_Visible_Operator returns True or if
+   --  there is a reason it is ok for Is_Visible_Operator to return False.
+
function Possible_Type_For_Conditional_Expression
  (T1, T2 : Entity_Id) return Entity_Id;
--  Given two types T1 and T2 that are _not_ compatible, return a type that
@@ -6641,6 +6653,8 @@ package body Sem_Ch4 is
and then (Covers (T1 => T1, T2 => T2)
or else
  Covers (T1 => T2, T2 => T1))
+   and then Is_Effectively_Visible_Operator
+  (N, Specific_Type (T1, T2))
  then
 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
  end if;
@@ -6670,6 +6684,8 @@ package body Sem_Ch4 is
and then (Covers (T1 => T1, T2 => T2)
or else
  Covers (T1 => T2, T2 => T1))
+   and then Is_Effectively_Visible_Operator
+  (N, Specific_Type (T1, T2))
  then
 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
 
@@ -6713,6 +6729,8 @@ package body Sem_Ch4 is
and then (Covers (T1 => T1, T2 => T2)
or else
  Covers (T1 => T2, T2 => T1))
+   and then Is_Effectively_Visible_Operator
+  (N, Specific_Type (T1, T2))
  then
 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
  end if;
@@ -7086,6 +7104,7 @@ package body Sem_Ch4 is
T := Any_Modular;
 end if;
 
+--  test Is_Effectively_Visible_Operator here ???
 Add_One_Interp (N, Op_Id, T);
  end if;
   end Check_Boolean_Pair;
@@ -7615,7 +7634,8 @@ package body Sem_Ch4 is
then
   null;
 
-   else
+   elsif Is_Effectively_Visible_Operator (N, Base_Type (It.Typ))
+   then
   Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
end if;
 end if;


[gcc r15-1513] ada: Fix gnatcheck violation reported after a recent cleanup

2024-06-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:39f35956587fe09fbdb87ebd203df6e3674f7b59

commit r15-1513-g39f35956587fe09fbdb87ebd203df6e3674f7b59
Author: Piotr Trojanek 
Date:   Wed Apr 17 14:58:24 2024 +0200

ada: Fix gnatcheck violation reported after a recent cleanup

Code cleanup; semantics is unaffected.

gcc/ada/

* sem_ch3.adb (Add_Interface_Tag_Components): Simplify with No.

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

diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index eebaedc216bc..a1112d7b44ae 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -1618,7 +1618,7 @@ package body Sem_Ch3 is
 
   Last_Tag := Empty;
 
-  if not Present (Component_List (Ext)) then
+  if No (Component_List (Ext)) then
  Set_Null_Present (Ext, False);
  L := New_List;
  Set_Component_List (Ext,


[gcc r15-1514] ada: Generic formal/actual matching -- misc cleanup

2024-06-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:9ce1b11e154a930de3ba20b9e26af5631a73c7f3

commit r15-1514-g9ce1b11e154a930de3ba20b9e26af5631a73c7f3
Author: Bob Duff 
Date:   Thu May 30 15:16:47 2024 -0400

ada: Generic formal/actual matching -- misc cleanup

The only substantive change is to remove Activation_Chain_Entity
from N_Generic_Package_Declaration. The comment in sinfo.ads suggesting
this change was written in 1993!

Various pieces of missing documentation are added to Sinfo and Einfo.

Also other minor cleanups.

gcc/ada/

* gen_il-gen-gen_nodes.adb
(N_Generic_Package_Declaration): Remove Activation_Chain_Entity.
* sinfo.ads: Comment improvements. Add missing doc.
Remove obsolete comment about Activation_Chain_Entity.
* einfo.ads: Comment improvements. Add missing doc.
* einfo-utils.adb (Base_Type): Add Assert (disabled for now).
(Next_Index): Minor cleanup.
* aspects.ads: Minor comment fix.
* exp_ch6.adb: Likewise.
* sem_ch3.adb: Likewise.

Diff:
---
 gcc/ada/aspects.ads  |  2 +-
 gcc/ada/einfo-utils.adb  | 29 -
 gcc/ada/einfo.ads| 29 +++--
 gcc/ada/exp_ch6.adb  |  4 ++--
 gcc/ada/gen_il-gen-gen_nodes.adb |  3 +--
 gcc/ada/sem_ch3.adb  |  4 ++--
 gcc/ada/sinfo.ads| 32 ++--
 7 files changed, 59 insertions(+), 44 deletions(-)

diff --git a/gcc/ada/aspects.ads b/gcc/ada/aspects.ads
index 140fb7c8fe12..cf992a89038f 100644
--- a/gcc/ada/aspects.ads
+++ b/gcc/ada/aspects.ads
@@ -1176,7 +1176,7 @@ package Aspects is
  Class_Present : Boolean := False;
  Or_Rep_Item   : Boolean := False) return Node_Id;
--  Find the aspect specification of aspect A (or A'Class if Class_Present)
-   --  associated with entity I.
+   --  associated with entity Id.
--  If found, then return the aspect specification.
--  If not found and Or_Rep_Item is true, then look for a representation
--  item (as opposed to an N_Aspect_Specification node) which specifies
diff --git a/gcc/ada/einfo-utils.adb b/gcc/ada/einfo-utils.adb
index 438868ac7573..4c86ba1c3b19 100644
--- a/gcc/ada/einfo-utils.adb
+++ b/gcc/ada/einfo-utils.adb
@@ -664,12 +664,22 @@ package body Einfo.Utils is
 
function Base_Type (Id : E) return E is
begin
-  if Is_Base_Type (Id) then
- return Id;
-  else
- pragma Assert (Is_Type (Id));
- return Etype (Id);
-  end if;
+  return Result : E do
+ if Is_Base_Type (Id) then
+Result := Id;
+ else
+pragma Assert (Is_Type (Id));
+Result := Etype (Id);
+if False then
+   pragma Assert (Is_Base_Type (Result));
+   --  ???It seems like Base_Type should return a base type,
+   --  but this assertion is disabled because it is not always
+   --  true. Hence the need to say "Base_Type (Base_Type (...))"
+   --  in some cases; Base_Type is not idempotent as one might
+   --  expect.
+end if;
+ end if;
+  end return;
end Base_Type;
 
--
@@ -2018,10 +2028,11 @@ package body Einfo.Utils is

 
function Next_Index (Id : N) return Node_Id is
-   begin
   pragma Assert (Nkind (Id) in N_Is_Index);
-  pragma Assert (No (Next (Id)) or else Nkind (Next (Id)) in N_Is_Index);
-  return Next (Id);
+  Result : constant Node_Id := Next (Id);
+  pragma Assert (No (Result) or else Nkind (Result) in N_Is_Index);
+   begin
+  return Result;
end Next_Index;
 
--
diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads
index 8ee419b3e071..dd95ea051c1b 100644
--- a/gcc/ada/einfo.ads
+++ b/gcc/ada/einfo.ads
@@ -1334,7 +1334,7 @@ package Einfo is
 --First_Component (synthesized)
 --   Applies to incomplete, private, protected, record and task types.
 --   Returns the first component by following the chain of declared
---   entities for the type a component is found (one with an Ekind of
+--   entities for the type until a component is found (one with an Ekind of
 --   E_Component). The discriminants are skipped. If the record is null,
 --   then Empty is returned.
 
@@ -1342,6 +1342,10 @@ package Einfo is
 --   Similar to First_Component, but discriminants are not skipped, so will
 --   find the first discriminant if discriminants are present.
 
+--First_Discriminant (synthesized)
+--   Defined for types with discriminants or unknown discriminants.
+--   Returns the first in the Next_Discriminant chain; see Sem_Aux.
+
 --First_Entity
 --   Defined in all entities that act as scopes to which a list of
 --   associated entities is attached, and al

[gcc r15-1515] ada: Fix incorrect handling of packed array with aliased composite components

2024-06-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:8c7ce88c00f9bea9fb6f7e466c8706439fb5b131

commit r15-1515-g8c7ce88c00f9bea9fb6f7e466c8706439fb5b131
Author: Eric Botcazou 
Date:   Fri May 31 00:13:44 2024 +0200

ada: Fix incorrect handling of packed array with aliased composite 
components

The problem is that the handling of the interaction between packing and
aliased/atomic/independent components of an array type is tied to that of
the interaction between a component clause and aliased/atomic/independent
components, although the semantics are different: packing is a best effort
thing, whereas a component clause must be honored or else an error be given.

This decouples the two handlings, but retrofits the separate processing of
independent components done in both cases into the common code and changes
the error message from "minimum allowed is" to "minimum allowed value is"
for the sake of consistency with the aliased/atomic processing.

gcc/ada/

* freeze.adb (Freeze_Array_Type): Decouple the handling of the
interaction between packing and aliased/atomic components from
that of the interaction between a component clause and aliased/
atomic components, and retrofit the processing of the interaction
between the two characteristics and independent components into
the common processing.

gcc/testsuite/ChangeLog:

* gnat.dg/atomic10.adb: Adjust.

Diff:
---
 gcc/ada/freeze.adb | 190 ++---
 gcc/testsuite/gnat.dg/atomic10.adb |   4 +-
 2 files changed, 93 insertions(+), 101 deletions(-)

diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
index 1867880b314b..29733a17a56c 100644
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -3634,7 +3634,9 @@ package body Freeze is
   procedure Freeze_Array_Type (Arr : Entity_Id) is
  FS : constant Entity_Id := First_Subtype (Arr);
  Ctyp   : constant Entity_Id := Component_Type (Arr);
- Clause : Entity_Id;
+
+ Clause : Node_Id;
+ --  Set to Component_Size clause or Atomic pragma, if any
 
  Non_Standard_Enum : Boolean := False;
  --  Set true if any of the index types is an enumeration type with a
@@ -3710,76 +3712,57 @@ package body Freeze is
end;
 end if;
 
---  Check for Aliased or Atomic_Components or Full Access with
---  unsuitable packing or explicit component size clause given.
-
-if (Has_Aliased_Components (Arr)
- or else Has_Atomic_Components (Arr)
- or else Is_Full_Access (Ctyp))
-  and then
-(Has_Component_Size_Clause (Arr) or else Is_Packed (Arr))
-then
-   Alias_Atomic_Check : declare
+--  Check for Aliased or Atomic or Full Access or Independent
+--  components with an unsuitable component size clause given.
+--  The main purpose is to give an error when bit packing would
+--  be required to honor the component size, because bit packing
+--  is incompatible with these aspects; when bit packing is not
+--  required, the final validation of the component size may be
+--  left to the back end.
 
-  procedure Complain_CS (T : String);
-  --  Outputs error messages for incorrect CS clause or pragma
-  --  Pack for aliased or full access components (T is either
-  --  "aliased" or "atomic" or "volatile full access");
+if Has_Component_Size_Clause (Arr) then
+   CS_Check : declare
+  procedure Complain_CS (T : String; Min : Boolean := False);
+  --  Output an error message for an unsuitable component size
+  --  clause for independent components (T is either "aliased"
+  --  or "atomic" or "volatile full access" or "independent").
 
   -
   -- Complain_CS --
   -
 
-  procedure Complain_CS (T : String) is
+  procedure Complain_CS (T : String; Min : Boolean := False) is
   begin
- if Has_Component_Size_Clause (Arr) then
-Clause :=
-  Get_Attribute_Definition_Clause
-(FS, Attribute_Component_Size);
+ Clause :=
+   Get_Attribute_Definition_Clause
+ (FS, Attribute_Component_Size);
 
-Error_Msg_N
-  ("incorrect component size for "
-   & T & " components", Clause);
-Error_Msg_Uint_1 := Esize (Ctyp);
-Error_Msg_N
-  ("\only allowed

[gcc r15-1517] ada: Fix missing index check with declare expression

2024-06-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:2b55cc520cf51089d961414a78e6e5371f3c3e20

commit r15-1517-g2b55cc520cf51089d961414a78e6e5371f3c3e20
Author: Eric Botcazou 
Date:   Thu May 30 12:46:57 2024 +0200

ada: Fix missing index check with declare expression

The Do_Range_Check flag is properly set on the Expression of the EWA node
built for the declare expression, so this instructs Generate_Index_Checks
to look into this Expression.

gcc/ada/

* checks.adb (Generate_Index_Checks): Add specific treatment for
index expressions that are N_Expression_With_Actions nodes.

Diff:
---
 gcc/ada/checks.adb | 36 ++--
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb
index bada3dffcbfc..c8a0696be671 100644
--- a/gcc/ada/checks.adb
+++ b/gcc/ada/checks.adb
@@ -7248,7 +7248,8 @@ package body Checks is
   Loc   : constant Source_Ptr := Sloc (N);
   A : constant Node_Id:= Prefix (N);
   A_Ent : constant Entity_Id  := Entity_Of_Prefix;
-  Sub   : Node_Id;
+
+  Expr : Node_Id;
 
--  Start of processing for Generate_Index_Checks
 
@@ -7294,13 +7295,13 @@ package body Checks is
   --  us to omit the check have already been taken into account in the
   --  setting of the Do_Range_Check flag earlier on.
 
-  Sub := First (Expressions (N));
+  Expr := First (Expressions (N));
 
   --  Handle string literals
 
   if Ekind (Etype (A)) = E_String_Literal_Subtype then
- if Do_Range_Check (Sub) then
-Set_Do_Range_Check (Sub, False);
+ if Do_Range_Check (Expr) then
+Set_Do_Range_Check (Expr, False);
 
 --  For string literals we obtain the bounds of the string from the
 --  associated subtype.
@@ -7310,8 +7311,8 @@ package body Checks is
 Condition =>
Make_Not_In (Loc,
  Left_Opnd  =>
-   Convert_To (Base_Type (Etype (Sub)),
- Duplicate_Subexpr_Move_Checks (Sub)),
+   Convert_To (Base_Type (Etype (Expr)),
+ Duplicate_Subexpr_Move_Checks (Expr)),
  Right_Opnd =>
Make_Attribute_Reference (Loc,
  Prefix => New_Occurrence_Of (Etype (A), Loc),
@@ -7330,11 +7331,19 @@ package body Checks is
 Ind : Pos;
 Num : List_Id;
 Range_N : Node_Id;
+Stmt: Node_Id;
+Sub : Node_Id;
 
  begin
 A_Idx := First_Index (Etype (A));
 Ind   := 1;
-while Present (Sub) loop
+while Present (Expr) loop
+   if Nkind (Expr) = N_Expression_With_Actions then
+  Sub := Expression (Expr);
+   else
+  Sub := Expr;
+   end if;
+
if Do_Range_Check (Sub) then
   Set_Do_Range_Check (Sub, False);
 
@@ -7396,7 +7405,7 @@ package body Checks is
  Expressions=> Num);
   end if;
 
-  Insert_Action (N,
+  Stmt :=
 Make_Raise_Constraint_Error (Loc,
   Condition =>
  Make_Not_In (Loc,
@@ -7404,14 +7413,21 @@ package body Checks is
  Convert_To (Base_Type (Etype (Sub)),
Duplicate_Subexpr_Move_Checks (Sub)),
Right_Opnd => Range_N),
-  Reason => CE_Index_Check_Failed));
+  Reason => CE_Index_Check_Failed);
+
+  if Nkind (Expr) = N_Expression_With_Actions then
+ Append_To (Actions (Expr), Stmt);
+ Analyze (Stmt);
+  else
+ Insert_Action (Expr, Stmt);
+  end if;
 
   Checks_Generated.Elements (Ind) := True;
end if;
 
Next_Index (A_Idx);
Ind := Ind + 1;
-   Next (Sub);
+   Next (Expr);
 end loop;
  end;
   end if;


[gcc r15-1516] ada: Fix internal error on case expression used as index of array component

2024-06-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:aa34d34f753cee8974af6942e0603dfc2f8ea160

commit r15-1516-gaa34d34f753cee8974af6942e0603dfc2f8ea160
Author: Eric Botcazou 
Date:   Tue May 28 23:08:32 2024 +0200

ada: Fix internal error on case expression used as index of array component

This occurs when the bounds of the array component depend on a discriminant
and the component reference is not nested, that is to say the component is
not (referenced as) a subcomponent of a larger record.

In this case, Analyze_Selected_Component does not build the actual subtype
for the component, but it turns out to be required for constructs generated
during the analysis of the case expression.

The change causes this actual subtype to be built, and also renames a local
variable used to hold the prefix of the selected component.

gcc/ada/

* sem_ch4.adb (Analyze_Selected_Component): Rename Name into Pref
and use Sel local variable consistently.
(Is_Simple_Indexed_Component): New predicate.
Call Is_Simple_Indexed_Component to determine whether to build an
actual subtype for the component.

Diff:
---
 gcc/ada/sem_ch4.adb | 108 +++-
 1 file changed, 73 insertions(+), 35 deletions(-)

diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
index dfeff02a011b..4e1d1bc7ed76 100644
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -4927,7 +4927,7 @@ package body Sem_Ch4 is
--  the selector must denote a visible entry.
 
procedure Analyze_Selected_Component (N : Node_Id) is
-  Name  : constant Node_Id := Prefix (N);
+  Pref  : constant Node_Id := Prefix (N);
   Sel   : constant Node_Id := Selector_Name (N);
   Act_Decl  : Node_Id;
   Comp  : Entity_Id := Empty;
@@ -4962,8 +4962,11 @@ package body Sem_Ch4 is
   --  indexed component rather than a function call.
 
   function Has_Dereference (Nod : Node_Id) return Boolean;
-  --  Check whether prefix includes a dereference, explicit or implicit,
-  --  at any recursive level.
+  --  Check whether Nod includes a dereference, explicit or implicit, at
+  --  any recursive level.
+
+  function Is_Simple_Indexed_Component (Nod : Node_Id) return Boolean;
+  --  Check whether Nod is a simple indexed component in the context
 
   function Try_By_Protected_Procedure_Prefixed_View return Boolean;
   --  Return True if N is an access attribute whose prefix is a prefixed
@@ -5107,6 +5110,40 @@ package body Sem_Ch4 is
  end if;
   end Has_Dereference;
 
+  -
+  -- Is_Simple_Indexed_Component --
+  -
+
+  function Is_Simple_Indexed_Component (Nod : Node_Id) return Boolean is
+ Expr : Node_Id;
+
+  begin
+ --  Nod must be an indexed component
+
+ if Nkind (Nod) /= N_Indexed_Component then
+return False;
+ end if;
+
+ --  The context must not be a nested selected component
+
+ if Nkind (Pref) = N_Selected_Component then
+return False;
+ end if;
+
+ --  The expressions must not be case expressions
+
+ Expr := First (Expressions (Nod));
+ while Present (Expr) loop
+if Nkind (Expr) = N_Case_Expression then
+   return False;
+end if;
+
+Next (Expr);
+ end loop;
+
+ return True;
+  end Is_Simple_Indexed_Component;
+
   --
   -- Try_By_Protected_Procedure_Prefixed_View --
   --
@@ -5292,17 +5329,17 @@ package body Sem_Ch4 is
begin
   Set_Etype (N, Any_Type);
 
-  if Is_Overloaded (Name) then
+  if Is_Overloaded (Pref) then
  Analyze_Overloaded_Selected_Component (N);
  return;
 
-  elsif Etype (Name) = Any_Type then
+  elsif Etype (Pref) = Any_Type then
  Set_Entity (Sel, Any_Id);
  Set_Etype (Sel, Any_Type);
  return;
 
   else
- Prefix_Type := Etype (Name);
+ Prefix_Type := Etype (Pref);
   end if;
 
   if Is_Access_Type (Prefix_Type) then
@@ -5345,8 +5382,8 @@ package body Sem_Ch4 is
   --  component prefixes because of the prefixed dispatching call case.
   --  Note that implicit dereferences are checked for this just above.
 
-  elsif Nkind (Name) = N_Explicit_Dereference
-and then Is_Remote_Access_To_Class_Wide_Type (Etype (Prefix (Name)))
+  elsif Nkind (Pref) = N_Explicit_Dereference
+and then Is_Remote_Access_To_Class_Wide_Type (Etype (Prefix (Pref)))
 and then Comes_From_Source (N)
   then
  if Try_Object_Operation (N) then
@@ -5397,7 +5434,7 @@ package body Sem_Ch4 is
 Is_Concurrent_Type (Prefix_Type)
   and then Is_Internal_Na

[gcc r15-1518] ada: Cannot override inherited function with controlling result

2024-06-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:df0637007e08eb11ead3ba4ac76de2b69a115327

commit r15-1518-gdf0637007e08eb11ead3ba4ac76de2b69a115327
Author: Javier Miranda 
Date:   Thu May 30 11:24:54 2024 +

ada: Cannot override inherited function with controlling result

When a package has the declaration of a derived tagged
type T with private null extension that inherits a public
function F with controlling result, and a derivation of T
is declared in the public part of another package, overriding
function F may be rejected by the compiler.

gcc/ada/

* sem_disp.adb (Find_Hidden_Overridden_Primitive): Check
public dispatching primitives of ancestors; previously,
only immediately-visible primitives were checked.

Diff:
---
 gcc/ada/sem_disp.adb | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/sem_disp.adb b/gcc/ada/sem_disp.adb
index 9c498ee9a3f7..fe822290e453 100644
--- a/gcc/ada/sem_disp.adb
+++ b/gcc/ada/sem_disp.adb
@@ -89,7 +89,9 @@ package body Sem_Disp is
--  to the found entity; otherwise return Empty.
--
--  This routine does not search for non-hidden primitives since they are
-   --  covered by the normal Ada 2005 rules.
+   --  covered by the normal Ada 2005 rules. Its name was motivated by an
+   --  intermediate version of AI05-0125 where this term was proposed to
+   --  name these entities in the RM.
 
function Is_Inherited_Public_Operation (Op : Entity_Id) return Boolean;
--  Check whether a primitive operation is inherited from an operation
@@ -2403,7 +2405,7 @@ package body Sem_Disp is
Orig_Prim := Original_Corresponding_Operation (Prim);
 
if Orig_Prim /= Prim
- and then Is_Immediately_Visible (Orig_Prim)
+ and then not Is_Hidden (Orig_Prim)
then
   Vis_Ancestor := First_Elmt (Vis_List);
   while Present (Vis_Ancestor) loop


[gcc r15-1519] ada: Revert conditional installation of signal handlers on VxWorks

2024-06-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:3c99b1a75585b3c5ea5f79c87702c33b60e47a14

commit r15-1519-g3c99b1a75585b3c5ea5f79c87702c33b60e47a14
Author: Doug Rupp 
Date:   Tue Jun 4 10:17:57 2024 -0700

ada: Revert conditional installation of signal handlers on VxWorks

The conditional installation resulted in a semantic change, and
although it is likely what is ultimately wanted (since HW interrupts
are being reworked on VxWorks). However it must be done in concert
with other modifications for the new formulation of HW interrupts and
not in isolation.

gcc/ada/

* init.c [vxworks] (__gnat_install_handler): Revert to
installing signal handlers without regard to interrupt_state.

Diff:
---
 gcc/ada/init.c | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/gcc/ada/init.c b/gcc/ada/init.c
index acb8c7cc57ee..93e73f53c64c 100644
--- a/gcc/ada/init.c
+++ b/gcc/ada/init.c
@@ -2100,14 +2100,10 @@ __gnat_install_handler (void)
 
   /* For VxWorks, install all signal handlers, since pragma Interrupt_State
  applies to vectored hardware interrupts, not signals.  */
-  if (__gnat_get_interrupt_state (SIGFPE) != 's')
- sigaction (SIGFPE,  &act, NULL);
-  if (__gnat_get_interrupt_state (SIGILL) != 's')
- sigaction (SIGILL,  &act, NULL);
-  if (__gnat_get_interrupt_state (SIGSEGV) != 's')
- sigaction (SIGSEGV, &act, NULL);
-  if (__gnat_get_interrupt_state (SIGBUS) != 's')
- sigaction (SIGBUS,  &act, NULL);
+  sigaction (SIGFPE,  &act, NULL);
+  sigaction (SIGILL,  &act, NULL);
+  sigaction (SIGSEGV, &act, NULL);
+  sigaction (SIGBUS,  &act, NULL);
 
 #if defined(__leon__) && defined(_WRS_KERNEL)
   /* Specific to the LEON VxWorks kernel run-time library */


[gcc r15-1520] ada: Small cleanup in processing of primitive operations

2024-06-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:7a51065e94e759d20dcb00cf58d4b472cc8185fd

commit r15-1520-g7a51065e94e759d20dcb00cf58d4b472cc8185fd
Author: Eric Botcazou 
Date:   Tue Jun 4 21:33:28 2024 +0200

ada: Small cleanup in processing of primitive operations

The processing of primitive operations is now always uniform for tagged and
untagged types, but the code contains left-overs from the time where it was
specific to tagged types, in particular for the handling of subtypes.

gcc/ada/

* einfo.ads (Direct_Primitive_Operations): Mention concurrent types
as well as GNAT extensions instead of implementation details.
(Primitive_Operations): Document that Direct_Primitive_Operations is
also used for concurrent types as a fallback.
* einfo-utils.adb (Primitive_Operations): Tweak formatting.
* exp_util.ads (Find_Prim_Op): Adjust description.
* exp_util.adb (Make_Subtype_From_Expr): In the private case with
unknown discriminants, always copy Direct_Primitive_Operations and
do not overwrite the Class_Wide_Type of the expression's base type.
* sem_ch3.adb (Analyze_Incomplete_Type_Decl): Tweak comment.
(Analyze_Subtype_Declaration): Remove older and now dead calls to
Set_Direct_Primitive_Operations.  Tweak comment.
(Build_Derived_Private_Type): Likewise.
(Build_Derived_Record_Type): Likewise.
(Build_Discriminated_Subtype): Set Direct_Primitive_Operations in
all cases instead of just for tagged types.
(Complete_Private_Subtype): Likewise.
(Derived_Type_Declaration): Tweak comment.
* sem_ch4.ads (Try_Object_Operation): Adjust description.

Diff:
---
 gcc/ada/einfo-utils.adb |  4 ++--
 gcc/ada/einfo.ads   | 34 ++-
 gcc/ada/exp_util.adb|  8 ++-
 gcc/ada/exp_util.ads| 10 
 gcc/ada/sem_ch3.adb | 61 +
 gcc/ada/sem_ch4.ads |  5 ++--
 6 files changed, 55 insertions(+), 67 deletions(-)

diff --git a/gcc/ada/einfo-utils.adb b/gcc/ada/einfo-utils.adb
index 4c86ba1c3b19..c0c79f92e136 100644
--- a/gcc/ada/einfo-utils.adb
+++ b/gcc/ada/einfo-utils.adb
@@ -2422,8 +2422,8 @@ package body Einfo.Utils is
begin
   if Is_Concurrent_Type (Id) then
  if Present (Corresponding_Record_Type (Id)) then
-return Direct_Primitive_Operations
-  (Corresponding_Record_Type (Id));
+return
+  Direct_Primitive_Operations (Corresponding_Record_Type (Id));
 
  --  When expansion is disabled, the corresponding record type is
  --  absent, but if this is a tagged type with ancestors, or if the
diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads
index dd95ea051c1b..de175310ee9d 100644
--- a/gcc/ada/einfo.ads
+++ b/gcc/ada/einfo.ads
@@ -932,18 +932,17 @@ package Einfo is
 --   subtypes. Contains the Digits value specified in the declaration.
 
 --Direct_Primitive_Operations
---   Defined in tagged types and subtypes (including synchronized types),
---   in tagged private types, and in tagged incomplete types. Moreover, it
---   is also defined for untagged types, both when Extensions_Allowed is
---   True (-gnatX) to support the extension feature of prefixed calls for
---   untagged types, and when Extensions_Allowed is False to get better
---   error messages. This field is an element list of entities for
---   primitive operations of the type. For incomplete types the list is
---   always empty. In order to follow the C++ ABI, entities of primitives
---   that come from source must be stored in this list in the order of
---   their occurrence in the sources. When expansion is disabled, the
---   corresponding record type of a synchronized type is not constructed.
---   In that case, such types carry this attribute directly.
+--   Defined in concurrent types, tagged record types and subtypes, tagged
+--   private types, and tagged incomplete types. Moreover, it is also
+--   defined in untagged types, both when GNAT extensions are allowed, to
+--   support prefixed calls for untagged types, and when GNAT extensions
+--   are not allowed, to give better error messages. Set to a list of
+--   entities for primitive operations of the type. For incomplete types
+--   the list is always empty. In order to follow the C++ ABI, entities of
+--   primitives that come from source must be stored in this list in the
+--   order of their occurrence in the sources. When expansion is disabled,
+--   the corresponding record type of concurrent types is not constructed;
+--   in this case, such types carry this attribute directly.
 
 --Directly_Designated_Type
 --   Defined in access types. This field points to the type that is
@@ -4066,10 +4065,13 

[gcc r15-1522] ada: Crash when using user defined string literals

2024-06-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:96e037bcd160d2f63a04de09f2d47ed9aae082ad

commit r15-1522-g96e037bcd160d2f63a04de09f2d47ed9aae082ad
Author: Javier Miranda 
Date:   Thu Jun 6 11:20:14 2024 +

ada: Crash when using user defined string literals

When a non-overridable aspect is explicitly specified for a
non-tagged derived type, the compiler blows up processing an
object declaration of an object of such type.

gcc/ada/

* sem_ch13.adb (Analyze_One_Aspect): Fix code locating the entity
of the parent type.

Diff:
---
 gcc/ada/sem_ch13.adb | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index a86f774018a3..90376f818a30 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -4801,8 +4801,14 @@ package body Sem_Ch13 is
   and then Nkind (Type_Definition (N)) = N_Derived_Type_Definition
   and then not In_Instance_Body
 then
+   --  In order to locate the parent type we must go first to its
+   --  base type because the frontend introduces an implicit base
+   --  type even if there is no constraint attached to it, since
+   --  this is closer to the Ada semantics.
+
declare
-  Parent_Type  : constant Entity_Id := Etype (E);
+  Parent_Type  : constant Entity_Id :=
+Etype (Base_Type (E));
   Inherited_Aspect : constant Node_Id :=
 Find_Aspect (Parent_Type, A_Id);
begin


[gcc r15-1523] ada: Fix crash in GNATbind during error reporting

2024-06-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:728c1454c2b405543687d80238d8af4f12bcdca2

commit r15-1523-g728c1454c2b405543687d80238d8af4f12bcdca2
Author: Eric Botcazou 
Date:   Wed Jun 5 10:40:35 2024 +0200

ada: Fix crash in GNATbind during error reporting

This is the minimal fix to avoid the crash.

gcc/ada/

* bcheck.adb (Check_Consistency_Of_Sdep): Guard against path to ALI
file not found.

Diff:
---
 gcc/ada/bcheck.adb | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/bcheck.adb b/gcc/ada/bcheck.adb
index 56a417cc5176..64a6734a330c 100644
--- a/gcc/ada/bcheck.adb
+++ b/gcc/ada/bcheck.adb
@@ -162,10 +162,14 @@ package body Bcheck is
 end if;
 
  else
-ALI_Path_Id :=
-  Osint.Full_Lib_File_Name (A.Afile);
+ALI_Path_Id := Osint.Full_Lib_File_Name (A.Afile);
+
+--  Guard against Find_File not finding (again) the file because
+--  Primary_Directory has been clobbered in between.
 
-if Osint.Is_Readonly_Library (ALI_Path_Id) then
+if Present (ALI_Path_Id)
+  and then Osint.Is_Readonly_Library (ALI_Path_Id)
+then
if Tolerate_Consistency_Errors then
   Error_Msg ("?{ should be recompiled");
   Error_Msg_File_1 := ALI_Path_Id;


[gcc r15-1524] ada: Apply fixes to Examine_Array_Bounds

2024-06-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:036a37eae64ba6ff73a913fa2f93fc888e4b28b9

commit r15-1524-g036a37eae64ba6ff73a913fa2f93fc888e4b28b9
Author: Ronan Desplanques 
Date:   Thu Jun 6 09:40:54 2024 +0200

ada: Apply fixes to Examine_Array_Bounds

gcc/ada/

* sem_util.adb (Examine_Array_Bounds): Add missing return
statements. Fix criterion for a string literal being empty.

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

diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 4cdac9443e6d..4dde5f3964e1 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -8157,13 +8157,15 @@ package body Sem_Util is
   if not Is_Constrained (Typ) then
  All_Static := False;
  Has_Empty  := False;
+ return;
 
   --  A string literal has static bounds, and is not empty as long as it
   --  contains at least one character.
 
   elsif Ekind (Typ) = E_String_Literal_Subtype then
  All_Static := True;
- Has_Empty  := String_Literal_Length (Typ) > 0;
+ Has_Empty  := String_Literal_Length (Typ) = 0;
+ return;
   end if;
 
   --  Assume that all bounds are static and not empty


[gcc r15-1525] ada: Reject ambiguous function calls in interpolated string expressions

2024-06-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:3cc00ccf4b8a866e2265445aa560a2ca00f613b8

commit r15-1525-g3cc00ccf4b8a866e2265445aa560a2ca00f613b8
Author: Javier Miranda 
Date:   Thu Jun 6 12:06:53 2024 +

ada: Reject ambiguous function calls in interpolated string expressions

When the interpolated expression is a call to an ambiguous call
the frontend does not reject it; erroneously accepts the call
and generates code that calls to one of them.

gcc/ada/

* sem_ch2.adb (Analyze_Interpolated_String_Literal): Reject
ambiguous function calls.

Diff:
---
 gcc/ada/sem_ch2.adb | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/gcc/ada/sem_ch2.adb b/gcc/ada/sem_ch2.adb
index aae9990eb4d9..08cc75c9104c 100644
--- a/gcc/ada/sem_ch2.adb
+++ b/gcc/ada/sem_ch2.adb
@@ -25,7 +25,9 @@
 
 with Atree;  use Atree;
 with Einfo;  use Einfo;
+with Einfo.Entities; use Einfo.Entities;
 with Einfo.Utils;use Einfo.Utils;
+with Errout; use Errout;
 with Ghost;  use Ghost;
 with Mutably_Tagged; use Mutably_Tagged;
 with Namet;  use Namet;
@@ -141,6 +143,14 @@ package body Sem_Ch2 is
   Str_Elem := First (Expressions (N));
   while Present (Str_Elem) loop
  Analyze (Str_Elem);
+
+ if Nkind (Str_Elem) = N_Identifier
+   and then Ekind (Entity (Str_Elem)) = E_Function
+   and then Is_Overloaded (Str_Elem)
+ then
+Error_Msg_NE ("ambiguous call to&", Str_Elem, Entity (Str_Elem));
+ end if;
+
  Next (Str_Elem);
   end loop;
end Analyze_Interpolated_String_Literal;


[gcc r15-1526] ada: Implement fast modulo reduction for nonbinary modular multiplication

2024-06-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:4e128544abc14871388ca194e61d6c482d3a11a6

commit r15-1526-g4e128544abc14871388ca194e61d6c482d3a11a6
Author: Eric Botcazou 
Date:   Fri Apr 5 20:47:34 2024 +0200

ada: Implement fast modulo reduction for nonbinary modular multiplication

This implements modulo reduction for nonbinary modular multiplication with
small moduli by means of the standard division-free algorithm also used in
the optimizer, but with fewer constraints and therefore better results.

For the sake of consistency, it is also used for the 'Mod attribute of the
same modular types and, more generally, for the Mod (and Rem) operators of
unsigned types if the second operand is static and not a power of two.

gcc/ada/

* gcc-interface/gigi.h (fast_modulo_reduction): Declare.
* gcc-interface/trans.cc (gnat_to_gnu) : In the unsigned
case, call fast_modulo_reduction for {FLOOR,TRUNC}_MOD_EXPR if the
RHS is a constant and not a power of two, and the precision is not
larger than the word size.
* gcc-interface/utils2.cc: Include expmed.h.
(fast_modulo_reduction): New function.
(nonbinary_modular_operation): Call fast_modulo_reduction for the
multiplication if the precision is not larger than the word size.

Diff:
---
 gcc/ada/gcc-interface/gigi.h|   5 ++
 gcc/ada/gcc-interface/trans.cc  |  17 +++
 gcc/ada/gcc-interface/utils2.cc | 102 ++--
 3 files changed, 121 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/gcc-interface/gigi.h b/gcc/ada/gcc-interface/gigi.h
index 6ed74d6879ee..40f3f0d3d137 100644
--- a/gcc/ada/gcc-interface/gigi.h
+++ b/gcc/ada/gcc-interface/gigi.h
@@ -1040,6 +1040,11 @@ extern bool simple_constant_p (Entity_Id gnat_entity);
 /* Return the size of TYPE, which must be a positive power of 2.  */
 extern unsigned int resolve_atomic_size (tree type);
 
+/* Try to compute the reduction of OP modulo MODULUS in PRECISION bits with a
+   division-free algorithm.  Return NULL_TREE if this is not easily doable.  */
+extern tree fast_modulo_reduction (tree op, tree modulus,
+  unsigned int precision);
+
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc
index e68fb3fd7769..7c5282602b2c 100644
--- a/gcc/ada/gcc-interface/trans.cc
+++ b/gcc/ada/gcc-interface/trans.cc
@@ -7317,6 +7317,23 @@ gnat_to_gnu (Node_Id gnat_node)
  gnu_result
= build_binary_op_trapv (code, gnu_type, gnu_lhs, gnu_rhs,
 gnat_node);
+
+ /* For an unsigned modulo operation with nonbinary constant modulus,
+we first try to do a reduction by means of a (multiplier, shifter)
+pair in the needed precision up to the word size.  But not when
+optimizing for size, because it will be longer than a div+mul+sub
+sequence.  */
+else if (!optimize_size
+&& (code == FLOOR_MOD_EXPR || code == TRUNC_MOD_EXPR)
+&& TYPE_UNSIGNED (gnu_type)
+&& TYPE_PRECISION (gnu_type) <= BITS_PER_WORD
+&& TREE_CODE (gnu_rhs) == INTEGER_CST
+&& !integer_pow2p (gnu_rhs)
+&& (gnu_expr
+= fast_modulo_reduction (gnu_lhs, gnu_rhs,
+ TYPE_PRECISION (gnu_type
+ gnu_result = gnu_expr;
+
else
  {
/* Some operations, e.g. comparisons of arrays, generate complex
diff --git a/gcc/ada/gcc-interface/utils2.cc b/gcc/ada/gcc-interface/utils2.cc
index 70271cf28365..a37eccc4cfb0 100644
--- a/gcc/ada/gcc-interface/utils2.cc
+++ b/gcc/ada/gcc-interface/utils2.cc
@@ -33,6 +33,7 @@
 #include "tree.h"
 #include "inchash.h"
 #include "builtins.h"
+#include "expmed.h"
 #include "fold-const.h"
 #include "stor-layout.h"
 #include "stringpool.h"
@@ -534,6 +535,91 @@ compare_fat_pointers (location_t loc, tree result_type, 
tree p1, tree p2)
   p1_array_is_null, same_bounds));
 }
 
+/* Try to compute the reduction of OP modulo MODULUS in PRECISION bits with a
+   division-free algorithm.  Return NULL_TREE if this is not easily doable.  */
+
+tree
+fast_modulo_reduction (tree op, tree modulus, unsigned int precision)
+{
+  const tree type = TREE_TYPE (op);
+  const unsigned int type_precision = TYPE_PRECISION (type);
+
+  /* The implementation is host-dependent for the time being.  */
+  if (type_precision <= HOST_BITS_PER_WIDE_INT)
+{
+  const unsigned HOST_WIDE_INT d = tree_to_uhwi (modulus);
+  unsigned HOST_WIDE_INT ml, mh;
+  int pre_shift, post_shift;
+  tree t;
+
+  /* The trick is to replace the division by d with a multiply-and-shift
+sequence parameterized by a (multiplier, shifter) pair computed from
+d, the prec

[gcc r15-1528] ada: Fix bogus Address Sanitizer stack-buffer-overflow on packed record equality

2024-06-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:d69c53f73dae181c79f6ec6c7276a172476a2728

commit r15-1528-gd69c53f73dae181c79f6ec6c7276a172476a2728
Author: Eric Botcazou 
Date:   Mon May 27 16:31:20 2024 +0200

ada: Fix bogus Address Sanitizer stack-buffer-overflow on packed record 
equality

We set DECL_BIT_FIELD optimistically during the translation of record types
and clear it afterward if needed, but fail to clear other attributes in the
latter case, which fools the logic of the Address Sanitizer.

gcc/ada/

* gcc-interface/utils.cc (clear_decl_bit_field): New function.
(finish_record_type): Call clear_decl_bit_field instead of clearing
DECL_BIT_FIELD manually.

Diff:
---
 gcc/ada/gcc-interface/utils.cc | 26 +++---
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/gcc/ada/gcc-interface/utils.cc b/gcc/ada/gcc-interface/utils.cc
index 771cb1a17cad..0eb9af8d4a2d 100644
--- a/gcc/ada/gcc-interface/utils.cc
+++ b/gcc/ada/gcc-interface/utils.cc
@@ -2002,6 +2002,21 @@ finish_fat_pointer_type (tree record_type, tree 
field_list)
   TYPE_CONTAINS_PLACEHOLDER_INTERNAL (record_type) = 2;
 }
 
+/* Clear DECL_BIT_FIELD flag and associated markers on FIELD, which is a field
+   of aggregate type TYPE.  */
+
+static void
+clear_decl_bit_field (tree field, tree type)
+{
+  DECL_BIT_FIELD (field) = 0;
+  DECL_BIT_FIELD_TYPE (field) = NULL_TREE;
+
+  /* DECL_BIT_FIELD_REPRESENTATIVE is not defined for QUAL_UNION_TYPE since
+ it uses the same slot as DECL_QUALIFIER.  */
+  if (TREE_CODE (type) != QUAL_UNION_TYPE)
+DECL_BIT_FIELD_REPRESENTATIVE (field) = NULL_TREE;
+}
+
 /* Given a record type RECORD_TYPE and a list of FIELD_DECL nodes FIELD_LIST,
finish constructing the record or union type.  If REP_LEVEL is zero, this
record has no representation clause and so will be entirely laid out here.
@@ -2112,7 +2127,7 @@ finish_record_type (tree record_type, tree field_list, 
int rep_level,
  if (TYPE_ALIGN (record_type) >= align)
{
  SET_DECL_ALIGN (field, MAX (DECL_ALIGN (field), align));
- DECL_BIT_FIELD (field) = 0;
+ clear_decl_bit_field (field, record_type);
}
  else if (!had_align
   && rep_level == 0
@@ -2122,7 +2137,7 @@ finish_record_type (tree record_type, tree field_list, 
int rep_level,
{
  SET_TYPE_ALIGN (record_type, align);
  SET_DECL_ALIGN (field, MAX (DECL_ALIGN (field), align));
- DECL_BIT_FIELD (field) = 0;
+ clear_decl_bit_field (field, record_type);
}
}
 
@@ -2130,7 +2145,7 @@ finish_record_type (tree record_type, tree field_list, 
int rep_level,
  if (!STRICT_ALIGNMENT
  && DECL_BIT_FIELD (field)
  && value_factor_p (pos, BITS_PER_UNIT))
-   DECL_BIT_FIELD (field) = 0;
+   clear_decl_bit_field (field, record_type);
}
 
   /* Clear DECL_BIT_FIELD_TYPE for a variant part at offset 0, it's simply
@@ -2453,10 +2468,7 @@ rest_of_record_type_compilation (tree record_type)
 avoid generating useless attributes for the field in DWARF.  */
  if (DECL_SIZE (old_field) == TYPE_SIZE (field_type)
  && value_factor_p (pos, BITS_PER_UNIT))
-   {
- DECL_BIT_FIELD (new_field) = 0;
- DECL_BIT_FIELD_TYPE (new_field) = NULL_TREE;
-   }
+   clear_decl_bit_field (new_field, new_record_type);
  DECL_CHAIN (new_field) = TYPE_FIELDS (new_record_type);
  TYPE_FIELDS (new_record_type) = new_field;


[gcc r15-1529] ada: Fix bogus Address Sanitizer stack-buffer-overflow on packed array copy

2024-06-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:2b510ac3aa521c6984495c63547914f271f1f51c

commit r15-1529-g2b510ac3aa521c6984495c63547914f271f1f51c
Author: Eric Botcazou 
Date:   Mon May 27 16:46:03 2024 +0200

ada: Fix bogus Address Sanitizer stack-buffer-overflow on packed array copy

The Address Sanitizer considers that the padding at the end of a justified
modular type may be accessed through the object, but it is never accessed
and therefore can always be reused.

gcc/ada/

* gcc-interface/decl.cc (gnat_to_gnu_entity) : Set
the TYPE_JUSTIFIED_MODULAR_P flag earlier.
* gcc-interface/misc.cc (gnat_unit_size_without_reusable_padding):
New function.
(LANG_HOOKS_UNIT_SIZE_WITHOUT_REUSABLE_PADDING): Redefine to above
function.

Diff:
---
 gcc/ada/gcc-interface/decl.cc |  2 +-
 gcc/ada/gcc-interface/misc.cc | 17 -
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc
index aa31a18f..5b3a3b4961b4 100644
--- a/gcc/ada/gcc-interface/decl.cc
+++ b/gcc/ada/gcc-interface/decl.cc
@@ -1976,6 +1976,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, 
bool definition)
 
  gnu_type = make_node (RECORD_TYPE);
  TYPE_NAME (gnu_type) = create_concat_name (gnat_entity, "JM");
+ TYPE_JUSTIFIED_MODULAR_P (gnu_type) = 1;
  TYPE_PACKED (gnu_type) = 1;
  TYPE_SIZE (gnu_type) = TYPE_SIZE (gnu_field_type);
  TYPE_SIZE_UNIT (gnu_type) = TYPE_SIZE_UNIT (gnu_field_type);
@@ -2006,7 +2007,6 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, 
bool definition)
 
  /* We will output additional debug info manually below.  */
  finish_record_type (gnu_type, gnu_field, 2, false);
- TYPE_JUSTIFIED_MODULAR_P (gnu_type) = 1;
 
  /* Make the original array type a parallel/debug type.  Note that
 gnat_get_array_descr_info needs a TYPE_IMPL_PACKED_ARRAY_P type
diff --git a/gcc/ada/gcc-interface/misc.cc b/gcc/ada/gcc-interface/misc.cc
index b703f00d3c0b..4f6f6774fe70 100644
--- a/gcc/ada/gcc-interface/misc.cc
+++ b/gcc/ada/gcc-interface/misc.cc
@@ -760,6 +760,19 @@ gnat_type_max_size (const_tree gnu_type)
   return max_size_unit;
 }
 
+/* Return the unit size of TYPE without reusable tail padding.  */
+
+static tree
+gnat_unit_size_without_reusable_padding (tree type)
+{
+  /* The padding of justified modular types can always be reused.  */
+  if (TYPE_JUSTIFIED_MODULAR_P (type))
+return fold_convert (sizetype,
+size_binop (CEIL_DIV_EXPR,
+TYPE_ADA_SIZE (type), bitsize_unit_node));
+  return TYPE_SIZE_UNIT (type);
+}
+
 static tree get_array_bit_stride (tree);
 
 /* Provide information in INFO for debug output about the TYPE array type.
@@ -1407,6 +1420,8 @@ const struct scoped_attribute_specs *const 
gnat_attribute_table[] =
 #define LANG_HOOKS_TYPE_FOR_SIZE   gnat_type_for_size
 #undef  LANG_HOOKS_TYPES_COMPATIBLE_P
 #define LANG_HOOKS_TYPES_COMPATIBLE_P  gnat_types_compatible_p
+#undef  LANG_HOOKS_UNIT_SIZE_WITHOUT_REUSABLE_PADDING
+#define LANG_HOOKS_UNIT_SIZE_WITHOUT_REUSABLE_PADDING 
gnat_unit_size_without_reusable_padding
 #undef  LANG_HOOKS_GET_ARRAY_DESCR_INFO
 #define LANG_HOOKS_GET_ARRAY_DESCR_INFOgnat_get_array_descr_info
 #undef  LANG_HOOKS_GET_SUBRANGE_BOUNDS
@@ -1433,7 +1448,7 @@ const struct scoped_attribute_specs *const 
gnat_attribute_table[] =
 #define LANG_HOOKS_DEEP_UNSHARING  true
 #undef  LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS
 #define LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS true
-#undef LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE
+#undef  LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE
 #define LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE gnat_get_sarif_source_language
 
 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;


[gcc r15-1530] ada: Fix internal error on protected type with -gnatc -gnatR

2024-06-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:fbe4dd20b9f25eaa0b6b90d008aff4708e47765b

commit r15-1530-gfbe4dd20b9f25eaa0b6b90d008aff4708e47765b
Author: Eric Botcazou 
Date:   Tue May 28 13:03:19 2024 +0200

ada: Fix internal error on protected type with -gnatc -gnatR

It occurs when the body of a protected subprogram is processed, because the
references to the components of the type have not been properly expanded.

gcc/ada/

* gcc-interface/trans.cc (Subprogram_Body_to_gnu): Also return early
for a protected subprogram in -gnatc mode.

Diff:
---
 gcc/ada/gcc-interface/trans.cc | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc
index 83ed17bff842..3f2eadd7b2bc 100644
--- a/gcc/ada/gcc-interface/trans.cc
+++ b/gcc/ada/gcc-interface/trans.cc
@@ -3934,6 +3934,12 @@ Subprogram_Body_to_gnu (Node_Id gnat_node)
   if (Is_Generic_Subprogram (gnat_subprog) || Is_Eliminated (gnat_subprog))
 return;
 
+  /* Likewise if this is a protected subprogram and we are only annotating
+ types, as the required expansion of references did not take place.  */
+  if (Convention (gnat_subprog) == Convention_Protected
+  && type_annotate_only)
+return;
+
   /* If this subprogram acts as its own spec, define it.  Otherwise, just get
  the already-elaborated tree node.  However, if this subprogram had its
  elaboration deferred, we will already have made a tree node for it.  So


[gcc r15-1521] ada: Change error message on invalid RTS path

2024-06-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:498c6260ce0508a4c865071fed11e964d6f22b35

commit r15-1521-g498c6260ce0508a4c865071fed11e964d6f22b35
Author: Marc Poulhiès 
Date:   Tue Jun 4 14:37:17 2024 +0200

ada: Change error message on invalid RTS path

Include the invalid path in the error message.

gcc/ada/

* make.adb (Scan_Make_Arg): Adjust error message.
* gnatls.adb (Search_RTS): Likewise.
* switch-b.adb (Scan_Debug_Switches): Likewise.

Diff:
---
 gcc/ada/gnatls.adb   | 11 ---
 gcc/ada/make.adb | 14 +-
 gcc/ada/switch-b.adb | 15 ++-
 3 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/gcc/ada/gnatls.adb b/gcc/ada/gnatls.adb
index 2c26001743ad..c52c1aea9c3f 100644
--- a/gcc/ada/gnatls.adb
+++ b/gcc/ada/gnatls.adb
@@ -1673,9 +1673,13 @@ procedure Gnatls is
   end if;
 
   if Lib_Path /= null then
- Osint.Fail ("RTS path not valid: missing adainclude directory");
+ Osint.Fail
+   ("RTS path """ & Name
+& """ not valid: missing adainclude directory");
   elsif Src_Path /= null then
- Osint.Fail ("RTS path not valid: missing adalib directory");
+ Osint.Fail
+   ("RTS path """ & Name
+& """ not valid: missing adalib directory");
   end if;
 
   --  Try to find the RTS on the project path. First setup the project path
@@ -1710,7 +1714,8 @@ procedure Gnatls is
   end if;
 
   Osint.Fail
-("RTS path not valid: missing adainclude and adalib directories");
+("RTS path """ & Name
+  & """ not valid: missing adainclude and adalib directories");
end Search_RTS;
 
---
diff --git a/gcc/ada/make.adb b/gcc/ada/make.adb
index 24b2d099bfeb..cef243411358 100644
--- a/gcc/ada/make.adb
+++ b/gcc/ada/make.adb
@@ -4478,13 +4478,14 @@ package body Make is
RTS_Switch := True;
 
declare
+  RTS_Arg_Path : constant String := Argv (7 .. Argv'Last);
   Src_Path_Name : constant String_Ptr :=
 Get_RTS_Search_Dir
-  (Argv (7 .. Argv'Last), Include);
+  (RTS_Arg_Path, Include);
 
   Lib_Path_Name : constant String_Ptr :=
 Get_RTS_Search_Dir
-  (Argv (7 .. Argv'Last), Objects);
+  (RTS_Arg_Path, Objects);
 
begin
   if Src_Path_Name /= null
@@ -4501,16 +4502,19 @@ package body Make is
 and then Lib_Path_Name = null
   then
  Make_Failed
-   ("RTS path not valid: missing adainclude and adalib "
+   ("RTS path """ & RTS_Arg_Path
+& """ not valid: missing adainclude and adalib "
 & "directories");
 
   elsif Src_Path_Name = null then
  Make_Failed
-   ("RTS path not valid: missing adainclude directory");
+   ("RTS path """ & RTS_Arg_Path
+& """ not valid: missing adainclude directory");
 
   else pragma Assert (Lib_Path_Name = null);
  Make_Failed
-   ("RTS path not valid: missing adalib directory");
+   ("RTS path """ & RTS_Arg_Path
+& """ not valid: missing adalib directory");
   end if;
end;
 end if;
diff --git a/gcc/ada/switch-b.adb b/gcc/ada/switch-b.adb
index 8d8dc58937c1..2de516dba56b 100644
--- a/gcc/ada/switch-b.adb
+++ b/gcc/ada/switch-b.adb
@@ -672,13 +672,15 @@ package body Switch.B is
   Opt.RTS_Switch := True;
 
   declare
+ RTS_Arg_Path : constant String :=
+   Switch_Chars (Ptr + 1 .. Max);
  Src_Path_Name : constant String_Ptr :=
Get_RTS_Search_Dir
- (Switch_Chars (Ptr + 1 .. Max),
+ (RTS_Arg_Path,
   Include);
  Lib_Path_Name : constant String_Ptr :=
Get_RTS_Search_Dir
- (Switch_Chars (Ptr + 1 .. Max),
+ (RTS_Arg_Path,
   Objects);
 
   begin
@@ -698,14 +700,17 @@ package body Switch.B is
and then Lib_Path_Name = null
  then
 Osint.Fail
-  ("RTS path not valid: missing adainclude and "
+  ("RTS path """ & RTS_Arg_Path
+ 

[gcc r15-1527] ada: Implement fast modulo reduction for nonbinary modular multiplication

2024-06-21 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:9aa8324e8a2c992593591d965b3e2d527ed891d3

commit r15-1527-g9aa8324e8a2c992593591d965b3e2d527ed891d3
Author: Eric Botcazou 
Date:   Sat Apr 20 12:26:52 2024 +0200

ada: Implement fast modulo reduction for nonbinary modular multiplication

This adds the missing guard to prevent the reduction from being used when
the target does not provide or cannot synthesize a high-part multiply.

gcc/ada/

* gcc-interface/trans.cc (gnat_to_gnu) : Fix formatting.
* gcc-interface/utils2.cc: Include optabs-query.h.
(fast_modulo_reduction): Call can_mult_highpart_p on the TYPE_MODE
before generating a high-part multiply.  Fix formatting.

Diff:
---
 gcc/ada/gcc-interface/trans.cc  |  2 +-
 gcc/ada/gcc-interface/utils2.cc | 12 +++-
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc
index 7c5282602b2c..83ed17bff842 100644
--- a/gcc/ada/gcc-interface/trans.cc
+++ b/gcc/ada/gcc-interface/trans.cc
@@ -7323,7 +7323,7 @@ gnat_to_gnu (Node_Id gnat_node)
 pair in the needed precision up to the word size.  But not when
 optimizing for size, because it will be longer than a div+mul+sub
 sequence.  */
-else if (!optimize_size
+   else if (!optimize_size
 && (code == FLOOR_MOD_EXPR || code == TRUNC_MOD_EXPR)
 && TYPE_UNSIGNED (gnu_type)
 && TYPE_PRECISION (gnu_type) <= BITS_PER_WORD
diff --git a/gcc/ada/gcc-interface/utils2.cc b/gcc/ada/gcc-interface/utils2.cc
index a37eccc4cfb0..d101d7729bf8 100644
--- a/gcc/ada/gcc-interface/utils2.cc
+++ b/gcc/ada/gcc-interface/utils2.cc
@@ -35,6 +35,7 @@
 #include "builtins.h"
 #include "expmed.h"
 #include "fold-const.h"
+#include "optabs-query.h"
 #include "stor-layout.h"
 #include "stringpool.h"
 #include "varasm.h"
@@ -558,11 +559,11 @@ fast_modulo_reduction (tree op, tree modulus, unsigned 
int precision)
 
   op / d = (op * multiplier) >> shifter
 
- But choose_multiplier provides a slightly different interface:
+But choose_multiplier provides a slightly different interface:
 
-   op / d = (op h* multiplier) >> reduced_shifter
+ op / d = (op h* multiplier) >> reduced_shifter
 
- that makes things easier by using a high-part multiplication.  */
+that makes things easier by using a high-part multiplication.  */
   mh = choose_multiplier (d, type_precision, precision, &ml, &post_shift);
 
   /* If the suggested multiplier is more than TYPE_PRECISION bits, we can
@@ -577,8 +578,9 @@ fast_modulo_reduction (tree op, tree modulus, unsigned int 
precision)
pre_shift = 0;
 
   /* If the suggested multiplier is still more than TYPE_PRECISION bits,
-try again with a larger type up to the word size.  */
-  if (mh != 0)
+or the TYPE_MODE does not have a high-part multiply, try again with
+a larger type up to the word size.  */
+  if (mh != 0 || !can_mult_highpart_p (TYPE_MODE (type), true))
{
  if (type_precision < BITS_PER_WORD)
{


[gcc r15-1531] sh: Make *minus_plus_one work after RA

2024-06-21 Thread Richard Sandiford via Gcc-cvs
https://gcc.gnu.org/g:f49267e1636872128249431e9e5d20c0908b7e8e

commit r15-1531-gf49267e1636872128249431e9e5d20c0908b7e8e
Author: Richard Sandiford 
Date:   Fri Jun 21 09:52:42 2024 +0100

sh: Make *minus_plus_one work after RA

*minus_plus_one had no constraints, which meant that it could be
matched after RA with operands 0, 1 and 2 all being different.
The associated split instead requires operand 0 to be tied to
operand 1.

gcc/
* config/sh/sh.md (*minus_plus_one): Add constraints.

Diff:
---
 gcc/config/sh/sh.md | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/config/sh/sh.md b/gcc/config/sh/sh.md
index 92a1efeb811..9491b49e55b 100644
--- a/gcc/config/sh/sh.md
+++ b/gcc/config/sh/sh.md
@@ -1642,9 +1642,9 @@
 ;; matched.  Split this up into a simple sub add sequence, as this will save
 ;; us one sett insn.
 (define_insn_and_split "*minus_plus_one"
-  [(set (match_operand:SI 0 "arith_reg_dest" "")
-   (plus:SI (minus:SI (match_operand:SI 1 "arith_reg_operand" "")
-  (match_operand:SI 2 "arith_reg_operand" ""))
+  [(set (match_operand:SI 0 "arith_reg_dest" "=r")
+   (plus:SI (minus:SI (match_operand:SI 1 "arith_reg_operand" "0")
+  (match_operand:SI 2 "arith_reg_operand" "r"))
 (const_int 1)))]
   "TARGET_SH1"
   "#"


[gcc r15-1532] libstdc++: Initialize base in test allocator's constructor

2024-06-21 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:e2fb245b07f489ed5bfd9a945e0053b4a3211245

commit r15-1532-ge2fb245b07f489ed5bfd9a945e0053b4a3211245
Author: Jonathan Wakely 
Date:   Thu Jun 20 16:13:10 2024 +0100

libstdc++: Initialize base in test allocator's constructor

This fixes a warning from one of the test allocators:
warning: base class 'class std::allocator<__gnu_test::copy_tracker>' should 
be explicitly initialized in the copy constructor [-Wextra]

libstdc++-v3/ChangeLog:

* testsuite/util/testsuite_allocator.h (tracker_allocator):
Initialize base class in copy constructor.

Diff:
---
 libstdc++-v3/testsuite/util/testsuite_allocator.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/testsuite/util/testsuite_allocator.h 
b/libstdc++-v3/testsuite/util/testsuite_allocator.h
index b7739f13ca3..2f9c453cbd1 100644
--- a/libstdc++-v3/testsuite/util/testsuite_allocator.h
+++ b/libstdc++-v3/testsuite/util/testsuite_allocator.h
@@ -154,7 +154,7 @@ namespace __gnu_test
   tracker_allocator()
   { }
 
-  tracker_allocator(const tracker_allocator&)
+  tracker_allocator(const tracker_allocator& a) : Alloc(a)
   { }
 
   ~tracker_allocator()


[gcc r15-1533] libstdc++: Fix std::to_array for trivial-ish types [PR115522]

2024-06-21 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:510ce5eed69ee1bea9c2c696fe3b2301e16d1486

commit r15-1533-g510ce5eed69ee1bea9c2c696fe3b2301e16d1486
Author: Jonathan Wakely 
Date:   Tue Jun 18 13:27:02 2024 +0100

libstdc++: Fix std::to_array for trivial-ish types [PR115522]

Due to PR c++/85723 the std::is_trivial trait is true for types with a
deleted default constructor, so the use of std::is_trivial in
std::to_array is not sufficient to ensure the type can be trivially
default constructed then filled using memcpy.

I also forgot that a type with a deleted assignment operator can still
be trivial, so we also need to check that it's assignable because the
is_constant_evaluated() path can't use memcpy.

Replace the uses of std::is_trivial with std::is_trivially_copyable
(needed for memcpy), std::is_trivially_default_constructible (needed so
that the default construction is valid and does no work) and
std::is_copy_assignable (needed for the constant evaluation case).

libstdc++-v3/ChangeLog:

PR libstdc++/115522
* include/std/array (to_array): Workaround the fact that
std::is_trivial is not sufficient to check that a type is
trivially default constructible and assignable.
* testsuite/23_containers/array/creation/115522.cc: New test.

Diff:
---
 libstdc++-v3/include/std/array |  8 --
 .../23_containers/array/creation/115522.cc | 33 ++
 2 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/array b/libstdc++-v3/include/std/array
index 39695471e24..8710bf75924 100644
--- a/libstdc++-v3/include/std/array
+++ b/libstdc++-v3/include/std/array
@@ -431,7 +431,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   static_assert(is_constructible_v<_Tp, _Tp&>);
   if constexpr (is_constructible_v<_Tp, _Tp&>)
{
- if constexpr (is_trivial_v<_Tp>)
+ if constexpr (is_trivially_copyable_v<_Tp>
+ && is_trivially_default_constructible_v<_Tp>
+ && is_copy_assignable_v<_Tp>)
{
  array, _Nm> __arr;
  if (!__is_constant_evaluated() && _Nm != 0)
@@ -460,7 +462,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   static_assert(is_move_constructible_v<_Tp>);
   if constexpr (is_move_constructible_v<_Tp>)
{
- if constexpr (is_trivial_v<_Tp>)
+ if constexpr (is_trivially_copyable_v<_Tp>
+ && is_trivially_default_constructible_v<_Tp>
+ && is_copy_assignable_v<_Tp>)
{
  array, _Nm> __arr;
  if (!__is_constant_evaluated() && _Nm != 0)
diff --git a/libstdc++-v3/testsuite/23_containers/array/creation/115522.cc 
b/libstdc++-v3/testsuite/23_containers/array/creation/115522.cc
new file mode 100644
index 000..37073e002bd
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/array/creation/115522.cc
@@ -0,0 +1,33 @@
+// { dg-do compile { target c++20 } }
+
+// PR libstdc++/115522 std::to_array no longer works for struct which is
+// trivial but not default constructible
+
+#include 
+
+void
+test_deleted_ctor()
+{
+  struct S
+  {
+S() = delete;
+S(int) { }
+  };
+
+  S arr[1] = {{1}};
+  auto arr1 = std::to_array(arr);
+  auto arr2 = std::to_array(std::move(arr));
+}
+
+void
+test_deleted_assignment()
+{
+  struct S
+  {
+void operator=(const S&) = delete;
+  };
+
+  S arr[1] = {};
+  auto a1 = std::to_array(arr);
+  auto a2 = std::to_array(std::move(arr));
+}


[gcc r15-1534] libstdc++: Fix __cpp_lib_chrono for old std::string ABI

2024-06-21 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:f906b107634bfac29676e7fcf364d0ca7ceed666

commit r15-1534-gf906b107634bfac29676e7fcf364d0ca7ceed666
Author: Jonathan Wakely 
Date:   Thu Jun 20 13:28:08 2024 +0100

libstdc++: Fix __cpp_lib_chrono for old std::string ABI

The  header is incomplete for the old std::string ABI, because
std::chrono::tzdb is only defined for the new ABI. The feature test
macro advertising full C++20 support should not be defined for the old
ABI.

libstdc++-v3/ChangeLog:

* include/bits/version.def (chrono): Add cxx11abi = yes.
* include/bits/version.h: Regenerate.
* testsuite/std/time/syn_c++20.cc: Adjust expected value for
the feature test macro.

Diff:
---
 libstdc++-v3/include/bits/version.def|  1 +
 libstdc++-v3/include/bits/version.h  |  2 +-
 libstdc++-v3/testsuite/std/time/syn_c++20.cc | 11 +--
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/include/bits/version.def 
b/libstdc++-v3/include/bits/version.def
index 683b967d54b..42cdef2f526 100644
--- a/libstdc++-v3/include/bits/version.def
+++ b/libstdc++-v3/include/bits/version.def
@@ -574,6 +574,7 @@ ftms = {
 v = 201907;
 cxxmin = 20;
 hosted = yes;
+cxx11abi = yes; // std::chrono::tzdb requires cxx11 std::string
   };
   values = {
 v = 201611;
diff --git a/libstdc++-v3/include/bits/version.h 
b/libstdc++-v3/include/bits/version.h
index 4850041c0a3..1eaf3733bc2 100644
--- a/libstdc++-v3/include/bits/version.h
+++ b/libstdc++-v3/include/bits/version.h
@@ -639,7 +639,7 @@
 #undef __glibcxx_want_boyer_moore_searcher
 
 #if !defined(__cpp_lib_chrono)
-# if (__cplusplus >= 202002L) && _GLIBCXX_HOSTED
+# if (__cplusplus >= 202002L) && _GLIBCXX_USE_CXX11_ABI && _GLIBCXX_HOSTED
 #  define __glibcxx_chrono 201907L
 #  if defined(__glibcxx_want_all) || defined(__glibcxx_want_chrono)
 #   define __cpp_lib_chrono 201907L
diff --git a/libstdc++-v3/testsuite/std/time/syn_c++20.cc 
b/libstdc++-v3/testsuite/std/time/syn_c++20.cc
index f0b86199e9d..4a527262e9d 100644
--- a/libstdc++-v3/testsuite/std/time/syn_c++20.cc
+++ b/libstdc++-v3/testsuite/std/time/syn_c++20.cc
@@ -20,9 +20,16 @@
 
 #include 
 
+// std::chrono::tzdb is not defined for the old std::string ABI.
+#if _GLIBCXX_USE_CXX_ABI
+# define EXPECTED_VALUE 201907L
+#else
+# define EXPECTED_VALUE 201611L
+#endif
+
 #ifndef __cpp_lib_chrono
 # error "Feature test macro for chrono is missing in "
-#elif __cpp_lib_chrono < 201907L
+#elif __cpp_lib_chrono < EXPECTED_VALUE
 # error "Feature test macro for chrono has wrong value in "
 #endif
 
@@ -94,7 +101,7 @@ namespace __gnu_test
   using std::chrono::make12;
   using std::chrono::make24;
 
-#if _GLIBCXX_USE_CXX11_ABI
+#if __cpp_lib_chrono >= 201803L
   using std::chrono::tzdb;
   using std::chrono::tzdb_list;
   using std::chrono::get_tzdb;


[gcc r15-1535] libstdc++: Add [[deprecated]] to std::wstring_convert and std::wbuffer_convert

2024-06-21 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:bb7d052adce7292d15a8400886013ff1843f774e

commit r15-1535-gbb7d052adce7292d15a8400886013ff1843f774e
Author: Jonathan Wakely 
Date:   Fri Mar 22 13:19:09 2024 +

libstdc++: Add [[deprecated]] to std::wstring_convert and 
std::wbuffer_convert

These were deprecated in C++17 and std::wstring_convert is planned for
removal in C++26.

libstdc++-v3/ChangeLog:

* include/bits/locale_conv.h (wstring_convert): Add deprecated
attribute for C++17 and later.
(wbuffer_convert): Likewise.
* testsuite/22_locale/codecvt/codecvt_utf16/79980.cc: Disable
deprecated warnings.
* testsuite/22_locale/codecvt/codecvt_utf8/79980.cc: Likewise.
* testsuite/22_locale/codecvt/codecvt_utf8_utf16/79511.cc:
Likewise.
* testsuite/22_locale/conversions/buffer/1.cc: Add dg-warning.
* testsuite/22_locale/conversions/buffer/2.cc: Likewise.
* testsuite/22_locale/conversions/buffer/3.cc: Likewise.
* testsuite/22_locale/conversions/buffer/requirements/typedefs.cc:
Likewise.
* testsuite/22_locale/conversions/string/1.cc: Likewise.
* testsuite/22_locale/conversions/string/2.cc: Likewise.
* testsuite/22_locale/conversions/string/3.cc: Likewise.
* testsuite/22_locale/conversions/string/66441.cc: Likewise.
* testsuite/22_locale/conversions/string/requirements/typedefs-2.cc:
Likewise.
* testsuite/22_locale/conversions/string/requirements/typedefs.cc:
Likewise.

Diff:
---
 libstdc++-v3/include/bits/locale_conv.h  | 5 +++--
 libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/79980.cc  | 1 +
 libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8/79980.cc   | 1 +
 libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8_utf16/79511.cc | 1 +
 libstdc++-v3/testsuite/22_locale/conversions/buffer/1.cc | 1 +
 libstdc++-v3/testsuite/22_locale/conversions/buffer/2.cc | 1 +
 libstdc++-v3/testsuite/22_locale/conversions/buffer/3.cc | 2 ++
 .../testsuite/22_locale/conversions/buffer/requirements/typedefs.cc  | 2 +-
 libstdc++-v3/testsuite/22_locale/conversions/string/1.cc | 1 +
 libstdc++-v3/testsuite/22_locale/conversions/string/2.cc | 1 +
 libstdc++-v3/testsuite/22_locale/conversions/string/3.cc | 1 +
 libstdc++-v3/testsuite/22_locale/conversions/string/66441.cc | 1 +
 .../22_locale/conversions/string/requirements/typedefs-2.cc  | 1 +
 .../testsuite/22_locale/conversions/string/requirements/typedefs.cc  | 1 +
 14 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/include/bits/locale_conv.h 
b/libstdc++-v3/include/bits/locale_conv.h
index 754c36b92b8..63dee1ac872 100644
--- a/libstdc++-v3/include/bits/locale_conv.h
+++ b/libstdc++-v3/include/bits/locale_conv.h
@@ -259,7 +259,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
   template,
   typename _Byte_alloc = allocator>
-class wstring_convert
+class _GLIBCXX17_DEPRECATED wstring_convert
 {
 public:
   typedef basic_string, _Byte_alloc>   byte_string;
@@ -406,7 +406,8 @@ _GLIBCXX_END_NAMESPACE_CXX11
   /// Buffer conversions
   template>
-class wbuffer_convert : public basic_streambuf<_Elem, _Tr>
+class _GLIBCXX17_DEPRECATED wbuffer_convert
+: public basic_streambuf<_Elem, _Tr>
 {
   typedef basic_streambuf<_Elem, _Tr> _Wide_streambuf;
 
diff --git a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/79980.cc 
b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/79980.cc
index 1c6711b56db..90cb844bba3 100644
--- a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/79980.cc
+++ b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/79980.cc
@@ -16,6 +16,7 @@
 // .
 
 // { dg-do run { target c++11 } }
+// { dg-additional-options "-Wno-deprecated-declarations" { target c++17 } }
 
 #include 
 #include 
diff --git a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8/79980.cc 
b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8/79980.cc
index d6cd89ce420..66aadc1161d 100644
--- a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8/79980.cc
+++ b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8/79980.cc
@@ -16,6 +16,7 @@
 // .
 
 // { dg-do run { target c++11 } }
+// { dg-additional-options "-Wno-deprecated-declarations" { target c++17 } }
 
 #include 
 #include 
diff --git 
a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8_utf16/79511.cc 
b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8_utf16/79511.cc
index d09aa41ee93..e6934818864 100644
--- a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8_utf16/79511.cc
+++ b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8_utf16/79511.cc
@@ -16,6 +16,7 @@
 // .

[gcc r15-1536] libstdc++: Add deprecation warnings to types

2024-06-21 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:577225a268ad203647746d4ae98620da0354d0a0

commit r15-1536-g577225a268ad203647746d4ae98620da0354d0a0
Author: Jonathan Wakely 
Date:   Sun Apr 7 14:12:25 2024 +0100

libstdc++: Add deprecation warnings to  types

libstdc++-v3/ChangeLog:

* include/backward/backward_warning.h: Adjust comments to
suggest  as another alternative to .
* include/backward/strstream (strstreambuf, istrstream)
(ostrstream, strstream): Add deprecated attribute.

Diff:
---
 libstdc++-v3/include/backward/backward_warning.h | 12 
 libstdc++-v3/include/backward/strstream  | 20 
 2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/libstdc++-v3/include/backward/backward_warning.h 
b/libstdc++-v3/include/backward/backward_warning.h
index 3f3330327d4..834fc5680cc 100644
--- a/libstdc++-v3/include/backward/backward_warning.h
+++ b/libstdc++-v3/include/backward/backward_warning.h
@@ -40,10 +40,14 @@
   A list of valid replacements is as follows:
 
   Use: Instead of:
-  , basic_stringbuf   , strstreambuf
-  , basic_istringstream   , istrstream
-  , basic_ostringstream   , ostrstream
-  , basic_stringstream, strstream
+  , stringbuf
+or , spanbuf   , strstreambuf
+  , istringstream
+or , ispanstream   , istrstream
+  , ostringstream
+or , ospanstream   , ostrstream
+  , stringstream
+or , spanstream, strstream
   , unordered_set   , hash_set
   , unordered_multiset  , hash_multiset
   , unordered_map   , hash_map
diff --git a/libstdc++-v3/include/backward/strstream 
b/libstdc++-v3/include/backward/strstream
index 152e93767f6..5e421143385 100644
--- a/libstdc++-v3/include/backward/strstream
+++ b/libstdc++-v3/include/backward/strstream
@@ -57,6 +57,12 @@ namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
+#if __glibcxx_spanstream
+# define _GLIBCXX_STRSTREAM_DEPR(A, B) _GLIBCXX_DEPRECATED_SUGGEST(A "' or '" 
B)
+#else
+# define _GLIBCXX_STRSTREAM_DEPR(A, B) _GLIBCXX_DEPRECATED_SUGGEST(A)
+#endif
+
   // Class strstreambuf, a streambuf class that manages an array of char.
   // Note that this class is not a template.
   class strstreambuf : public basic_streambuf >
@@ -151,7 +157,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 bool _M_dynamic  : 1;
 bool _M_frozen   : 1;
 bool _M_constant : 1;
-  };
+  } _GLIBCXX_STRSTREAM_DEPR("std::stringbuf", "std::spanbuf");
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
 
   // Class istrstream, an istream that manages a strstreambuf.
   class istrstream : public basic_istream
@@ -176,7 +185,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   private:
 strstreambuf _M_buf;
-  };
+  } _GLIBCXX_STRSTREAM_DEPR("std::istringstream", "std::ispanstream");
 
   // Class ostrstream
   class ostrstream : public basic_ostream
@@ -201,7 +210,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   private:
 strstreambuf _M_buf;
-  };
+  } _GLIBCXX_STRSTREAM_DEPR("std::ostringstream", "std::ospanstream");
 
   // Class strstream
   class strstream : public basic_iostream
@@ -231,7 +240,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   private:
 strstreambuf _M_buf;
-  };
+  } _GLIBCXX_STRSTREAM_DEPR("std::stringstream", "std::spanstream");
+
+#undef _GLIBCXX_STRSTREAM_DEPR
+#pragma GCC diagnostic pop
 
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace


[gcc r15-1537] libstdc++: Undeprecate std::pmr::polymorphic_allocator::destroy (P2875R4)

2024-06-21 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:c3e237338eb7ffc90f3cc8d32a3971d17f6d0b31

commit r15-1537-gc3e237338eb7ffc90f3cc8d32a3971d17f6d0b31
Author: Jonathan Wakely 
Date:   Tue Jun 18 16:09:08 2024 +0100

libstdc++: Undeprecate std::pmr::polymorphic_allocator::destroy (P2875R4)

This member function was previously deprecated, but that was reverted by
P2875R4, approved earlier this year in Tokyo. Since it's not going to be
deprecated in C++26, and so presumably not removed, there is no point in
giving deprecated warnings for C++23 mode.

libstdc++-v3/ChangeLog:

* include/bits/memory_resource.h (polymorphic_allocator::destroy):
Remove deprecated attribute.

Diff:
---
 libstdc++-v3/include/bits/memory_resource.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/memory_resource.h 
b/libstdc++-v3/include/bits/memory_resource.h
index 022371245c1..5f50b296df7 100644
--- a/libstdc++-v3/include/bits/memory_resource.h
+++ b/libstdc++-v3/include/bits/memory_resource.h
@@ -305,7 +305,6 @@ namespace pmr
 #endif
 
   template
-   _GLIBCXX20_DEPRECATED_SUGGEST("allocator_traits::destroy")
__attribute__((__nonnull__))
void
destroy(_Up* __p)


[gcc r15-1538] libstdc++: Make std::any_cast ill-formed (LWG 3305)

2024-06-21 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:466ee78e3e975627440992dac67973ee314a0551

commit r15-1538-g466ee78e3e975627440992dac67973ee314a0551
Author: Jonathan Wakely 
Date:   Tue Jun 18 16:59:52 2024 +0100

libstdc++: Make std::any_cast ill-formed (LWG 3305)

LWG 3305 was approved earlier this year in Tokyo. We need to give an
error if using std::any_cast, but std::any_cast is valid
(but always returns null).

libstdc++-v3/ChangeLog:

* include/std/any (any_cast(any*), any_cast(const any*)): Add
static assertion to reject void types, as per LWG 3305.
* testsuite/20_util/any/misc/lwg3305.cc: New test.

Diff:
---
 libstdc++-v3/include/std/any   |  8 
 libstdc++-v3/testsuite/20_util/any/misc/lwg3305.cc | 15 +++
 2 files changed, 23 insertions(+)

diff --git a/libstdc++-v3/include/std/any b/libstdc++-v3/include/std/any
index 690ddc2aa57..e4709b1ce04 100644
--- a/libstdc++-v3/include/std/any
+++ b/libstdc++-v3/include/std/any
@@ -554,6 +554,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 inline const _ValueType* any_cast(const any* __any) noexcept
 {
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // 3305. any_cast
+  static_assert(!is_void_v<_ValueType>);
+
+  // As an optimization, don't bother instantiating __any_caster for
+  // function types, since std::any can only hold objects.
   if constexpr (is_object_v<_ValueType>)
if (__any)
  return static_cast<_ValueType*>(__any_caster<_ValueType>(__any));
@@ -563,6 +569,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 inline _ValueType* any_cast(any* __any) noexcept
 {
+  static_assert(!is_void_v<_ValueType>);
+
   if constexpr (is_object_v<_ValueType>)
if (__any)
  return static_cast<_ValueType*>(__any_caster<_ValueType>(__any));
diff --git a/libstdc++-v3/testsuite/20_util/any/misc/lwg3305.cc 
b/libstdc++-v3/testsuite/20_util/any/misc/lwg3305.cc
new file mode 100644
index 000..49f5d747ab3
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/any/misc/lwg3305.cc
@@ -0,0 +1,15 @@
+// { dg-do compile { target c++17 } }
+
+// LWG 3305. any_cast
+
+#include 
+
+void
+test_lwg3305()
+{
+  std::any a;
+  (void) std::any_cast(&a); // { dg-error "here" }
+  const std::any a2;
+  (void) std::any_cast(&a2); // { dg-error "here" }
+}
+// { dg-error "static assertion failed" "" { target *-*-* } 0 }


[gcc r15-1539] libstdc++: Qualify calls in to prevent ADL

2024-06-21 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:09ca26cd24778e0820525edfac1cce07262f7e6c

commit r15-1539-g09ca26cd24778e0820525edfac1cce07262f7e6c
Author: Jonathan Wakely 
Date:   Fri Jun 21 00:25:32 2024 +0100

libstdc++: Qualify calls in  to prevent ADL

libstdc++-v3/ChangeLog:

* include/bits/stl_uninitialized.h (uninitialized_default_construct)
(uninitialized_default_construct_n, uninitialized_value_construct)
(uninitialized_value_construct_n): Qualify calls to prevent ADL.

Diff:
---
 libstdc++-v3/include/bits/stl_uninitialized.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/include/bits/stl_uninitialized.h 
b/libstdc++-v3/include/bits/stl_uninitialized.h
index 7f84da31578..3c405d8fbe8 100644
--- a/libstdc++-v3/include/bits/stl_uninitialized.h
+++ b/libstdc++-v3/include/bits/stl_uninitialized.h
@@ -975,7 +975,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 uninitialized_default_construct(_ForwardIterator __first,
_ForwardIterator __last)
 {
-  __uninitialized_default_novalue(__first, __last);
+  std::__uninitialized_default_novalue(__first, __last);
 }
 
   /**
@@ -989,7 +989,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 inline _ForwardIterator
 uninitialized_default_construct_n(_ForwardIterator __first, _Size __count)
 {
-  return __uninitialized_default_novalue_n(__first, __count);
+  return std::__uninitialized_default_novalue_n(__first, __count);
 }
 
   /**
@@ -1003,7 +1003,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 uninitialized_value_construct(_ForwardIterator __first,
  _ForwardIterator __last)
 {
-  return __uninitialized_default(__first, __last);
+  return std::__uninitialized_default(__first, __last);
 }
 
   /**
@@ -1017,7 +1017,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 inline _ForwardIterator
 uninitialized_value_construct_n(_ForwardIterator __first, _Size __count)
 {
-  return __uninitialized_default_n(__first, __count);
+  return std::__uninitialized_default_n(__first, __count);
 }
 
   /**


[gcc r11-11520] tree-optimization/114027 - conditional reduction chain

2024-06-21 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:b6a029286d5034d63063ae78f406ba677c37d015

commit r11-11520-gb6a029286d5034d63063ae78f406ba677c37d015
Author: Richard Biener 
Date:   Thu Feb 22 10:50:12 2024 +0100

tree-optimization/114027 - conditional reduction chain

When we classify a conditional reduction chain as CONST_COND_REDUCTION
we fail to verify all involved conditionals have the same constant.
That's a quite unlikely situation so the following simply disables
such classification when there's more than one reduction statement.

PR tree-optimization/114027
* tree-vect-loop.c (vecctorizable_reduction): Use optimized
condition reduction classification only for single-element
chains.

* gcc.dg/vect/pr114027.c: New testcase.

(cherry picked from commit 549f251f055e3a0b0084189a3012c4f15d635e75)

Diff:
---
 gcc/testsuite/gcc.dg/vect/pr114027.c | 26 ++
 gcc/tree-vect-loop.c | 11 ++-
 2 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/vect/pr114027.c 
b/gcc/testsuite/gcc.dg/vect/pr114027.c
new file mode 100644
index 000..ead9cdd982d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr114027.c
@@ -0,0 +1,26 @@
+#include "tree-vect.h"
+
+int __attribute__((noipa))
+foo (int *f, int n)
+{
+  int res = 0;
+  for (int i = 0; i < n; ++i)
+{
+  if (f[2*i])
+res = 2;
+  if (f[2*i+1])
+res = -2;
+}
+  return res;
+}
+
+int f[] = { 1, 1, 1, 1, 1, 1, 1, 1,
+1, 1, 1, 1, 1, 1, 1, 0 };
+
+int
+main ()
+{
+  if (foo (f, 16) != 2)
+__builtin_abort ();
+  return 0;
+}
diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index 01d1361c9f0..48dbdc24490 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -6762,17 +6762,18 @@ vectorizable_reduction (loop_vec_info loop_vinfo,
  < GET_MODE_SIZE (SCALAR_TYPE_MODE (TREE_TYPE 
(vectype_op[i]))
vectype_in = vectype_op[i];
 
-  if (code == COND_EXPR)
+  /* Record how the non-reduction-def value of COND_EXPR is defined.
+???  For a chain of multiple CONDs we'd have to match them up all.  */
+  if (code == COND_EXPR && reduc_chain_length == 1)
{
- /* Record how the non-reduction-def value of COND_EXPR is defined.  */
  if (dt == vect_constant_def)
{
  cond_reduc_dt = dt;
  cond_reduc_val = op;
}
- if (dt == vect_induction_def
- && def_stmt_info
- && is_nonwrapping_integer_induction (def_stmt_info, loop))
+ else if (dt == vect_induction_def
+  && def_stmt_info
+  && is_nonwrapping_integer_induction (def_stmt_info, loop))
{
  cond_reduc_dt = dt;
  cond_stmt_vinfo = def_stmt_info;


[gcc r11-11522] tree-optimization/112793 - SLP of constant/external code-generated twice

2024-06-21 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:7e4dedbf9ff64964e356521d03a06838cbd4ca2e

commit r11-11522-g7e4dedbf9ff64964e356521d03a06838cbd4ca2e
Author: Richard Biener 
Date:   Wed Dec 13 14:23:31 2023 +0100

tree-optimization/112793 - SLP of constant/external code-generated twice

The following makes the attempt at code-generating a constant/external
SLP node twice well-formed as that can happen when partitioning BB
vectorization attempts where we keep constants/externals unpartitioned.

PR tree-optimization/112793
* tree-vect-slp.c (vect_schedule_slp_node): Already
code-generated constant/external nodes are OK.

* g++.dg/vect/pr112793.cc: New testcase.

(cherry picked from commit d782ec8362eadc3169286eb1e39c631effd02323)

Diff:
---
 gcc/testsuite/g++.dg/vect/pr112793.cc | 32 
 gcc/tree-vect-slp.c   | 16 +---
 2 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/gcc/testsuite/g++.dg/vect/pr112793.cc 
b/gcc/testsuite/g++.dg/vect/pr112793.cc
new file mode 100644
index 000..258d7c1b111
--- /dev/null
+++ b/gcc/testsuite/g++.dg/vect/pr112793.cc
@@ -0,0 +1,32 @@
+// { dg-do compile }
+// { dg-require-effective-target c++11 }
+// { dg-additional-options "-march=znver2" { target x86_64-*-* i?86-*-* } }
+
+typedef double T;
+T c, s;
+T a[16];
+struct Matrix4 {
+  Matrix4(){}
+  Matrix4(T e, T f, T i, T j) {
+r[1] = r[4] = e;
+r[5] = f;
+r[8] = i;
+r[9] = j;
+  }
+  Matrix4 operator*(Matrix4 a) {
+return Matrix4(
+   r[0] * a.r[4] + r[4] + r[15] + r[6],
+   r[1] * a.r[4] + 1 + 2 + 3,  r[0] * r[8] + 1 + 2 + 3,
+   r[1] * r[8] + r[1] + r[14] + r[2] * r[3]);
+  }
+  T r[16] = {};
+};
+Matrix4 t1, t2;
+Matrix4 tt;
+Matrix4 getRotAltAzToEquatorial()
+{
+  t2.r[4] =  0;
+  t1.r[1] =  -s;
+  t1.r[8] = 0;
+  return t1 * t2;
+}
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index 7c75799f625..a7eb9149221 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -6202,12 +6202,6 @@ vect_schedule_slp_node (vec_info *vinfo,
   int i;
   slp_tree child;
 
-  /* For existing vectors there's nothing to do.  */
-  if (SLP_TREE_VEC_DEFS (node).exists ())
-return;
-
-  gcc_assert (SLP_TREE_VEC_STMTS (node).is_empty ());
-
   /* Vectorize externals and constants.  */
   if (SLP_TREE_DEF_TYPE (node) == vect_constant_def
   || SLP_TREE_DEF_TYPE (node) == vect_external_def)
@@ -6218,10 +6212,18 @@ vect_schedule_slp_node (vec_info *vinfo,
   if (!SLP_TREE_VECTYPE (node))
return;
 
-  vect_create_constant_vectors (vinfo, node);
+  /* There are two reasons vector defs might already exist.  The first
+is that we are vectorizing an existing vector def.  The second is
+when performing BB vectorization shared constant/external nodes
+are not split apart during partitioning so during the code-gen
+DFS walk we can end up visiting them twice.  */
+  if (! SLP_TREE_VEC_DEFS (node).exists ())
+   vect_create_constant_vectors (vinfo, node);
   return;
 }
 
+  gcc_assert (SLP_TREE_VEC_DEFS (node).is_empty ());
+
   stmt_vec_info stmt_info = SLP_TREE_REPRESENTATIVE (node);
 
   gcc_assert (SLP_TREE_NUMBER_OF_VEC_STMTS (node) != 0);


[gcc r11-11521] tree-optimization/114027 - fix testcase

2024-06-21 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:70ebb2ecbbcdfc40e0beff95dd11c9d678694888

commit r11-11521-g70ebb2ecbbcdfc40e0beff95dd11c9d678694888
Author: Richard Biener 
Date:   Tue Mar 26 09:46:06 2024 +0100

tree-optimization/114027 - fix testcase

The following fixes out-of-bounds read in the testcase.

PR tree-optimization/114027
* gcc.dg/vect/pr114027.c: Fix iteration count.

(cherry picked from commit 4470611e20f3217ee81647b01fda65b6a62229aa)

Diff:
---
 gcc/testsuite/gcc.dg/vect/pr114027.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/vect/pr114027.c 
b/gcc/testsuite/gcc.dg/vect/pr114027.c
index ead9cdd982d..b3f3e30e15f 100644
--- a/gcc/testsuite/gcc.dg/vect/pr114027.c
+++ b/gcc/testsuite/gcc.dg/vect/pr114027.c
@@ -20,7 +20,7 @@ int f[] = { 1, 1, 1, 1, 1, 1, 1, 1,
 int
 main ()
 {
-  if (foo (f, 16) != 2)
+  if (foo (f, 8) != 2)
 __builtin_abort ();
   return 0;
 }


[gcc r11-11524] tree-optimization/112505 - bit-precision induction vectorization

2024-06-21 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:ffaa61eb15dce3e48b4dcbca7161fc79ac9734b8

commit r11-11524-gffaa61eb15dce3e48b4dcbca7161fc79ac9734b8
Author: Richard Biener 
Date:   Thu Jan 11 14:00:33 2024 +0100

tree-optimization/112505 - bit-precision induction vectorization

Vectorization of bit-precision inductions isn't implemented but we
don't check this, instead we ICE during transform.

PR tree-optimization/112505
* tree-vect-loop.c (vectorizable_induction): Reject
bit-precision induction.

* gcc.dg/vect/pr112505.c: New testcase.

(cherry picked from commit ec345df53556ec581590347f71c3d9ff3cdbca76)

Diff:
---
 gcc/testsuite/gcc.dg/vect/pr112505.c | 14 ++
 gcc/tree-vect-loop.c |  9 +
 2 files changed, 23 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/vect/pr112505.c 
b/gcc/testsuite/gcc.dg/vect/pr112505.c
new file mode 100644
index 000..56546c1095a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr112505.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-O3" } */
+
+short int w9;
+struct T {
+  short a : 14;
+  int b;
+};
+struct T v;
+void zc()
+{
+  for(int i = 0; i < 4; i ++)
+w9 *= v.b ? v.a-- < 0 : 0;
+}
diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index 48dbdc24490..0c1f7e49ed9 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -8032,6 +8032,15 @@ vectorizable_induction (loop_vec_info loop_vinfo,
 
   step_expr = STMT_VINFO_LOOP_PHI_EVOLUTION_PART (stmt_info);
   gcc_assert (step_expr != NULL_TREE);
+  if (INTEGRAL_TYPE_P (TREE_TYPE (step_expr))
+  && !type_has_mode_precision_p (TREE_TYPE (step_expr)))
+{
+  if (dump_enabled_p ())
+   dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+"bit-precision induction vectorization not "
+"supported.\n");
+  return false;
+}
   tree step_vectype = get_same_sized_vectype (TREE_TYPE (step_expr), vectype);
 
   /* Check for backend support of PLUS/MINUS_EXPR. */


[gcc r11-11519] middle-end/114734 - wrong code with expand_call_mem_ref

2024-06-21 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:a43c9bea7bd80af33ae116e7197f814ad911857e

commit r11-11519-ga43c9bea7bd80af33ae116e7197f814ad911857e
Author: Richard Biener 
Date:   Fri Apr 26 15:47:13 2024 +0200

middle-end/114734 - wrong code with expand_call_mem_ref

When expand_call_mem_ref looks at the definition of the address
argument to eventually expand a &TARGET_MEM_REF argument together
with a masked load it fails to honor constraints imposed by SSA
coalescing decisions.  The following fixes this.

PR middle-end/114734
* internal-fn.c (expand_call_mem_ref): Use
get_gimple_for_ssa_name to get at the def stmt of the address
argument to honor SSA coalescing constraints.

(cherry picked from commit 20ebcaf826c91ddaf2aac35417ec1e5e6d31ad50)

Diff:
---
 gcc/internal-fn.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c
index dc4337c2285..ebd3da32623 100644
--- a/gcc/internal-fn.c
+++ b/gcc/internal-fn.c
@@ -51,6 +51,11 @@ along with GCC; see the file COPYING3.  If not see
 #include "ssa-iterators.h"
 #include "explow.h"
 #include "rtl-iter.h"
+#include "tree-ssa-live.h"
+#include "tree-outof-ssa.h"
+
+/* For lang_hooks.types.type_for_mode.  */
+#include "langhooks.h"
 
 /* The names of each internal function, indexed by function number.  */
 const char *const internal_fn_name_array[] = {
@@ -2677,8 +2682,8 @@ expand_call_mem_ref (tree type, gcall *stmt, int index)
   tree tmp = addr;
   if (TREE_CODE (tmp) == SSA_NAME)
 {
-  gimple *def = SSA_NAME_DEF_STMT (tmp);
-  if (gimple_assign_single_p (def))
+  gimple *def = get_gimple_for_ssa_name (tmp);
+  if (def && gimple_assign_single_p (def))
tmp = gimple_assign_rhs1 (def);
 }


[gcc r11-11528] tree-optimization/111039 - abnormals and bit test merging

2024-06-21 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:bae5dcf29c6cb1f0da437858aa7214811ece53a5

commit r11-11528-gbae5dcf29c6cb1f0da437858aa7214811ece53a5
Author: Richard Biener 
Date:   Thu Aug 17 13:10:14 2023 +0200

tree-optimization/111039 - abnormals and bit test merging

The following guards the bit test merging code in if-combine against
the appearance of SSA names used in abnormal PHIs.

PR tree-optimization/111039
* tree-ssa-ifcombine.c (ifcombine_ifandif): Check for
SSA_NAME_OCCURS_IN_ABNORMAL_PHI.

* gcc.dg/pr111039.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/pr111039.c | 15 +++
 gcc/tree-ssa-ifcombine.c|  7 +++
 2 files changed, 22 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/pr111039.c b/gcc/testsuite/gcc.dg/pr111039.c
new file mode 100644
index 000..bec9983b35f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr111039.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O" } */
+
+int _setjmp ();
+void abcd ();
+void abcde ();
+void compiler_corruption_function(int flags)
+{
+  int nowait = flags & 1048576, isexpand = flags & 8388608;
+  abcd();
+  _setjmp(flags);
+  if (nowait && isexpand)
+flags &= 0;
+  abcde();
+}
diff --git a/gcc/tree-ssa-ifcombine.c b/gcc/tree-ssa-ifcombine.c
index 836a12d6b80..c366e872bcd 100644
--- a/gcc/tree-ssa-ifcombine.c
+++ b/gcc/tree-ssa-ifcombine.c
@@ -413,6 +413,9 @@ ifcombine_ifandif (basic_block inner_cond_bb, bool 
inner_inv,
 {
   tree t, t2;
 
+  if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name1))
+   return false;
+
   /* Do it.  */
   gsi = gsi_for_stmt (inner_cond);
   t = fold_build2 (LSHIFT_EXPR, TREE_TYPE (name1),
@@ -463,6 +466,10 @@ ifcombine_ifandif (basic_block inner_cond_bb, bool 
inner_inv,
   gimple_stmt_iterator gsi;
   tree t;
 
+  if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name1)
+ || SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name2))
+   return false;
+
   /* Find the common name which is bit-tested.  */
   if (name1 == name2)
;


[gcc r11-11523] debug/112718 - reset all type units with -ffat-lto-objects

2024-06-21 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:33e6997ef0ea30f57089038a15e2a33fcbd81648

commit r11-11523-g33e6997ef0ea30f57089038a15e2a33fcbd81648
Author: Richard Biener 
Date:   Mon Jan 22 15:42:59 2024 +0100

debug/112718 - reset all type units with -ffat-lto-objects

When mixing -flto, -ffat-lto-objects and -fdebug-type-section we
fail to reset all type units after early output resulting in an
ICE when attempting to add then duplicate sibling attributes.

PR debug/112718
* dwarf2out.c (dwarf2out_finish): Reset all type units
for the fat part of an LTO compile.

* gcc.dg/debug/pr112718.c: New testcase.

(cherry picked from commit 7218f5050cb7163edae331f54ca163248ab48bfa)

Diff:
---
 gcc/dwarf2out.c   | 12 
 gcc/testsuite/gcc.dg/debug/pr112718.c | 12 
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index bd6c00957ac..b276665a598 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -31697,24 +31697,12 @@ dwarf2out_finish (const char *filename)
   reset_dies (comp_unit_die ());
   for (limbo_die_node *node = cu_die_list; node; node = node->next)
reset_dies (node->die);
-
-  hash_table comdat_type_table (100);
   for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
{
- comdat_type_node **slot
- = comdat_type_table.find_slot (ctnode, INSERT);
-
- /* Don't reset types twice.  */
- if (*slot != HTAB_EMPTY_ENTRY)
-   continue;
-
  /* Remove the pointer to the line table.  */
  remove_AT (ctnode->root_die, DW_AT_stmt_list);
-
  if (debug_info_level >= DINFO_LEVEL_TERSE)
reset_dies (ctnode->root_die);
-
- *slot = ctnode;
}
 
   /* Reset die CU symbol so we don't output it twice.  */
diff --git a/gcc/testsuite/gcc.dg/debug/pr112718.c 
b/gcc/testsuite/gcc.dg/debug/pr112718.c
new file mode 100644
index 000..ff80ca5a298
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/pr112718.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target lto } */
+/* { dg-options "-g -fdebug-types-section -flto -ffat-lto-objects" } */
+
+struct {
+  int h;
+  unsigned char data[20 + 24 * 6];
+} _EC_X9_62_PRIME_192V2;
+struct {
+  int h;
+  unsigned char data[20 + 24 * 6];
+} _EC_X9_62_PRIME_192V3;


[gcc r11-11529] tree-optimization/111070 - fix ICE with recent ifcombine fix

2024-06-21 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:8d7ff01933c18532c82c864bd9182db619fcab43

commit r11-11529-g8d7ff01933c18532c82c864bd9182db619fcab43
Author: Richard Biener 
Date:   Mon Aug 21 09:01:00 2023 +0200

tree-optimization/111070 - fix ICE with recent ifcombine fix

We now got test coverage for non-SSA name bits so the following amends
the SSA_NAME_OCCURS_IN_ABNORMAL_PHI checks.

PR tree-optimization/111070
* tree-ssa-ifcombine.c (ifcombine_ifandif): Check we have
an SSA name before checking SSA_NAME_OCCURS_IN_ABNORMAL_PHI.

* gcc.dg/pr111070.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/pr111070.c | 20 
 gcc/tree-ssa-ifcombine.c|  9 ++---
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/pr111070.c b/gcc/testsuite/gcc.dg/pr111070.c
new file mode 100644
index 000..1ebc7adf782
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr111070.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-O" } */
+
+/* common */
+char c;
+/* arrays must be 8 byte aligned, regardless of size */
+char c_ary[1];
+
+/* data */
+char d = 1;
+char d_ary[1] = {1};
+
+int main ()
+{
+  if (((unsigned long)&c_ary[0] & 7) != 0)
+return 1;
+  if (((unsigned long)&d_ary[0] & 7) != 0)
+return 1;
+  return 0;
+}
diff --git a/gcc/tree-ssa-ifcombine.c b/gcc/tree-ssa-ifcombine.c
index c366e872bcd..e22bed94f11 100644
--- a/gcc/tree-ssa-ifcombine.c
+++ b/gcc/tree-ssa-ifcombine.c
@@ -413,7 +413,8 @@ ifcombine_ifandif (basic_block inner_cond_bb, bool 
inner_inv,
 {
   tree t, t2;
 
-  if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name1))
+  if (TREE_CODE (name1) == SSA_NAME
+ && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name1))
return false;
 
   /* Do it.  */
@@ -466,8 +467,10 @@ ifcombine_ifandif (basic_block inner_cond_bb, bool 
inner_inv,
   gimple_stmt_iterator gsi;
   tree t;
 
-  if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name1)
- || SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name2))
+  if ((TREE_CODE (name1) == SSA_NAME
+  && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name1))
+ || (TREE_CODE (name2) == SSA_NAME
+ && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name2)))
return false;
 
   /* Find the common name which is bit-tested.  */


[gcc r11-11527] debug/111080 - avoid outputting debug info for unused restrict qualified type

2024-06-21 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:80ded4e8f871c98481bab912997034b9d24b1c96

commit r11-11527-g80ded4e8f871c98481bab912997034b9d24b1c96
Author: Richard Biener 
Date:   Mon Aug 21 10:34:30 2023 +0200

debug/111080 - avoid outputting debug info for unused restrict qualified 
type

The following applies some maintainance with respect to type qualifiers
and kinds added by later DWARF standards to prune_unused_types_walk.
The particular case in the bug is not handling (thus marking required)
all restrict qualified type DIEs.  I've found more DW_TAG_*_type that
are unhandled, looked up the DWARF docs and added them as well based
on common sense.

PR debug/111080
* dwarf2out.c (prune_unused_types_walk): Handle
DW_TAG_restrict_type, DW_TAG_shared_type, DW_TAG_atomic_type,
DW_TAG_immutable_type, DW_TAG_coarray_type, DW_TAG_unspecified_type
and DW_TAG_dynamic_type as to only output them when referenced.

* gcc.dg/debug/dwarf2/pr111080.c: New testcase.

Diff:
---
 gcc/dwarf2out.c  |  7 +++
 gcc/testsuite/gcc.dg/debug/dwarf2/pr111080.c | 18 ++
 2 files changed, 25 insertions(+)

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index b276665a598..3d8e0e6d6b3 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -29693,8 +29693,13 @@ prune_unused_types_walk (dw_die_ref die)
 case DW_TAG_reference_type:
 case DW_TAG_rvalue_reference_type:
 case DW_TAG_volatile_type:
+case DW_TAG_restrict_type:
+case DW_TAG_shared_type:
+case DW_TAG_atomic_type:
+case DW_TAG_immutable_type:
 case DW_TAG_typedef:
 case DW_TAG_array_type:
+case DW_TAG_coarray_type:
 case DW_TAG_friend:
 case DW_TAG_enumeration_type:
 case DW_TAG_subroutine_type:
@@ -29703,6 +29708,8 @@ prune_unused_types_walk (dw_die_ref die)
 case DW_TAG_subrange_type:
 case DW_TAG_ptr_to_member_type:
 case DW_TAG_file_type:
+case DW_TAG_unspecified_type:
+case DW_TAG_dynamic_type:
   /* Type nodes are useful only when other DIEs reference them --- don't
 mark them.  */
   /* FALLTHROUGH */
diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/pr111080.c 
b/gcc/testsuite/gcc.dg/debug/dwarf2/pr111080.c
new file mode 100644
index 000..3949d7e7c64
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/dwarf2/pr111080.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-save-temps -gdwarf-3 -dA" } */
+
+struct foo {
+int field_number_1;
+int field_number_2;
+int field_number_3;
+int field_number_4;
+int field_number_5;
+};
+
+typedef int fun_t(struct foo *restrict);
+
+int main() {
+return 0;
+}
+
+/* { dg-final { scan-assembler-not "DW_TAG_structure_type" } } */


[gcc r11-11530] middle-end/110176 - wrong zext (bool) <= (int) 4294967295u folding

2024-06-21 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:0d0f181dedb928a6dbb9af040a09cda3f4d5da64

commit r11-11530-g0d0f181dedb928a6dbb9af040a09cda3f4d5da64
Author: Richard Biener 
Date:   Wed Jan 31 14:40:24 2024 +0100

middle-end/110176 - wrong zext (bool) <= (int) 4294967295u folding

The following fixes a wrong pattern that didn't match the behavior
of the original fold_widened_comparison in that get_unwidened
returned a constant always in the wider type.  But here we're
using (int) 4294967295u without the conversion applied.  Fixed
by doing as earlier in the pattern - matching constants only
if the conversion was actually applied.

PR middle-end/110176
* match.pd (zext (bool) <= (int) 4294967295u): Make sure
to match INTEGER_CST only without outstanding conversion.

* gcc.dg/torture/pr110176.c: New testcase.

(cherry picked from commit 22dbfbe8767ff4c1d93e39f68ec7c2d5b1358beb)

Diff:
---
 gcc/match.pd| 12 -
 gcc/testsuite/gcc.dg/torture/pr110176.c | 46 +
 2 files changed, 52 insertions(+), 6 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index d040c853942..7f59b1dac8a 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4712,19 +4712,19 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   >= TYPE_PRECISION (TREE_TYPE (@10)))
  && (TYPE_UNSIGNED (TREE_TYPE (@00))
  == TYPE_UNSIGNED (TREE_TYPE (@10
- || (TREE_CODE (@10) == INTEGER_CST
+ || (TREE_CODE (@1) == INTEGER_CST
  && INTEGRAL_TYPE_P (TREE_TYPE (@00))
- && int_fits_type_p (@10, TREE_TYPE (@00)
+ && int_fits_type_p (@1, TREE_TYPE (@00)
   (cmp @00 (convert @10))
-  (if (TREE_CODE (@10) == INTEGER_CST
+  (if (TREE_CODE (@1) == INTEGER_CST
   && INTEGRAL_TYPE_P (TREE_TYPE (@00))
-  && !int_fits_type_p (@10, TREE_TYPE (@00)))
+  && !int_fits_type_p (@1, TREE_TYPE (@00)))
(with
{
  tree min = lower_bound_in_type (TREE_TYPE (@10), TREE_TYPE (@00));
  tree max = upper_bound_in_type (TREE_TYPE (@10), TREE_TYPE (@00));
- bool above = integer_nonzerop (const_binop (LT_EXPR, type, max, @10));
- bool below = integer_nonzerop (const_binop (LT_EXPR, type, @10, min));
+ bool above = integer_nonzerop (const_binop (LT_EXPR, type, max, @1));
+ bool below = integer_nonzerop (const_binop (LT_EXPR, type, @1, min));
}
(if (above || below)
 (if (cmp == EQ_EXPR || cmp == NE_EXPR)
diff --git a/gcc/testsuite/gcc.dg/torture/pr110176.c 
b/gcc/testsuite/gcc.dg/torture/pr110176.c
new file mode 100644
index 000..e41e3a0c3a7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr110176.c
@@ -0,0 +1,46 @@
+/* { dg-do run } */
+
+int f(_Bool t)
+{
+int tt = t;
+unsigned x = -1;
+int xx = x;
+return xx <= tt;
+}
+
+int a, b;
+void c() {}
+__attribute__((noipa))
+void h() {__builtin_abort();}
+int d() {
+  unsigned f[1];
+  int i;
+  if (a)
+goto h;
+  f[0] = -1;
+  while (1) {
+c();
+for (; a < 1; a++) {
+  if (0) {
+  j:
+continue;
+  }
+  i = f[0];
+  if (a)
+break;
+  b = i >= (b == 0);
+}
+if (!b) {
+  if (0) {
+  h:
+goto j;
+  }
+  return 0;
+}
+h();
+  }
+}
+int main() {
+  d();
+  return 0;
+}


[gcc r11-11525] tree-optimization/112495 - alias versioning and address spaces

2024-06-21 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:20fe647365a922c6dd7a7f283abb99b5588476e8

commit r11-11525-g20fe647365a922c6dd7a7f283abb99b5588476e8
Author: Richard Biener 
Date:   Mon Nov 13 10:20:37 2023 +0100

tree-optimization/112495 - alias versioning and address spaces

We are not correctly handling differing address spaces in dependence
analysis runtime alias check generation so refuse to do that.

PR tree-optimization/112495
* tree-data-ref.c (runtime_alias_check_p): Reject checks
between different address spaces.

* gcc.target/i386/pr112495.c: New testcase.

(cherry picked from commit 0f593c0521caab8cfac53514b1a5e7d0d0dd1932)

Diff:
---
 gcc/testsuite/gcc.target/i386/pr112495.c | 12 
 gcc/tree-data-ref.c  |  7 +++
 2 files changed, 19 insertions(+)

diff --git a/gcc/testsuite/gcc.target/i386/pr112495.c 
b/gcc/testsuite/gcc.target/i386/pr112495.c
new file mode 100644
index 000..21afbaa6945
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr112495.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O3" } */
+
+typedef struct { int v; } T1;
+typedef struct { T1 v[32]; } T2;
+
+T1 s;
+T1 f1() { return s; }
+
+void f2(__seg_gs T2 *p, int n) {
+  for (int i = 0; i < n; ++i) p->v[i] = f1();
+}
diff --git a/gcc/tree-data-ref.c b/gcc/tree-data-ref.c
index d127aba8792..53c73bd5ba0 100644
--- a/gcc/tree-data-ref.c
+++ b/gcc/tree-data-ref.c
@@ -1642,6 +1642,13 @@ runtime_alias_check_p (ddr_p ddr, class loop *loop, bool 
speed_p)
   "runtime alias check not supported for"
   " outer loop.\n");
 
+  /* FORNOW: We don't support handling different address spaces.  */
+  if (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (DR_BASE_ADDRESS (DDR_A (ddr)
+  != TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (DR_BASE_ADDRESS (DDR_B 
(ddr))
+return opt_result::failure_at (DR_STMT (DDR_A (ddr)),
+  "runtime alias check between different "
+  "address spaces not supported.\n");
+
   return opt_result::success ();
 }


[gcc r11-11526] tree-optimization/111445 - simple_iv simplification fault

2024-06-21 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:ce653fa683643d4e5a7146181954358f1060dfed

commit r11-11526-gce653fa683643d4e5a7146181954358f1060dfed
Author: Richard Biener 
Date:   Fri Oct 20 15:08:49 2023 +0200

tree-optimization/111445 - simple_iv simplification fault

The following fixes a missed check in the simple_iv attempt
to simplify (signed T)((unsigned T) base + step) where it
allows a truncating inner conversion leading to wrong code.

PR tree-optimization/111445
* tree-scalar-evolution.c (simple_iv_with_niters):
Add missing check for a sign-conversion.

* gcc.dg/torture/pr111445.c: New testcase.

(cherry picked from commit 9692309ed6b625f0fb358c0e230404b5603f69a6)

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr111445.c | 29 +
 gcc/tree-scalar-evolution.c |  3 ++-
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr111445.c 
b/gcc/testsuite/gcc.dg/torture/pr111445.c
new file mode 100644
index 000..320e0b90675
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr111445.c
@@ -0,0 +1,29 @@
+/* { dg-do run } */
+
+extern void abort (void);
+short a, b;
+unsigned char c = 255;
+unsigned cnt;
+void __attribute__((noipa))
+check (int x)
+{
+  if (x != 0)
+abort ();
+  cnt++;
+}
+int main()
+{
+  int d;
+  unsigned char e;
+  d = 0;
+  for (; a >= 0; a--) {
+int *f = &d;
+*f = c;
+  }
+  e = 0;
+  for (; (unsigned char)(d - 255) + e <= 1; e++)
+check (b);
+  if (cnt != 2)
+abort ();
+  return 0;
+}
diff --git a/gcc/tree-scalar-evolution.c b/gcc/tree-scalar-evolution.c
index ff052be1021..da85647c70d 100644
--- a/gcc/tree-scalar-evolution.c
+++ b/gcc/tree-scalar-evolution.c
@@ -3281,7 +3281,8 @@ simple_iv_with_niters (class loop *wrto_loop, class loop 
*use_loop,
 
   type = TREE_TYPE (iv->base);
   e = TREE_OPERAND (iv->base, 0);
-  if (TREE_CODE (e) != PLUS_EXPR
+  if (!tree_nop_conversion_p (type, TREE_TYPE (e))
+  || TREE_CODE (e) != PLUS_EXPR
   || TREE_CODE (TREE_OPERAND (e, 1)) != INTEGER_CST
   || !tree_int_cst_equal (iv->step,
  fold_convert (type, TREE_OPERAND (e, 1


[gcc r14-10333] Avoid SLP_REPRESENTATIVE access for VEC_PERM in SLP scheduling

2024-06-21 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:85d32e6f75e7395c12b9979a47b70fe9479ca1ff

commit r14-10333-g85d32e6f75e7395c12b9979a47b70fe9479ca1ff
Author: Richard Biener 
Date:   Fri May 17 15:23:38 2024 +0200

Avoid SLP_REPRESENTATIVE access for VEC_PERM in SLP scheduling

SLP permute nodes can end up without a SLP_REPRESENTATIVE now,
the following avoids touching it in this case in vect_schedule_slp_node.

* tree-vect-slp.cc (vect_schedule_slp_node): Avoid looking
at SLP_REPRESENTATIVE for VEC_PERM nodes.

(cherry picked from commit 31e9bae0ea5e5413abfa3ca9050e66cc6760553e)

Diff:
---
 gcc/tree-vect-slp.cc | 28 
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index 133606fa6f3..e55191c83a6 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -9271,13 +9271,8 @@ vect_schedule_slp_node (vec_info *vinfo,
   gcc_assert (SLP_TREE_NUMBER_OF_VEC_STMTS (node) != 0);
   SLP_TREE_VEC_DEFS (node).create (SLP_TREE_NUMBER_OF_VEC_STMTS (node));
 
-  if (dump_enabled_p ())
-dump_printf_loc (MSG_NOTE, vect_location,
-"-->vectorizing SLP node starting from: %G",
-stmt_info->stmt);
-
-  if (STMT_VINFO_DATA_REF (stmt_info)
-  && SLP_TREE_CODE (node) != VEC_PERM_EXPR)
+  if (SLP_TREE_CODE (node) != VEC_PERM_EXPR
+  && STMT_VINFO_DATA_REF (stmt_info))
 {
   /* Vectorized loads go before the first scalar load to make it
 ready early, vectorized stores go before the last scalar
@@ -9289,10 +9284,10 @@ vect_schedule_slp_node (vec_info *vinfo,
last_stmt_info = vect_find_last_scalar_stmt_in_slp (node);
   si = gsi_for_stmt (last_stmt_info->stmt);
 }
-  else if ((STMT_VINFO_TYPE (stmt_info) == cycle_phi_info_type
-   || STMT_VINFO_TYPE (stmt_info) == induc_vec_info_type
-   || STMT_VINFO_TYPE (stmt_info) == phi_info_type)
-  && SLP_TREE_CODE (node) != VEC_PERM_EXPR)
+  else if (SLP_TREE_CODE (node) != VEC_PERM_EXPR
+  && (STMT_VINFO_TYPE (stmt_info) == cycle_phi_info_type
+  || STMT_VINFO_TYPE (stmt_info) == induc_vec_info_type
+  || STMT_VINFO_TYPE (stmt_info) == phi_info_type))
 {
   /* For PHI node vectorization we do not use the insertion iterator.  */
   si = gsi_none ();
@@ -9426,6 +9421,9 @@ vect_schedule_slp_node (vec_info *vinfo,
   /* Handle purely internal nodes.  */
   if (SLP_TREE_CODE (node) == VEC_PERM_EXPR)
 {
+  if (dump_enabled_p ())
+   dump_printf_loc (MSG_NOTE, vect_location,
+"-->vectorizing SLP permutation node\n");
   /* ???  the transform kind is stored to STMT_VINFO_TYPE which might
 be shared with different SLP nodes (but usually it's the same
 operation apart from the case the stmt is only there for denoting
@@ -9444,7 +9442,13 @@ vect_schedule_slp_node (vec_info *vinfo,
  }
 }
   else
-vect_transform_stmt (vinfo, stmt_info, &si, node, instance);
+{
+  if (dump_enabled_p ())
+   dump_printf_loc (MSG_NOTE, vect_location,
+"-->vectorizing SLP node starting from: %G",
+stmt_info->stmt);
+  vect_transform_stmt (vinfo, stmt_info, &si, node, instance);
+}
 }
 
 /* Replace scalar calls from SLP node NODE with setting of their lhs to zero.


[gcc r14-10334] tree-optimization/115508 - fix ICE with SLP scheduling and extern vector

2024-06-21 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:65e25860f49ee7a2cfd4872db06d94ed7675e12e

commit r14-10334-g65e25860f49ee7a2cfd4872db06d94ed7675e12e
Author: Richard Biener 
Date:   Mon Jun 17 14:36:56 2024 +0200

tree-optimization/115508 - fix ICE with SLP scheduling and extern vector

When there's a permute after an extern vector we can run into a case
that didn't consider the scheduled node being a permute which lacks
a representative.

PR tree-optimization/115508
* tree-vect-slp.cc (vect_schedule_slp_node): Guard check on
representative.

* gcc.target/i386/pr115508.c: New testcase.

(cherry picked from commit 65e72b95c63a5501cf1482f3814ae8c8e672bf06)

Diff:
---
 gcc/testsuite/gcc.target/i386/pr115508.c | 15 +++
 gcc/tree-vect-slp.cc |  1 +
 2 files changed, 16 insertions(+)

diff --git a/gcc/testsuite/gcc.target/i386/pr115508.c 
b/gcc/testsuite/gcc.target/i386/pr115508.c
new file mode 100644
index 000..a97b2007f7a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr115508.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=znver1" } */
+
+typedef long long v4di __attribute__((vector_size(4 * sizeof (long long;
+
+v4di vec_var;
+extern long long array1[];
+long long g(void)
+{
+  int total_error_4 = 0;
+  total_error_4 += array1 [0] + array1 [1] + array1 [2] + array1 [3];
+  v4di t = vec_var;
+  long long iorvar = t [1] | t [0] | t [2] | t [3];
+  return iorvar + total_error_4;
+}
diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index e55191c83a6..5e7e9b5bf08 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -9395,6 +9395,7 @@ vect_schedule_slp_node (vec_info *vinfo,
  si = gsi_after_labels (as_a  (vinfo)->bbs[0]);
}
   else if (is_a  (vinfo)
+  && SLP_TREE_CODE (node) != VEC_PERM_EXPR
   && gimple_bb (last_stmt) != gimple_bb (stmt_info->stmt)
   && gimple_could_trap_p (stmt_info->stmt))
{


[gcc r14-10335] tree-optimization/115278 - fix DSE in if-conversion wrt volatiles

2024-06-21 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:272e8c90af527fc1d0055ad0f17f1d97bb0bd6cb

commit r14-10335-g272e8c90af527fc1d0055ad0f17f1d97bb0bd6cb
Author: Richard Biener 
Date:   Fri May 31 10:14:25 2024 +0200

tree-optimization/115278 - fix DSE in if-conversion wrt volatiles

The following adds the missing guard for volatile stores to the
embedded DSE in the loop if-conversion pass.

PR tree-optimization/115278
* tree-if-conv.cc (ifcvt_local_dce): Do not DSE volatile stores.

* g++.dg/vect/pr115278.cc: New testcase.

(cherry picked from commit 65dbe0ab7cdaf2aa84b09a74e594f0faacf1945c)

Diff:
---
 gcc/testsuite/g++.dg/vect/pr115278.cc | 38 +++
 gcc/tree-if-conv.cc   |  4 +++-
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/vect/pr115278.cc 
b/gcc/testsuite/g++.dg/vect/pr115278.cc
new file mode 100644
index 000..331075fb278
--- /dev/null
+++ b/gcc/testsuite/g++.dg/vect/pr115278.cc
@@ -0,0 +1,38 @@
+// { dg-do compile }
+// { dg-require-effective-target c++11 }
+// { dg-additional-options "-fdump-tree-optimized" }
+
+#include 
+
+const int runs = 92;
+
+union BitfieldStructUnion {
+struct {
+uint64_t a : 17;
+uint64_t padding: 39;
+uint64_t b : 8;
+} __attribute__((packed));
+
+struct {
+uint32_t value_low;
+uint32_t value_high;
+} __attribute__((packed));
+
+BitfieldStructUnion(uint32_t value_low, uint32_t value_high) : 
value_low(value_low), value_high(value_high) {}
+};
+
+volatile uint32_t *WRITE = (volatile unsigned*)0x42;
+
+void buggy() {
+for (int i = 0; i < runs; i++) {
+BitfieldStructUnion rt{*WRITE, *WRITE};
+
+rt.a = 99;
+rt.b = 1;
+
+*WRITE = rt.value_low;
+*WRITE = rt.value_high;
+}
+}
+
+// { dg-final { scan-tree-dump-times "\\\*WRITE\[^\r\n\]* ={v} " 2 "optimized" 
} }
diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc
index 09d99fb9dda..c4c3ed41a44 100644
--- a/gcc/tree-if-conv.cc
+++ b/gcc/tree-if-conv.cc
@@ -3381,7 +3381,9 @@ ifcvt_local_dce (class loop *loop)
   gimple_stmt_iterator gsiprev = gsi;
   gsi_prev (&gsiprev);
   stmt = gsi_stmt (gsi);
-  if (gimple_store_p (stmt) && gimple_vdef (stmt))
+  if (!gimple_has_volatile_ops (stmt)
+ && gimple_store_p (stmt)
+ && gimple_vdef (stmt))
{
  tree lhs = gimple_get_lhs (stmt);
  ao_ref write;


[gcc r15-1540] diagnostics: fixes to SARIF output [PR109360]

2024-06-21 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:9f4fdc3acebcf6b045edea1361570658da4bc0ab

commit r15-1540-g9f4fdc3acebcf6b045edea1361570658da4bc0ab
Author: David Malcolm 
Date:   Fri Jun 21 08:46:13 2024 -0400

diagnostics: fixes to SARIF output [PR109360]

When adding validation of .sarif files against the schema
(PR testsuite/109360) I discovered various issues where we were
generating invalid .sarif files.

Specifically, in
  c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c
the relatedLocations for the "note" diagnostics were missing column
numbers, leading to validation failure due to non-unique elements,
such as multiple:
"message": {"text": "invalid UTF-8 character "}},
on line 25 with no column information.

Root cause is that for some diagnostics in libcpp we have a location_t
representing the line as a whole, setting a column_override on the
rich_location (since the line hasn't been fully read yet).  We were
handling this column override for plain text output, but not for .sarif
output.

Similarly, in diagnostic-format-sarif-file-pr111700.c there is a warning
emitted on "line 0" of the file, whereas SARIF requires line numbers to
be positive.

We also use column == 0 internally to mean "the line as a whole",
whereas SARIF required column numbers to be positive.

This patch fixes these various issues.

gcc/ChangeLog:
PR testsuite/109360
* diagnostic-format-sarif.cc
(sarif_builder::make_location_object): Pass any column override
from rich_loc to maybe_make_physical_location_object.
(sarif_builder::maybe_make_physical_location_object): Add
"column_override" param and pass it to maybe_make_region_object.
(sarif_builder::maybe_make_region_object): Add "column_override"
param and use it when the location has 0 for a column.  Don't
add "startLine", "startColumn", "endLine", or "endColumn" if
the values aren't positive.
(sarif_builder::maybe_make_region_object_for_context): Don't
add "startLine" or "endLine" if the values aren't positive.

libcpp/ChangeLog:
PR testsuite/109360
* include/rich-location.h (rich_location::get_column_override):
New accessor.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/diagnostic-format-sarif.cc | 75 ++
 libcpp/include/rich-location.h |  2 ++
 2 files changed, 56 insertions(+), 21 deletions(-)

diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc
index 5f438dd38a8..5581aa1579e 100644
--- a/gcc/diagnostic-format-sarif.cc
+++ b/gcc/diagnostic-format-sarif.cc
@@ -243,11 +243,13 @@ private:
   json::array *maybe_make_kinds_array (diagnostic_event::meaning m) const;
   json::object *
   maybe_make_physical_location_object (location_t loc,
-  enum diagnostic_artifact_role role);
+  enum diagnostic_artifact_role role,
+  int column_override);
   json::object *make_artifact_location_object (location_t loc);
   json::object *make_artifact_location_object (const char *filename);
   json::object *make_artifact_location_object_for_pwd () const;
-  json::object *maybe_make_region_object (location_t loc) const;
+  json::object *maybe_make_region_object (location_t loc,
+ int column_override) const;
   json::object *maybe_make_region_object_for_context (location_t loc) const;
   json::object *make_region_object_for_hint (const fixit_hint &hint) const;
   json::object *make_multiformat_message_string (const char *msg) const;
@@ -924,8 +926,9 @@ sarif_builder::make_location_object (const rich_location 
&rich_loc,
   location_t loc = rich_loc.get_loc ();
 
   /* "physicalLocation" property (SARIF v2.1.0 section 3.28.3).  */
-  if (json::object *phs_loc_obj = maybe_make_physical_location_object (loc,
-  role))
+  if (json::object *phs_loc_obj
+   = maybe_make_physical_location_object (loc, role,
+  rich_loc.get_column_override ()))
 location_obj->set ("physicalLocation", phs_loc_obj);
 
   /* "logicalLocations" property (SARIF v2.1.0 section 3.28.4).  */
@@ -946,7 +949,7 @@ sarif_builder::make_location_object (const diagnostic_event 
&event,
   /* "physicalLocation" property (SARIF v2.1.0 section 3.28.3).  */
   location_t loc = event.get_location ();
   if (json::object *phs_loc_obj
-   = maybe_make_physical_location_object (loc, role))
+   = maybe_make_physical_location_object (loc, role, 0))
 location_obj->set ("physicalLocation", phs_loc_obj);
 
   /* "logicalLocations" property (SARIF v2.1.0 section 3.28.4).  */
@@ -961,7 +964,10 @@ sarif_build

[gcc r15-1541] testsuite: check that generated .sarif files validate against the SARIF schema [PR109360]

2024-06-21 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:a84fe222029ff21903283cc8ee4bc760ebf80ec2

commit r15-1541-ga84fe222029ff21903283cc8ee4bc760ebf80ec2
Author: David Malcolm 
Date:   Fri Jun 21 08:46:14 2024 -0400

testsuite: check that generated .sarif files validate against the SARIF 
schema [PR109360]

This patch extends the dg directive verify-sarif-file so that if
the "jsonschema" tool is available, it will be used to validate the
generated .sarif file.

Tested with jsonschema 3.2 with Python 3.8

gcc/ChangeLog:
PR testsuite/109360
* doc/install.texi: Mention optional usage of "jsonschema" tool.

gcc/testsuite/ChangeLog:
PR testsuite/109360
* lib/sarif-schema-2.1.0.json: New file, downloaded from

https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/schemas/sarif-schema-2.1.0.json
Licensing information can be seen at
https://github.com/oasis-tcs/sarif-spec/issues/583
which states "They are free to incorporate it into their
implementation. No need for special permission or paperwork from
OASIS."
* lib/scansarif.exp (verify-sarif-file): If "jsonschema" is
available, use it to verify that the .sarif file complies with the
SARIF schema.
* lib/target-supports.exp (check_effective_target_jsonschema):
New.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/doc/install.texi  |5 +
 gcc/testsuite/lib/sarif-schema-2.1.0.json | 3370 +
 gcc/testsuite/lib/scansarif.exp   |   23 +
 gcc/testsuite/lib/target-supports.exp |   12 +
 4 files changed, 3410 insertions(+)

diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 1774a010889..0c769165146 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -460,6 +460,11 @@ is shown below:
 @item g++ testsuite
 @code{gcov}, @code{gzip}, @code{json}, @code{os} and @code{pytest}.
 
+@item SARIF testsuite
+Tests of SARIF output will use the @code{jsonschema} program from the
+@code{jsonschema} module (if available) to validate generated .sarif files.
+If this tool is not found, the validation parts of those tests are skipped.
+
 @item c++ cxx api generation
 @code{csv}, @code{os}, @code{sys} and @code{time}.
 
diff --git a/gcc/testsuite/lib/sarif-schema-2.1.0.json 
b/gcc/testsuite/lib/sarif-schema-2.1.0.json
new file mode 100644
index 000..e0b65245710
--- /dev/null
+++ b/gcc/testsuite/lib/sarif-schema-2.1.0.json
@@ -0,0 +1,3370 @@
+{
+  "$schema": "http://json-schema.org/draft-07/schema#";,
+  "title": "Static Analysis Results Format (SARIF) Version 2.1.0 JSON Schema",
+  "$id": 
"https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json";,
+  "description": "Static Analysis Results Format (SARIF) Version 2.1.0 JSON 
Schema: a standard format for the output of static analysis tools.",
+  "additionalProperties": false,
+  "type": "object",
+  "properties": {
+
+"$schema": {
+  "description": "The URI of the JSON schema corresponding to the 
version.",
+  "type": "string",
+  "format": "uri"
+},
+
+"version": {
+  "description": "The SARIF format version of this log file.",
+  "enum": [ "2.1.0" ]
+},
+
+"runs": {
+  "description": "The set of runs contained in this log file.",
+  "type": "array",
+  "minItems": 0,
+  "uniqueItems": false,
+  "items": {
+"$ref": "#/definitions/run"
+  }
+},
+
+"inlineExternalProperties": {
+  "description": "References to external property files that share data 
between runs.",
+  "type": "array",
+  "minItems": 0,
+  "uniqueItems": true,
+  "items": {
+"$ref": "#/definitions/externalProperties"
+  }
+},
+
+"properties": {
+  "description": "Key/value pairs that provide additional information 
about the log file.",
+  "$ref": "#/definitions/propertyBag"
+}
+  },
+
+  "required": [ "version", "runs" ],
+
+  "definitions": {
+
+"address": {
+  "description": "A physical or virtual address, or a range of addresses, 
in an 'addressable region' (memory or a binary file).",
+  "additionalProperties": false,
+  "type": "object",
+  "properties": {
+
+"absoluteAddress": {
+  "description": "The address expressed as a byte offset from the 
start of the addressable region.",
+  "type": "integer",
+  "minimum": -1,
+  "default": -1
+
+},
+
+"relativeAddress": {
+  "description": "The address expressed as a byte offset from the 
absolute address of the top-most parent object.",
+  "type": "integer"
+
+},
+
+"length": {
+  "description": "The number of bytes in this range of addresses.",
+  "type": "integer"
+},
+
+"kind": {
+  "description": "An open-ended string that i

[gcc r15-1542] Add builtin_unreachable processing for fast_vrp.

2024-06-21 Thread Andrew Macleod via Gcc-cvs
https://gcc.gnu.org/g:ffaa806c302cca23b36173b65140a1ee1b1826af

commit r15-1542-gffaa806c302cca23b36173b65140a1ee1b1826af
Author: Andrew MacLeod 
Date:   Mon Jun 17 11:23:12 2024 -0400

Add builtin_unreachable processing for fast_vrp.

Add a remove_unreachable object to fast vrp, and honor the final_p flag.

* tree-vrp.cc (remove_unreachable::remove): Export global range
if builtin_unreachable dominates all uses.
(remove_unreachable::remove_and_update_globals): Do not reset SCEV.
(execute_ranger_vrp): Reset SCEV here instead.
(fvrp_folder::fvrp_folder): Take final pass flag
and create a remove_unreachable object when specified.
(fvrp_folder::pre_fold_stmt): Register GIMPLE_CONDs with
the remove_unreachcable object.
(fvrp_folder::m_unreachable): New.
(execute_fast_vrp): Process remove_unreachable object.
(pass_vrp::execute): Add final_p flag to execute_fast_vrp.

Diff:
---
 gcc/tree-vrp.cc | 52 +---
 1 file changed, 41 insertions(+), 11 deletions(-)

diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc
index 5f5eb9b57e9..a3b1a5cd337 100644
--- a/gcc/tree-vrp.cc
+++ b/gcc/tree-vrp.cc
@@ -280,6 +280,25 @@ remove_unreachable::remove ()
   gimple *s = gimple_outgoing_range_stmt_p (e->src);
   gcc_checking_assert (gimple_code (s) == GIMPLE_COND);
 
+  tree name = gimple_range_ssa_p (gimple_cond_lhs (s));
+  if (!name)
+   name = gimple_range_ssa_p (gimple_cond_rhs (s));
+  // Check if global value can be set for NAME.
+  if (name && fully_replaceable (name, src))
+   {
+ value_range r (TREE_TYPE (name));
+ if (gori_name_on_edge (r, name, e, &m_ranger)
+ && set_range_info (name, r) &&(dump_file))
+   {
+ fprintf (dump_file, "Global Exported (via unreachable): ");
+ print_generic_expr (dump_file, name, TDF_SLIM);
+ fprintf (dump_file, " = ");
+ gimple_range_global (r, name);
+ r.dump (dump_file);
+ fputc ('\n', dump_file);
+   }
+   }
+
   change = true;
   // Rewrite the condition.
   if (e->flags & EDGE_TRUE_VALUE)
@@ -305,14 +324,10 @@ remove_unreachable::remove_and_update_globals ()
   if (m_list.length () == 0)
 return false;
 
-  // If there is no import/export info, just remove unreachables if necessary.
+  // If there is no import/export info, Do basic removal.
   if (!m_ranger.gori_ssa ())
 return remove ();
 
-  // Ensure the cache in SCEV has been cleared before processing
-  // globals to be removed.
-  scev_reset ();
-
   bool change = false;
   tree name;
   unsigned i;
@@ -1107,6 +1122,9 @@ execute_ranger_vrp (struct function *fun, bool final_p)
   rvrp_folder folder (ranger, final_p);
   phi_analysis_initialize (ranger->const_query ());
   folder.substitute_and_fold ();
+  // Ensure the cache in SCEV has been cleared before processing
+  // globals to be removed.
+  scev_reset ();
   // Remove tagged builtin-unreachable and maybe update globals.
   folder.m_unreachable.remove_and_update_globals ();
   if (dump_file && (dump_flags & TDF_DETAILS))
@@ -1168,9 +1186,15 @@ execute_ranger_vrp (struct function *fun, bool final_p)
 class fvrp_folder : public substitute_and_fold_engine
 {
 public:
-  fvrp_folder (dom_ranger *dr) : substitute_and_fold_engine (),
-m_simplifier (dr)
-  { m_dom_ranger = dr; }
+  fvrp_folder (dom_ranger *dr, bool final_p) : substitute_and_fold_engine (),
+  m_simplifier (dr)
+  {
+m_dom_ranger = dr;
+if (final_p)
+  m_unreachable = new remove_unreachable (*dr, final_p);
+else
+  m_unreachable = NULL;
+  }
 
   ~fvrp_folder () { }
 
@@ -1228,6 +1252,9 @@ public:
value_range vr(type);
m_dom_ranger->range_of_stmt (vr, s);
   }
+if (m_unreachable && gimple_code (s) == GIMPLE_COND)
+  m_unreachable->maybe_register (s);
+
   }
 
   bool fold_stmt (gimple_stmt_iterator *gsi) override
@@ -1238,6 +1265,7 @@ public:
 return ret;
   }
 
+  remove_unreachable *m_unreachable;
 private:
   DISABLE_COPY_AND_ASSIGN (fvrp_folder);
   simplify_using_ranges m_simplifier;
@@ -1248,16 +1276,18 @@ private:
 // Main entry point for a FAST VRP pass using a dom ranger.
 
 unsigned int
-execute_fast_vrp (struct function *fun)
+execute_fast_vrp (struct function *fun, bool final_p)
 {
   calculate_dominance_info (CDI_DOMINATORS);
   dom_ranger dr;
-  fvrp_folder folder (&dr);
+  fvrp_folder folder (&dr, final_p);
 
   gcc_checking_assert (!fun->x_range_query);
   fun->x_range_query = &dr;
 
   folder.substitute_and_fold ();
+  if (folder.m_unreachable)
+folder.m_unreachable->remove ();
 
   fun->x_range_query = NULL;
   return 0;
@@ -1325,7 +1355,7 @@ public:
 {
   // Check for fast vrp.
   if (&data == &pass_

[gcc r15-1543] Change fast VRP algorithm

2024-06-21 Thread Andrew Macleod via Gcc-cvs
https://gcc.gnu.org/g:68532d3c63725777aaa63b9ac2e4a086c6359bfa

commit r15-1543-g68532d3c63725777aaa63b9ac2e4a086c6359bfa
Author: Andrew MacLeod 
Date:   Mon Jun 17 11:32:51 2024 -0400

Change fast VRP algorithm

Change the fast VRP algorithm to track contextual ranges active within
each basic block.

* gimple-range.cc (dom_ranger::dom_ranger): Create a block
vector.
(dom_ranger::~dom_ranger): Dispose of the block vector.
(dom_ranger::edge_range): Delete.
(dom_ranger::range_on_edge): Combine range in src BB with any
range gori_nme_on_edge returns.
(dom_ranger::range_in_bb): Combine global range with any active
contextual range for an ssa-name.
(dom_ranger::range_of_stmt): Fix non-ssa LHS case, use
fur_depend for folding so relations can be registered.
(dom_ranger::maybe_push_edge): Delete.
(dom_ranger::pre_bb): Create incoming contextual range vector.
(dom_ranger::post_bb): Free contextual range vector.
* gimple-range.h (dom_ranger::edge_range): Delete.
(dom_ranger::m_e0): Delete.
(dom_ranger::m_e1): Delete.
(dom_ranger::m_bb): New.
(dom_ranger::m_pop_list): Delete.
* tree-vrp.cc (execute_fast_vrp): Enable relation oracle.

Diff:
---
 gcc/gimple-range.cc | 232 +++-
 gcc/gimple-range.h  |   8 +-
 gcc/tree-vrp.cc |   2 +
 3 files changed, 90 insertions(+), 152 deletions(-)

diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc
index f3e4ec2d249..4e507485f5e 100644
--- a/gcc/gimple-range.cc
+++ b/gcc/gimple-range.cc
@@ -918,7 +918,15 @@ assume_query::dump (FILE *f)
 }
 
 // ---
-
+//
+// The DOM based ranger assumes a single DOM walk through the IL, and is
+// used by the fvrp_folder as a fast VRP.
+// During the dom walk, the current block has an ssa_lazy_cache pointer
+// m_bb[bb->index] which represents all the cumulative contextual ranges
+// active in the block.
+// These ranges are pure static ranges generated by branches, and must be
+// combined with the equivlaent global range to produce the final range.
+// A NULL pointer means there are no contextual ranges.
 
 // Create a DOM based ranger for use by a DOM walk pass.
 
@@ -926,11 +934,8 @@ dom_ranger::dom_ranger () : m_global ()
 {
   m_freelist.create (0);
   m_freelist.truncate (0);
-  m_e0.create (0);
-  m_e0.safe_grow_cleared (last_basic_block_for_fn (cfun));
-  m_e1.create (0);
-  m_e1.safe_grow_cleared (last_basic_block_for_fn (cfun));
-  m_pop_list = BITMAP_ALLOC (NULL);
+  m_bb.create (0);
+  m_bb.safe_grow_cleared (last_basic_block_for_fn (cfun));
   if (dump_file && (param_ranger_debug & RANGER_DEBUG_TRACE))
 tracer.enable_trace ();
 }
@@ -945,9 +950,7 @@ dom_ranger::~dom_ranger ()
   fprintf (dump_file, "=:\n");
   m_global.dump (dump_file);
 }
-  BITMAP_FREE (m_pop_list);
-  m_e1.release ();
-  m_e0.release ();
+  m_bb.release ();
   m_freelist.release ();
 }
 
@@ -973,6 +976,7 @@ dom_ranger::range_of_expr (vrange &r, tree expr, gimple *s)
  fprintf (dump_file, "\n");
 }
 
+  // If there is a statement, return the range in that statements block.
   if (s)
 range_in_bb (r, gimple_bb (s), expr);
   else
@@ -983,37 +987,15 @@ dom_ranger::range_of_expr (vrange &r, tree expr, gimple 
*s)
   return true;
 }
 
-
-// Return TRUE and the range if edge E has a range set for NAME in
-// block E->src.
-
-bool
-dom_ranger::edge_range (vrange &r, edge e, tree name)
-{
-  bool ret = false;
-  basic_block bb = e->src;
-
-  // Check if BB has any outgoing ranges on edge E.
-  ssa_lazy_cache *out = NULL;
-  if (EDGE_SUCC (bb, 0) == e)
-out = m_e0[bb->index];
-  else if (EDGE_SUCC (bb, 1) == e)
-out = m_e1[bb->index];
-
-  // If there is an edge vector and it has a range, pick it up.
-  if (out && out->has_range (name))
-ret = out->get_range (r, name);
-
-  return ret;
-}
-
-
 // Return the range of EXPR on edge E in R.
 // Return false if no range can be calculated.
 
 bool
 dom_ranger::range_on_edge (vrange &r, edge e, tree expr)
 {
+  if (!gimple_range_ssa_p (expr))
+return get_tree_range (r, expr, NULL);
+
   basic_block bb = e->src;
   unsigned idx;
   if ((idx = tracer.header ("range_on_edge ")))
@@ -1023,11 +1005,10 @@ dom_ranger::range_on_edge (vrange &r, edge e, tree expr)
   fputc ('\n',dump_file);
 }
 
-  if (!gimple_range_ssa_p (expr))
-return get_tree_range (r, expr, NULL);
-
-  if (!edge_range (r, e, expr))
-range_in_bb (r, bb, expr);
+  range_in_bb (r, bb, expr);
+  value_range vr(TREE_TYPE (expr));
+  if (gori_name_on_edge (vr, expr, e, this))
+r.intersect (vr);
 
   if (idx)
 tracer.trailer (idx, " ", true, expr, r);
@@ -1039,35 +1020,23 @@ dom_ranger::range_on_edge (vrange &r, 

[gcc r15-1544] Print "Global Exported" to dump_file from set_range_info.

2024-06-21 Thread Andrew Macleod via Gcc-cvs
https://gcc.gnu.org/g:747a06017196b6344e3f664706a11231ba712548

commit r15-1544-g747a06017196b6344e3f664706a11231ba712548
Author: Andrew MacLeod 
Date:   Mon Jun 17 16:07:16 2024 -0400

Print "Global Exported" to dump_file from set_range_info.

* gimple-range.cc (gimple_ranger::register_inferred_ranges): Do not
dump global range info after set_range_info.
(gimple_ranger::register_transitive_inferred_ranges): Likewise.
(dom_ranger::range_of_stmt): Likewise.
* tree-ssanames.cc (set_range_info): If global range info
changes, maybe print new range to dump_file.
* tree-vrp.cc (remove_unreachable::handle_early): Do not
dump global range info after set_range_info.
(remove_unreachable::remove): Likewise.
(remove_unreachable::remove_and_update_globals): Likewise.
(pass_assumptions::execute): Likewise.

Diff:
---
 gcc/gimple-range.cc  | 60 ++--
 gcc/tree-ssanames.cc | 42 +++-
 gcc/tree-vrp.cc  | 43 -
 3 files changed, 47 insertions(+), 98 deletions(-)

diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc
index 4e507485f5e..50448ef81a2 100644
--- a/gcc/gimple-range.cc
+++ b/gcc/gimple-range.cc
@@ -495,15 +495,8 @@ gimple_ranger::register_inferred_ranges (gimple *s)
   if (lhs)
 {
   value_range tmp (TREE_TYPE (lhs));
-  if (range_of_stmt (tmp, s, lhs) && !tmp.varying_p ()
- && set_range_info (lhs, tmp) && dump_file)
-   {
- fprintf (dump_file, "Global Exported: ");
- print_generic_expr (dump_file, lhs, TDF_SLIM);
- fprintf (dump_file, " = ");
- tmp.dump (dump_file);
- fputc ('\n', dump_file);
-   }
+  if (range_of_stmt (tmp, s, lhs) && !tmp.varying_p ())
+   set_range_info (lhs, tmp);
 }
   m_cache.apply_inferred_ranges (s);
 }
@@ -562,38 +555,25 @@ gimple_ranger::register_transitive_inferred_ranges 
(basic_block bb)
 void
 gimple_ranger::export_global_ranges ()
 {
-  /* Cleared after the table header has been printed.  */
-  bool print_header = true;
+  if (dump_file)
+{
+  /* Print the header only when there's something else
+to print below.  */
+  fprintf (dump_file, "Exporting new  global ranges:\n");
+  fprintf (dump_file, "\n");
+}
   for (unsigned x = 1; x < num_ssa_names; x++)
 {
   tree name = ssa_name (x);
   if (!name)
continue;
   value_range r (TREE_TYPE (name));
-  if (name && !SSA_NAME_IN_FREE_LIST (name)
- && gimple_range_ssa_p (name)
- && m_cache.get_global_range (r, name)
- && !r.varying_p())
-   {
- bool updated = set_range_info (name, r);
- if (!updated || !dump_file)
-   continue;
-
- if (print_header)
-   {
- /* Print the header only when there's something else
-to print below.  */
- fprintf (dump_file, "Exported global range table:\n");
- fprintf (dump_file, "\n");
- print_header = false;
-   }
-
- print_generic_expr (dump_file, name , TDF_SLIM);
- fprintf (dump_file, "  : ");
- r.dump (dump_file);
- fprintf (dump_file, "\n");
-   }
+  if (name && !SSA_NAME_IN_FREE_LIST (name) && gimple_range_ssa_p (name)
+ && m_cache.get_global_range (r, name) && !r.varying_p())
+   set_range_info (name, r);
 }
+  if (dump_file)
+fprintf (dump_file, "= Done =\n");
 }
 
 // Print the known table values to file F.
@@ -1069,16 +1049,8 @@ dom_ranger::range_of_stmt (vrange &r, gimple *s, tree 
name)
   // If there is a new calculated range and it is not varying, set
   // a global range.
   if (ret && name && m_global.merge_range (name, r) && !r.varying_p ())
-{
-  if (set_range_info (name, r) && dump_file)
-   {
- fprintf (dump_file, "Global Exported: ");
- print_generic_expr (dump_file, name, TDF_SLIM);
- fprintf (dump_file, " = ");
- r.dump (dump_file);
- fputc ('\n', dump_file);
-   }
-}
+set_range_info (name, r);
+
   if (idx)
 tracer.trailer (idx, " ", ret, name, r);
   return ret;
diff --git a/gcc/tree-ssanames.cc b/gcc/tree-ssanames.cc
index 615d522d0b1..411ea848c49 100644
--- a/gcc/tree-ssanames.cc
+++ b/gcc/tree-ssanames.cc
@@ -25,6 +25,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple.h"
 #include "tree-pass.h"
 #include "ssa.h"
+#include "gimple-pretty-print.h"
 #include "gimple-iterator.h"
 #include "stor-layout.h"
 #include "tree-into-ssa.h"
@@ -425,23 +426,34 @@ set_range_info (tree name, const vrange &r)
   struct ptr_info_def *pi = get_ptr_info (name);
   // If R is nonnull and pi is not, set nonnull.
   if (r.nonzero_p () && (!pi || p

[gcc r14-10336] Build: Set gcc_cv_as_mips_explicit_relocs if gcc_cv_as_mips_explicit_relocs_pcrel

2024-06-21 Thread YunQiang Su via Gcc-cvs
https://gcc.gnu.org/g:a16f47f5f34d08b13ee58ea362027c6a479eb82f

commit r14-10336-ga16f47f5f34d08b13ee58ea362027c6a479eb82f
Author: YunQiang Su 
Date:   Thu Jun 20 10:37:39 2024 +0800

Build: Set gcc_cv_as_mips_explicit_relocs if 
gcc_cv_as_mips_explicit_relocs_pcrel

We check gcc_cv_as_mips_explicit_relocs if 
gcc_cv_as_mips_explicit_relocs_pcrel
only, while gcc_cv_as_mips_explicit_relocs is used by later code.

gcc
* configure.ac: Set gcc_cv_as_mips_explicit_relocs if
gcc_cv_as_mips_explicit_relocs_pcrel.
* configure: Regenerate.

(cherry picked from commit 573f11ec34eeb6a6c3bd3d7619738f927236727b)

Diff:
---
 gcc/configure| 2 ++
 gcc/configure.ac | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/gcc/configure b/gcc/configure
index 23da7d55d62..abc8bfdc244 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -30489,6 +30489,8 @@ $as_echo "#define MIPS_EXPLICIT_RELOCS 
MIPS_EXPLICIT_RELOCS_BASE" >>confdefs.h
 
 fi
 
+else
+  gcc_cv_as_mips_explicit_relocs=yes
 fi
 
 if test x$gcc_cv_as_mips_explicit_relocs = xno; then \
diff --git a/gcc/configure.ac b/gcc/configure.ac
index d7cf0b92cd8..1d2cefa3f6a 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -5304,6 +5304,8 @@ LCF0:
 [  lw $4,%gp_rel(foo)($4)],,
   [AC_DEFINE(MIPS_EXPLICIT_RELOCS, MIPS_EXPLICIT_RELOCS_BASE,
 [Define if assembler supports %reloc.])])
+else
+  gcc_cv_as_mips_explicit_relocs=yes
 fi
 
 if test x$gcc_cv_as_mips_explicit_relocs = xno; then \


[gcc r15-1545] rtl-ssa: Don't cost no-op moves

2024-06-21 Thread Richard Sandiford via Gcc-cvs
https://gcc.gnu.org/g:4a43a06c7b2bcc3402ac69d6e5ce7b8008acc69a

commit r15-1545-g4a43a06c7b2bcc3402ac69d6e5ce7b8008acc69a
Author: Richard Sandiford 
Date:   Fri Jun 21 15:40:10 2024 +0100

rtl-ssa: Don't cost no-op moves

No-op moves are given the code NOOP_MOVE_INSN_CODE if we plan
to delete them later.  Such insns shouldn't be costed, partly
because they're going to disappear, and partly because targets
won't recognise the insn code.

gcc/
* rtl-ssa/changes.cc (rtl_ssa::changes_are_worthwhile): Don't
cost no-op moves.
* rtl-ssa/insns.cc (insn_info::calculate_cost): Likewise.

Diff:
---
 gcc/rtl-ssa/changes.cc | 6 +-
 gcc/rtl-ssa/insns.cc   | 7 ++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/gcc/rtl-ssa/changes.cc b/gcc/rtl-ssa/changes.cc
index 11639e81bb7..3101f2dc4fc 100644
--- a/gcc/rtl-ssa/changes.cc
+++ b/gcc/rtl-ssa/changes.cc
@@ -177,13 +177,17 @@ rtl_ssa::changes_are_worthwhile (array_slice changes,
   auto entry_count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
   for (insn_change *change : changes)
 {
+  // Count zero for the old cost if the old instruction was a no-op
+  // move or had an unknown cost.  This should reduce the chances of
+  // making an unprofitable change.
   old_cost += change->old_cost ();
   basic_block cfg_bb = change->bb ()->cfg_bb ();
   bool for_speed = optimize_bb_for_speed_p (cfg_bb);
   if (for_speed)
weighted_old_cost += (cfg_bb->count.to_sreal_scale (entry_count)
  * change->old_cost ());
-  if (!change->is_deletion ())
+  if (!change->is_deletion ()
+ && INSN_CODE (change->rtl ()) != NOOP_MOVE_INSN_CODE)
{
  change->new_cost = insn_cost (change->rtl (), for_speed);
  new_cost += change->new_cost;
diff --git a/gcc/rtl-ssa/insns.cc b/gcc/rtl-ssa/insns.cc
index 0171d93c357..68365e323ec 100644
--- a/gcc/rtl-ssa/insns.cc
+++ b/gcc/rtl-ssa/insns.cc
@@ -48,7 +48,12 @@ insn_info::calculate_cost () const
 {
   basic_block cfg_bb = BLOCK_FOR_INSN (m_rtl);
   temporarily_undo_changes (0);
-  m_cost_or_uid = insn_cost (m_rtl, optimize_bb_for_speed_p (cfg_bb));
+  if (INSN_CODE (m_rtl) == NOOP_MOVE_INSN_CODE)
+// insn_cost also uses 0 to mean "don't know".  Callers that
+// want to distinguish the cases will need to check INSN_CODE.
+m_cost_or_uid = 0;
+  else
+m_cost_or_uid = insn_cost (m_rtl, optimize_bb_for_speed_p (cfg_bb));
   redo_changes (0);
 }


[gcc r15-1546] iq2000: Fix test and branch instructions

2024-06-21 Thread Richard Sandiford via Gcc-cvs
https://gcc.gnu.org/g:8f254cd4e40b692e5f01a3b40f2b5b60c8528a1e

commit r15-1546-g8f254cd4e40b692e5f01a3b40f2b5b60c8528a1e
Author: Richard Sandiford 
Date:   Fri Jun 21 15:40:10 2024 +0100

iq2000: Fix test and branch instructions

The iq2000 test and branch instructions had patterns like:

  [(set (pc)
(if_then_else
 (eq (and:SI (match_operand:SI 0 "register_operand" "r")
 (match_operand:SI 1 "power_of_2_operand" "I"))
  (const_int 0))
 (match_operand 2 "pc_or_label_operand" "")
 (match_operand 3 "pc_or_label_operand" "")))]

power_of_2_operand allows any 32-bit power of 2, whereas "I" only
accepts 16-bit signed constants.  This meant that any power of 2
greater than 32768 would cause an "insn does not satisfy its
constraints" ICE.

Also, the %p operand modifier barfed on 1<<31, which is sign-
rather than zero-extended to 64 bits.  The code is inherently
limited to 32-bit operands -- power_of_2_operand contains a test
involving "unsigned" -- so this patch just ands with 0x.

gcc/
* config/iq2000/iq2000.cc (iq2000_print_operand): Make %p handle 
1<<31.
* config/iq2000/iq2000.md: Remove "I" constraints on
power_of_2_operands.

Diff:
---
 gcc/config/iq2000/iq2000.cc | 2 +-
 gcc/config/iq2000/iq2000.md | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/config/iq2000/iq2000.cc b/gcc/config/iq2000/iq2000.cc
index f9f8c417841..136675d0fbb 100644
--- a/gcc/config/iq2000/iq2000.cc
+++ b/gcc/config/iq2000/iq2000.cc
@@ -3127,7 +3127,7 @@ iq2000_print_operand (FILE *file, rtx op, int letter)
 {
   int value;
   if (code != CONST_INT
- || (value = exact_log2 (INTVAL (op))) < 0)
+ || (value = exact_log2 (UINTVAL (op) & 0x)) < 0)
output_operand_lossage ("invalid %%p value");
   else
fprintf (file, "%d", value);
diff --git a/gcc/config/iq2000/iq2000.md b/gcc/config/iq2000/iq2000.md
index 8617efac3c6..e62c250ce8c 100644
--- a/gcc/config/iq2000/iq2000.md
+++ b/gcc/config/iq2000/iq2000.md
@@ -1175,7 +1175,7 @@
   [(set (pc)
(if_then_else
 (eq (and:SI (match_operand:SI 0 "register_operand" "r")
-(match_operand:SI 1 "power_of_2_operand" "I"))
+(match_operand:SI 1 "power_of_2_operand"))
  (const_int 0))
 (match_operand 2 "pc_or_label_operand" "")
 (match_operand 3 "pc_or_label_operand" "")))]
@@ -1189,7 +1189,7 @@
   [(set (pc)
(if_then_else
 (ne (and:SI (match_operand:SI 0 "register_operand" "r")
-(match_operand:SI 1 "power_of_2_operand" "I"))
+(match_operand:SI 1 "power_of_2_operand"))
 (const_int 0))
 (match_operand 2 "pc_or_label_operand" "")
 (match_operand 3 "pc_or_label_operand" "")))]


[gcc r15-1547] xstormy16: Fix xs_hi_nonmemory_operand

2024-06-21 Thread Richard Sandiford via Gcc-cvs
https://gcc.gnu.org/g:5320bcbd342a985a6e1db60bff2918f73dcad1a0

commit r15-1547-g5320bcbd342a985a6e1db60bff2918f73dcad1a0
Author: Richard Sandiford 
Date:   Fri Jun 21 15:40:11 2024 +0100

xstormy16: Fix xs_hi_nonmemory_operand

All uses of xs_hi_nonmemory_operand allow constraint "i",
which means that they allow consts, symbol_refs and label_refs.
The definition of xs_hi_nonmemory_operand accounted for consts,
but not for symbol_refs and label_refs.

gcc/
* config/stormy16/predicates.md (xs_hi_nonmemory_operand): Handle
symbol_ref and label_ref.

Diff:
---
 gcc/config/stormy16/predicates.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/stormy16/predicates.md 
b/gcc/config/stormy16/predicates.md
index 67c2ddc107c..085c9c5ed2d 100644
--- a/gcc/config/stormy16/predicates.md
+++ b/gcc/config/stormy16/predicates.md
@@ -152,7 +152,7 @@
 })
 
 (define_predicate "xs_hi_nonmemory_operand"
-  (match_code "const_int,reg,subreg,const")
+  (match_code "const_int,reg,subreg,const,symbol_ref,label_ref")
 {
   return nonmemory_operand (op, mode);
 })


[gcc r15-1548] libstdc++: Fix test on x86_64 and non-simd targets

2024-06-21 Thread Matthias Kretz via Libstdc++-cvs
https://gcc.gnu.org/g:77f321435b4ac37992c2ed6737ca0caa1dd50551

commit r15-1548-g77f321435b4ac37992c2ed6737ca0caa1dd50551
Author: Matthias Kretz 
Date:   Fri Jun 21 16:22:22 2024 +0200

libstdc++: Fix test on x86_64 and non-simd targets

* Running a test compiled with AVX512 instructions requires
avx512f_runtime not just avx512f.

* The 'reduce2' test violated an invariant of fixed_size_simd_mask and
thus failed on all targets without 16-Byte vector builtins enabled (in
bits/simd.h).

Signed-off-by: Matthias Kretz 

libstdc++-v3/ChangeLog:

PR libstdc++/115575
* testsuite/experimental/simd/pr115454_find_last_set.cc: Require
avx512f_runtime. Don't memcpy fixed_size masks.

Diff:
---
 libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc 
b/libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc
index b47f19d3067..25a713b4e94 100644
--- a/libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc
+++ b/libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc
@@ -1,7 +1,7 @@
 // { dg-options "-std=gnu++17" }
 // { dg-do run { target *-*-* } }
 // { dg-require-effective-target c++17 }
-// { dg-additional-options "-march=x86-64-v4" { target avx512f } }
+// { dg-additional-options "-march=x86-64-v4" { target avx512f_runtime } }
 // { dg-require-cmath "" }
 
 #include 
@@ -25,7 +25,9 @@ int reduce2()
 {
   using M8 = typename V::mask_type;
   using M4 = typename V::mask_type;
-  if constexpr (sizeof(M8) == sizeof(M4))
+  if constexpr (sizeof(M8) == sizeof(M4)
+ && !std::is_same_v>)
+// fixed_size invariant: padding bits of masks are zero, the memcpy would 
violate that
 {
   M4 k;
   __builtin_memcpy(&__data(k), &__data(M8(true)), sizeof(M4));


[gcc r15-1549] libstdc++: Fix std::fill and std::fill_n optimizations [PR109150]

2024-06-21 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:b3743181899c5490a94c4dbde56a69ab77a40f11

commit r15-1549-gb3743181899c5490a94c4dbde56a69ab77a40f11
Author: Jonathan Wakely 
Date:   Wed Jun 19 16:14:56 2024 +0100

libstdc++: Fix std::fill and std::fill_n optimizations [PR109150]

As noted in the PR, the optimization used for scalar types in std::fill
and std::fill_n is non-conforming, because it doesn't consider that
assigning a scalar type might have non-trivial side effects which are
affected by the optimization.

By changing the condition under which the optimization is done we ensure
it's only performed when safe to do so, and we also enable it for
additional types, which was the original subject of the PR.

Instead of two overloads using __enable_if<__is_scalar::__value, R>
we can combine them into one and create a local variable which is either
a local copy of __value or another reference to it, depending on whether
the optimization is allowed.

This removes a use of std::__is_scalar, which is a step towards fixing
PR 115497 by removing std::__is_pointer from 

libstdc++-v3/ChangeLog:

PR libstdc++/109150
* include/bits/stl_algobase.h (__fill_a1): Combine the
!__is_scalar and __is_scalar overloads into one and rewrite the
condition used to decide whether to perform the load outside the
loop.
* testsuite/25_algorithms/fill/109150.cc: New test.
* testsuite/25_algorithms/fill_n/109150.cc: New test.

Diff:
---
 libstdc++-v3/include/bits/stl_algobase.h   | 79 ++
 .../testsuite/25_algorithms/fill/109150.cc | 62 +
 .../testsuite/25_algorithms/fill_n/109150.cc   | 62 +
 3 files changed, 173 insertions(+), 30 deletions(-)

diff --git a/libstdc++-v3/include/bits/stl_algobase.h 
b/libstdc++-v3/include/bits/stl_algobase.h
index d831e0e9883..1a0f8c14073 100644
--- a/libstdc++-v3/include/bits/stl_algobase.h
+++ b/libstdc++-v3/include/bits/stl_algobase.h
@@ -929,28 +929,39 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
 #define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::copy_backward(_Tp, _Up, 
_Vp)
 #endif
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wc++17-extensions"
   template
 _GLIBCXX20_CONSTEXPR
-inline typename
-__gnu_cxx::__enable_if::__value, void>::__type
-__fill_a1(_ForwardIterator __first, _ForwardIterator __last,
- const _Tp& __value)
-{
-  for (; __first != __last; ++__first)
-   *__first = __value;
-}
-
-  template
-_GLIBCXX20_CONSTEXPR
-inline typename
-__gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type
+inline void
 __fill_a1(_ForwardIterator __first, _ForwardIterator __last,
  const _Tp& __value)
 {
-  const _Tp __tmp = __value;
+  // We can optimize this loop by moving the load from __value outside
+  // the loop, but only if we know that making that copy is trivial,
+  // and the assignment in the loop is also trivial (so that the identity
+  // of the operand doesn't matter).
+  const bool __load_outside_loop =
+#if __has_builtin(__is_trivially_constructible) \
+  && __has_builtin(__is_trivially_assignable)
+   __is_trivially_constructible(_Tp, const _Tp&)
+   && __is_trivially_assignable(__decltype(*__first), const _Tp&)
+#else
+   __is_trivially_copyable(_Tp)
+   && __is_same(_Tp, __typeof__(*__first))
+#endif
+   && sizeof(_Tp) <= sizeof(long long);
+
+  // When the condition is true, we use a copy of __value,
+  // otherwise we just use another reference.
+  typedef typename __gnu_cxx::__conditional_type<__load_outside_loop,
+const _Tp,
+const _Tp&>::__type _Up;
+  _Up __val(__value);
   for (; __first != __last; ++__first)
-   *__first = __tmp;
+   *__first = __val;
 }
+#pragma GCC diagnostic pop
 
   // Specialization: for char types we can use memset.
   template
@@ -1079,28 +1090,36 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
   __size_to_integer(__float128 __n) { return (long long)__n; }
 #endif
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wc++17-extensions"
   template
 _GLIBCXX20_CONSTEXPR
-inline typename
-__gnu_cxx::__enable_if::__value, _OutputIterator>::__type
-__fill_n_a1(_OutputIterator __first, _Size __n, const _Tp& __value)
-{
-  for (; __n > 0; --__n, (void) ++__first)
-   *__first = __value;
-  return __first;
-}
-
-  template
-_GLIBCXX20_CONSTEXPR
-inline typename
-__gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type
+inline _OutputIterator
 __fill_n_a1(_OutputIterator __first, _Size __n, const _Tp& __value)
 {
-  const _Tp __tmp = __value;
+  // See std::__fil

[gcc r15-1550] libstdc++: Don't use std::__is_scalar in std::valarray initialization [PR115497]

2024-06-21 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:139d65d1f5a60ac90479653a4f9b63618509f3f9

commit r15-1550-g139d65d1f5a60ac90479653a4f9b63618509f3f9
Author: Jonathan Wakely 
Date:   Wed Jun 19 11:19:58 2024 +0100

libstdc++: Don't use std::__is_scalar in std::valarray initialization 
[PR115497]

This removes the use of the std::__is_scalar trait from ,
where it can be replaced by __is_trivial. It's used to decide whether we
can use memset to value-initialize valarray elements, but memset is
suitable for any trivial types, because value-initializing them is
equivalent to filling them with zeros.

This is another step towards removing the class templates in
 that conflict with Clang built-in names.

libstdc++-v3/ChangeLog:

PR libstdc++/115497
* include/bits/valarray_array.h (__valarray_default_construct):
Use __is_trivial(_Tp). instead of __is_scalar<_Tp>.

Diff:
---
 libstdc++-v3/include/bits/valarray_array.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/bits/valarray_array.h 
b/libstdc++-v3/include/bits/valarray_array.h
index 66b74f9aaac..07c49ce1057 100644
--- a/libstdc++-v3/include/bits/valarray_array.h
+++ b/libstdc++-v3/include/bits/valarray_array.h
@@ -80,7 +80,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 struct _Array_default_ctor<_Tp, true>
 {
-  // For fundamental types, it suffices to say 'memset()'
+  // For trivial types, it suffices to say 'memset()'
   inline static void
   _S_do_it(_Tp* __b, _Tp* __e)
   { __builtin_memset(__b, 0, (__e - __b) * sizeof(_Tp)); }
@@ -90,7 +90,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 inline void
 __valarray_default_construct(_Tp* __b, _Tp* __e)
 {
-  _Array_default_ctor<_Tp, __is_scalar<_Tp>::__value>::_S_do_it(__b, __e);
+  _Array_default_ctor<_Tp, __is_trivial(_Tp)>::_S_do_it(__b, __e);
 }
 
   // Turn a raw-memory into an array of _Tp filled with __t


[gcc r15-1552] libstdc++: Remove std::__is_void class template [PR115497]

2024-06-21 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:51cc77672add517123ef9ea45335b08442e8d57c

commit r15-1552-g51cc77672add517123ef9ea45335b08442e8d57c
Author: Jonathan Wakely 
Date:   Wed Jun 19 11:19:58 2024 +0100

libstdc++: Remove std::__is_void class template [PR115497]

This removes the std::__is_void trait, as it conflicts with a Clang
built-in. There is only one use of the trait, which can easily be
replaced by simpler code.

Although Clang has a hack to make the class template work despite using
a reserved name, removing std::__is_void will allow that hack to be
dropped at some future date.

libstdc++-v3/ChangeLog:

PR libstdc++/115497
* include/bits/cpp_type_traits.h (__is_void): Remove.
* include/debug/helper_functions.h (_Distance_traits):
Adjust partial specialization to match void directly, instead of
using __is_void::__type and matching __true_type.

Diff:
---
 libstdc++-v3/include/bits/cpp_type_traits.h   | 15 ---
 libstdc++-v3/include/debug/helper_functions.h |  5 ++---
 2 files changed, 2 insertions(+), 18 deletions(-)

diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h 
b/libstdc++-v3/include/bits/cpp_type_traits.h
index 6834dee5557..4d83b9472e6 100644
--- a/libstdc++-v3/include/bits/cpp_type_traits.h
+++ b/libstdc++-v3/include/bits/cpp_type_traits.h
@@ -105,21 +105,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   typedef __true_type __type;
 };
 
-  // Holds if the template-argument is a void type.
-  template
-struct __is_void
-{
-  enum { __value = 0 };
-  typedef __false_type __type;
-};
-
-  template<>
-struct __is_void
-{
-  enum { __value = 1 };
-  typedef __true_type __type;
-};
-
   //
   // Integer types
   //
diff --git a/libstdc++-v3/include/debug/helper_functions.h 
b/libstdc++-v3/include/debug/helper_functions.h
index 5474399dc67..d686a29e8ee 100644
--- a/libstdc++-v3/include/debug/helper_functions.h
+++ b/libstdc++-v3/include/debug/helper_functions.h
@@ -66,13 +66,12 @@ namespace __gnu_debug
   typedef
typename std::iterator_traits<_Iterator>::difference_type _ItDiffType;
 
-  template::__type>
+  template // PR c++/85282
struct _DiffTraits
{ typedef _DiffType __type; };
 
   template
-   struct _DiffTraits<_DiffType, std::__true_type>
+   struct _DiffTraits<_DiffType, void>
{ typedef std::ptrdiff_t __type; };
 
   typedef typename _DiffTraits<_ItDiffType>::__type _DiffType;


[gcc r14-10337] libstdc++: Fix test on x86_64 and non-simd targets

2024-06-21 Thread Matthias Kretz via Libstdc++-cvs
https://gcc.gnu.org/g:a851931bc0d7a2b39ccc1f236015aabf24ee51f9

commit r14-10337-ga851931bc0d7a2b39ccc1f236015aabf24ee51f9
Author: Matthias Kretz 
Date:   Fri Jun 21 16:22:22 2024 +0200

libstdc++: Fix test on x86_64 and non-simd targets

* Running a test compiled with AVX512 instructions requires
avx512f_runtime not just avx512f.

* The 'reduce2' test violated an invariant of fixed_size_simd_mask and
thus failed on all targets without 16-Byte vector builtins enabled (in
bits/simd.h).

Signed-off-by: Matthias Kretz 

libstdc++-v3/ChangeLog:

PR libstdc++/115575
* testsuite/experimental/simd/pr115454_find_last_set.cc: Require
avx512f_runtime. Don't memcpy fixed_size masks.

(cherry picked from commit 77f321435b4ac37992c2ed6737ca0caa1dd50551)

Diff:
---
 libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc 
b/libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc
index b47f19d3067..25a713b4e94 100644
--- a/libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc
+++ b/libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc
@@ -1,7 +1,7 @@
 // { dg-options "-std=gnu++17" }
 // { dg-do run { target *-*-* } }
 // { dg-require-effective-target c++17 }
-// { dg-additional-options "-march=x86-64-v4" { target avx512f } }
+// { dg-additional-options "-march=x86-64-v4" { target avx512f_runtime } }
 // { dg-require-cmath "" }
 
 #include 
@@ -25,7 +25,9 @@ int reduce2()
 {
   using M8 = typename V::mask_type;
   using M4 = typename V::mask_type;
-  if constexpr (sizeof(M8) == sizeof(M4))
+  if constexpr (sizeof(M8) == sizeof(M4)
+ && !std::is_same_v>)
+// fixed_size invariant: padding bits of masks are zero, the memcpy would 
violate that
 {
   M4 k;
   __builtin_memcpy(&__data(k), &__data(M8(true)), sizeof(M4));


[gcc r15-1551] libstdc++: Stop using std::__is_pointer in and [PR115497]

2024-06-21 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:5f10547e021db3a4a34382cd067668f9ef97fdeb

commit r15-1551-g5f10547e021db3a4a34382cd067668f9ef97fdeb
Author: Jonathan Wakely 
Date:   Wed Jun 19 17:21:16 2024 +0100

libstdc++: Stop using std::__is_pointer in  and  
[PR115497]

This replaces all uses of the std::__is_pointer type trait with uses of
the new __is_pointer built-in. Since the class template was only used to
enable some performance optimizations for algorithms, we can use the
built-in when __has_builtin(__is_pointer) is true (which is the case for
GCC trunk and for current versions of Clang) and just forego the
optimization otherwise.

Removing the uses of std::__is_pointer means it can be removed from
, which is another step towards fixing PR
115497.

libstdc++-v3/ChangeLog:

PR libstdc++/115497
* include/bits/deque.tcc (__lex_cmp_dit): Replace __is_pointer
class template with __is_pointer(T) built-in.
(__lexicographical_compare_aux1): Likewise.
* include/bits/stl_algobase.h (__equal_aux1): Likewise.
(__lexicographical_compare_aux1): Likewise.

Diff:
---
 libstdc++-v3/include/bits/deque.tcc  | 19 ---
 libstdc++-v3/include/bits/stl_algobase.h | 13 +
 2 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/libstdc++-v3/include/bits/deque.tcc 
b/libstdc++-v3/include/bits/deque.tcc
index 2c12358ca5b..deb010a0ebb 100644
--- a/libstdc++-v3/include/bits/deque.tcc
+++ b/libstdc++-v3/include/bits/deque.tcc
@@ -1271,18 +1271,21 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
_GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref, _Ptr> __last1,
const _Tp2* __first2, const _Tp2* __last2)
 {
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
   const bool __simple =
(__is_memcmp_ordered_with<_Tp1, _Tp2>::__value
-&& __is_pointer<_Ptr>::__value
+&& __is_pointer(_Ptr)
 #if __cplusplus > 201703L && __cpp_lib_concepts
 // For C++20 iterator_traits::value_type is non-volatile
 // so __is_byte could be true, but we can't use memcmp with
 // volatile data.
-&& !is_volatile_v<_Tp1>
-&& !is_volatile_v<_Tp2>
+&& !is_volatile_v<_Tp1> && !is_volatile_v<_Tp2>
 #endif
 );
   typedef std::__lexicographical_compare<__simple> _Lc;
+#else
+  typedef std::__lexicographical_compare _Lc;
+#endif
 
   while (__first1._M_node != __last1._M_node)
{
@@ -1327,19 +1330,21 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
_GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2> __first2,
_GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2> __last2)
 {
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
   const bool __simple =
(__is_memcmp_ordered_with<_Tp1, _Tp2>::__value
-&& __is_pointer<_Ptr1>::__value
-&& __is_pointer<_Ptr2>::__value
+&& __is_pointer(_Ptr1) && __is_pointer(_Ptr2)
 #if __cplusplus > 201703L && __cpp_lib_concepts
 // For C++20 iterator_traits::value_type is non-volatile
 // so __is_byte could be true, but we can't use memcmp with
 // volatile data.
-&& !is_volatile_v<_Tp1>
-&& !is_volatile_v<_Tp2>
+&& !is_volatile_v<_Tp1> && !is_volatile_v<_Tp2>
 #endif
 );
   typedef std::__lexicographical_compare<__simple> _Lc;
+#else
+  typedef std::__lexicographical_compare _Lc;
+#endif
 
   while (__first1 != __last1)
{
diff --git a/libstdc++-v3/include/bits/stl_algobase.h 
b/libstdc++-v3/include/bits/stl_algobase.h
index 1a0f8c14073..57ff2f7cb08 100644
--- a/libstdc++-v3/include/bits/stl_algobase.h
+++ b/libstdc++-v3/include/bits/stl_algobase.h
@@ -1256,8 +1256,10 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
 {
   typedef typename iterator_traits<_II1>::value_type _ValueType1;
   const bool __simple = ((__is_integer<_ValueType1>::__value
- || __is_pointer<_ValueType1>::__value)
-&& __memcmpable<_II1, _II2>::__value);
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
+ || __is_pointer(_ValueType1)
+#endif
+) && __memcmpable<_II1, _II2>::__value);
   return std::__equal<__simple>::equal(__first1, __last1, __first2);
 }
 
@@ -1420,10 +1422,10 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
 {
   typedef typename iterator_traits<_II1>::value_type _ValueType1;
   typedef typename iterator_traits<_II2>::value_type _ValueType2;
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
   const bool __simple =
(__is_memcmp_ordered_with<_ValueType1, _ValueType2>::__value
-&& __is_pointer<_II1>::__value
-&& __is_pointer<_II2>::__value
+&& __is_pointer(_II1) && __is_pointer(_II2)
 #if __cplusplus > 201703L && __glibcxx_concepts
 // For C++20 iterator_traits::value_type is non-volatile
 // so __is_byte could be true, but we can

[gcc r15-1553] libstdc++: Remove std::__is_pointer and std::__is_scalar [PR115497]

2024-06-21 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:52a82359073653e312aaa5703f7e0ce339588961

commit r15-1553-g52a82359073653e312aaa5703f7e0ce339588961
Author: Jonathan Wakely 
Date:   Wed Jun 19 17:26:37 2024 +0100

libstdc++: Remove std::__is_pointer and std::__is_scalar [PR115497]

This removes the std::__is_pointer and std::__is_scalar traits, as they
conflicts with a Clang built-in.

Although Clang has a hack to make the class templates work despite using
reserved names, removing these class templates will allow that hack to
be dropped at some future date.

libstdc++-v3/ChangeLog:

PR libstdc++/115497
* include/bits/cpp_type_traits.h (__is_pointer, __is_scalar):
Remove.
(__is_arithmetic): Do not use __is_pointer in the primary
template. Add partial specialization for pointers.

Diff:
---
 libstdc++-v3/include/bits/cpp_type_traits.h | 33 -
 1 file changed, 33 deletions(-)

diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h 
b/libstdc++-v3/include/bits/cpp_type_traits.h
index 4d83b9472e6..abe0c7603e3 100644
--- a/libstdc++-v3/include/bits/cpp_type_traits.h
+++ b/libstdc++-v3/include/bits/cpp_type_traits.h
@@ -343,31 +343,6 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3)
 };
 #endif
 
-  //
-  // Pointer types
-  //
-#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
-  template
-struct __is_pointer : __truth_type<_IsPtr>
-{
-  enum { __value = _IsPtr };
-};
-#else
-  template
-struct __is_pointer
-{
-  enum { __value = 0 };
-  typedef __false_type __type;
-};
-
-  template
-struct __is_pointer<_Tp*>
-{
-  enum { __value = 1 };
-  typedef __true_type __type;
-};
-#endif
-
   //
   // An arithmetic type is an integer type or a floating point type
   //
@@ -376,14 +351,6 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3)
 : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> >
 { };
 
-  //
-  // A scalar type is an arithmetic type or a pointer type
-  // 
-  template
-struct __is_scalar
-: public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> >
-{ };
-
   //
   // For use in std::copy and std::find overloads for streambuf iterators.
   //


[gcc r11-11531] libstdc++: Fix test on x86_64 and non-simd targets

2024-06-21 Thread Matthias Kretz via Libstdc++-cvs
https://gcc.gnu.org/g:87cda03e707f9f3e049905a0f698221f3c7db148

commit r11-11531-g87cda03e707f9f3e049905a0f698221f3c7db148
Author: Matthias Kretz 
Date:   Fri Jun 21 16:22:22 2024 +0200

libstdc++: Fix test on x86_64 and non-simd targets

* Running a test compiled with AVX512 instructions requires
avx512f_runtime not just avx512f.

* The 'reduce2' test violated an invariant of fixed_size_simd_mask and
thus failed on all targets without 16-Byte vector builtins enabled (in
bits/simd.h).

Signed-off-by: Matthias Kretz 

libstdc++-v3/ChangeLog:

PR libstdc++/115575
* testsuite/experimental/simd/pr115454_find_last_set.cc: Require
avx512f_runtime. Don't memcpy fixed_size masks.

(cherry picked from commit 77f321435b4ac37992c2ed6737ca0caa1dd50551)

Diff:
---
 libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc 
b/libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc
index b47f19d3067..25a713b4e94 100644
--- a/libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc
+++ b/libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc
@@ -1,7 +1,7 @@
 // { dg-options "-std=gnu++17" }
 // { dg-do run { target *-*-* } }
 // { dg-require-effective-target c++17 }
-// { dg-additional-options "-march=x86-64-v4" { target avx512f } }
+// { dg-additional-options "-march=x86-64-v4" { target avx512f_runtime } }
 // { dg-require-cmath "" }
 
 #include 
@@ -25,7 +25,9 @@ int reduce2()
 {
   using M8 = typename V::mask_type;
   using M4 = typename V::mask_type;
-  if constexpr (sizeof(M8) == sizeof(M4))
+  if constexpr (sizeof(M8) == sizeof(M4)
+ && !std::is_same_v>)
+// fixed_size invariant: padding bits of masks are zero, the memcpy would 
violate that
 {
   M4 k;
   __builtin_memcpy(&__data(k), &__data(M8(true)), sizeof(M4));


[gcc r13-8861] libstdc++: Fix find_last_set(simd_mask) to ignore padding bits

2024-06-21 Thread Matthias Kretz via Libstdc++-cvs
https://gcc.gnu.org/g:fbd088a069b172cae4e268abe2d38e567ef97990

commit r13-8861-gfbd088a069b172cae4e268abe2d38e567ef97990
Author: Matthias Kretz 
Date:   Fri Jun 14 15:11:25 2024 +0200

libstdc++: Fix find_last_set(simd_mask) to ignore padding bits

With the change to the AVX512 find_last_set implementation, the change
to AVX512 operator!= is unnecessary. However, the latter was not
producing optimal code and unnecessarily set the padding bits. In
theory, the compiler could determine that with the new !=
implementation, the bit operation for clearing the padding bits is a
no-op and can be elided.

Signed-off-by: Matthias Kretz 

libstdc++-v3/ChangeLog:

PR libstdc++/115454
* include/experimental/bits/simd_x86.h (_S_not_equal_to): Use
neq comparison instead of bitwise negation after eq.
(_S_find_last_set): Clear unused high bits before computing
bit_width.
* testsuite/experimental/simd/pr115454_find_last_set.cc: New
test.

(cherry picked from commit 1340ddea0158de3f49aeb75b4013e5fc313ff6f4)

Diff:
---
 libstdc++-v3/include/experimental/bits/simd_x86.h  | 26 ++--
 .../experimental/simd/pr115454_find_last_set.cc| 49 ++
 2 files changed, 62 insertions(+), 13 deletions(-)

diff --git a/libstdc++-v3/include/experimental/bits/simd_x86.h 
b/libstdc++-v3/include/experimental/bits/simd_x86.h
index 79c246455ee..5f427ccd90f 100644
--- a/libstdc++-v3/include/experimental/bits/simd_x86.h
+++ b/libstdc++-v3/include/experimental/bits/simd_x86.h
@@ -2339,29 +2339,29 @@ template 
  __assert_unreachable<_Tp>();
  }
else if constexpr (sizeof(__xi) == 64 && sizeof(_Tp) == 8)
- return ~_mm512_mask_cmpeq_epi64_mask(__k1, __xi, __yi);
+ return _mm512_mask_cmpneq_epi64_mask(__k1, __xi, __yi);
else if constexpr (sizeof(__xi) == 64 && sizeof(_Tp) == 4)
- return ~_mm512_mask_cmpeq_epi32_mask(__k1, __xi, __yi);
+ return _mm512_mask_cmpneq_epi32_mask(__k1, __xi, __yi);
else if constexpr (sizeof(__xi) == 64 && sizeof(_Tp) == 2)
- return ~_mm512_mask_cmpeq_epi16_mask(__k1, __xi, __yi);
+ return _mm512_mask_cmpneq_epi16_mask(__k1, __xi, __yi);
else if constexpr (sizeof(__xi) == 64 && sizeof(_Tp) == 1)
- return ~_mm512_mask_cmpeq_epi8_mask(__k1, __xi, __yi);
+ return _mm512_mask_cmpneq_epi8_mask(__k1, __xi, __yi);
else if constexpr (sizeof(__xi) == 32 && sizeof(_Tp) == 8)
- return ~_mm256_mask_cmpeq_epi64_mask(__k1, __xi, __yi);
+ return _mm256_mask_cmpneq_epi64_mask(__k1, __xi, __yi);
else if constexpr (sizeof(__xi) == 32 && sizeof(_Tp) == 4)
- return ~_mm256_mask_cmpeq_epi32_mask(__k1, __xi, __yi);
+ return _mm256_mask_cmpneq_epi32_mask(__k1, __xi, __yi);
else if constexpr (sizeof(__xi) == 32 && sizeof(_Tp) == 2)
- return ~_mm256_mask_cmpeq_epi16_mask(__k1, __xi, __yi);
+ return _mm256_mask_cmpneq_epi16_mask(__k1, __xi, __yi);
else if constexpr (sizeof(__xi) == 32 && sizeof(_Tp) == 1)
- return ~_mm256_mask_cmpeq_epi8_mask(__k1, __xi, __yi);
+ return _mm256_mask_cmpneq_epi8_mask(__k1, __xi, __yi);
else if constexpr (sizeof(__xi) == 16 && sizeof(_Tp) == 8)
- return ~_mm_mask_cmpeq_epi64_mask(__k1, __xi, __yi);
+ return _mm_mask_cmpneq_epi64_mask(__k1, __xi, __yi);
else if constexpr (sizeof(__xi) == 16 && sizeof(_Tp) == 4)
- return ~_mm_mask_cmpeq_epi32_mask(__k1, __xi, __yi);
+ return _mm_mask_cmpneq_epi32_mask(__k1, __xi, __yi);
else if constexpr (sizeof(__xi) == 16 && sizeof(_Tp) == 2)
- return ~_mm_mask_cmpeq_epi16_mask(__k1, __xi, __yi);
+ return _mm_mask_cmpneq_epi16_mask(__k1, __xi, __yi);
else if constexpr (sizeof(__xi) == 16 && sizeof(_Tp) == 1)
- return ~_mm_mask_cmpeq_epi8_mask(__k1, __xi, __yi);
+ return _mm_mask_cmpneq_epi8_mask(__k1, __xi, __yi);
else
  __assert_unreachable<_Tp>();
  }   // }}}
@@ -5292,7 +5292,7 @@ template 
   _S_find_last_set(simd_mask<_Tp, _Abi> __k)
   {
if constexpr (__is_avx512_abi<_Abi>())
- return std::__bit_width(__k._M_data._M_data) - 1;
+ return std::__bit_width(_Abi::_S_masked(__k._M_data)._M_data) - 1;
else
  return _Base::_S_find_last_set(__k);
   }
diff --git a/libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc 
b/libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc
new file mode 100644
index 000..b47f19d3067
--- /dev/null
+++ b/libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc
@@ -0,0 +

[gcc r13-8862] libstdc++: Fix test on x86_64 and non-simd targets

2024-06-21 Thread Matthias Kretz via Gcc-cvs
https://gcc.gnu.org/g:c335e34ff89ec9aec1ba874dc5cece9c2303c906

commit r13-8862-gc335e34ff89ec9aec1ba874dc5cece9c2303c906
Author: Matthias Kretz 
Date:   Fri Jun 21 16:22:22 2024 +0200

libstdc++: Fix test on x86_64 and non-simd targets

* Running a test compiled with AVX512 instructions requires
avx512f_runtime not just avx512f.

* The 'reduce2' test violated an invariant of fixed_size_simd_mask and
thus failed on all targets without 16-Byte vector builtins enabled (in
bits/simd.h).

Signed-off-by: Matthias Kretz 

libstdc++-v3/ChangeLog:

PR libstdc++/115575
* testsuite/experimental/simd/pr115454_find_last_set.cc: Require
avx512f_runtime. Don't memcpy fixed_size masks.

(cherry picked from commit 77f321435b4ac37992c2ed6737ca0caa1dd50551)

Diff:
---
 libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc 
b/libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc
index b47f19d3067..25a713b4e94 100644
--- a/libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc
+++ b/libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc
@@ -1,7 +1,7 @@
 // { dg-options "-std=gnu++17" }
 // { dg-do run { target *-*-* } }
 // { dg-require-effective-target c++17 }
-// { dg-additional-options "-march=x86-64-v4" { target avx512f } }
+// { dg-additional-options "-march=x86-64-v4" { target avx512f_runtime } }
 // { dg-require-cmath "" }
 
 #include 
@@ -25,7 +25,9 @@ int reduce2()
 {
   using M8 = typename V::mask_type;
   using M4 = typename V::mask_type;
-  if constexpr (sizeof(M8) == sizeof(M4))
+  if constexpr (sizeof(M8) == sizeof(M4)
+ && !std::is_same_v>)
+// fixed_size invariant: padding bits of masks are zero, the memcpy would 
violate that
 {
   M4 k;
   __builtin_memcpy(&__data(k), &__data(M8(true)), sizeof(M4));


[gcc r12-10574] libstdc++: Fix find_last_set(simd_mask) to ignore padding bits

2024-06-21 Thread Matthias Kretz via Libstdc++-cvs
https://gcc.gnu.org/g:8b5bdeb8aa2c2f6dbd448a8f7d500d9eaece48e1

commit r12-10574-g8b5bdeb8aa2c2f6dbd448a8f7d500d9eaece48e1
Author: Matthias Kretz 
Date:   Fri Jun 14 15:11:25 2024 +0200

libstdc++: Fix find_last_set(simd_mask) to ignore padding bits

With the change to the AVX512 find_last_set implementation, the change
to AVX512 operator!= is unnecessary. However, the latter was not
producing optimal code and unnecessarily set the padding bits. In
theory, the compiler could determine that with the new !=
implementation, the bit operation for clearing the padding bits is a
no-op and can be elided.

Signed-off-by: Matthias Kretz 

libstdc++-v3/ChangeLog:

PR libstdc++/115454
* include/experimental/bits/simd_x86.h (_S_not_equal_to): Use
neq comparison instead of bitwise negation after eq.
(_S_find_last_set): Clear unused high bits before computing
bit_width.
* testsuite/experimental/simd/pr115454_find_last_set.cc: New
test.

(cherry picked from commit 1340ddea0158de3f49aeb75b4013e5fc313ff6f4)

Diff:
---
 libstdc++-v3/include/experimental/bits/simd_x86.h  | 26 ++--
 .../experimental/simd/pr115454_find_last_set.cc| 49 ++
 2 files changed, 62 insertions(+), 13 deletions(-)

diff --git a/libstdc++-v3/include/experimental/bits/simd_x86.h 
b/libstdc++-v3/include/experimental/bits/simd_x86.h
index 7cda7f7d0e0..a88cc535f50 100644
--- a/libstdc++-v3/include/experimental/bits/simd_x86.h
+++ b/libstdc++-v3/include/experimental/bits/simd_x86.h
@@ -2339,29 +2339,29 @@ template 
  __assert_unreachable<_Tp>();
  }
else if constexpr (sizeof(__xi) == 64 && sizeof(_Tp) == 8)
- return ~_mm512_mask_cmpeq_epi64_mask(__k1, __xi, __yi);
+ return _mm512_mask_cmpneq_epi64_mask(__k1, __xi, __yi);
else if constexpr (sizeof(__xi) == 64 && sizeof(_Tp) == 4)
- return ~_mm512_mask_cmpeq_epi32_mask(__k1, __xi, __yi);
+ return _mm512_mask_cmpneq_epi32_mask(__k1, __xi, __yi);
else if constexpr (sizeof(__xi) == 64 && sizeof(_Tp) == 2)
- return ~_mm512_mask_cmpeq_epi16_mask(__k1, __xi, __yi);
+ return _mm512_mask_cmpneq_epi16_mask(__k1, __xi, __yi);
else if constexpr (sizeof(__xi) == 64 && sizeof(_Tp) == 1)
- return ~_mm512_mask_cmpeq_epi8_mask(__k1, __xi, __yi);
+ return _mm512_mask_cmpneq_epi8_mask(__k1, __xi, __yi);
else if constexpr (sizeof(__xi) == 32 && sizeof(_Tp) == 8)
- return ~_mm256_mask_cmpeq_epi64_mask(__k1, __xi, __yi);
+ return _mm256_mask_cmpneq_epi64_mask(__k1, __xi, __yi);
else if constexpr (sizeof(__xi) == 32 && sizeof(_Tp) == 4)
- return ~_mm256_mask_cmpeq_epi32_mask(__k1, __xi, __yi);
+ return _mm256_mask_cmpneq_epi32_mask(__k1, __xi, __yi);
else if constexpr (sizeof(__xi) == 32 && sizeof(_Tp) == 2)
- return ~_mm256_mask_cmpeq_epi16_mask(__k1, __xi, __yi);
+ return _mm256_mask_cmpneq_epi16_mask(__k1, __xi, __yi);
else if constexpr (sizeof(__xi) == 32 && sizeof(_Tp) == 1)
- return ~_mm256_mask_cmpeq_epi8_mask(__k1, __xi, __yi);
+ return _mm256_mask_cmpneq_epi8_mask(__k1, __xi, __yi);
else if constexpr (sizeof(__xi) == 16 && sizeof(_Tp) == 8)
- return ~_mm_mask_cmpeq_epi64_mask(__k1, __xi, __yi);
+ return _mm_mask_cmpneq_epi64_mask(__k1, __xi, __yi);
else if constexpr (sizeof(__xi) == 16 && sizeof(_Tp) == 4)
- return ~_mm_mask_cmpeq_epi32_mask(__k1, __xi, __yi);
+ return _mm_mask_cmpneq_epi32_mask(__k1, __xi, __yi);
else if constexpr (sizeof(__xi) == 16 && sizeof(_Tp) == 2)
- return ~_mm_mask_cmpeq_epi16_mask(__k1, __xi, __yi);
+ return _mm_mask_cmpneq_epi16_mask(__k1, __xi, __yi);
else if constexpr (sizeof(__xi) == 16 && sizeof(_Tp) == 1)
- return ~_mm_mask_cmpeq_epi8_mask(__k1, __xi, __yi);
+ return _mm_mask_cmpneq_epi8_mask(__k1, __xi, __yi);
else
  __assert_unreachable<_Tp>();
  }   // }}}
@@ -5292,7 +5292,7 @@ template 
   _S_find_last_set(simd_mask<_Tp, _Abi> __k)
   {
if constexpr (__is_avx512_abi<_Abi>())
- return std::__bit_width(__k._M_data._M_data) - 1;
+ return std::__bit_width(_Abi::_S_masked(__k._M_data)._M_data) - 1;
else
  return _Base::_S_find_last_set(__k);
   }
diff --git a/libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc 
b/libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc
new file mode 100644
index 000..b47f19d3067
--- /dev/null
+++ b/libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc
@@ -0,0 

[gcc r12-10575] libstdc++: Fix test on x86_64 and non-simd targets

2024-06-21 Thread Matthias Kretz via Gcc-cvs
https://gcc.gnu.org/g:169d4d1addaac7eef6cde4049aa8b4f3d81c28b0

commit r12-10575-g169d4d1addaac7eef6cde4049aa8b4f3d81c28b0
Author: Matthias Kretz 
Date:   Fri Jun 21 16:22:22 2024 +0200

libstdc++: Fix test on x86_64 and non-simd targets

* Running a test compiled with AVX512 instructions requires
avx512f_runtime not just avx512f.

* The 'reduce2' test violated an invariant of fixed_size_simd_mask and
thus failed on all targets without 16-Byte vector builtins enabled (in
bits/simd.h).

Signed-off-by: Matthias Kretz 

libstdc++-v3/ChangeLog:

PR libstdc++/115575
* testsuite/experimental/simd/pr115454_find_last_set.cc: Require
avx512f_runtime. Don't memcpy fixed_size masks.

(cherry picked from commit 77f321435b4ac37992c2ed6737ca0caa1dd50551)

Diff:
---
 libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc 
b/libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc
index b47f19d3067..25a713b4e94 100644
--- a/libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc
+++ b/libstdc++-v3/testsuite/experimental/simd/pr115454_find_last_set.cc
@@ -1,7 +1,7 @@
 // { dg-options "-std=gnu++17" }
 // { dg-do run { target *-*-* } }
 // { dg-require-effective-target c++17 }
-// { dg-additional-options "-march=x86-64-v4" { target avx512f } }
+// { dg-additional-options "-march=x86-64-v4" { target avx512f_runtime } }
 // { dg-require-cmath "" }
 
 #include 
@@ -25,7 +25,9 @@ int reduce2()
 {
   using M8 = typename V::mask_type;
   using M4 = typename V::mask_type;
-  if constexpr (sizeof(M8) == sizeof(M4))
+  if constexpr (sizeof(M8) == sizeof(M4)
+ && !std::is_same_v>)
+// fixed_size invariant: padding bits of masks are zero, the memcpy would 
violate that
 {
   M4 k;
   __builtin_memcpy(&__data(k), &__data(M8(true)), sizeof(M4));


[gcc r14-10338] AArch64: Fix cpu features initialization [PR115342]

2024-06-21 Thread Wilco Dijkstra via Gcc-cvs
https://gcc.gnu.org/g:9421f02916676d27e24fcda918f85e359329ac69

commit r14-10338-g9421f02916676d27e24fcda918f85e359329ac69
Author: Wilco Dijkstra 
Date:   Wed Jun 5 14:04:33 2024 +0100

AArch64: Fix cpu features initialization [PR115342]

The CPU features initialization code uses CPUID registers (rather than
HWCAP).  The equality comparisons it uses are incorrect: for example 
FEAT_SVE
is not set if SVE2 is available.  Using HWCAPs for these is both simpler and
correct.  The initialization must also be done atomically to avoid multiple
threads causing corruption due to non-atomic RMW accesses to the global.

libgcc:
PR target/115342
* config/aarch64/cpuinfo.c (__init_cpu_features_constructor):
Use HWCAP where possible.  Use atomic write for initialization.
Fix FEAT_PREDRES comparison.
(__init_cpu_features_resolver): Use atomic load for correct
initialization.
(__init_cpu_features): Likewise.
(cherry picked from commit d7cbcfe7c33645eaf95f175f19884d443817857b)

Diff:
---
 libgcc/config/aarch64/cpuinfo.c | 181 +---
 1 file changed, 75 insertions(+), 106 deletions(-)

diff --git a/libgcc/config/aarch64/cpuinfo.c b/libgcc/config/aarch64/cpuinfo.c
index eb0ac97255d..ec36d105738 100644
--- a/libgcc/config/aarch64/cpuinfo.c
+++ b/libgcc/config/aarch64/cpuinfo.c
@@ -230,14 +230,22 @@ struct {
 #ifndef HWCAP2_SVE_EBF16
 #define HWCAP2_SVE_EBF16 (1UL << 33)
 #endif
+#ifndef HWCAP2_SME2
+#define HWCAP2_SME2 (1UL << 37)
+#endif
+#ifndef HWCAP2_LRCPC3
+#define HWCAP2_LRCPC3  (1UL << 46)
+#endif
 
 static void
-__init_cpu_features_constructor(unsigned long hwcap,
-   const __ifunc_arg_t *arg) {
-#define setCPUFeature(F) __aarch64_cpu_features.features |= 1ULL << F
+__init_cpu_features_constructor (unsigned long hwcap,
+const __ifunc_arg_t *arg)
+{
+  unsigned long feat = 0;
+#define setCPUFeature(F) feat |= 1UL << F
 #define getCPUFeature(id, ftr) __asm__("mrs %0, " #id : "=r"(ftr))
 #define extractBits(val, start, number) \
-  (val & ((1ULL << number) - 1ULL) << start) >> start
+  (val & ((1UL << number) - 1UL) << start) >> start
   unsigned long hwcap2 = 0;
   if (hwcap & _IFUNC_ARG_HWCAP)
 hwcap2 = arg->_hwcap2;
@@ -247,26 +255,20 @@ __init_cpu_features_constructor(unsigned long hwcap,
 setCPUFeature(FEAT_PMULL);
   if (hwcap & HWCAP_FLAGM)
 setCPUFeature(FEAT_FLAGM);
-  if (hwcap2 & HWCAP2_FLAGM2) {
-setCPUFeature(FEAT_FLAGM);
+  if (hwcap2 & HWCAP2_FLAGM2)
 setCPUFeature(FEAT_FLAGM2);
-  }
-  if (hwcap & HWCAP_SM3 && hwcap & HWCAP_SM4)
+  if (hwcap & HWCAP_SM4)
 setCPUFeature(FEAT_SM4);
   if (hwcap & HWCAP_ASIMDDP)
 setCPUFeature(FEAT_DOTPROD);
   if (hwcap & HWCAP_ASIMDFHM)
 setCPUFeature(FEAT_FP16FML);
-  if (hwcap & HWCAP_FPHP) {
+  if (hwcap & HWCAP_FPHP)
 setCPUFeature(FEAT_FP16);
-setCPUFeature(FEAT_FP);
-  }
   if (hwcap & HWCAP_DIT)
 setCPUFeature(FEAT_DIT);
   if (hwcap & HWCAP_ASIMDRDM)
 setCPUFeature(FEAT_RDM);
-  if (hwcap & HWCAP_ILRCPC)
-setCPUFeature(FEAT_RCPC2);
   if (hwcap & HWCAP_AES)
 setCPUFeature(FEAT_AES);
   if (hwcap & HWCAP_SHA1)
@@ -280,22 +282,21 @@ __init_cpu_features_constructor(unsigned long hwcap,
   if (hwcap & HWCAP_SB)
 setCPUFeature(FEAT_SB);
   if (hwcap & HWCAP_SSBS)
-setCPUFeature(FEAT_SSBS2);
-  if (hwcap2 & HWCAP2_MTE) {
-setCPUFeature(FEAT_MEMTAG);
-setCPUFeature(FEAT_MEMTAG2);
-  }
-  if (hwcap2 & HWCAP2_MTE3) {
-setCPUFeature(FEAT_MEMTAG);
-setCPUFeature(FEAT_MEMTAG2);
+{
+  setCPUFeature(FEAT_SSBS);
+  setCPUFeature(FEAT_SSBS2);
+}
+  if (hwcap2 & HWCAP2_MTE)
+{
+  setCPUFeature(FEAT_MEMTAG);
+  setCPUFeature(FEAT_MEMTAG2);
+}
+  if (hwcap2 & HWCAP2_MTE3)
 setCPUFeature(FEAT_MEMTAG3);
-  }
   if (hwcap2 & HWCAP2_SVEAES)
 setCPUFeature(FEAT_SVE_AES);
-  if (hwcap2 & HWCAP2_SVEPMULL) {
-setCPUFeature(FEAT_SVE_AES);
+  if (hwcap2 & HWCAP2_SVEPMULL)
 setCPUFeature(FEAT_SVE_PMULL128);
-  }
   if (hwcap2 & HWCAP2_SVEBITPERM)
 setCPUFeature(FEAT_SVE_BITPERM);
   if (hwcap2 & HWCAP2_SVESHA3)
@@ -332,108 +333,76 @@ __init_cpu_features_constructor(unsigned long hwcap,
 setCPUFeature(FEAT_WFXT);
   if (hwcap2 & HWCAP2_SME)
 setCPUFeature(FEAT_SME);
+  if (hwcap2 & HWCAP2_SME2)
+setCPUFeature(FEAT_SME2);
   if (hwcap2 & HWCAP2_SME_I16I64)
 setCPUFeature(FEAT_SME_I64);
   if (hwcap2 & HWCAP2_SME_F64F64)
 setCPUFeature(FEAT_SME_F64);
-  if (hwcap & HWCAP_CPUID) {
-unsigned long ftr;
-getCPUFeature(ID_AA64PFR1_EL1, ftr);
-/* ID_AA64PFR1_EL1.MTE >= 0b0001  */
-if (extractBits(ftr, 8, 4) >= 0x1)
-  setCPUFeature(FEAT_MEMTAG);
-/* ID_AA64PFR1_EL1.SSBS == 0b0001  */
-if (extractBits(ftr, 4, 4) == 0x1)
-  setCPUFeature(FEAT_SSBS);
-/* ID_AA64PFR1_EL1.SME == 0b0010  */
-if (extractBits(

[gcc(refs/users/meissner/heads/work169-tar)] Allow CCmodes in TAR register.

2024-06-21 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:83684672e6614489c15e5beaa640492deeb8fcd9

commit 83684672e6614489c15e5beaa640492deeb8fcd9
Author: Michael Meissner 
Date:   Fri Jun 21 12:43:18 2024 -0400

Allow CCmodes in TAR register.

2024-06-21  Michael Meissner  

gcc/

* config/rs6000/rs6000.md (movcc_): Add support for the TAR
register.

Diff:
---
 gcc/config/rs6000/rs6000.md | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index 73aac467e74..e42038c9fec 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -8120,9 +8120,9 @@
 
 (define_insn "*movcc_"
   [(set (match_operand:CC_any 0 "nonimmediate_operand"
-   "=y,x,?y,y,r,r,r,r, r,*c*l,r,m")
+   "=y,x,?y,y,r,r,r,r, r,*wt*c*l,r,m")
(match_operand:CC_any 1 "general_operand"
-   " y,r, r,O,x,y,r,I,*h,   r,m,r"))]
+   " y,r, r,O,x,y,r,I,*h,   r,m,r"))]
   "register_operand (operands[0], mode)
|| register_operand (operands[1], mode)"
   "@


[gcc(refs/users/meissner/heads/work169-tar)] Update ChangeLog.*

2024-06-21 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:1241778ce6d55a8f5e253762cd89c9204031bd8a

commit 1241778ce6d55a8f5e253762cd89c9204031bd8a
Author: Michael Meissner 
Date:   Fri Jun 21 12:44:46 2024 -0400

Update ChangeLog.*

Diff:
---
 gcc/ChangeLog.tar | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/gcc/ChangeLog.tar b/gcc/ChangeLog.tar
index c5b3554401d..597388b43a9 100644
--- a/gcc/ChangeLog.tar
+++ b/gcc/ChangeLog.tar
@@ -1,3 +1,14 @@
+ Branch work169-tar, patch #205 
+
+Allow CCmodes in TAR register.
+
+2024-06-21  Michael Meissner  
+
+gcc/
+
+   * config/rs6000/rs6000.md (movcc_): Add support for the TAR
+   register.
+
  Branch work169-tar, patch #204 
 
 Add -mlrspr.


[gcc r15-1554] [committed] Fix testsuite fallout on stormy16 after IOR->PLUS change

2024-06-21 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:37f3000a57d62b808188eb6a14a369f6a789e1ea

commit r15-1554-g37f3000a57d62b808188eb6a14a369f6a789e1ea
Author: Jeff Law 
Date:   Fri Jun 21 15:58:12 2024 -0600

[committed] Fix testsuite fallout on stormy16 after IOR->PLUS change

More minor fallout from the IOR->PLUS change a little while ago.  This time 
on
xstormy16.

The pattern to swap nibbles actually tries to handle all the cases of IOR, 
XOR
and PLUS.  But when we generate PLUS earlier in the pipeline, the
simplifications/canonicalizations are slightly different resulting in the
pattern not matching.

This patch adds an alternate pattern which matches what we get now.  
Basically
it looks like QImode rotate by 4, zero extended to HI.

Run in my tester to verify the regression was fixed.  Pushing to the trunk.

gcc/
* config/stormy16/stormy16.md (swpn_zext): New pattern.

Diff:
---
 gcc/config/stormy16/stormy16.md | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/gcc/config/stormy16/stormy16.md b/gcc/config/stormy16/stormy16.md
index 7f12679847b..62318345cdc 100644
--- a/gcc/config/stormy16/stormy16.md
+++ b/gcc/config/stormy16/stormy16.md
@@ -1363,6 +1363,20 @@
   "swpn %0 | and %0,#255"
   [(set_attr "length" "6")])
 
+;; Alternate form when we use PLUS instead of IOR early in the
+;; expanders.
+(define_insn "*swpn_zext"
+  [(set (match_operand:HI 0 "register_operand" "=r")
+   (zero_extend:HI
+ (subreg:QI
+   (any_or_plus:HI
+ (ashift:HI (match_operand:HI 1 "register_operand" "0")
+(const_int 4))
+ (lshiftrt:HI (match_dup 1) (const_int 4))) 0)))]
+  ""
+  "swpn %0 | and %0,#255"
+  [(set_attr "length" "6")])
+
 (define_insn "*swpn_sext"
   [(set (match_operand:HI 0 "register_operand" "=r")
(sign_extend:HI


[gcc r15-1555] diagnostics: move diagnostic_{event, path} functions to diagnostic-path.cc

2024-06-21 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:4819dc7d4b84afa98881ffb8471cf19bc362221b

commit r15-1555-g4819dc7d4b84afa98881ffb8471cf19bc362221b
Author: David Malcolm 
Date:   Fri Jun 21 18:20:38 2024 -0400

diagnostics: move diagnostic_{event,path} functions to diagnostic-path.cc

No functional change intended.

gcc/ChangeLog:
* diagnostic-path.cc (diagnostic_event::meaning::dump_to_pp): Move
here from diagnostic.cc.
(diagnostic_event::meaning::maybe_get_verb_str): Likewise.
(diagnostic_event::meaning::maybe_get_noun_str): Likewise.
(diagnostic_event::meaning::maybe_get_property_str): Likewise.
(diagnostic_path::get_first_event_in_a_function): Likewise.
(diagnostic_path::interprocedural_p): Likewise.
(debug): Likewise for diagnostic_path * overload.
* diagnostic.cc (diagnostic_event::meaning::dump_to_pp): Move from
here to diagnostic-path.cc.
(diagnostic_event::meaning::maybe_get_verb_str): Likewise.
(diagnostic_event::meaning::maybe_get_noun_str): Likewise.
(diagnostic_event::meaning::maybe_get_property_str): Likewise.
(diagnostic_path::get_first_event_in_a_function): Likewise.
(diagnostic_path::interprocedural_p): Likewise.
(debug): Likewise for diagnostic_path * overload.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/diagnostic-path.cc | 168 +
 gcc/diagnostic.cc  | 168 -
 2 files changed, 168 insertions(+), 168 deletions(-)

diff --git a/gcc/diagnostic-path.cc b/gcc/diagnostic-path.cc
index 882dc1c5805..ea5b1f65e02 100644
--- a/gcc/diagnostic-path.cc
+++ b/gcc/diagnostic-path.cc
@@ -45,6 +45,174 @@ along with GCC; see the file COPYING3.  If not see
 #  pragma GCC diagnostic ignored "-Wformat-diag"
 #endif
 
+/* class diagnostic_event.  */
+
+/* struct diagnostic_event::meaning.  */
+
+void
+diagnostic_event::meaning::dump_to_pp (pretty_printer *pp) const
+{
+  bool need_comma = false;
+  pp_character (pp, '{');
+  if (const char *verb_str = maybe_get_verb_str (m_verb))
+{
+  pp_printf (pp, "verb: %qs", verb_str);
+  need_comma = true;
+}
+  if (const char *noun_str = maybe_get_noun_str (m_noun))
+{
+  if (need_comma)
+   pp_string (pp, ", ");
+  pp_printf (pp, "noun: %qs", noun_str);
+  need_comma = true;
+}
+  if (const char *property_str = maybe_get_property_str (m_property))
+{
+  if (need_comma)
+   pp_string (pp, ", ");
+  pp_printf (pp, "property: %qs", property_str);
+  need_comma = true;
+}
+  pp_character (pp, '}');
+}
+
+/* Get a string (or NULL) for V suitable for use within a SARIF
+   threadFlowLocation "kinds" property (SARIF v2.1.0 section 3.38.8).  */
+
+const char *
+diagnostic_event::meaning::maybe_get_verb_str (enum verb v)
+{
+  switch (v)
+{
+default:
+  gcc_unreachable ();
+case VERB_unknown:
+  return NULL;
+case VERB_acquire:
+  return "acquire";
+case VERB_release:
+  return "release";
+case VERB_enter:
+  return "enter";
+case VERB_exit:
+  return "exit";
+case VERB_call:
+  return "call";
+case VERB_return:
+  return "return";
+case VERB_branch:
+  return "branch";
+case VERB_danger:
+  return "danger";
+}
+}
+
+/* Get a string (or NULL) for N suitable for use within a SARIF
+   threadFlowLocation "kinds" property (SARIF v2.1.0 section 3.38.8).  */
+
+const char *
+diagnostic_event::meaning::maybe_get_noun_str (enum noun n)
+{
+  switch (n)
+{
+default:
+  gcc_unreachable ();
+case NOUN_unknown:
+  return NULL;
+case NOUN_taint:
+  return "taint";
+case NOUN_sensitive:
+  return "sensitive";
+case NOUN_function:
+  return "function";
+case NOUN_lock:
+  return "lock";
+case NOUN_memory:
+  return "memory";
+case NOUN_resource:
+  return "resource";
+}
+}
+
+/* Get a string (or NULL) for P suitable for use within a SARIF
+   threadFlowLocation "kinds" property (SARIF v2.1.0 section 3.38.8).  */
+
+const char *
+diagnostic_event::meaning::maybe_get_property_str (enum property p)
+{
+  switch (p)
+{
+default:
+  gcc_unreachable ();
+case PROPERTY_unknown:
+  return NULL;
+case PROPERTY_true:
+  return "true";
+case PROPERTY_false:
+  return "false";
+}
+}
+
+/* class diagnostic_path.  */
+
+/* Subroutine of diagnostic_path::interprocedural_p.
+   Look for the first event in this path that is within a function
+   i.e. has a non-null logical location for which function_p is true.
+   If found, write its index to *OUT_IDX and return true.
+   Otherwise return false.  */
+
+bool
+diagnostic_path::get_first_event_in_a_function (unsigned *out_idx) const
+{
+  const unsigned num = num_events ();
+  for (unsigned i = 0; i < num; i++)

[gcc r15-1556] diagnostics: remove duplicate copies of diagnostic_kind_text

2024-06-21 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:ccbcde5ec0e481e1ea775649d59691b6f5fcc5a1

commit r15-1556-gccbcde5ec0e481e1ea775649d59691b6f5fcc5a1
Author: David Malcolm 
Date:   Fri Jun 21 18:20:38 2024 -0400

diagnostics: remove duplicate copies of diagnostic_kind_text

No functional change intended.

gcc/ChangeLog:
* diagnostic-format-json.cc
(json_output_format::on_end_diagnostic): Use
get_diagnostic_kind_text rather than embedding a duplicate copy of
the table.
* diagnostic-format-sarif.cc
(make_rule_id_for_diagnostic_kind): Likewise.
* diagnostic.cc (get_diagnostic_kind_text): New.
* diagnostic.h (get_diagnostic_kind_text): New decl.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/diagnostic-format-json.cc  | 8 +---
 gcc/diagnostic-format-sarif.cc | 8 +---
 gcc/diagnostic.cc  | 8 
 gcc/diagnostic.h   | 2 ++
 4 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc
index ec03ac15aeb..8f2ff6cfde2 100644
--- a/gcc/diagnostic-format-json.cc
+++ b/gcc/diagnostic-format-json.cc
@@ -231,14 +231,8 @@ json_output_format::on_end_diagnostic (const 
diagnostic_info &diagnostic,
 
   /* Get "kind" of diagnostic.  */
   {
-static const char *const diagnostic_kind_text[] = {
-#define DEFINE_DIAGNOSTIC_KIND(K, T, C) (T),
-#include "diagnostic.def"
-#undef DEFINE_DIAGNOSTIC_KIND
-  "must-not-happen"
-};
 /* Lose the trailing ": ".  */
-const char *kind_text = diagnostic_kind_text[diagnostic.kind];
+const char *kind_text = get_diagnostic_kind_text (diagnostic.kind);
 size_t len = strlen (kind_text);
 gcc_assert (len > 2);
 gcc_assert (kind_text[len - 2] == ':');
diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc
index 5581aa1579e..2745c72ea3e 100644
--- a/gcc/diagnostic-format-sarif.cc
+++ b/gcc/diagnostic-format-sarif.cc
@@ -662,14 +662,8 @@ maybe_get_sarif_level (diagnostic_t diag_kind)
 static char *
 make_rule_id_for_diagnostic_kind (diagnostic_t diag_kind)
 {
-  static const char *const diagnostic_kind_text[] = {
-#define DEFINE_DIAGNOSTIC_KIND(K, T, C) (T),
-#include "diagnostic.def"
-#undef DEFINE_DIAGNOSTIC_KIND
-"must-not-happen"
-  };
   /* Lose the trailing ": ".  */
-  const char *kind_text = diagnostic_kind_text[diag_kind];
+  const char *kind_text = get_diagnostic_kind_text (diag_kind);
   size_t len = strlen (kind_text);
   gcc_assert (len > 2);
   gcc_assert (kind_text[len - 2] == ':');
diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc
index c66aa5af5ff..8fc22466b92 100644
--- a/gcc/diagnostic.cc
+++ b/gcc/diagnostic.cc
@@ -590,6 +590,14 @@ static const char *const diagnostic_kind_text[] = {
   "must-not-happen"
 };
 
+/* Get unlocalized string describing KIND.  */
+
+const char *
+get_diagnostic_kind_text (diagnostic_t kind)
+{
+  return diagnostic_kind_text[kind];
+}
+
 /* Return a malloc'd string describing a location and the severity of the
diagnostic, e.g. "foo.c:42:10: error: ".  The caller is responsible for
freeing the memory.  */
diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h
index c6846525da3..4969f07836c 100644
--- a/gcc/diagnostic.h
+++ b/gcc/diagnostic.h
@@ -1121,4 +1121,6 @@ option_unspecified_p (int opt)
 
 extern char *get_cwe_url (int cwe);
 
+extern const char *get_diagnostic_kind_text (diagnostic_t kind);
+
 #endif /* ! GCC_DIAGNOSTIC_H */