[gcc r15-3958] Ensure coarrays in calls use a descriptor [PR81265]

2024-09-30 Thread Andre Vehreschild via Gcc-cvs
https://gcc.gnu.org/g:bac95615b50d4a012c448cba080c106702184e3a

commit r15-3958-gbac95615b50d4a012c448cba080c106702184e3a
Author: Andre Vehreschild 
Date:   Fri Sep 27 14:18:42 2024 +0200

Ensure coarrays in calls use a descriptor [PR81265]

gcc/fortran/ChangeLog:

PR fortran/81265

* trans-expr.cc (gfc_conv_procedure_call): Ensure coarrays use a
descriptor when passed.

gcc/testsuite/ChangeLog:

* gfortran.dg/coarray/pr81265.f90: New test.

Diff:
---
 gcc/fortran/trans-expr.cc |  8 ++-
 gcc/testsuite/gfortran.dg/coarray/pr81265.f90 | 74 +++
 2 files changed, 81 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index e4c491a98486..9f223a1314a6 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -6438,11 +6438,15 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
 {
   bool finalized = false;
   tree derived_array = NULL_TREE;
+  symbol_attribute *attr;
 
   e = arg->expr;
   fsym = formal ? formal->sym : NULL;
   parm_kind = MISSING;
 
+  attr = fsym ? &(fsym->ts.type == BT_CLASS ? CLASS_DATA (fsym)->attr
+   : fsym->attr)
+ : nullptr;
   /* If the procedure requires an explicit interface, the actual
 argument is passed according to the corresponding formal
 argument.  If the corresponding formal argument is a POINTER,
@@ -6458,7 +6462,9 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
   if (comp)
nodesc_arg = nodesc_arg || !comp->attr.always_explicit;
   else
-   nodesc_arg = nodesc_arg || !sym->attr.always_explicit;
+   nodesc_arg
+ = nodesc_arg
+   || !(sym->attr.always_explicit || (attr && attr->codimension));
 
   /* Class array expressions are sometimes coming completely unadorned
 with either arrayspec or _data component.  Correct that here.
diff --git a/gcc/testsuite/gfortran.dg/coarray/pr81265.f90 
b/gcc/testsuite/gfortran.dg/coarray/pr81265.f90
new file mode 100644
index ..378733bfa7c2
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/coarray/pr81265.f90
@@ -0,0 +1,74 @@
+!{ dg-do run }
+
+! Contributed by Anton Shterenlikht  
+! Check PR81265 is fixed.
+
+module m
+implicit none
+private
+public :: s
+
+abstract interface
+  subroutine halo_exchange( array )
+integer, allocatable, intent( inout ) :: array(:,:,:,:)[:,:,:]
+  end subroutine halo_exchange
+end interface
+
+interface
+  module subroutine s( coarray, hx )
+integer, allocatable, intent( inout ) :: coarray(:,:,:,:)[:,:,:]
+procedure( halo_exchange ) :: hx
+  end subroutine s
+end interface
+
+end module m
+submodule( m ) sm
+contains
+module procedure s
+
+if ( .not. allocated(coarray) ) then
+  write (*,*) "ERROR: s: coarray is not allocated"
+  error stop
+end if
+
+sync all
+
+call hx( coarray ) 
+
+end procedure s
+
+end submodule sm
+module m2
+  implicit none
+  private
+  public :: s2
+  contains
+subroutine s2( coarray )
+  integer, allocatable, intent( inout ) :: coarray(:,:,:,:)[:,:,:]
+  if ( .not. allocated( coarray ) ) then
+write (*,'(a)') "ERROR: s2: coarray is not allocated"
+error stop
+  end if
+end subroutine s2
+end module m2
+program p
+use m
+use m2
+implicit none
+integer, allocatable :: space(:,:,:,:)[:,:,:]
+integer :: errstat
+
+allocate( space(10,10,10,2) [2,2,*], source=0, stat=errstat )
+if ( errstat .ne. 0 ) then
+  write (*,*) "ERROR: p: allocate( space ) )"
+  error stop
+end if
+
+if ( .not. allocated (space) ) then
+  write (*,*) "ERROR: p: space is not allocated"
+  error stop
+end if
+
+call s( space, s2 )
+
+end program p


[gcc(refs/users/meissner/heads/work179-vpair)] Add vector pair init and splat.

2024-09-30 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:9ec911bb924f1de91f8e581ddec1ccbd42b83dbb

commit 9ec911bb924f1de91f8e581ddec1ccbd42b83dbb
Author: Michael Meissner 
Date:   Fri Sep 27 00:19:47 2024 -0400

Add vector pair init and splat.

2024-09-27  Michael Meissner  

gcc/

* config/rs6000/rs6000-builtins.def (__builtin_vpair_zero): New
built-in function.
(__builtin_vpair_f32_splat): Likewise.
(__builtin_vpair_f64_splat): Likewise.
* config/rs6000/vector-pair.h: Update power10 splat patterns.
* config/rs6000/vector-pair.md (UNSPEC_VPAIR_ZERO): New unspec.
(UNSPEC_VPAIR_SPLAT): Likewise.
(VPAIR_SPLAT_VMODE): New mode iterator.
(VPAIR_SPLAT_ELEMENT_TO_VMODE): New mode attribute.
(vpair_splat_name): Likewise.
(vpair_zero): New insn.
(vpair_splat_): New define_expand.
(vpair_splat__internal): New insns.

gcc/testsuite/

* gcc.target/powerpc/vector-pair-5.c: New test.
* gcc.target/powerpc/vector-pair-6.c: Likewise.

Diff:
---
 gcc/config/rs6000/rs6000-builtins.def|  10 +++
 gcc/config/rs6000/vector-pair.md | 102 ++-
 gcc/doc/extend.texi  |   9 ++
 gcc/testsuite/gcc.target/powerpc/vector-pair-5.c |  54 
 gcc/testsuite/gcc.target/powerpc/vector-pair-6.c |  56 +
 5 files changed, 230 insertions(+), 1 deletion(-)

diff --git a/gcc/config/rs6000/rs6000-builtins.def 
b/gcc/config/rs6000/rs6000-builtins.def
index 2bac0e58971d..e0b1c744f7c6 100644
--- a/gcc/config/rs6000/rs6000-builtins.def
+++ b/gcc/config/rs6000/rs6000-builtins.def
@@ -3934,6 +3934,10 @@
   void __builtin_vsx_stxvp (v256, unsigned long, const v256 *);
 STXVP nothing {mma,pair}
 
+;; Vector pair built-in functions.
+  v256 __builtin_vpair_zero ();
+VPAIR_ZERO vpair_zero {mma}
+
 ;; Vector pair built-in functions with float elements
   v256 __builtin_vpair_f32_abs (v256);
 VPAIR_F32_ABS vpair_abs_v8sf2 {mma}
@@ -3974,6 +3978,9 @@
   v256 __builtin_vpair_f32_nfms (v256, v256, v256);
 VPAIR_F32_NFMS vpair_nfms_v8sf4 {mma}
 
+  v256 __builtin_vpair_f32_splat (float);
+VPAIR_F32_SPLAT vpair_splat_v8sf {mma}
+
   v256 __builtin_vpair_f32_sub (v256, v256);
 VPAIR_F32_SUB vpair_sub_v8sf3 {mma}
 
@@ -4017,5 +4024,8 @@
   v256 __builtin_vpair_f64_nfms (v256, v256, v256);
 VPAIR_F64_NFMS vpair_nfms_v4df4 {mma}
 
+  v256 __builtin_vpair_f64_splat (double);
+VPAIR_F64_SPLAT vpair_splat_v4df {mma}
+
   v256 __builtin_vpair_f64_sub (v256, v256);
 VPAIR_F64_SUB vpair_sub_v4df3 {mma}
diff --git a/gcc/config/rs6000/vector-pair.md b/gcc/config/rs6000/vector-pair.md
index fe8004b75d54..6fbc90cf528a 100644
--- a/gcc/config/rs6000/vector-pair.md
+++ b/gcc/config/rs6000/vector-pair.md
@@ -39,7 +39,9 @@
UNSPEC_VPAIR_PLUS
UNSPEC_VPAIR_SMAX
UNSPEC_VPAIR_SMIN
-   UNSPEC_VPAIR_SQRT])
+   UNSPEC_VPAIR_SPLAT
+   UNSPEC_VPAIR_SQRT
+   UNSPEC_VPAIR_ZERO])
 
 ;; Vector pair element ID that defines the scaler element within the vector 
pair.
 (define_c_enum "vpair_element"
@@ -102,6 +104,104 @@
 ;; Map the scalar element ID into the appropriate insn type for divide.
 (define_int_attr vpair_divtype [(VPAIR_ELEMENT_FLOAT  "vecfdiv")
(VPAIR_ELEMENT_DOUBLE "vecdiv")])
+
+;; Mode iterator for the vector modes that we provide splat operations for.
+(define_mode_iterator VPAIR_SPLAT_VMODE [V4SF V2DF])
+
+;; Map element mode to 128-bit vector mode for splat operations
+(define_mode_attr VPAIR_SPLAT_ELEMENT_TO_VMODE [(SF "V4SF")
+   (DF "V2DF")])
+
+;; Map either element mode or vector mode into the name for the splat insn.
+(define_mode_attr vpair_splat_name [(SF   "v8sf")
+   (DF   "v4df")
+   (V4SF "v8sf")
+   (V2DF "v4df")])
+
+;; Initialize a vector pair to 0
+(define_insn_and_split "vpair_zero"
+  [(set (match_operand:OO 0 "vsx_register_operand" "=wa")
+   (unspec:OO [(const_int 0)] UNSPEC_VPAIR_ZERO))]
+  "TARGET_MMA"
+  "#"
+  "&& reload_completed"
+  [(set (match_dup 1) (match_dup 3))
+   (set (match_dup 2) (match_dup 3))]
+{
+  rtx op0 = operands[0];
+
+  operands[1] = simplify_gen_subreg (V2DFmode, op0, OOmode, 0);
+  operands[2] = simplify_gen_subreg (V2DFmode, op0, OOmode, 16);
+  operands[3] = CONST0_RTX (V2DFmode);
+}
+  [(set_attr "length" "8")
+   (set_attr "type" "vecperm")])
+
+;; Create a vector pair with a value splat'ed (duplicated) to all of the
+;; elements.
+(define_expand "vpair_splat_"
+  [(use (match_operand:OO 0 "vsx_register_operand"))
+   (use (match_operand:SFDF 1 "input_operand"))]
+  "TARGET_MMA"
+{
+  rtx op0 = operands[0];
+  rtx op1 = operands[1];
+  machine_mode element_mode = mode;
+
+  if (op1 == CONST0_RTX (element_mode))
+{
+  emit_insn (g

[gcc(refs/users/meissner/heads/work179-vpair)] Add support for vector pair unary and binary operations.

2024-09-30 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:e3e197b8a52cb74e879a24eaf6161f5e19861daf

commit e3e197b8a52cb74e879a24eaf6161f5e19861daf
Author: Michael Meissner 
Date:   Fri Sep 27 00:12:44 2024 -0400

Add support for vector pair unary and binary operations.

2024-09-27  Michael Meissner  

gcc/

* config/rs6000/rs6000-builtins.def (__builtin_vpair_*): Add new
built-in functions for vector pair support.
* config/rs6000/rs6000-protos.h (enum vpair_split_unary): New
enumeration.
(vpair_split_unary): New declaration.
(vpair_split_binary): Likewise.
* config/rs6000/rs6000.cc (print_operand): Add 'S' output modifier.
(vpair_split_unary): New function to split vector pair operations.
(vpair_split_binary): Likewise.
* config/rs6000/rs6000.md (toplevel): Include vector-pair.md.
* config/rs6000/t-rs6000 (MD_INCLUDES): Add vector-pair.md.
* config/rs6000/vector-pair.md: New file.
* doc/extend.texi (PowerPC Vector Pair Built-in Functions): Add
documentation for the new vector pair built-in functions.

gcc/testsuite/

* gcc.target/powerpc/vector-pair-1.c: New test.
* gcc.target/powerpc/vector-pair-2.c: Likewise.

Diff:
---
 gcc/config/rs6000/rs6000-builtins.def|  62 +
 gcc/config/rs6000/rs6000-protos.h|  12 ++
 gcc/config/rs6000/rs6000.cc  | 113 
 gcc/config/rs6000/rs6000.md  |   1 +
 gcc/config/rs6000/t-rs6000   |   1 +
 gcc/config/rs6000/vector-pair.md | 164 +++
 gcc/doc/extend.texi  |  51 +++
 gcc/testsuite/gcc.target/powerpc/vector-pair-1.c |  87 
 gcc/testsuite/gcc.target/powerpc/vector-pair-2.c |  86 
 9 files changed, 577 insertions(+)

diff --git a/gcc/config/rs6000/rs6000-builtins.def 
b/gcc/config/rs6000/rs6000-builtins.def
index 0e9dc05dbcff..cf22389542d8 100644
--- a/gcc/config/rs6000/rs6000-builtins.def
+++ b/gcc/config/rs6000/rs6000-builtins.def
@@ -3933,3 +3933,65 @@
 
   void __builtin_vsx_stxvp (v256, unsigned long, const v256 *);
 STXVP nothing {mma,pair}
+
+;; Vector pair built-in functions with float elements
+  v256 __builtin_vpair_f32_abs (v256);
+VPAIR_F32_ABS vpair_abs_v8sf2 {mma}
+
+  v256 __builtin_vpair_f32_add (v256, v256);
+VPAIR_F32_ADD vpair_add_v8sf3 {mma}
+
+  v256 __builtin_vpair_f32_div (v256, v256);
+VPAIR_F32_DIV vpair_div_v8sf3 {mma}
+
+  v256 __builtin_vpair_f32_max (v256, v256);
+VPAIR_F32_MAX vpair_smax_v8sf3 {mma}
+
+  v256 __builtin_vpair_f32_min (v256, v256);
+VPAIR_F32_MIN vpair_smin_v8sf3 {mma}
+
+  v256 __builtin_vpair_f32_mul (v256, v256);
+VPAIR_F32_MUL vpair_mul_v8sf3 {mma}
+
+  v256 __builtin_vpair_f32_nabs (v256);
+VPAIR_F32_NABS vpair_nabs_v8sf2 {mma}
+
+  v256 __builtin_vpair_f32_neg (v256);
+VPAIR_F32_NEG vpair_neg_v8sf2 {mma}
+
+  v256 __builtin_vpair_f32_sqrt (v256);
+VPAIR_F32_SQRT vpair_sqrt_v8sf2 {mma}
+
+  v256 __builtin_vpair_f32_sub (v256, v256);
+VPAIR_F32_SUB vpair_sub_v8sf3 {mma}
+
+;; Vector pair built-in functions with double elements
+  v256 __builtin_vpair_f64_abs (v256);
+VPAIR_F64_ABS vpair_abs_v4df2 {mma}
+
+  v256 __builtin_vpair_f64_add (v256, v256);
+VPAIR_F64_ADD vpair_add_v4df3 {mma}
+
+  v256 __builtin_vpair_f64_div (v256, v256);
+VPAIR_F64_DIV vpair_div_v4df3 {mma}
+
+  v256 __builtin_vpair_f64_max (v256, v256);
+VPAIR_F64_MAX vpair_smax_v4df3 {mma}
+
+  v256 __builtin_vpair_f64_min (v256, v256);
+VPAIR_F64_MIN vpair_smin_v4df3 {mma}
+
+  v256 __builtin_vpair_f64_mul (v256, v256);
+VPAIR_F64_MUL vpair_mul_v4df3 {mma}
+
+  v256 __builtin_vpair_f64_nabs (v256);
+VPAIR_F64_NABS vpair_nabs_v4df2 {mma}
+
+  v256 __builtin_vpair_f64_neg (v256);
+VPAIR_F64_NEG vpair_neg_v4df2 {mma}
+
+  v256 __builtin_vpair_f64_sqrt (v256);
+VPAIR_F64_SQRT vpair_sqrt_v4df2 {mma}
+
+  v256 __builtin_vpair_f64_sub (v256, v256);
+VPAIR_F64_SUB vpair_sub_v4df3 {mma}
diff --git a/gcc/config/rs6000/rs6000-protos.h 
b/gcc/config/rs6000/rs6000-protos.h
index da658cd5ab2e..7b8b3b0c2377 100644
--- a/gcc/config/rs6000/rs6000-protos.h
+++ b/gcc/config/rs6000/rs6000-protos.h
@@ -161,6 +161,18 @@ extern bool rs6000_pcrel_p (void);
 extern bool rs6000_fndecl_pcrel_p (const_tree);
 extern void rs6000_output_addr_vec_elt (FILE *, int);
 
+/* If we are splitting a vector pair unary operator into two separate vector
+   operations, we need to generate a NEG if this is NABS.  */
+
+enum vpair_split_unary {
+  VPAIR_SPLIT_NORMAL,  /* No extra processing is needed.  */
+  VPAIR_SPLIT_NEGATE   /* Wrap operation with a NEG.  */
+};
+
+extern void vpair_split_unary (rtx [], machine_mode, enum rtx_code,
+  enum vpair_split_unary);
+extern void vpair_split_binary 

[gcc(refs/users/meissner/heads/work179-vpair)] Add vector pair optimizations.

2024-09-30 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:89b41f0f8a8efb19fb68bd8a43082a2aae9f6747

commit 89b41f0f8a8efb19fb68bd8a43082a2aae9f6747
Author: Michael Meissner 
Date:   Fri Sep 27 00:22:53 2024 -0400

Add vector pair optimizations.

2024-09-27  Michael Meissner  

gcc/

* config/rs6000/vector-pair.md (vpair_add_neg_3): 
New
combiner insn to convert vector plus/neg into a minus operation.
(vpair_fma__merge): Optimize multiply, 
add/subtract, and
negation into fma operations if the user specifies to create fmas.
(vpair_fma__merge): Likewise.
(vpair_fma__merge2): Likewise.
(vpair_nfma__merge): Likewise.
(vpair_nfms__merge): Likewise.
(vpair_nfms__merge2): Likewise.

gcc/testsuite/

* gcc.target/powerpc/vector-pair-7.c: New test.
* gcc.target/powerpc/vector-pair-8.c: Likewise.
* gcc.target/powerpc/vector-pair-9.c: Likewise.
* gcc.target/powerpc/vector-pair-10.c: Likewise.
* gcc.target/powerpc/vector-pair-11.c: Likewise.
* gcc.target/powerpc/vector-pair-12xs.c: Likewise.

Diff:
---
 gcc/config/rs6000/vector-pair.md  | 224 ++
 gcc/testsuite/gcc.target/powerpc/vector-pair-10.c |  61 ++
 gcc/testsuite/gcc.target/powerpc/vector-pair-11.c |  65 +++
 gcc/testsuite/gcc.target/powerpc/vector-pair-12.c |  65 +++
 gcc/testsuite/gcc.target/powerpc/vector-pair-7.c  |  18 ++
 gcc/testsuite/gcc.target/powerpc/vector-pair-8.c  |  18 ++
 gcc/testsuite/gcc.target/powerpc/vector-pair-9.c  |  61 ++
 7 files changed, 512 insertions(+)

diff --git a/gcc/config/rs6000/vector-pair.md b/gcc/config/rs6000/vector-pair.md
index 6fbc90cf528a..01d32e460f6e 100644
--- a/gcc/config/rs6000/vector-pair.md
+++ b/gcc/config/rs6000/vector-pair.md
@@ -265,6 +265,31 @@
(set (attr "type") (if_then_else (match_test " == DIV")
(const_string "")
(const_string "")))])
+
+;; Optimize vector pair add of a negative value into a subtract.
+(define_insn_and_split "*vpair_add_neg_3"
+  [(set (match_operand:OO 0 "vsx_register_operand" "=wa")
+   (unspec:OO
+[(match_operand:OO 1 "vsx_register_operand" "wa")
+ (unspec:OO
+  [(match_operand:OO 2 "vsx_register_operand" "wa")
+   (const_int VPAIR_FP_ELEMENT)]
+  UNSPEC_VPAIR_NEG)
+ (const_int VPAIR_FP_ELEMENT)]
+VPAIR_FP_BINARY))]
+  "TARGET_MMA"
+  "#"
+  "&& 1"
+  [(set (match_dup 0)
+   (unspec:OO
+[(match_dup 1)
+ (match_dup 2)
+ (const_int VPAIR_FP_ELEMENT)]
+UNSPEC_VPAIR_MINUS))]
+{
+}
+  [(set_attr "length" "8")
+   (set_attr "type" "")])
 
 ;; Vector pair fused-multiply (FMA) operations.  The last argument in the
 ;; UNSPEC is a CONST_INT which identifies what the scalar element is.
@@ -358,3 +383,202 @@
 }
   [(set_attr "length" "8")
(set_attr "type" "")])
+
+;; Optimize vector pair multiply and vector pair add into vector pair fma,
+;; providing the compiler would do this optimization for scalar and vectors.
+;; Unlike most of the define_insn_and_splits, this can be done before register
+;; allocation.
+(define_insn_and_split "*vpair_fma__merge"
+  [(set (match_operand:OO 0 "vsx_register_operand" "=wa,wa")
+   (unspec:OO
+[(unspec:OO
+  [(match_operand:OO 1 "vsx_register_operand" "%wa,wa")
+   (match_operand:OO 2 "vsx_register_operand" "wa,0")
+   (const_int VPAIR_FP_ELEMENT)]
+  UNSPEC_VPAIR_MULT)
+ (match_operand:OO 3 "vsx_register_operand" "0,wa")
+ (const_int VPAIR_FP_ELEMENT)]
+UNSPEC_VPAIR_PLUS))]
+  "TARGET_MMA && flag_fp_contract_mode == FP_CONTRACT_FAST"
+  "#"
+  "&& 1"
+  [(set (match_dup 0)
+   (unspec:OO
+[(match_dup 1)
+ (match_dup 2)
+ (match_dup 3)
+ (const_int VPAIR_FP_ELEMENT)]
+UNSPEC_VPAIR_FMA))]
+{
+}
+  [(set_attr "length" "8")
+   (set_attr "type" "")])
+
+;; Merge multiply and subtract.
+(define_insn_and_split "*vpair_fma__merge"
+  [(set (match_operand:OO 0 "vsx_register_operand" "=wa,wa")
+   (unspec:OO
+[(unspec:OO
+  [(match_operand:OO 1 "vsx_register_operand" "%wa,wa")
+   (match_operand:OO 2 "vsx_register_operand" "wa,0")
+   (const_int VPAIR_FP_ELEMENT)]
+  UNSPEC_VPAIR_MULT)
+ (match_operand:OO 3 "vsx_register_operand" "0,wa")
+ (const_int VPAIR_FP_ELEMENT)]
+UNSPEC_VPAIR_MINUS))]
+  "TARGET_MMA && flag_fp_contract_mode == FP_CONTRACT_FAST"
+  "#"
+  "&& 1"
+  [(set (match_dup 0)
+   (unspec:OO
+[(match_dup 1)
+ (match_dup 2)
+ (unspec:OO
+  [(match_dup 3)
+   (const_int VPAIR_FP_ELEMENT)]
+  UNSPEC_VPAIR_NEG)
+ (const_int VPAIR_FP_ELEMENT)]
+UNSPEC_VPAIR_FMA))]
+{
+}
+  [(set_attr "length" "8")
+   (set_attr "type"

[gcc(refs/users/meissner/heads/work179-vpair)] Add support for vector pair fma operations.

2024-09-30 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:dcbcb6bc88da8e9667e67ef02c315e532eae34a0

commit dcbcb6bc88da8e9667e67ef02c315e532eae34a0
Author: Michael Meissner 
Date:   Fri Sep 27 00:16:50 2024 -0400

Add support for vector pair fma operations.

2024-09-27  Michael Meissner  

gcc/

* config/rs6000/rs6000-builtins.def (__builtin_vpair_f32_fma): New
built-in.
(__builtin_vpair_f32_fms): Likewise.
(__builtin_vpair_f32_nfma): Likewise.
(__builtin_vpair_f32_nfms): Likewise.
(__builtin_vpair_f64_fma): Likewise.
(__builtin_vpair_f64_fms): Likewise.
(__builtin_vpair_f64_nfma): Likewise.
* config/rs6000/rs6000/rs6000-proto.h (enum vpair_split_fma): New
enumeration.
(vpair_split_fma): New declaration.
* config/rs6000/rs6000.cc (vpair_split_fma): New function to split
vector pair FMA operations.
* config/rs6000/vector-pair.md (UNSPEC_VPAIR_FMA): New unspec.
(vpair_stdname): Add UNSPEC_VPAIR_FMA.
(VPAIR_OP): Likewise.
(vpair_fma_4): New insns.
(vpair_fms_4): Likewise.
(vpair_nfma_4): Likewise.
(vpair_nfms_4): Likewise.
* doc/extend.texi (PowerPC Vector Pair Built-in Functions): 
Document new
vector pair fma built-in functions.

gcc/testsuite/

* gcc.target/powerpc/vector-pair-3.c: New test.
* gcc.target/powerpc/vector-pair-4.c: Likewise.

Diff:
---
 gcc/config/rs6000/rs6000-builtins.def| 24 ++
 gcc/config/rs6000/rs6000-protos.h| 13 
 gcc/config/rs6000/rs6000.cc  | 71 ++
 gcc/config/rs6000/vector-pair.md | 96 
 gcc/doc/extend.texi  | 25 ++
 gcc/testsuite/gcc.target/powerpc/vector-pair-3.c | 57 ++
 gcc/testsuite/gcc.target/powerpc/vector-pair-4.c | 57 ++
 7 files changed, 343 insertions(+)

diff --git a/gcc/config/rs6000/rs6000-builtins.def 
b/gcc/config/rs6000/rs6000-builtins.def
index cf22389542d8..2bac0e58971d 100644
--- a/gcc/config/rs6000/rs6000-builtins.def
+++ b/gcc/config/rs6000/rs6000-builtins.def
@@ -3944,6 +3944,12 @@
   v256 __builtin_vpair_f32_div (v256, v256);
 VPAIR_F32_DIV vpair_div_v8sf3 {mma}
 
+  v256 __builtin_vpair_f32_fma (v256, v256, v256);
+VPAIR_F32_FMA vpair_fma_v8sf4 {mma}
+
+  v256 __builtin_vpair_f32_fms (v256, v256, v256);
+VPAIR_F32_FMS vpair_fms_v8sf4 {mma}
+
   v256 __builtin_vpair_f32_max (v256, v256);
 VPAIR_F32_MAX vpair_smax_v8sf3 {mma}
 
@@ -3962,6 +3968,12 @@
   v256 __builtin_vpair_f32_sqrt (v256);
 VPAIR_F32_SQRT vpair_sqrt_v8sf2 {mma}
 
+  v256 __builtin_vpair_f32_nfma (v256, v256, v256);
+VPAIR_F32_NFMA vpair_nfma_v8sf4 {mma}
+
+  v256 __builtin_vpair_f32_nfms (v256, v256, v256);
+VPAIR_F32_NFMS vpair_nfms_v8sf4 {mma}
+
   v256 __builtin_vpair_f32_sub (v256, v256);
 VPAIR_F32_SUB vpair_sub_v8sf3 {mma}
 
@@ -3975,6 +3987,12 @@
   v256 __builtin_vpair_f64_div (v256, v256);
 VPAIR_F64_DIV vpair_div_v4df3 {mma}
 
+  v256 __builtin_vpair_f64_fma (v256, v256, v256);
+VPAIR_F64_FMA vpair_fma_v4df4 {mma}
+
+  v256 __builtin_vpair_f64_fms (v256, v256, v256);
+VPAIR_F64_FMS vpair_fms_v4df4 {mma}
+
   v256 __builtin_vpair_f64_max (v256, v256);
 VPAIR_F64_MAX vpair_smax_v4df3 {mma}
 
@@ -3993,5 +4011,11 @@
   v256 __builtin_vpair_f64_sqrt (v256);
 VPAIR_F64_SQRT vpair_sqrt_v4df2 {mma}
 
+  v256 __builtin_vpair_f64_nfma (v256, v256, v256);
+VPAIR_F64_NFMA vpair_nfma_v4df4 {mma}
+
+  v256 __builtin_vpair_f64_nfms (v256, v256, v256);
+VPAIR_F64_NFMS vpair_nfms_v4df4 {mma}
+
   v256 __builtin_vpair_f64_sub (v256, v256);
 VPAIR_F64_SUB vpair_sub_v4df3 {mma}
diff --git a/gcc/config/rs6000/rs6000-protos.h 
b/gcc/config/rs6000/rs6000-protos.h
index 7b8b3b0c2377..bab5fb437c27 100644
--- a/gcc/config/rs6000/rs6000-protos.h
+++ b/gcc/config/rs6000/rs6000-protos.h
@@ -173,6 +173,19 @@ extern void vpair_split_unary (rtx [], machine_mode, enum 
rtx_code,
   enum vpair_split_unary);
 extern void vpair_split_binary (rtx [], machine_mode, enum rtx_code);
 
+/* When we are splitting a vector pair FMA operation into two vector 
operations, we
+   may need to modify the code generated.  This enumeration encodes the
+   different choices.  */
+
+enum vpair_split_fma {
+  VPAIR_SPLIT_FMA, /* Fused multiply-add.  */
+  VPAIR_SPLIT_FMS, /* Fused multiply-subtract.  */
+  VPAIR_SPLIT_NFMA,/* Fused negate multiply-add.  */
+  VPAIR_SPLIT_NFMS /* Fused negate multiply-subtract.  */
+};
+
+extern void vpair_split_fma (rtx [], machine_mode, enum vpair_split_fma);
+
 /* Different PowerPC instruction formats that are used by GCC.  There are
various other instruction formats used by the PowerPC hardware, but these
f

[gcc(refs/users/meissner/heads/work179-vpair)] Initial vector-pair.h support

2024-09-30 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:b75aa06732e45bc81d48858c4b69a04f8396cb6f

commit b75aa06732e45bc81d48858c4b69a04f8396cb6f
Author: Michael Meissner 
Date:   Fri Sep 27 00:08:55 2024 -0400

Initial vector-pair.h support

2024-09-26  Michael Meissner  

gcc/

* config.gcc (powerpc*-*-*): Add vector-pair.h to extra headers.
* config/rs6000/vector-pair.h: New file.
* doc/extend.texi (PowerPC Vector Pair Support): Document the vector
pair support functions.

Diff:
---
 gcc/config.gcc  |   2 +-
 gcc/config/rs6000/vector-pair.h | 563 
 gcc/doc/extend.texi |  98 +++
 3 files changed, 662 insertions(+), 1 deletion(-)

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 0b794e977f6a..3627bed8b863 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -537,7 +537,7 @@ powerpc*-*-*)
extra_headers="${extra_headers} pmmintrin.h tmmintrin.h smmintrin.h"
extra_headers="${extra_headers} nmmintrin.h immintrin.h x86gprintrin.h"
extra_headers="${extra_headers} ppu_intrinsics.h spu2vmx.h vec_types.h 
si2vmx.h"
-   extra_headers="${extra_headers} amo.h"
+   extra_headers="${extra_headers} amo.h vector-pair.h"
case x$with_cpu in

xpowerpc64|xdefault64|x6[23]0|x970|xG5|xpower[3456789]|xpower1[01]|xpower6x|xrs64a|xcell|xa2|xe500mc64|xe5500|xe6500|xfuture)
cpu_is_64bit=yes
diff --git a/gcc/config/rs6000/vector-pair.h b/gcc/config/rs6000/vector-pair.h
new file mode 100644
index ..e0023842f331
--- /dev/null
+++ b/gcc/config/rs6000/vector-pair.h
@@ -0,0 +1,563 @@
+/* PowerPC vector pair include file.
+   Copyright (C) 2024 Free Software Foundation, Inc.
+   Contributed by Aldy Hernandez (al...@redhat.com).
+   Rewritten by Paolo Bonzini (bonz...@gnu.org).
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published
+   by the Free Software Foundation; either version 3, or (at your
+   option) any later version.
+
+   GCC is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+   License for more details.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   .  */
+
+/* Provide support for vector pairs, even on systems that do not have native
+   support for loading and storing pairs of vectors.  */
+
+#ifndef _VECTOR_PAIR_H
+#define _VECTOR_PAIR_H 1
+
+/* During testing, allow vector-pair.h to be included multiple times.  */
+#undef  vector_pair_t
+#undef  vector_pair_f64_t
+#undef  vector_pair_f32_t
+
+#undef  vpair_f64_abs
+#undef  vpair_f64_add
+#undef  vpair_f64_div
+#undef  vpair_f64_fma
+#undef  vpair_f64_fms
+#undef  vpair_f64_max
+#undef  vpair_f64_min
+#undef  vpair_f64_mul
+#undef  vpair_f64_nabs
+#undef  vpair_f64_neg
+#undef  vpair_f64_nfma
+#undef  vpair_f64_nfms
+#undef  vpair_f64_splat
+#undef  vpair_f64_sqrt
+#undef  vpair_f64_sub
+
+#undef  vpair_f32_abs
+#undef  vpair_f32_add
+#undef  vpair_f32_div
+#undef  vpair_f32_fma
+#undef  vpair_f32_fms
+#undef  vpair_f32_max
+#undef  vpair_f32_min
+#undef  vpair_f32_mul
+#undef  vpair_f32_nabs
+#undef  vpair_f32_neg
+#undef  vpair_f32_nfma
+#undef  vpair_f32_nfms
+#undef  vpair_f32_splat
+#undef  vpair_f32_sqrt
+#undef  vpair_f32_sub
+
+/* Union of the various vector pair types.  For testing, allow vector-pair.h to
+   be included multiple times, so protect the union from re-declaration.  */
+#ifndef __VECTOR_PAIR_UNION__
+#define __VECTOR_PAIR_UNION__  1
+
+union __vpair_union {
+
+#ifdef __MMA__
+  __vector_pair__vpair;
+#endif
+
+  vector double__vp_f64[2];
+  vector float __vp_f32[2];
+  vector unsigned char __vp_uc[2];
+};
+
+typedef union __vpair_unionvector_pair_t;
+typedef union __vpair_unionvector_pair_f64_t;
+typedef union __vpair_unionvector_pair_f32_t;
+typedef union __vpair_union*__vpair_ptr_t;
+
+#endif /* __VECTOR_PAIR_UNION__.  */
+
+#if !__VPAIR_ASM__ && !__VPAIR_NOP10__
+#if __MMA__
+#define __VPAIR_ASM__  1
+
+#else
+#define __VPAIR_NOP10__1
+#endif
+#endif
+
+/* ISA 3.1 (power10/power11) support with explicit vector pair type.  */
+
+#if __VPAIR_ASM__ && __MMA__
+
+#undef  __VPAIR_FP_UNARY_ASM
+#define __VPAIR_FP_UNARY_ASM(OPCODE, R, A) \
+  __asm__ (OPCODE " %x0,%x1\n\t" OPCODE " %x0+1,%x1+1" 

[gcc(refs/users/meissner/heads/work179-vpair)] Rewrite vector-pair.h.

2024-09-30 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:b5dc5d0e1843ec1bb40270b684e161a06359b6a8

commit b5dc5d0e1843ec1bb40270b684e161a06359b6a8
Author: Michael Meissner 
Date:   Mon Sep 30 13:25:21 2024 -0400

Rewrite vector-pair.h.

2024-09-30  Michael Meissner  

gcc/

* config/rs6000/vector-pair.h: Rewrite.

Diff:
---
 gcc/config/rs6000/vector-pair.h | 1447 ++-
 1 file changed, 973 insertions(+), 474 deletions(-)

diff --git a/gcc/config/rs6000/vector-pair.h b/gcc/config/rs6000/vector-pair.h
index e0023842f331..78dfc74c0d59 100644
--- a/gcc/config/rs6000/vector-pair.h
+++ b/gcc/config/rs6000/vector-pair.h
@@ -30,47 +30,9 @@
 #ifndef _VECTOR_PAIR_H
 #define _VECTOR_PAIR_H 1
 
-/* During testing, allow vector-pair.h to be included multiple times.  */
-#undef  vector_pair_t
-#undef  vector_pair_f64_t
-#undef  vector_pair_f32_t
-
-#undef  vpair_f64_abs
-#undef  vpair_f64_add
-#undef  vpair_f64_div
-#undef  vpair_f64_fma
-#undef  vpair_f64_fms
-#undef  vpair_f64_max
-#undef  vpair_f64_min
-#undef  vpair_f64_mul
-#undef  vpair_f64_nabs
-#undef  vpair_f64_neg
-#undef  vpair_f64_nfma
-#undef  vpair_f64_nfms
-#undef  vpair_f64_splat
-#undef  vpair_f64_sqrt
-#undef  vpair_f64_sub
-
-#undef  vpair_f32_abs
-#undef  vpair_f32_add
-#undef  vpair_f32_div
-#undef  vpair_f32_fma
-#undef  vpair_f32_fms
-#undef  vpair_f32_max
-#undef  vpair_f32_min
-#undef  vpair_f32_mul
-#undef  vpair_f32_nabs
-#undef  vpair_f32_neg
-#undef  vpair_f32_nfma
-#undef  vpair_f32_nfms
-#undef  vpair_f32_splat
-#undef  vpair_f32_sqrt
-#undef  vpair_f32_sub
-
-/* Union of the various vector pair types.  For testing, allow vector-pair.h to
-   be included multiple times, so protect the union from re-declaration.  */
-#ifndef __VECTOR_PAIR_UNION__
-#define __VECTOR_PAIR_UNION__  1
+/* Union of the various vector pair types.  */
+#ifndef __VPAIR_UNION__
+#define __VPAIR_UNION__1
 
 union __vpair_union {
 
@@ -87,11 +49,13 @@ typedef union __vpair_union vector_pair_t;
 typedef union __vpair_unionvector_pair_f64_t;
 typedef union __vpair_unionvector_pair_f32_t;
 typedef union __vpair_union*__vpair_ptr_t;
+#endif /* __VPAIR_UNION__.  */
 
-#endif /* __VECTOR_PAIR_UNION__.  */
+#if !__VPAIR_BUILTIN__ && !__VPAIR_ASM__ && !__VPAIR_NOP10__
+#if __MMA__ && __VPAIR__
+#define __VPAIR_BUILTIN__  1
 
-#if !__VPAIR_ASM__ && !__VPAIR_NOP10__
-#if __MMA__
+#elif __MMA__
 #define __VPAIR_ASM__  1
 
 #else
@@ -99,9 +63,379 @@ typedef union __vpair_union *__vpair_ptr_t;
 #endif
 #endif
 
-/* ISA 3.1 (power10/power11) support with explicit vector pair type.  */
+
+/* ISA 3.1 (power10/power11) support with explicit vector pair type and
+   built-in functions for the vector pair operations.  */
+
+#if __VPAIR_BUILTIN__ && __MMA__
+
+/* Allow vector-pair.h to be included multiple times during testing.  */
+#undef vpair_f64_abs
+#undef vpair_f64_add
+#undef vpair_f64_div
+#undef vpair_f64_fma
+#undef vpair_f64_fms
+#undef vpair_f64_max
+#undef vpair_f64_min
+#undef vpair_f64_mul
+#undef vpair_f64_nabs
+#undef vpair_f64_neg
+#undef vpair_f64_nfma
+#undef vpair_f64_nfms
+#undef vpair_f64_splat
+#undef vpair_f64_sqrt
+#undef vpair_f64_sub
+
+#undef vpair_f32_abs
+#undef vpair_f32_add
+#undef vpair_f32_div
+#undef vpair_f32_fma
+#undef vpair_f32_fms
+#undef vpair_f32_max
+#undef vpair_f32_min
+#undef vpair_f32_mul
+#undef vpair_f32_nabs
+#undef vpair_f32_neg
+#undef vpair_f32_nfma
+#undef vpair_f32_nfms
+#undef vpair_f32_splat
+#undef vpair_f32_sqrt
+#undef vpair_f32_sub
+
+#define vpair_f64_abs  __vpair_f64_abs_builtin
+#define vpair_f64_add  __vpair_f64_add_builtin
+#define vpair_f64_div  __vpair_f64_div_builtin
+#define vpair_f64_fma  __vpair_f64_fma_builtin
+#define vpair_f64_fms  __vpair_f64_fms_builtin
+#define vpair_f64_max  __vpair_f64_max_builtin
+#define vpair_f64_min  __vpair_f64_min_builtin
+#define vpair_f64_mul  __vpair_f64_mul_builtin
+#define vpair_f64_nabs __vpair_f64_nabs_builtin
+#define vpair_f64_neg  __vpair_f64_neg_builtin
+#define vpair_f64_nfma __vpair_f64_nfma_builtin
+#define vpair_f64_nfms __vpair_f64_nfms_builtin
+#define vpair_f64_splat__vpair_f64_splat_builtin
+#define vpair_f64_sqrt __vpair_f64_sqrt_builtin
+#define vpair_f64_sub  __vpair_f64_sub_builtin
+
+#define vpair_f32_abs  __vpair_f32_abs_builtin
+#define vpair_f32_add  __vpair_f32_add_builtin
+#define vpair_f32_div  __vpair_f32_div_builtin
+#define vpair_f32_fma  __vpair_f32_fma_builtin
+#define vpair_f32_fms  __vpair_f32_fms_builtin
+#define vpair_f32_max  __vpair_f32_max_builtin
+#define vpair_f32_min  __vpair_f32_min_builtin
+#define vpair_f32_mul  __vpair_f32_mul_builtin
+#define vpair_f32_nabs __vpair_f32_nabs_builtin
+#define vpair_f32_neg  __vpair_f32_neg_builtin
+#define vpair_f32_nfma __vpai

[gcc(refs/users/meissner/heads/work179-vpair)] Update ChangeLog.*

2024-09-30 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:3a75fc2e391239bb658a2e4ec14a61fbc46d590b

commit 3a75fc2e391239bb658a2e4ec14a61fbc46d590b
Author: Michael Meissner 
Date:   Mon Sep 30 13:29:46 2024 -0400

Update ChangeLog.*

Diff:
---
 gcc/ChangeLog.vpair | 152 +++-
 1 file changed, 151 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.vpair b/gcc/ChangeLog.vpair
index 7c411bb99148..020ed7b272b2 100644
--- a/gcc/ChangeLog.vpair
+++ b/gcc/ChangeLog.vpair
@@ -1,6 +1,156 @@
+ Branch work179-vpair, patch #300 
+
+Rewrite vector-pair.h.
+
+2024-09-30  Michael Meissner  
+
+gcc/
+
+   * config/rs6000/vector-pair.h: Rewrite.
+
+ Branch work179-vpair, patch #300 
+
+Add vector pair optimizations.
+
+2024-09-27  Michael Meissner  
+
+gcc/
+
+   * config/rs6000/vector-pair.md (vpair_add_neg_3): New
+   combiner insn to convert vector plus/neg into a minus operation.
+   (vpair_fma__merge): Optimize multiply, add/subtract, and
+   negation into fma operations if the user specifies to create fmas.
+   (vpair_fma__merge): Likewise.
+   (vpair_fma__merge2): Likewise.
+   (vpair_nfma__merge): Likewise.
+   (vpair_nfms__merge): Likewise.
+   (vpair_nfms__merge2): Likewise.
+
+gcc/testsuite/
+
+   * gcc.target/powerpc/vector-pair-7.c: New test.
+   * gcc.target/powerpc/vector-pair-8.c: Likewise.
+   * gcc.target/powerpc/vector-pair-9.c: Likewise.
+   * gcc.target/powerpc/vector-pair-10.c: Likewise.
+   * gcc.target/powerpc/vector-pair-11.c: Likewise.
+   * gcc.target/powerpc/vector-pair-12xs.c: Likewise.
+
+ Branch work179-vpair, patch #300 
+
+Add vector pair init and splat.
+
+2024-09-27  Michael Meissner  
+
+gcc/
+
+   * config/rs6000/rs6000-builtins.def (__builtin_vpair_zero): New
+   built-in function.
+   (__builtin_vpair_f32_splat): Likewise.
+   (__builtin_vpair_f64_splat): Likewise.
+   * config/rs6000/vector-pair.h: Update power10 splat patterns.
+   * config/rs6000/vector-pair.md (UNSPEC_VPAIR_ZERO): New unspec.
+   (UNSPEC_VPAIR_SPLAT): Likewise.
+   (VPAIR_SPLAT_VMODE): New mode iterator.
+   (VPAIR_SPLAT_ELEMENT_TO_VMODE): New mode attribute.
+   (vpair_splat_name): Likewise.
+   (vpair_zero): New insn.
+   (vpair_splat_): New define_expand.
+   (vpair_splat__internal): New insns.
+
+gcc/testsuite/
+
+   * gcc.target/powerpc/vector-pair-5.c: New test.
+   * gcc.target/powerpc/vector-pair-6.c: Likewise.
+
+ Branch work179-vpair, patch #300 
+
+Add support for vector pair fma operations.
+
+2024-09-27  Michael Meissner  
+
+gcc/
+
+   * config/rs6000/rs6000-builtins.def (__builtin_vpair_f32_fma): New
+   built-in.
+   (__builtin_vpair_f32_fms): Likewise.
+   (__builtin_vpair_f32_nfma): Likewise.
+   (__builtin_vpair_f32_nfms): Likewise.
+   (__builtin_vpair_f64_fma): Likewise.
+   (__builtin_vpair_f64_fms): Likewise.
+   (__builtin_vpair_f64_nfma): Likewise.
+   * config/rs6000/rs6000/rs6000-proto.h (enum vpair_split_fma): New
+   enumeration.
+   (vpair_split_fma): New declaration.
+   * config/rs6000/rs6000.cc (vpair_split_fma): New function to split
+   vector pair FMA operations.
+   * config/rs6000/vector-pair.md (UNSPEC_VPAIR_FMA): New unspec.
+   (vpair_stdname): Add UNSPEC_VPAIR_FMA.
+   (VPAIR_OP): Likewise.
+   (vpair_fma_4): New insns.
+   (vpair_fms_4): Likewise.
+   (vpair_nfma_4): Likewise.
+   (vpair_nfms_4): Likewise.
+   * doc/extend.texi (PowerPC Vector Pair Built-in Functions): Document new
+   vector pair fma built-in functions.
+
+gcc/testsuite/
+
+   * gcc.target/powerpc/vector-pair-3.c: New test.
+   * gcc.target/powerpc/vector-pair-4.c: Likewise.
+
+ Branch work179-vpair, patch #300 
+
+Add support for vector pair unary and binary operations.
+
+2024-09-27  Michael Meissner  
+
+gcc/
+
+   * config/rs6000/rs6000-builtins.def (__builtin_vpair_*): Add new
+   built-in functions for vector pair support.
+   * config/rs6000/rs6000-protos.h (enum vpair_split_unary): New
+   enumeration.
+   (vpair_split_unary): New declaration.
+   (vpair_split_binary): Likewise.
+   * config/rs6000/rs6000.cc (print_operand): Add 'S' output modifier.
+   (vpair_split_unary): New function to split vector pair operations.
+   (vpair_split_binary): Likewise.
+   * config/rs6000/rs6000.md (toplevel): Include vector-pair.md.
+   * config/rs6000/t-rs6000 (MD_INCLUDES): Add vector-pair.md.
+   * config/rs6000/vector-pair.md: New file.
+   * doc/extend.texi (PowerPC Vector Pair Built-in Functions): Add
+   documentation for the new vector pair built-in functions.
+
+gcc/testsuite/
+
+   * gcc.target/powerpc/vector

[gcc r13-9068] Zen5 tuning part 2: disable gather and scatter

2024-09-30 Thread Jan Hubicka via Gcc-cvs
https://gcc.gnu.org/g:456719b5c0705a6c2065fc261f41d0c2a30f3045

commit r13-9068-g456719b5c0705a6c2065fc261f41d0c2a30f3045
Author: Jan Hubicka 
Date:   Tue Sep 3 15:07:41 2024 +0200

Zen5 tuning part 2: disable gather and scatter

We disable gathers for zen4.  It seems that gather has improved a bit 
compared
to zen4 and Zen5 optimization manual suggests "Avoid GATHER instructions 
when
the indices are known ahead of time. Vector loads followed by shuffles 
result
in a higher load bandwidth." however the situation seems to be more
complicated.

gather is 5-10% loss on parest benchmark as well as 30% loss on sparse dot
products in TSVC. Curiously enough breaking these out into microbenchmark
reversed the situation and it turns out that the performance depends on
how indices are distributed.  gather is loss if indices are sequential,
neutral if they are random and win for some strides (4, 8).

This seems to be similar to earlier zens, so I think (especially for
backporting znver5 support) that it makes sense to be conistent and disable
gather unless we work out a good heuristics on when to use it. Since we
typically do not know the indices in advance, I don't see how that can be 
done.

I opened PR116582 with some examples of wins and loses

gcc/ChangeLog:

* config/i386/x86-tune.def (X86_TUNE_USE_GATHER_2PARTS): Disable for
ZNVER5.
(X86_TUNE_USE_SCATTER_2PARTS): Disable for ZNVER5.
(X86_TUNE_USE_GATHER_4PARTS): Disable for ZNVER5.
(X86_TUNE_USE_SCATTER_4PARTS): Disable for ZNVER5.
(X86_TUNE_USE_GATHER_8PARTS): Disable for ZNVER5.
(X86_TUNE_USE_SCATTER_8PARTS): Disable for ZNVER5.

(cherry picked from commit d82edbe92eed53a479736fcbbe6d54d0fb42daa4)

Diff:
---
 gcc/config/i386/x86-tune.def | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/gcc/config/i386/x86-tune.def b/gcc/config/i386/x86-tune.def
index 629e1fdf5f77..4231ca90b0ed 100644
--- a/gcc/config/i386/x86-tune.def
+++ b/gcc/config/i386/x86-tune.def
@@ -481,35 +481,35 @@ DEF_TUNE (X86_TUNE_AVOID_4BYTE_PREFIXES, 
"avoid_4byte_prefixes",
 /* X86_TUNE_USE_GATHER_2PARTS: Use gather instructions for vectors with 2
elements.  */
 DEF_TUNE (X86_TUNE_USE_GATHER_2PARTS, "use_gather_2parts",
- ~(m_ZNVER1 | m_ZNVER2 | m_ZNVER3 | m_ZNVER4 | m_ALDERLAKE
+ ~(m_ZNVER | m_ALDERLAKE
| m_CORE_ATOM | m_GENERIC | m_GDS))
 
 /* X86_TUNE_USE_SCATTER_2PARTS: Use scater instructions for vectors with 2
elements.  */
 DEF_TUNE (X86_TUNE_USE_SCATTER_2PARTS, "use_scatter_2parts",
- ~(m_ZNVER4))
+ ~(m_ZNVER4 | m_ZNVER5))
 
 /* X86_TUNE_USE_GATHER_4PARTS: Use gather instructions for vectors with 4
elements.  */
 DEF_TUNE (X86_TUNE_USE_GATHER_4PARTS, "use_gather_4parts",
- ~(m_ZNVER1 | m_ZNVER2 | m_ZNVER3 | m_ZNVER4 | m_ALDERLAKE
+ ~(m_ZNVER | m_ALDERLAKE
| m_CORE_ATOM | m_GENERIC | m_GDS))
 
 /* X86_TUNE_USE_SCATTER_4PARTS: Use scater instructions for vectors with 4
elements.  */
 DEF_TUNE (X86_TUNE_USE_SCATTER_4PARTS, "use_scatter_4parts",
- ~(m_ZNVER4))
+ ~(m_ZNVER4 | m_ZNVER5))
 
 /* X86_TUNE_USE_GATHER: Use gather instructions for vectors with 8 or more
elements.  */
 DEF_TUNE (X86_TUNE_USE_GATHER_8PARTS, "use_gather_8parts",
- ~(m_ZNVER1 | m_ZNVER2 | m_ZNVER4 | m_ALDERLAKE
+ ~(m_ZNVER1 | m_ZNVER2 | m_ZNVER4 | m_ZNVER5 | m_ALDERLAKE
| m_CORE_ATOM | m_GENERIC | m_GDS))
 
 /* X86_TUNE_USE_SCATTER: Use scater instructions for vectors with 8 or more
elements.  */
 DEF_TUNE (X86_TUNE_USE_SCATTER_8PARTS, "use_scatter_8parts",
- ~(m_ZNVER4))
+ ~(m_ZNVER4 | m_ZNVER5))
 
 /* X86_TUNE_AVOID_128FMA_CHAINS: Avoid creating loops with tight 128bit or
smaller FMA chain.  */


[gcc r15-3961] optabs: Make all `*dot_prod_optab's modeled as conversions

2024-09-30 Thread Victor Do Nascimento via Gcc-cvs
https://gcc.gnu.org/g:2f68d69e47b5b627c6bb71a6bb3d7b2e0e641b2f

commit r15-3961-g2f68d69e47b5b627c6bb71a6bb3d7b2e0e641b2f
Author: Victor Do Nascimento 
Date:   Tue May 21 11:17:45 2024 +0100

optabs: Make all `*dot_prod_optab's modeled as conversions

Given the specification in the GCC internals manual defines the
{u|s}dot_prod standard name as taking "two signed elements of the
same mode, adding them to a third operand of wider mode", there is
currently ambiguity in the relationship between the mode of the first
two arguments and that of the third.

This vagueness means that, in theory, different modes may be
supportable in the third argument.  This flexibility would allow for a
given backend to add to the accumulator a different number of
vectorized products, e.g. A backend may provide instructions for both:

  accum += a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]

and

  accum += a[0] * b[0] + a[1] * b[1],

as is now seen in the SVE2.1 extension to AArch64.  In spite of the
aforementioned flexibility, modeling the dot-product operation as a
direct optab means that we have no way to encode both input and the
accumulator data modes into the backend pattern name, which prevents
us from harnessing this flexibility.

We therefore make all dot_prod optabs conversions, allowing, for
example, for the encoding of both 2-way and 4-way dot product backend
patterns.

gcc/ChangeLog:

* optabs.def (sdot_prod_optab): Convert from OPTAB_D to
OPTAB_CD.
(udot_prod_optab): Likewise.
(usdot_prod_optab): Likewise.
* doc/md.texi (Standard Names): update entries for u,s and us
dot_prod names.

Diff:
---
 gcc/doc/md.texi | 46 ++
 gcc/optabs.def  |  6 +++---
 2 files changed, 25 insertions(+), 27 deletions(-)

diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi
index a92591122517..7001dafdc9e1 100644
--- a/gcc/doc/md.texi
+++ b/gcc/doc/md.texi
@@ -5760,15 +5760,14 @@ for (i = 0; i < LEN + BIAS; i++)
 operand0 += operand2[i];
 @end smallexample
 
-@cindex @code{sdot_prod@var{m}} instruction pattern
-@item @samp{sdot_prod@var{m}}
-
-Compute the sum of the products of two signed elements.
-Operand 1 and operand 2 are of the same mode. Their
-product, which is of a wider mode, is computed and added to operand 3.
-Operand 3 is of a mode equal or wider than the mode of the product. The
-result is placed in operand 0, which is of the same mode as operand 3.
-@var{m} is the mode of operand 1 and operand 2.
+@cindex @code{sdot_prod@var{m}@var{n}} instruction pattern
+@item @samp{sdot_prod@var{m}@var{n}}
+
+Multiply operand 1 by operand 2 without loss of precision, given that
+both operands contain signed elements.  Add each product to the overlapping
+element of operand 3 and store the result in operand 0.  Operands 0 and 3
+have mode @var{m} and operands 1 and 2 have mode @var{n}, with @var{n}
+having narrower elements than @var{m}.
 
 Semantically the expressions perform the multiplication in the following signs
 
@@ -5778,15 +5777,14 @@ sdot ==
 @dots{}
 @end smallexample
 
-@cindex @code{udot_prod@var{m}} instruction pattern
-@item @samp{udot_prod@var{m}}
+@cindex @code{udot_prod@var{m}@var{n}} instruction pattern
+@item @samp{udot_prod@var{m}@var{n}}
 
-Compute the sum of the products of two unsigned elements.
-Operand 1 and operand 2 are of the same mode. Their
-product, which is of a wider mode, is computed and added to operand 3.
-Operand 3 is of a mode equal or wider than the mode of the product. The
-result is placed in operand 0, which is of the same mode as operand 3.
-@var{m} is the mode of operand 1 and operand 2.
+Multiply operand 1 by operand 2 without loss of precision, given that
+both operands contain unsigned elements.  Add each product to the overlapping
+element of operand 3 and store the result in operand 0.  Operands 0 and 3
+have mode @var{m} and operands 1 and 2 have mode @var{n}, with @var{n}
+having narrower elements than @var{m}.
 
 Semantically the expressions perform the multiplication in the following signs
 
@@ -5796,14 +5794,14 @@ udot ==
 @dots{}
 @end smallexample
 
-@cindex @code{usdot_prod@var{m}} instruction pattern
-@item @samp{usdot_prod@var{m}}
+@cindex @code{usdot_prod@var{m}@var{n}} instruction pattern
+@item @samp{usdot_prod@var{m}@var{n}}
 Compute the sum of the products of elements of different signs.
-Operand 1 must be unsigned and operand 2 signed. Their
-product, which is of a wider mode, is computed and added to operand 3.
-Operand 3 is of a mode equal or wider than the mode of the product. The
-result is placed in operand 0, which is of the same mode as operand 3.
-@var{m} is the mode of operand 1 and operand 2.
+Multiply operand 1 by operand 2 without loss of precision, given that operand 1
+is unsigned and operand 2 is signed.  Add each pro

[gcc r12-10736] Zen5 tuning part 1: avoid FMA chains

2024-09-30 Thread Jan Hubicka via Gcc-cvs
https://gcc.gnu.org/g:be6334fffdf2a7df3b7f92ea933b804664dfc383

commit r12-10736-gbe6334fffdf2a7df3b7f92ea933b804664dfc383
Author: Jan Hubicka 
Date:   Tue Sep 3 13:38:33 2024 +0200

Zen5 tuning part 1: avoid FMA chains

testing matrix multiplication benchmarks shows that FMA on a critical chain
is a perofrmance loss over separate multiply and add. While the latency of 4
is lower than multiply + add (3+2) the problem is that all values needs to
be ready before computation starts.

While on znver4 AVX512 code fared well with FMA, it was because of the split
registers. Znver5 benefits from avoding FMA on all widths.  This may be 
different
with the mobile version though.

On naive matrix multiplication benchmark the difference is 8% with -O3
only since with -Ofast loop interchange solves the problem differently.
It is 30% win, for example, on S323 from TSVC:

real_t s323(struct args_t * func_args)
{

//recurrences
//coupled recurrence

initialise_arrays(__func__);
gettimeofday(&func_args->t1, NULL);

for (int nl = 0; nl < iterations/2; nl++) {
for (int i = 1; i < LEN_1D; i++) {
a[i] = b[i-1] + c[i] * d[i];
b[i] = a[i] + c[i] * e[i];
}
dummy(a, b, c, d, e, aa, bb, cc, 0.);
}

gettimeofday(&func_args->t2, NULL);
return calc_checksum(__func__);
}

gcc/ChangeLog:

* config/i386/x86-tune.def (X86_TUNE_AVOID_128FMA_CHAINS): Enable 
for
znver5.
(X86_TUNE_AVOID_256FMA_CHAINS): Likewise.
(X86_TUNE_AVOID_512FMA_CHAINS): Likewise.

(cherry picked from commit d6360b4083695970789fd65b9c515c11a5ce25b4)

Diff:
---
 gcc/config/i386/x86-tune.def | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/config/i386/x86-tune.def b/gcc/config/i386/x86-tune.def
index f5bf331242aa..249a239de775 100644
--- a/gcc/config/i386/x86-tune.def
+++ b/gcc/config/i386/x86-tune.def
@@ -499,16 +499,16 @@ DEF_TUNE (X86_TUNE_USE_SCATTER_8PARTS, 
"use_scatter_8parts",
 
 /* X86_TUNE_AVOID_128FMA_CHAINS: Avoid creating loops with tight 128bit or
smaller FMA chain.  */
-DEF_TUNE (X86_TUNE_AVOID_128FMA_CHAINS, "avoid_fma_chains", m_ZNVER1 | 
m_ZNVER2 | m_ZNVER3)
+DEF_TUNE (X86_TUNE_AVOID_128FMA_CHAINS, "avoid_fma_chains", m_ZNVER)
 
 /* X86_TUNE_AVOID_256FMA_CHAINS: Avoid creating loops with tight 256bit or
smaller FMA chain.  */
 DEF_TUNE (X86_TUNE_AVOID_256FMA_CHAINS, "avoid_fma256_chains", m_ZNVER2 | 
m_ZNVER3
- | m_ALDERLAKE | m_SAPPHIRERAPIDS | m_GENERIC | m_ZNVER4)
+ | m_ALDERLAKE | m_SAPPHIRERAPIDS | m_GENERIC | m_ZNVER4 | m_ZNVER5)
 
 /* X86_TUNE_AVOID_512FMA_CHAINS: Avoid creating loops with tight 512bit or
smaller FMA chain.  */
-DEF_TUNE (X86_TUNE_AVOID_512FMA_CHAINS, "avoid_fma512_chains", m_NONE)
+DEF_TUNE (X86_TUNE_AVOID_512FMA_CHAINS, "avoid_fma512_chains", m_ZNVER5)
 
 /* X86_TUNE_V2DF_REDUCTION_PREFER_PHADDPD: Prefer haddpd
for v2df vector reduction.  */


[gcc r15-3962] autovectorizer: Add basic support for convert optabs

2024-09-30 Thread Victor Do Nascimento via Gcc-cvs
https://gcc.gnu.org/g:c7fba0e96641e57164fc72bdbffd9a1cea244818

commit r15-3962-gc7fba0e96641e57164fc72bdbffd9a1cea244818
Author: Victor Do Nascimento 
Date:   Wed May 22 10:06:57 2024 +0100

autovectorizer: Add basic support for convert optabs

Given the shift from modeling dot products as direct optabs to
treating them as conversion optabs, we make necessary changes to the
autovectorizer code to ensure that given the relevant tree code,
together with the input and output data modes, we can retrieve the
relevant optab and subsequently the insn_code for it.

gcc/ChangeLog:

* gimple-match-exports.cc (directly_supported_p): Add overload
for conversion-type optabs.
* gimple-match.h (directly_supported_p): Add new function
prototype.
* optabs.cc (expand_widen_pattern_expr): Make the
DOT_PROD_EXPR tree code use `find_widening_optab_handler' to
retrieve icode.
* tree-vect-loop.cc (vect_is_emulated_mixed_dot_prod): make it
call conversion-type overloaded `directly_supported_p'.
* tree-vect-patterns.cc (vect_supportable_conv_optab_p): New.
(vect_recog_dot_prod_pattern): s/direct/conv/ in call to
`vect_supportable_direct_optab_p'.

Diff:
---
 gcc/gimple-match-exports.cc | 23 +++
 gcc/gimple-match.h  |  2 ++
 gcc/optabs.cc   |  3 ++-
 gcc/tree-vect-loop.cc   |  1 +
 gcc/tree-vect-patterns.cc   | 33 +++--
 5 files changed, 59 insertions(+), 3 deletions(-)

diff --git a/gcc/gimple-match-exports.cc b/gcc/gimple-match-exports.cc
index 86e40100899a..d3e626a1a245 100644
--- a/gcc/gimple-match-exports.cc
+++ b/gcc/gimple-match-exports.cc
@@ -1401,6 +1401,29 @@ directly_supported_p (code_helper code, tree type, 
optab_subtype query_type)
  && direct_internal_fn_supported_p (ifn, type, OPTIMIZE_FOR_SPEED));
 }
 
+/* As above, overloading the function for conversion-type optabs.  */
+bool
+directly_supported_p (code_helper code, tree otype, tree itype,
+ optab_subtype query_type)
+{
+  if (code.is_tree_code ())
+{
+  convert_optab optab = optab_for_tree_code (tree_code (code), itype,
+   query_type);
+  return (optab != unknown_optab
+ && convert_optab_handler (optab, TYPE_MODE (otype),
+   TYPE_MODE (itype)) != CODE_FOR_nothing);
+}
+  gcc_assert (query_type == optab_default
+ || (query_type == optab_vector && VECTOR_TYPE_P (itype))
+ || (query_type == optab_scalar && !VECTOR_TYPE_P (itype)));
+  internal_fn ifn = associated_internal_fn (combined_fn (code), itype);
+  return (direct_internal_fn_p (ifn)
+ && direct_internal_fn_supported_p (ifn, tree_pair (otype, itype),
+OPTIMIZE_FOR_SPEED));
+}
+
+
 /* A wrapper around the internal-fn.cc versions of get_conditional_internal_fn
for a code_helper CODE operating on type TYPE.  */
 
diff --git a/gcc/gimple-match.h b/gcc/gimple-match.h
index 8edff578ba9a..645810076d15 100644
--- a/gcc/gimple-match.h
+++ b/gcc/gimple-match.h
@@ -421,6 +421,8 @@ code_helper canonicalize_code (code_helper, tree);
 
 #ifdef GCC_OPTABS_TREE_H
 bool directly_supported_p (code_helper, tree, optab_subtype = optab_default);
+bool directly_supported_p (code_helper, tree, tree,
+  optab_subtype = optab_default);
 #endif
 
 internal_fn get_conditional_internal_fn (code_helper, tree);
diff --git a/gcc/optabs.cc b/gcc/optabs.cc
index 2bcb3f7b47ae..0e651e9e5140 100644
--- a/gcc/optabs.cc
+++ b/gcc/optabs.cc
@@ -317,7 +317,8 @@ expand_widen_pattern_expr (const_sepops ops, rtx op0, rtx 
op1, rtx wide_op,
 widen_pattern_optab
   = optab_for_tree_code (ops->code, TREE_TYPE (oprnd0), optab_default);
   if (ops->code == WIDEN_MULT_PLUS_EXPR
-  || ops->code == WIDEN_MULT_MINUS_EXPR)
+  || ops->code == WIDEN_MULT_MINUS_EXPR
+  || ops->code == DOT_PROD_EXPR)
 icode = find_widening_optab_handler (widen_pattern_optab,
 TYPE_MODE (TREE_TYPE (ops->op2)),
 tmode0);
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 0ce1bf8ebbac..a5a44613cb24 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -5244,6 +5244,7 @@ vect_is_emulated_mixed_dot_prod (stmt_vec_info stmt_info)
 
   gcc_assert (STMT_VINFO_REDUC_VECTYPE_IN (stmt_info));
   return !directly_supported_p (DOT_PROD_EXPR,
+   STMT_VINFO_VECTYPE (stmt_info),
STMT_VINFO_REDUC_VECTYPE_IN (stmt_info),
optab_vector_mixed_sign);
 }
diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index b174ff1e705c..9bf8526ac995 100644
--- a/gcc/tree-vect-patterns.cc
+++ 

[gcc r15-3964] arm: Fix arm backend-use of (u|s|us)dot_prod patterns

2024-09-30 Thread Victor Do Nascimento via Gcc-cvs
https://gcc.gnu.org/g:bfa44e604d63ebb90dd2ef645820c4db44cdfd7c

commit r15-3964-gbfa44e604d63ebb90dd2ef645820c4db44cdfd7c
Author: Victor Do Nascimento 
Date:   Wed Jun 5 11:11:06 2024 +0100

arm: Fix arm backend-use of (u|s|us)dot_prod patterns

Given recent changes to the dot_prod standard pattern name, this patch
fixes the arm back-end by implementing the following changes:

1. Add 2nd mode to all patterns relating to the dot-product in .md
files.
2. redirect the single-mode CODE_FOR_neon_(u|s|us)dot values
generated from `arm_neon_builtins.def' to their new 2-mode
equivalents via means of simple aliases, as per the following example:

  constexpr insn_code CODE_FOR_neon_sdotv8qi
= CODE_FOR_neon_sdotv2siv8qi;

gcc/ChangeLog:

* config/arm/neon.md (dot_prod): Renamed to...
(dot_prod): ...this.
(neon_dot): Renamed to...
(neon_dot): ...this.
(neon_usdot): Renamed to...
(neon_usdot): ...this.
(usdot_prod): Renamed to...
(usdot_prod): ...this.
* config/arm/arm-builtins.cc
(CODE_FOR_neon_sdotv8qi): Definie as alias to
new CODE_FOR_neon_sdotv2siv8qi.
(CODE_FOR_neon_udotv8qi): Definie as alias to
new CODE_FOR_neon_udotv2siv8qi.
(CODE_FOR_neon_usdotv8qi): Definie as alias to
new CODE_FOR_neon_usdotv2siv8qi.
(CODE_FOR_neon_sdotv16qi): Definie as alias to
new CODE_FOR_neon_sdotv4siv16qi.
(CODE_FOR_neon_udotv16qi): Definie as alias to
new CODE_FOR_neon_udotv4siv16qi.
(CODE_FOR_neon_usdotv16qi): Definie as alias to
new CODE_FOR_neon_usdotv4siv16qi.

Diff:
---
 gcc/config/arm/arm-builtins.cc | 7 +++
 gcc/config/arm/neon.md | 8 
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/gcc/config/arm/arm-builtins.cc b/gcc/config/arm/arm-builtins.cc
index c9d50bf8fbb1..74cea8900b48 100644
--- a/gcc/config/arm/arm-builtins.cc
+++ b/gcc/config/arm/arm-builtins.cc
@@ -908,6 +908,13 @@ typedef struct {
   enum arm_type_qualifiers *qualifiers;
 } arm_builtin_datum;
 
+constexpr insn_code CODE_FOR_neon_sdotv8qi = CODE_FOR_neon_sdotv2siv8qi;
+constexpr insn_code CODE_FOR_neon_udotv8qi = CODE_FOR_neon_udotv2siv8qi;
+constexpr insn_code CODE_FOR_neon_usdotv8qi = CODE_FOR_neon_usdotv2siv8qi;
+constexpr insn_code CODE_FOR_neon_sdotv16qi = CODE_FOR_neon_sdotv4siv16qi;
+constexpr insn_code CODE_FOR_neon_udotv16qi = CODE_FOR_neon_udotv4siv16qi;
+constexpr insn_code CODE_FOR_neon_usdotv16qi = CODE_FOR_neon_usdotv4siv16qi;
+
 #define CF(N,X) CODE_FOR_neon_##N##X
 
 #define VAR1(T, N, A) \
diff --git a/gcc/config/arm/neon.md b/gcc/config/arm/neon.md
index fa4a7aeda357..6892b7b0f44a 100644
--- a/gcc/config/arm/neon.md
+++ b/gcc/config/arm/neon.md
@@ -2989,7 +2989,7 @@
 ;; ...
 ;;
 ;; and so the vectorizer provides r, in which the result has to be accumulated.
-(define_insn "dot_prod"
+(define_insn "dot_prod"
   [(set (match_operand:VCVTI 0 "register_operand" "=w")
(plus:VCVTI
  (unspec:VCVTI [(match_operand: 1 "register_operand" "w")
@@ -3002,7 +3002,7 @@
 )
 
 ;; These instructions map to the __builtins for the Dot Product operations
-(define_expand "neon_dot"
+(define_expand "neon_dot"
   [(set (match_operand:VCVTI 0 "register_operand" "=w")
(plus:VCVTI
  (unspec:VCVTI [(match_operand: 2 "register_operand")
@@ -3013,7 +3013,7 @@
 )
 
 ;; These instructions map to the __builtins for the Dot Product operations.
-(define_insn "neon_usdot"
+(define_insn "neon_usdot"
   [(set (match_operand:VCVTI 0 "register_operand" "=w")
(plus:VCVTI
  (unspec:VCVTI
@@ -3112,7 +3112,7 @@
 )
 
 ;; Auto-vectorizer pattern for usdot
-(define_expand "usdot_prod"
+(define_expand "usdot_prod"
   [(set (match_operand:VCVTI 0 "register_operand")
(plus:VCVTI (unspec:VCVTI [(match_operand: 1
"register_operand")


[gcc r15-3965] i386: Fix dot_prod backend patterns for mmx and sse targets

2024-09-30 Thread Victor Do Nascimento via Gcc-cvs
https://gcc.gnu.org/g:c45ef5ee8da4de239bf7f5b66a45f7e6e797f954

commit r15-3965-gc45ef5ee8da4de239bf7f5b66a45f7e6e797f954
Author: Victor Do Nascimento 
Date:   Tue Jun 4 17:11:07 2024 +0100

i386: Fix dot_prod backend patterns for mmx and sse targets

Following the migration of the dot_prod optab from a direct to a
conversion-type optab, ensure all back-end patterns incorporate the
second machine mode into pattern names.

gcc/ChangeLog:

* config/i386/mmx.md (usdot_prodv8qi): Renamed to...
(usdot_prodv2siv8qi): ...this.
(sdot_prodv8qi): Renamed to...
(sdot_prodv2siv8qi): ...this.
(udot_prodv8qi): Renamed to...
(udot_prodv2siv8qi): ...this.
(usdot_prodv4hi): Renamed to...
(usdot_prodv2siv4hi): ...this.
(udot_prodv4hi): Renamed to...
(udot_prodv2siv4hi): ...this.
(sdot_prodv4hi): Renamed to...
(sdot_prodv2siv4hi): ...this.
* config/i386/sse.md (sdot_prod): Renamed to...
(sdot_prod): ...this.
(sdot_prodv4si): Renamed to...
(sdot_prodv2div4si): ...this.
(usdot_prod): Renamed to...
(usdot_prod): ...this.
(sdot_prod): Renamed to...
(sdot_prod): ...this.
(sdot_prodv64qi): Renamed to...
(sdot_prodv16siv64qi): ...this.
(udot_prod): Renamed to...
(udot_prod): ...this.
(udot_prodv64qi): Renamed to...
(udot_prodv16qiv64qi): ...this.
(usdot_prod): Renamed to...
(usdot_prod): ...this.
(udot_prod): Renamed to...
(udot_prod): ...this.

Diff:
---
 gcc/config/i386/mmx.md | 30 +++---
 gcc/config/i386/sse.md | 41 ++---
 2 files changed, 37 insertions(+), 34 deletions(-)

diff --git a/gcc/config/i386/mmx.md b/gcc/config/i386/mmx.md
index ca768b95df79..9d2a82c598e5 100644
--- a/gcc/config/i386/mmx.md
+++ b/gcc/config/i386/mmx.md
@@ -6504,7 +6504,7 @@
   DONE;
 })
 
-(define_expand "usdot_prodv8qi"
+(define_expand "usdot_prodv2siv8qi"
   [(match_operand:V2SI 0 "register_operand")
(match_operand:V8QI 1 "register_operand")
(match_operand:V8QI 2 "register_operand")
@@ -6523,7 +6523,7 @@
   rtx op3 = lowpart_subreg (V4SImode, operands[3], V2SImode);
   rtx op0 = gen_reg_rtx (V4SImode);
 
-  emit_insn (gen_usdot_prodv16qi (op0, op1, op2, op3));
+  emit_insn (gen_usdot_prodv4siv16qi (op0, op1, op2, op3));
   emit_move_insn (operands[0], lowpart_subreg (V2SImode, op0, V4SImode));
  }
else
@@ -6537,7 +6537,7 @@
   emit_move_insn (op3, CONST0_RTX (V4SImode));
   emit_insn (gen_zero_extendv8qiv8hi2 (op1, operands[1]));
   emit_insn (gen_extendv8qiv8hi2 (op2, operands[2]));
-  emit_insn (gen_sdot_prodv8hi (op0, op1, op2, op3));
+  emit_insn (gen_sdot_prodv4siv8hi (op0, op1, op2, op3));
 
   /* vec_perm (op0, 2, 3, 0, 1);  */
   emit_insn (gen_sse2_pshufd (op0_1, op0, GEN_INT (78)));
@@ -6548,7 +6548,7 @@
 DONE;
 })
 
-(define_expand "sdot_prodv8qi"
+(define_expand "sdot_prodv2siv8qi"
   [(match_operand:V2SI 0 "register_operand")
(match_operand:V8QI 1 "register_operand")
(match_operand:V8QI 2 "register_operand")
@@ -6566,7 +6566,7 @@
   rtx op3 = lowpart_subreg (V4SImode, operands[3], V2SImode);
   rtx op0 = gen_reg_rtx (V4SImode);
 
-  emit_insn (gen_sdot_prodv16qi (op0, op1, op2, op3));
+  emit_insn (gen_sdot_prodv4siv16qi (op0, op1, op2, op3));
   emit_move_insn (operands[0], lowpart_subreg (V2SImode, op0, V4SImode));
 }
   else
@@ -6580,7 +6580,7 @@
   emit_move_insn (op3, CONST0_RTX (V4SImode));
   emit_insn (gen_extendv8qiv8hi2 (op1, operands[1]));
   emit_insn (gen_extendv8qiv8hi2 (op2, operands[2]));
-  emit_insn (gen_sdot_prodv8hi (op0, op1, op2, op3));
+  emit_insn (gen_sdot_prodv4siv8hi (op0, op1, op2, op3));
 
   /* vec_perm (op0, 2, 3, 0, 1);  */
   emit_insn (gen_sse2_pshufd (op0_1, op0, GEN_INT (78)));
@@ -6592,7 +6592,7 @@
 
 })
 
-(define_expand "udot_prodv8qi"
+(define_expand "udot_prodv2siv8qi"
   [(match_operand:V2SI 0 "register_operand")
(match_operand:V8QI 1 "register_operand")
(match_operand:V8QI 2 "register_operand")
@@ -6610,7 +6610,7 @@
   rtx op3 = lowpart_subreg (V4SImode, operands[3], V2SImode);
   rtx op0 = gen_reg_rtx (V4SImode);
 
-  emit_insn (gen_udot_prodv16qi (op0, op1, op2, op3));
+  emit_insn (gen_udot_prodv4siv16qi (op0, op1, op2, op3));
   emit_move_insn (operands[0], lowpart_subreg (V2SImode, op0, V4SImode));
 }
   else
@@ -6624,7 +6624,7 @@
   emit_move_insn (op3, CONST0_RTX (V4SImode));
   emit_insn (gen_zero_extendv8qiv8hi2 (op1, operands[1]));
   emit_insn (gen_zero_extendv8qiv8hi2 (op2, operands[2]));
-  emit_insn (gen_sdot_prodv8hi (op0, op1, op2, op3));
+  emit_insn (gen_sd

[gcc r15-3966] arc: Adjust dot-product backend patterns

2024-09-30 Thread Victor Do Nascimento via Gcc-cvs
https://gcc.gnu.org/g:85a2ed05483ceb17bc33bd6e02d7e452fcaa02e1

commit r15-3966-g85a2ed05483ceb17bc33bd6e02d7e452fcaa02e1
Author: Victor Do Nascimento 
Date:   Wed Jun 5 10:35:50 2024 +0100

arc: Adjust dot-product backend patterns

Following the migration of the dot_prod optab from a direct to a
conversion-type optab, ensure all back-end patterns incorporate the
second machine mode into pattern names.

gcc/ChangeLog:

* config/arc/simdext.md (sdot_prodv2hi): Renamed to...
(sdot_prodsiv2hi): ...this.
(udot_prodv2hi): Renamed to...
(udot_prodsiv2hi): ...this.
(sdot_prodv4hi): Renamed to...
(sdot_prodv2siv4hi): ...this.
(udot_prodv4hi): Renamed to...
(udot_prodv2siv4hi): ...this.

Diff:
---
 gcc/config/arc/simdext.md | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/config/arc/simdext.md b/gcc/config/arc/simdext.md
index 4e51a237c3ae..0696f0abb700 100644
--- a/gcc/config/arc/simdext.md
+++ b/gcc/config/arc/simdext.md
@@ -1643,7 +1643,7 @@
 
 ;; We can use dmac as well here.  To be investigated which version
 ;; brings more.
-(define_expand "sdot_prodv2hi"
+(define_expand "sdot_prodsiv2hi"
   [(match_operand:SI 0 "register_operand" "")
(match_operand:V2HI 1 "register_operand" "")
(match_operand:V2HI 2 "register_operand" "")
@@ -1656,7 +1656,7 @@
  DONE;
 })
 
-(define_expand "udot_prodv2hi"
+(define_expand "udot_prodsiv2hi"
   [(match_operand:SI 0 "register_operand" "")
(match_operand:V2HI 1 "register_operand" "")
(match_operand:V2HI 2 "register_operand" "")
@@ -1669,7 +1669,7 @@
  DONE;
 })
 
-(define_expand "sdot_prodv4hi"
+(define_expand "sdot_prodv2siv4hi"
   [(match_operand:V2SI 0 "register_operand" "")
(match_operand:V4HI 1 "register_operand" "")
(match_operand:V4HI 2 "register_operand" "")
@@ -1688,7 +1688,7 @@
  DONE;
 })
 
-(define_expand "udot_prodv4hi"
+(define_expand "udot_prodv2siv4hi"
   [(match_operand:V2SI 0 "register_operand" "")
(match_operand:V4HI 1 "register_operand" "")
(match_operand:V4HI 2 "register_operand" "")


[gcc r15-3963] aarch64: Fix aarch64 backend-use of (u|s|us)dot_prod patterns

2024-09-30 Thread Victor Do Nascimento via Gcc-cvs
https://gcc.gnu.org/g:0d0be1d10db2a1877804feb3b9f58f8461835815

commit r15-3963-g0d0be1d10db2a1877804feb3b9f58f8461835815
Author: Victor Do Nascimento 
Date:   Tue May 21 17:13:03 2024 +0100

aarch64: Fix aarch64 backend-use of (u|s|us)dot_prod patterns

Given recent changes to the dot_prod standard pattern name, this patch
fixes the aarch64 back-end by implementing the following changes:

1. Add 2nd mode to all (u|s|us)dot_prod patterns in .md files.
2. Rewrite initialization and function expansion mechanism for simd
builtins.
3. Fix all direct calls to back-end `dot_prod' patterns in SVE
builtins.

Finally, given that it is now possible for the compiler to
differentiate between the two- and four-way dot product, we add a test
to ensure that autovectorization picks up on dot-product patterns
where the result is twice the width of the operands.

gcc/ChangeLog:

* config/aarch64/aarch64-simd.md
(dot_prod): Renamed to...
(dot_prod): ...this.
(usdot_prod): Renamed to...
(usdot_prod): ...this.
(sadv16qi): Adjust call to gen_udot_prod take second mode.
(popcount): fix use of `udot_prod_optab'.
* config/aarch64/aarch64-sve.md
(dot_prod): Renamed to...
(dot_prod): ...this.
(@dot_prod): Renamed to...
(@dot_prod): ...this.
(sad): Adjust call to gen_udot_prod take second mode.
* config/aarch64/aarch64-sve2.md
(@aarch64_sve_dotvnx4sivnx8hi): Renamed to...
(dot_prodvnx4sivnx8hi): ...this.
* config/aarch64/aarch64-simd-builtins.def: Modify macro
expansion-based initialization and expansion
of (u|s|us)dot_prod builtins.
* config/aarch64/aarch64-builtins.cc
(CODE_FOR_aarch64_sdot_prodv8qi): Define as alias to
new CODE_FOR_sdot_prodv2siv8qi.
(CODE_FOR_aarch64_udot_prodv8qi): Define as alias to
new CODE_FOR_udot_prodv2siv8qi.
(CODE_FOR_aarch64_usdot_prodv8qi): Define as alias to
new CODE_FOR_usdot_prodv2siv8qi.
(CODE_FOR_aarch64_sdot_prodv16qi): Define as alias to
new CODE_FOR_sdot_prodv4siv16qi.
(CODE_FOR_aarch64_udot_prodv16qi): Define as alias to
new CODE_FOR_udot_prodv4siv16qi.
(CODE_FOR_aarch64_usdot_prodv16qi): Define as alias to
new CODE_FOR_usdot_prodv4siv16qi.
* config/aarch64/aarch64-sve-builtins-base.cc
(svdot_impl::expand): s/direct/convert/ in
`convert_optab_handler_for_sign' function call.
(svusdot_impl::expand): add second mode argument in call to
`code_for_dot_prod'.
* config/aarch64/aarch64-sve-builtins.cc
(function_expander::convert_optab_handler_for_sign): New class
method.
* config/aarch64/aarch64-sve-builtins.h
(class function_expander): Add prototype for new
`convert_optab_handler_for_sign' method.

gcc/testsuite/ChangeLog:
* gcc.target/aarch64/sme/vect-dotprod-twoway.c (udot2): New.

Diff:
---
 gcc/config/aarch64/aarch64-builtins.cc | 13 +++
 gcc/config/aarch64/aarch64-simd-builtins.def   |  6 ++---
 gcc/config/aarch64/aarch64-simd.md | 10 +
 gcc/config/aarch64/aarch64-sve-builtins-base.cc| 13 ++-
 gcc/config/aarch64/aarch64-sve-builtins.cc | 15 +
 gcc/config/aarch64/aarch64-sve-builtins.h  |  2 ++
 gcc/config/aarch64/aarch64-sve.md  |  7 +++---
 gcc/config/aarch64/aarch64-sve2.md |  2 +-
 .../gcc.target/aarch64/sme/vect-dotprod-twoway.c   | 26 ++
 9 files changed, 77 insertions(+), 17 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-builtins.cc 
b/gcc/config/aarch64/aarch64-builtins.cc
index 6266bea3b39c..38b860c176a4 100644
--- a/gcc/config/aarch64/aarch64-builtins.cc
+++ b/gcc/config/aarch64/aarch64-builtins.cc
@@ -458,6 +458,19 @@ 
aarch64_types_storestruct_lane_p_qualifiers[SIMD_MAX_BUILTIN_ARGS]
   qualifier_poly, qualifier_struct_load_store_lane_index };
 #define TYPES_STORESTRUCT_LANE_P (aarch64_types_storestruct_lane_p_qualifiers)
 
+constexpr insn_code CODE_FOR_aarch64_sdot_prodv8qi
+  = CODE_FOR_sdot_prodv2siv8qi;
+constexpr insn_code CODE_FOR_aarch64_udot_prodv8qi
+  = CODE_FOR_udot_prodv2siv8qi;
+constexpr insn_code CODE_FOR_aarch64_usdot_prodv8qi
+  = CODE_FOR_usdot_prodv2siv8qi;
+constexpr insn_code CODE_FOR_aarch64_sdot_prodv16qi
+  = CODE_FOR_sdot_prodv4siv16qi;
+constexpr insn_code CODE_FOR_aarch64_udot_prodv16qi
+  = CODE_FOR_udot_prodv4siv16qi;
+constexpr insn_code CODE_FOR_aarch64_usdot_prodv16qi
+  = CODE_FOR_usdot_prodv4siv16qi;
+
 #define CF0(N, X) CODE_FOR_aarch64_##N##X
 #define CF1(N, X) CODE_FOR_##N##X##1
 #define CF2(N, X) CODE_F

[gcc r15-3967] mips: Adjust dot-product backend patterns

2024-09-30 Thread Victor Do Nascimento via Gcc-cvs
https://gcc.gnu.org/g:d33786b1628f5bcfc5120f8f5390e1042e36618c

commit r15-3967-gd33786b1628f5bcfc5120f8f5390e1042e36618c
Author: Victor Do Nascimento 
Date:   Wed Jun 5 10:45:32 2024 +0100

mips:  Adjust dot-product backend patterns

Following the migration of the dot_prod optab from a direct to a
conversion-type optab, ensure all back-end patterns incorporate the
second machine mode into pattern names.

gcc/ChangeLog:

* config/mips/loongson-mmi.md (sdot_prodv4hi): Renamed to...
(sdot_prodv2siv4hi): ...this.

Diff:
---
 gcc/config/mips/loongson-mmi.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/mips/loongson-mmi.md b/gcc/config/mips/loongson-mmi.md
index dd166bfa4c96..4d9587301390 100644
--- a/gcc/config/mips/loongson-mmi.md
+++ b/gcc/config/mips/loongson-mmi.md
@@ -394,7 +394,7 @@
   "pmaddhw\t%0,%1,%2"
   [(set_attr "type" "fmul")])
 
-(define_expand "sdot_prodv4hi"
+(define_expand "sdot_prodv2siv4hi"
   [(match_operand:V2SI 0 "register_operand" "")
(match_operand:V4HI 1 "register_operand" "")
(match_operand:V4HI 2 "register_operand" "")


[gcc r15-3969] c6x: Adjust dot-product backend patterns

2024-09-30 Thread Victor Do Nascimento via Gcc-cvs
https://gcc.gnu.org/g:fd35d99914051c9c58b91b167f4802c8db460038

commit r15-3969-gfd35d99914051c9c58b91b167f4802c8db460038
Author: Victor Do Nascimento 
Date:   Wed Jun 5 10:55:06 2024 +0100

c6x:  Adjust dot-product backend patterns

Following the migration of the dot_prod optab from a direct to a
conversion-type optab, ensure all back-end patterns incorporate the
second machine mode into pattern names.

gcc/ChangeLog:

* config/c6x/c6x.md (sdot_prodv2hi): Renamed to...
(sdot_prodsiv2hi): ...this.

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

diff --git a/gcc/config/c6x/c6x.md b/gcc/config/c6x/c6x.md
index 5964dd69d0d0..ea9ffe8b4e10 100644
--- a/gcc/config/c6x/c6x.md
+++ b/gcc/config/c6x/c6x.md
@@ -3082,7 +3082,7 @@
 ;; Widening vector multiply and dot product.
 ;; See c6x-mult.md.in for the define_insn patterns
 
-(define_expand "sdot_prodv2hi"
+(define_expand "sdot_prodsiv2hi"
   [(match_operand:SI 0 "register_operand" "")
(match_operand:V2HI 1 "register_operand" "")
(match_operand:V2HI 2 "register_operand" "")


[gcc r15-3968] rs6000: Adjust altivec dot-product backend patterns

2024-09-30 Thread Victor Do Nascimento via Gcc-cvs
https://gcc.gnu.org/g:113e31cc32450fffbb7cc9b72c8d597b29ad9f0e

commit r15-3968-g113e31cc32450fffbb7cc9b72c8d597b29ad9f0e
Author: Victor Do Nascimento 
Date:   Wed Jun 5 10:51:29 2024 +0100

rs6000: Adjust altivec dot-product backend patterns

Following the migration of the dot_prod optab from a direct to a
conversion-type optab, ensure all back-end patterns incorporate the
second machine mode into pattern names.

gcc/ChangeLog:

* config/rs6000/altivec.md (udot_prod): Renamed to...
(udot_prodv4si): ...this.
(sdot_prodv8hi): Renamed to...
(sdot_prodv4siv8hi): ...this.

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

diff --git a/gcc/config/rs6000/altivec.md b/gcc/config/rs6000/altivec.md
index e4576c6d0967..00dad4b91f1c 100644
--- a/gcc/config/rs6000/altivec.md
+++ b/gcc/config/rs6000/altivec.md
@@ -3749,7 +3749,7 @@
 }
 })
 
-(define_expand "udot_prod"
+(define_expand "udot_prodv4si"
   [(set (match_operand:V4SI 0 "register_operand" "=v")
 (plus:V4SI (match_operand:V4SI 3 "register_operand" "v")
(unspec:V4SI [(match_operand:VIshort 1 "register_operand" 
"v")  
@@ -3761,7 +3761,7 @@
   DONE;
 })
 
-(define_expand "sdot_prodv8hi"
+(define_expand "sdot_prodv4siv8hi"
   [(set (match_operand:V4SI 0 "register_operand" "=v")
 (plus:V4SI (match_operand:V4SI 3 "register_operand" "v")
(unspec:V4SI [(match_operand:V8HI 1 "register_operand" "v")


[gcc r15-3970] autovectorizer: Test autovectorization of different dot-prod modes.

2024-09-30 Thread Victor Do Nascimento via Gcc-cvs
https://gcc.gnu.org/g:8398ef96cc503cffb1447c5b02741e24423ec120

commit r15-3970-g8398ef96cc503cffb1447c5b02741e24423ec120
Author: Victor Do Nascimento 
Date:   Fri Jul 5 15:18:32 2024 +0100

autovectorizer: Test autovectorization of different dot-prod modes.

Given the novel treatment of the dot product optab as a conversion, we
are now able to target different relationships between output modes and
input modes.

This is made clearer by way of example. Previously, on AArch64, the
following loop was vectorizable:

uint32_t udot4(int n, uint8_t* data) {
  uint32_t sum = 0;
  for (int i=0; i
+
+uint32_t udot4(int n, uint8_t* data) {
+  uint32_t sum = 0;
+  for (int i=0; i
+#include 
+#pragma GCC target "+sme2"
+
+uint32_t
+udot2 (int n, uint16_t* data)  __arm_streaming
+{
+  uint32_t sum = 0;
+  for (int i=0; i

[gcc r15-3974] diagnostics: use "%e" to avoid intermediate strings [PR116613]

2024-09-30 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:3d3d20ccd8365970f34002bfe0a632f2868bc95b

commit r15-3974-g3d3d20ccd8365970f34002bfe0a632f2868bc95b
Author: David Malcolm 
Date:   Mon Sep 30 11:48:29 2024 -0400

diagnostics: use "%e" to avoid intermediate strings [PR116613]

Various diagnostics build an intermediate string, potentially with
colorization, and then use this in a diagnostic message.

This won't work if we have multiple diagnostic sinks, where some might
be colorized and some not.

This patch reworks such places using "%e" and pp_element subclasses, so
that any colorization happens within report_diagnostic's call to
pp_format.

gcc/analyzer/ChangeLog:
PR other/116613
* kf-analyzer.cc: Include "pretty-print-markup.h".
(kf_analyzer_dump_escaped::impl_call_pre): Defer colorization
choices by eliminating the construction of a intermediate string,
replacing it with a new pp_element subclass via "%e".

gcc/ChangeLog:
PR other/116613
* attribs.cc: Include "pretty-print-markup.h".
(decls_mismatched_attributes): Defer colorization choices by
replacing printing to a pretty_printer * param with appending
to a vec of strings.
(maybe_diag_alias_attributes): As above, replacing pretty_printer
with usage of pp_markup::comma_separated_quoted_strings and "%e"
in two places.
* attribs.h (decls_mismatched_attributes): Update decl.
* gimple-ssa-warn-access.cc: Include "pretty-print-markup.h".
(pass_waccess::maybe_warn_memmodel): Defer colorization choices by
replacing printing to a pretty_printer * param with use of
pp_markup::comma_separated_quoted_strings and "%e".
(pass_waccess::maybe_warn_memmodel): Likewise, replacing printing
to a temporary buffer.
* pretty-print-markup.h
(class pp_markup::comma_separated_quoted_strings): New.
* pretty-print.cc
(pp_markup::comma_separated_quoted_strings::add_to_phase_2): New.
(selftest::test_pp_printf_within_pp_element): New.
(selftest::test_comma_separated_quoted_strings): New.
(selftest::pretty_print_cc_tests): Call the new tests.

gcc/cp/ChangeLog:
PR other/116613
* pt.cc: Include "pretty-print-markup.h".
(warn_spec_missing_attributes): Defer colorization choices by
replacing printing to a pretty_printer * param with appending
to a vec of strings.  Replace pretty_printer with usage of
pp_markup::comma_separated_quoted_strings and "%e".

gcc/testsuite/ChangeLog:
PR other/116613
* c-c++-common/analyzer/escaping-1.c: Update expected results to
remove type information from C++ results.  Previously we were
using %qD with default_tree_printer, which used
lang_hooks.decl_printable_name, whereas now we're using %qD with
a clone of the cxx_pretty_printer.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/analyzer/kf-analyzer.cc  | 42 +++
 gcc/attribs.cc   | 33 +
 gcc/attribs.h|  2 +-
 gcc/cp/pt.cc | 18 +++--
 gcc/gimple-ssa-warn-access.cc| 21 +++---
 gcc/pretty-print-markup.h| 17 +
 gcc/pretty-print.cc  | 92 
 gcc/testsuite/c-c++-common/analyzer/escaping-1.c |  9 +--
 8 files changed, 179 insertions(+), 55 deletions(-)

diff --git a/gcc/analyzer/kf-analyzer.cc b/gcc/analyzer/kf-analyzer.cc
index 26c2e41da6ff..da49baa5bff1 100644
--- a/gcc/analyzer/kf-analyzer.cc
+++ b/gcc/analyzer/kf-analyzer.cc
@@ -36,6 +36,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "analyzer/pending-diagnostic.h"
 #include "analyzer/call-details.h"
 #include "make-unique.h"
+#include "pretty-print-markup.h"
 
 #if ENABLE_ANALYZER
 
@@ -176,23 +177,40 @@ public:
probably most user-friendly.  */
 escaped_decls.qsort (cmp_decls_ptr_ptr);
 
-pretty_printer pp;
-pp_format_decoder (&pp) = default_tree_printer;
-pp_show_color (&pp) = pp_show_color (global_dc->m_printer);
-bool first = true;
-for (auto iter : escaped_decls)
+class escaped_list_element : public pp_element
+{
+public:
+  escaped_list_element (auto_vec &escaped_decls)
+  : m_escaped_decls (escaped_decls)
   {
-   if (first)
- first = false;
-   else
- pp_string (&pp, ", ");
-   pp_printf (&pp, "%qD", iter);
   }
+
+  void add_to_phase_2 (pp_markup::context &ctxt) final override
+  {
+   /* We can't call pp_printf directly on ctxt.m_pp from within
+  formatting.  As a workaround, 

[gcc r15-3971] diagnostics: fix memory leak in SARIF selftests

2024-09-30 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:ab6c7a329d4958aa1f2975196358f7f56a463b3b

commit r15-3971-gab6c7a329d4958aa1f2975196358f7f56a463b3b
Author: David Malcolm 
Date:   Mon Sep 30 11:48:28 2024 -0400

diagnostics: fix memory leak in SARIF selftests

"make selftest-valgrind" was complaining about leaks of artifact objects
in SARIF's selftest::test_make_location_object:

-fself-test: 7638695 pass(es) in 89.999249 seconds
==3306525==
==3306525== HEAP SUMMARY:
==3306525== in use at exit: 1,215,639 bytes in 2,808 blocks
==3306525==   total heap usage: 2,860,898 allocs, 2,858,090 frees, 
1,336,446,579 bytes allocated
==3306525==
==3306525== 11,728 (1,536 direct, 10,192 indirect) bytes in 16 blocks are 
definitely lost in loss record 353 of 375
==3306525==at 0x514FE7D: operator new(unsigned long) 
(vg_replace_malloc.c:342)
==3306525==by 0x36E5FD2: sarif_builder::get_or_create_artifact(char 
const*, diagnostic_artifact_role, bool) (diagnostic-format-sarif.cc:2884)
==3306525==by 0x36E3D57: 
sarif_builder::maybe_make_physical_location_object(unsigned int, 
diagnostic_artifact_role, int, content_renderer const*) 
(diagnostic-format-sarif.cc:2097)
==3306525==by 0x36E34CE: 
sarif_builder::make_location_object(sarif_location_manager&, rich_location 
const&, logical_location const*, diagnostic_artifact_role) 
(diagnostic-format-sarif.cc:1922)
==3306525==by 0x36E72C6: 
selftest::test_make_location_object(selftest::line_table_case const&) 
(diagnostic-format-sarif.cc:3500)
==3306525==by 0x375609B: selftest::for_each_line_table_case(void 
(*)(selftest::line_table_case const&)) (input.cc:3898)
==3306525==by 0x36E9668: selftest::diagnostic_format_sarif_cc_tests() 
(diagnostic-format-sarif.cc:3910)
==3306525==by 0x3592A11: selftest::run_tests() 
(selftest-run-tests.cc:100)
==3306525==by 0x17DBEF3: toplev::run_self_tests() (toplev.cc:2268)
==3306525==by 0x17DC2BF: toplev::main(int, char**) (toplev.cc:2376)
==3306525==by 0x36A1919: main (main.cc:39)
==3306525==
==3306525== 12,400 (1,536 direct, 10,864 indirect) bytes in 16 blocks are 
definitely lost in loss record 355 of 375
==3306525==at 0x514FE7D: operator new(unsigned long) 
(vg_replace_malloc.c:342)
==3306525==by 0x36E5FD2: sarif_builder::get_or_create_artifact(char 
const*, diagnostic_artifact_role, bool) (diagnostic-format-sarif.cc:2884)
==3306525==by 0x36E2323: 
sarif_builder::sarif_builder(diagnostic_context&, line_maps const*, char 
const*, bool) (diagnostic-format-sarif.cc:1500)
==3306525==by 0x36E70AA: 
selftest::test_make_location_object(selftest::line_table_case const&) 
(diagnostic-format-sarif.cc:3469)
==3306525==by 0x375609B: selftest::for_each_line_table_case(void 
(*)(selftest::line_table_case const&)) (input.cc:3898)
==3306525==by 0x36E9668: selftest::diagnostic_format_sarif_cc_tests() 
(diagnostic-format-sarif.cc:3910)
==3306525==by 0x3592A11: selftest::run_tests() 
(selftest-run-tests.cc:100)
==3306525==by 0x17DBEF3: toplev::run_self_tests() (toplev.cc:2268)
==3306525==by 0x17DC2BF: toplev::main(int, char**) (toplev.cc:2376)
==3306525==by 0x36A1919: main (main.cc:39)
==3306525==
==3306525== LEAK SUMMARY:
==3306525==definitely lost: 3,072 bytes in 32 blocks
==3306525==indirectly lost: 21,056 bytes in 368 blocks
==3306525==  possibly lost: 0 bytes in 0 blocks
==3306525==still reachable: 1,191,511 bytes in 2,408 blocks
==3306525== suppressed: 0 bytes in 0 blocks
==3306525== Reachable blocks (those to which a pointer was found) are not 
shown.
==3306525== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==3306525==
==3306525== For lists of detected and suppressed errors, rerun with: -s
==3306525== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)

Fixed thusly.

gcc/ChangeLog:
* diagnostic-format-sarif.cc (sarif_builder::~sarif_builder): New,
deleting any remaining artifact objects.
(sarif_builder::make_run_object): Empty the artifact map.
* ordered-hash-map.h (ordered_hash_map::empty): New.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/diagnostic-format-sarif.cc | 14 ++
 gcc/ordered-hash-map.h |  2 ++
 2 files changed, 16 insertions(+)

diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc
index 6cd18cef6c89..7b11dfd89a31 100644
--- a/gcc/diagnostic-format-sarif.cc
+++ b/gcc/diagnostic-format-sarif.cc
@@ -649,6 +649,7 @@ public:
 const line_maps *line_maps,
 const char *main_input_filename_,
 bool formatted);
+  ~sarif_builder ();
 
   void on_report_diagnostic (const diagnostic_info &diagnostic,
 diagnostic_t orig_diag_kind);
@@ -1500,6 +1501,18 @@ sarif_builder::

[gcc r15-3972] diagnostics: fix typo in XHTML output [PR116792]

2024-09-30 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:3286b6724ec1d005436dffa5228516db88e754b9

commit r15-3972-g3286b6724ec1d005436dffa5228516db88e754b9
Author: David Malcolm 
Date:   Mon Sep 30 11:48:28 2024 -0400

diagnostics: fix typo in XHTML output [PR116792]

gcc/testsuite/ChangeLog:
PR other/116792
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.c: Fix stray
reference to JSON.

Signed-off-by: David Malcolm 

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

diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_xhtml_format.c 
b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_xhtml_format.c
index 192288aff1bc..0f13e8d6d01a 100644
--- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_xhtml_format.c
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_xhtml_format.c
@@ -751,7 +751,7 @@ diagnostic_output_format_init_xhtml_file 
(diagnostic_context &context,
 namespace selftest {
 
 /* A subclass of xhtml_output_format for writing selftests.
-   The JSON output is cached internally, rather than written
+   The XML output is cached internally, rather than written
out to a file.  */
 
 class test_xhtml_diagnostic_context : public test_diagnostic_context


[gcc r15-3976] diagnostics: isolate diagnostic_context with interface classes [PR116613]

2024-09-30 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:be02253af810348be689cfa6f235af96c8cc5802

commit r15-3976-gbe02253af810348be689cfa6f235af96c8cc5802
Author: David Malcolm 
Date:   Mon Sep 30 11:48:29 2024 -0400

diagnostics: isolate diagnostic_context with interface classes [PR116613]

As work towards supporting multiple diagnostic outputs (where each
output has its own pretty_printer), avoid passing around
diagnostic_context to the various printing routines, so that we
can be more explicit about which pretty_printer is in use.

Introduce a set of "policy" classes that capture the parts of
diagnostic_context that are needed, and use these rather than
diagnostic_context *.  Pass around pretty_printer & rather than
taking value from context.  Split out the pretty_printer-using code
from class layout into a new class layout_printer, separating the
responsibilities of determining layout when quoting source versus
actually printing the source.

No functional change intended.

gcc/analyzer/ChangeLog:
PR other/116613
* program-point.cc (function_point::print_source_line): Replace
call to diagnostic_show_locus with a call to
diagnostic_source_print_policy::print.

gcc/ChangeLog:
PR other/116613
* diagnostic-format-json.cc (json_from_expanded_location): Replace
call to diagnostic_context::converted_column with call to
diagnostic_column_policy::converted_column.
* diagnostic-format-sarif.cc
(sarif_builder::make_location_object): Replace call to
diagnostic_show_locus with call to
diagnostic_source_print_policy::print.
* diagnostic-format-text.cc (get_location_text): Replace call to
diagnostic_context::get_location_text with call to
diagnostic_column_policy::get_location_text.
(diagnostic_text_output_format::report_current_module): Replace call
to diagnostic_context::converted_column with call to
diagnostic_column_policy::converted_column.
* diagnostic-format-text.h
(diagnostic_text_output_format::diagnostic_output_format):
Initialize m_column_policy.
(diagnostic_text_output_format::get_column_policy): New.
(diagnostic_text_output_format::m_column_policy): New.
* diagnostic-path.cc (class path_print_policy): New.
(event_range::maybe_add_event): Replace diagnostic_context param
with path_print_policy.
(event_range::print): Convert "pp" from * to &.  Convert first
param of start_span callback from diagnostic_context to
diagnostic_location_print_policy.
(path_summary::path_summary): Convert first param from
diagnostic_text_output_format to path_print_policy.  Add
colorize param.  Update for changes to
event_range::maybe_add_event.
(thread_event_printer::print_swimlane_for_event_range): Assert
that pp is non-null.  Update for change to event_range::print.
(diagnostic_text_output_format::print_path): Pass
path_print_policy to path_summary's ctor.
(selftest::test_empty_path): Likewise.
(selftest::test_intraprocedural_path): Likewise.
(selftest::test_interprocedural_path_1): Likewise.
(selftest::test_interprocedural_path_2): Likewise.
(selftest::test_recursion): Likewise.
(selftest::test_control_flow_1): Likewise.
(selftest::test_control_flow_2): Likewise.
(selftest::test_control_flow_3): Likewise.
(selftest::assert_cfg_edge_path_streq): Likewise.
(selftest::test_control_flow_5): Likewise.
(selftest::test_control_flow_6): Likewise.
* diagnostic-show-locus.cc (colorizer::set_range): Update for
change to m_pp.
(colorizer::m_pp): Convert from * to &.
(class layout): Add friend class layout_printer and move various
decls to it.
(layout::m_pp): Drop field.
(layout::m_policy): Rename to...
(layout::m_char_policy): ...this.
(layout::m_colorizer): Move field to class layout_printer.
(layout::m_diagnostic_path_p): Drop field.
(class layout_printer): New class, by refactoring class layout.
(colorizer::colorizer): Convert "pp" param from * to &.
(colorizer::set_named_color): Update for above change.
(colorizer::begin_state): Likewise.
(colorizer::finish_state): Likewise.
(make_policy): Rename to...
(make_char_policy): ...this, and update param from
diagnostic_context to diagnostic_source_print_policy.
(layout::layout): Update param from diagnostic_context to
diagnostic_source_print_p

[gcc r15-3978] diagnostics: return text buffer from test_show_locus [PR116613]

2024-09-30 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:9c14f9a9c19957d9a45a7df97701bad475c80eea

commit r15-3978-g9c14f9a9c19957d9a45a7df97701bad475c80eea
Author: David Malcolm 
Date:   Mon Sep 30 11:48:30 2024 -0400

diagnostics: return text buffer from test_show_locus [PR116613]

As work towards supporting multiple diagnostic outputs (where each
output has its own pretty_printer), avoid referencing dc.m_printer
throughout the selftests of diagnostic-show-locus.cc.  Instead
have test_diagnostic_context::test_show_locus return the result
buffer, hiding the specifics of which printer is in use in such
test cases.

No functional change intended.

gcc/ChangeLog:
PR other/116613
* diagnostic-show-locus.cc
(selftest::test_diagnostic_show_locus_unknown_location): Move call
to dc.test_show_locus into ASSERT_STREQ, and compare against its
result, rather than explicitly using dc.m_printer.
(selftest::test_one_liner_simple_caret): Likewise.
(selftest::test_one_liner_no_column): Likewise.
(selftest::test_one_liner_caret_and_range): Likewise.
(selftest::test_one_liner_multiple_carets_and_ranges): Likewise.
(selftest::test_one_liner_fixit_insert_before): Likewise.
(selftest::test_one_liner_fixit_insert_after): Likewise.
(selftest::test_one_liner_fixit_remove): Likewise.
(selftest::test_one_liner_fixit_replace): Likewise.
(selftest::test_one_liner_fixit_replace_non_equal_range):
Likewise.
(selftest::test_one_liner_fixit_replace_equal_secondary_range):
Likewise.
(selftest::test_one_liner_fixit_validation_adhoc_locations):
Likewise.
(selftest::test_one_liner_many_fixits_1): Likewise.
(selftest::test_one_liner_many_fixits_2): Likewise.
(selftest::test_one_liner_labels): Likewise.
(selftest::test_one_liner_simple_caret_utf8): Likewise.
(selftest::test_one_liner_multiple_carets_and_ranges_utf8):
Likewise.
(selftest::test_one_liner_fixit_insert_before_utf8): Likewise.
(selftest::test_one_liner_fixit_insert_after_utf8): Likewise.
(selftest::test_one_liner_fixit_remove_utf8): Likewise.
(selftest::test_one_liner_fixit_replace_utf8): Likewise.
(selftest::test_one_liner_fixit_replace_non_equal_range_utf8):
Likewise.
(selftest::test_one_liner_fixit_replace_equal_secondary_range_utf8):
Likewise.
(selftest::test_one_liner_fixit_validation_adhoc_locations_utf8):
Likewise.
(selftest::test_one_liner_many_fixits_1_utf8): Likewise.
(selftest::test_one_liner_many_fixits_2_utf8): Likewise.
(selftest::test_one_liner_labels_utf8): Likewise.
(selftest::test_one_liner_colorized_utf8): Likewise.
(selftest::test_add_location_if_nearby): Likewise.
(selftest::test_diagnostic_show_locus_fixit_lines): Likewise.
(selftest::test_overlapped_fixit_printing): Likewise.
(selftest::test_overlapped_fixit_printing_utf8): Likewise.
(selftest::test_overlapped_fixit_printing_utf8): Likewise.
(selftest::test_overlapped_fixit_printing_2): Likewise.
(selftest::test_fixit_insert_containing_newline): Likewise.
(selftest::test_fixit_insert_containing_newline_2): Likewise.
(selftest::test_fixit_replace_containing_newline): Likewise.
(selftest::test_fixit_deletion_affecting_newline): Likewise.
(selftest::test_tab_expansion): Likewise.
(selftest::test_escaping_bytes_1): Likewise.
(selftest::test_escaping_bytes_2): Likewise.
(selftest::test_line_numbers_multiline_range): Likewise.
* selftest-diagnostic.cc
(selftest::test_diagnostic_context::test_show_locus): Return the
formatted text of m_printer.
* selftest-diagnostic.h
(selftest::test_diagnostic_context::test_show_locus): Convert
return type from void to const char *.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/diagnostic-show-locus.cc | 248 +++
 gcc/selftest-diagnostic.cc   |   6 +-
 gcc/selftest-diagnostic.h|   2 +-
 3 files changed, 88 insertions(+), 168 deletions(-)

diff --git a/gcc/diagnostic-show-locus.cc b/gcc/diagnostic-show-locus.cc
index b575dc51a78c..415de42cbc7b 100644
--- a/gcc/diagnostic-show-locus.cc
+++ b/gcc/diagnostic-show-locus.cc
@@ -3742,8 +3742,7 @@ test_diagnostic_show_locus_unknown_location ()
 {
   test_diagnostic_context dc;
   rich_location richloc (line_table, UNKNOWN_LOCATION);
-  dc.test_show_locus (richloc);
-  ASSERT_STREQ ("", pp_formatted_text (dc.m_printer));
+  ASSERT_STREQ ("", dc.test_show_locus (richloc));
 }
 
 /* Ve

[gcc r15-3975] diagnostics: avoid using diagnostic_context's m_printer [PR116613]

2024-09-30 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:cce52867d1892c08386f780107288473ec0033b7

commit r15-3975-gcce52867d1892c08386f780107288473ec0033b7
Author: David Malcolm 
Date:   Mon Sep 30 11:48:29 2024 -0400

diagnostics: avoid using diagnostic_context's m_printer [PR116613]

As work towards supporting multiple diagnostic outputs (where each
output has its own pretty_printer), avoid using diagnostic_context's
m_printer field.  Instead, use the output format's printer.  Currently
this *is* the dc's printer, but eventually it might not be.

No functional change intended.

gcc/ChangeLog:
PR other/116613
* diagnostic-format-json.cc (diagnostic_output_format_init_json):
Pass in the format.  Use the format's printer when disabling
colorization.  Move the call to set_output_format into here.
(diagnostic_output_format_init_json_stderr): Update for above
change.
(diagnostic_output_format_init_json_file): Likewise.
* diagnostic-format-sarif.cc
(diagnostic_output_format_init_sarif): Use the format's printer
when disabling colorization.
* diagnostic-path.cc (selftest::test_empty_path): Use the
text_output's printer.
(selftest::test_intraprocedural_path): Likewise.
(selftest::test_interprocedural_path_1): Likewise.
(selftest::test_interprocedural_path_2): Likewise.
(selftest::test_recursion): Likewise.
(selftest::test_control_flow_1): Likewise.
(selftest::test_control_flow_2): Likewise.
(selftest::test_control_flow_3): Likewise.
(selftest::assert_cfg_edge_path_streq): Likewise.
(selftest::test_control_flow_5): Likewise.
(selftest::test_control_flow_6): Likewise.

gcc/testsuite/ChangeLog:
PR other/116613
* gcc.dg/plugin/diagnostic_group_plugin.c
(test_output_format::on_begin_group): Use get_printer () rather
than accessing m_context.m_printer.
(test_output_format::on_end_group): Likewise.
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.c
(xhtml_builder::m_printer): New field.
(xhtml_builder::xhtml_builder): Add "pp" param and use it to
initialize m_printer.
(xhtml_builder::on_report_diagnostic): Drop "context" param.
(xhtml_builder::make_element_for_diagnostic): Likewise.  Use
this->m_printer rather than the context's m_printer.  Pass
m_printer to call to diagnostic_show_locus.
(xhtml_builder::emit_diagram): Drop "context" param.
(xhtml_output_format::on_report_diagnostic): Drop context param
from call to m_builder.
(xhtml_output_format::on_diagram): Likewise.
(xhtml_output_format::xhtml_output_format): Pass result of
get_printer as printer for builder.
(diagnostic_output_format_init_xhtml): Use the fmt's printer
rather than the context's.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/diagnostic-format-json.cc  | 23 ++-
 gcc/diagnostic-format-sarif.cc |  2 +-
 gcc/diagnostic-path.cc | 38 -
 .../gcc.dg/plugin/diagnostic_group_plugin.c| 12 +++---
 .../gcc.dg/plugin/diagnostic_plugin_xhtml_format.c | 47 +++---
 5 files changed, 64 insertions(+), 58 deletions(-)

diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc
index 448b6cb54eee..cf900a9ecba2 100644
--- a/gcc/diagnostic-format-json.cc
+++ b/gcc/diagnostic-format-json.cc
@@ -393,14 +393,17 @@ private:
to a file).  */
 
 static void
-diagnostic_output_format_init_json (diagnostic_context &context)
+diagnostic_output_format_init_json (diagnostic_context &context,
+   std::unique_ptr fmt)
 {
   /* Suppress normal textual path output.  */
   context.set_path_format (DPF_NONE);
 
   /* Don't colorize the text.  */
-  pp_show_color (context.m_printer) = false;
+  pp_show_color (fmt->get_printer ()) = false;
   context.set_show_highlight_colors (false);
+
+  context.set_output_format (fmt.release ());
 }
 
 /* Populate CONTEXT in preparation for JSON output to stderr.  */
@@ -409,9 +412,10 @@ void
 diagnostic_output_format_init_json_stderr (diagnostic_context &context,
   bool formatted)
 {
-  diagnostic_output_format_init_json (context);
-  context.set_output_format (new json_stderr_output_format (context,
-   formatted));
+  diagnostic_output_format_init_json
+(context,
+ ::make_unique (context,
+  formatted));
 }
 
 /* Populate CONTEXT in preparation for JSON output to a file named
@@ -422,10 +426,11 @@ diagnostic_output

[gcc r15-3973] diagnostics: add "dump" to pretty_printer and output_buffer

2024-09-30 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:4c7a58ac2617e24069c9ad3d469a7f87dc96091d

commit r15-3973-g4c7a58ac2617e24069c9ad3d469a7f87dc96091d
Author: David Malcolm 
Date:   Mon Sep 30 11:48:28 2024 -0400

diagnostics: add "dump" to pretty_printer and output_buffer

No functional change intended.

gcc/ChangeLog:
* pretty-print.cc (output_buffer::dump): New.
(pretty_printer::dump): New.
* pretty-print.h (output_buffer::dump): New decls.
(pretty_printer::dump): New decls.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/pretty-print.cc | 23 +++
 gcc/pretty-print.h  |  6 ++
 2 files changed, 29 insertions(+)

diff --git a/gcc/pretty-print.cc b/gcc/pretty-print.cc
index 68c145e2d532..6a1d1ec484ba 100644
--- a/gcc/pretty-print.cc
+++ b/gcc/pretty-print.cc
@@ -790,6 +790,21 @@ output_buffer::pop_formatted_chunks ()
   obstack_free (&m_chunk_obstack, old_top);
 }
 
+/* Dump state of this output_buffer to OUT, for debugging.  */
+
+void
+output_buffer::dump (FILE *out) const
+{
+  int depth = 0;
+  for (pp_formatted_chunks *iter = m_cur_formatted_chunks;
+   iter;
+   iter = iter->m_prev, depth++)
+{
+  fprintf (out, "pp_formatted_chunks: depth %i\n", depth);
+  iter->dump (out);
+}
+}
+
 #ifndef PTRDIFF_MAX
 #define PTRDIFF_MAX INTTYPE_MAXIMUM (ptrdiff_t)
 #endif
@@ -3013,6 +3028,14 @@ pretty_printer::end_url ()
 pp_string (this, get_end_url_string (this));
 }
 
+/* Dump state of this pretty_printer to OUT, for debugging.  */
+
+void
+pretty_printer::dump (FILE *out) const
+{
+  m_buffer->dump (out);
+}
+
 /* class pp_markup::context.  */
 
 void
diff --git a/gcc/pretty-print.h b/gcc/pretty-print.h
index b5ded5cdd5e0..ec64a167327b 100644
--- a/gcc/pretty-print.h
+++ b/gcc/pretty-print.h
@@ -93,6 +93,9 @@ public:
   pp_formatted_chunks *push_formatted_chunks ();
   void pop_formatted_chunks ();
 
+  void dump (FILE *out) const;
+  void DEBUG_FUNCTION dump () const { dump (stderr); }
+
   /* Obstack where the text is built up.  */
   struct obstack m_formatted_obstack;
 
@@ -313,6 +316,9 @@ public:
   void set_real_maximum_length ();
   int remaining_character_count_for_line ();
 
+  void dump (FILE *out) const;
+  void DEBUG_FUNCTION dump () const { dump (stderr); }
+
 private:
   /* Where we print external representation of ENTITY.  */
   output_buffer *m_buffer;


[gcc r15-3977] diagnostics: require callers of diagnostic_show_locus to be explicit about the printer [PR116613]

2024-09-30 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:e7a8fbe2fed83b5ce6e2bdb6fd66d9bf47f74db7

commit r15-3977-ge7a8fbe2fed83b5ce6e2bdb6fd66d9bf47f74db7
Author: David Malcolm 
Date:   Mon Sep 30 11:48:30 2024 -0400

diagnostics: require callers of diagnostic_show_locus to be explicit about 
the printer [PR116613]

As work towards supporting multiple diagnostic outputs (where each
output has its own pretty_printer), update diagnostic_show_locus
so that the pretty_printer must always be explicitly passed in.

No functional change intended.

gcc/c-family/ChangeLog:
PR other/116613
* c-format.cc (selftest::test_type_mismatch_range_labels):
Explicitly pass in dc.m_printer to diagnostic_show_locus.

gcc/ChangeLog:
PR other/116613
* diagnostic-show-locus.cc (diagnostic_context::maybe_show_locus):
Convert param "pp" from * to &.  Drop logic for using the
context's m_printer when the param is null.
* diagnostic.h (diagnostic_context::maybe_show_locus): Convert
param "pp" from * to &.
(diagnostic_show_locus): Drop default "nullptr" value for pp
param.  Assert that it and context are nonnull.  Pass pp by
reference to maybe_show_locus.

gcc/testsuite/ChangeLog:
PR other/116613
* gcc.dg/plugin/expensive_selftests_plugin.c (test_richloc):
Explicitly pass in dc.m_printer to diagnostic_show_locus.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/c-family/c-format.cc | 2 +-
 gcc/diagnostic-show-locus.cc | 8 ++--
 gcc/diagnostic.h | 8 +---
 gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.c | 2 +-
 4 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/gcc/c-family/c-format.cc b/gcc/c-family/c-format.cc
index 614b43266a31..f4a65a5019c3 100644
--- a/gcc/c-family/c-format.cc
+++ b/gcc/c-family/c-format.cc
@@ -5578,7 +5578,7 @@ test_type_mismatch_range_labels ()
   richloc.add_range (param, SHOW_RANGE_WITHOUT_CARET, ¶m_label);
 
   test_diagnostic_context dc;
-  diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+  diagnostic_show_locus (&dc, &richloc, DK_ERROR, dc.m_printer);
   if (c_dialect_cxx ())
 /* "char*", without a space.  */
 ASSERT_STREQ ("   printf (\"msg: %i\\n\", msg);\n"
diff --git a/gcc/diagnostic-show-locus.cc b/gcc/diagnostic-show-locus.cc
index a1d66cf493d6..b575dc51a78c 100644
--- a/gcc/diagnostic-show-locus.cc
+++ b/gcc/diagnostic-show-locus.cc
@@ -3265,7 +3265,7 @@ add_location_if_nearby (const diagnostic_context &dc,
 void
 diagnostic_context::maybe_show_locus (const rich_location &richloc,
  diagnostic_t diagnostic_kind,
- pretty_printer *pp,
+ pretty_printer &pp,
  diagnostic_source_effect_info *effects)
 {
   const location_t loc = richloc.get_loc ();
@@ -3287,12 +3287,8 @@ diagnostic_context::maybe_show_locus (const 
rich_location &richloc,
 
   m_last_location = loc;
 
-  if (!pp)
-pp = m_printer;
-  gcc_assert (pp);
-
   diagnostic_source_print_policy source_policy (*this);
-  source_policy.print (*pp, richloc, diagnostic_kind, effects);
+  source_policy.print (pp, richloc, diagnostic_kind, effects);
 }
 
 diagnostic_source_print_policy::
diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h
index bc0e67cb4ef2..23a9a1b117b9 100644
--- a/gcc/diagnostic.h
+++ b/gcc/diagnostic.h
@@ -528,7 +528,7 @@ public:
 
   void maybe_show_locus (const rich_location &richloc,
 diagnostic_t diagnostic_kind,
-pretty_printer *pp,
+pretty_printer &pp,
 diagnostic_source_effect_info *effect_info);
 
   void emit_diagram (const diagnostic_diagram &diagram);
@@ -981,11 +981,13 @@ inline void
 diagnostic_show_locus (diagnostic_context *context,
   rich_location *richloc,
   diagnostic_t diagnostic_kind,
-  pretty_printer *pp = nullptr,
+  pretty_printer *pp,
   diagnostic_source_effect_info *effect_info = nullptr)
 {
+  gcc_assert (context);
   gcc_assert (richloc);
-  context->maybe_show_locus (*richloc, diagnostic_kind, pp, effect_info);
+  gcc_assert (pp);
+  context->maybe_show_locus (*richloc, diagnostic_kind, *pp, effect_info);
 }
 
 /* Because we read source files a second time after the frontend did it the
diff --git a/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.c 
b/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.c
index 3c534005a419..554dad6fa35a 100644
--- a/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.c
+++ b/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.c
@@ -48,7 +48,7 @@ test_richloc (rich_location *richloc)

[gcc/devel/nothrow-detection] (1597 commits) Merge branch 'master' of git+ssh://gcc.gnu.org/git/gcc into

2024-09-30 Thread Pranil Dey via Gcc-cvs
The branch 'devel/nothrow-detection' was updated to point to:

 b602de4ed9f8... Merge branch 'master' of git+ssh://gcc.gnu.org/git/gcc into

It previously pointed to:

 c16d4a0ae162... Fix handling of types

Diff:

Summary of changes (added commits):
---

  b602de4... Merge branch 'master' of git+ssh://gcc.gnu.org/git/gcc into
  87905f6... middle-end: check explicitly for external or constants when (*)
  bac9561... Ensure coarrays in calls use a descriptor [PR81265] (*)
  71bf3da... tree-optimization/116842 - vectorizer load hosting breaks U (*)
  85f5d06... tree-optimization/116785 - relax volatile handling in PTA (*)
  6416365... tree-optimization/116850 - corrupt post-dom info (*)
  3f8b1b2... Match: Support form 1 for scalar signed integer SAT_SUB (*)
  f0d0c56... Daily bump. (*)
  a2a78c0... RISC-V: Add testcases for form 1 of scalar signed SAT_SUB (*)
  b6ea98b... RISC-V: Implement scalar SAT_SUB for signed integer (*)
  7372672... cselib: Discard useless locs of preserved VALUEs [PR116627] (*)
  f4d0c6a... testsuite: XFAIL gfortran.dg/initialization_25.f90 properly (*)
  01a42a0... [PATCH] SH: Document extended asm operand modifers (*)
  0cd24b0... [PATCH] [PATCH] Avoid integer overflow in gcc.dg/cpp/charco (*)
  a0f1f50... [PATCH v2] RISC-V: Improve code generation for select of co (*)
  a30a9d5... doc: Document struct-layout-1.exp for ABI checks (*)
  74a0ff6... Daily bump. (*)
  786773d... Implement FINDLOC for UNSIGNED. (*)
  1c92800... Implement CSHIFT and EOSHIFT for unsigned. (*)
  2531f01... doc: Remove i?86-*-linux* installation note from 2003 (*)
  9261339... Daily bump. (*)
  2196a20... c++: Implement resolution for DR 36 [PR116160] (*)
  b9ac51a... c++: Don't strip USING_DECLs when updating local bindings [ (*)
  cf9efe5... c++/modules: Propagate purview/import for templates in dupl (*)
  6885407... libstdc++: Fix more pedwarns in headers for C++98 (*)
  16491e1... libstdc++: Refactor experimental::filesystem::path string c (*)
  7040c20... libstdc++: Fix -Wsign-compare warning in std::string::resiz (*)
  96e0370... c++: ICE with structured bindings and m-d array [PR102594] (*)
  c580b8a... libstdc++: Fix test FAILs due to -Wreturn-local-addr (*)
  500046d... libstdc++: Fix test FAIL due to -Wpointer-arith (*)
  0ff49a5... aarch64: fix build failure on aarch64-none-elf (*)
  64072e6... diagnostic: Save/restore diagnostic context history and pus (*)
  ddc72ba... diagnostic: Use vec instead of custom array reallocations f (*)
  a721089... i386: Modernize AMD processor types (*)
  cd430b1... Widening-Mul: Fix one ICE when iterate on phi node (*)
  9085cc2... Fix sorting in Contributors.html (*)
  dd5b823... libgcc, Darwin: Don't build legacy libgcc_s.1 on macOS 14 [ (*)
  d888a8a... c++/coro: ignore cleanup_point_exprs while expanding awaits (*)
  de03ef6... c++: simplify handling implicit INDIRECT_REF and co_await i (*)
  05e4f07... c++/coro: prevent ICV_STATEMENT diagnostics in temp promoti (*)
  037c97e... [MAINTAINERS]: Add myself as MVE Reviewer for the AArch32 ( (*)
  cfdc0a3... libgomp.texi: Remove now duplicate TR13 item (*)
  bb01c9d... RISC-V/libgcc: Save/Restore routines for E goes with ABI. (*)
  6b7eaec... libgomp.texi: fix formatting; add post-TR13 OpenMP impl. st (*)
  b1c7095... tree-optimization/116818 - try VMAT_GATHER_SCATTER also for (*)
  3db9e99... Fix bogus SLP nvector compute in check_load_store_for_parti (*)
  9c04112... unswitch: Replace manual ondemand maybe_undef with ssa_name (*)
  1a0b33e... c++/modules: Allow imported references in constant expressi (*)
  d0762e9... c++/modules: Fix linkage checks for exported using-decls (*)
  ad08ef0... c++/modules: Use decl_linkage in maybe_record_mergeable_dec (*)
  af4471c... c++: Update decl_linkage for C++11 (*)
  3471ae3... testsuite/gfortran.dg/open_errors_2.f90: Remove now-redunda (*)
  ff20f2b... Daily bump. (*)
  48e1b89... libstdc++: Add missing 'inline' to always_inline function (*)
  6a4d1c3... libgcc, libstdc++: Make declarations no longer TU-local [PR (*)
  6ac4e2f... c++: tweak for -Wrange-loop-construct [PR116731] (*)
  e23e537... libstdc++: Fix freebsd/dragonfly build [PR116859] (*)
  ee9f006... libstdc++: Preserve signbit of nan when converting float to (*)
  5ad6ff2... libstdc++: Fix comments in  tests that mention bas (*)
  240285e... libstdc++: Add [[nodiscard]] to iostream members (*)
  9ec258b... libgomp.texi: Fix deprecation note for omp_{get,set}_nested (*)
  819098d... testsuite: XFAIL gfortran.dg/initialization_25.f90 properly (*)
  e9f3414... doc: Remove index reference to removed documentation in for (*)
  6f76ce8... Add virtual destructor to AbstractExpr (*)
  942bbb2... tree-optimization/114855 - speed up dom_oracle::register_tr (*)
  e4a58b6... Fortran/OpenMP: Middle-end support for mapping of DT with a (*)
  d797202... libstdc++: Suppress an attribute suggestion warning [PR1168 (*)
  c45844e... libstdc++: Fix std::basic_stracktrace to not assume allocat (*)
  

[gcc(refs/users/meissner/heads/work179-vpair)] Delete __vpair_ptr_t.

2024-09-30 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:dc8a4292558a12761f35960cff126d7a3c5fb626

commit dc8a4292558a12761f35960cff126d7a3c5fb626
Author: Michael Meissner 
Date:   Mon Sep 30 13:46:15 2024 -0400

Delete __vpair_ptr_t.

2024-09-30  Michael Meissner  

gcc/

* config/rs6000/vector-pair.h: Delete __vpair_ptr_t.

Diff:
---
 gcc/config/rs6000/vector-pair.h | 21 ++---
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/gcc/config/rs6000/vector-pair.h b/gcc/config/rs6000/vector-pair.h
index 78dfc74c0d59..3443d32198df 100644
--- a/gcc/config/rs6000/vector-pair.h
+++ b/gcc/config/rs6000/vector-pair.h
@@ -48,8 +48,7 @@ union __vpair_union {
 typedef union __vpair_unionvector_pair_t;
 typedef union __vpair_unionvector_pair_f64_t;
 typedef union __vpair_unionvector_pair_f32_t;
-typedef union __vpair_union*__vpair_ptr_t;
-#endif /* __VPAIR_UNION__.  */
+#endif /* __VPAIR_UNION__.  */
 
 #if !__VPAIR_BUILTIN__ && !__VPAIR_ASM__ && !__VPAIR_NOP10__
 #if __MMA__ && __VPAIR__
@@ -440,24 +439,24 @@ vpair_f32_nfms (vector_ptr_f32_t *__r,
 #undef  __VPAIR_FP_UNARY_ASM
 #define __VPAIR_FP_UNARY_ASM(OPCODE, R, A) \
   __asm__ (OPCODE " %x0,%x1\n\t" OPCODE " %x0+1,%x1+1" \
-   : "=wa" (((__vpair_ptr_t)(R))->__vpair) \
-   : "wa" (((__vpair_ptr_t)(A))->__vpair));
+   : "=wa" (((R))->__vpair)\
+   : "wa" (((A))->__vpair));
 
 #undef  __VPAIR_FP_BINARY_ASM
 #define __VPAIR_FP_BINARY_ASM(OPCODE, R, A, B) \
   __asm__ (OPCODE " %x0,%x1,%x2\n\t" OPCODE " %x0+1,%x1+1,%x2+1"   \
-   : "=wa" (((__vpair_ptr_t)(R))->__vpair) \
-   : "wa" (((__vpair_ptr_t)(A))->__vpair), \
- "wa" (((__vpair_ptr_t)(B))->__vpair));
+   : "=wa" (((R))->__vpair)\
+   : "wa" (((A))->__vpair),\
+ "wa" (((B))->__vpair));
 
 /* Note the 'a' version of the FMA instruction must be used.  */
 #undef  __VPAIR_FP_FMA_ASM
 #define __VPAIR_FP_FMA_ASM(OPCODE, R, A, B, C) \
   __asm__ (OPCODE " %x0,%x1,%x2\n\t" OPCODE " %x0+1,%x1+1,%x2+1"   \
-   : "=wa" (((__vpair_ptr_t)(R))->__vpair) \
-   : "wa" (((__vpair_ptr_t)(A))->__vpair), \
- "wa" (((__vpair_ptr_t)(B))->__vpair), \
- "0"  (((__vpair_ptr_t)(C))->__vpair));
+   : "=wa" (((R))->__vpair)\
+   : "wa" (((A))->__vpair),\
+ "wa" (((B))->__vpair),\
+ "0"  (((C))->__vpair));
 
 /* vector pair double operations on power10/power11.  */
 static inline void


[gcc(refs/users/meissner/heads/work179-vpair)] Update ChangeLog.*

2024-09-30 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:4272b9e9005fa7a2f80467aeb0f4938e5ec4f8cb

commit 4272b9e9005fa7a2f80467aeb0f4938e5ec4f8cb
Author: Michael Meissner 
Date:   Mon Sep 30 13:49:24 2024 -0400

Update ChangeLog.*

Diff:
---
 gcc/ChangeLog.vpair | 20 +++-
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/gcc/ChangeLog.vpair b/gcc/ChangeLog.vpair
index 020ed7b272b2..fdd35ca21cfc 100644
--- a/gcc/ChangeLog.vpair
+++ b/gcc/ChangeLog.vpair
@@ -1,4 +1,14 @@
- Branch work179-vpair, patch #300 
+ Branch work179-vpair, patch #306 
+
+Delete __vpair_ptr_t.
+
+2024-09-30  Michael Meissner  
+
+gcc/
+
+   * config/rs6000/vector-pair.h: Delete __vpair_ptr_t.
+
+ Branch work179-vpair, patch #305 
 
 Rewrite vector-pair.h.
 
@@ -8,7 +18,7 @@ gcc/
 
* config/rs6000/vector-pair.h: Rewrite.
 
- Branch work179-vpair, patch #300 
+ Branch work179-vpair, patch #304 
 
 Add vector pair optimizations.
 
@@ -35,7 +45,7 @@ gcc/testsuite/
* gcc.target/powerpc/vector-pair-11.c: Likewise.
* gcc.target/powerpc/vector-pair-12xs.c: Likewise.
 
- Branch work179-vpair, patch #300 
+ Branch work179-vpair, patch #303 
 
 Add vector pair init and splat.
 
@@ -62,7 +72,7 @@ gcc/testsuite/
* gcc.target/powerpc/vector-pair-5.c: New test.
* gcc.target/powerpc/vector-pair-6.c: Likewise.
 
- Branch work179-vpair, patch #300 
+ Branch work179-vpair, patch #302 
 
 Add support for vector pair fma operations.
 
@@ -98,7 +108,7 @@ gcc/testsuite/
* gcc.target/powerpc/vector-pair-3.c: New test.
* gcc.target/powerpc/vector-pair-4.c: Likewise.
 
- Branch work179-vpair, patch #300 
+ Branch work179-vpair, patch #301 
 
 Add support for vector pair unary and binary operations.


[gcc/devel/nothrow-detection] Fixed some indentations and function names

2024-09-30 Thread Pranil Dey via Gcc-cvs
https://gcc.gnu.org/g:70505f5757f09145f4465f5cf597ecc2b64069e0

commit 70505f5757f09145f4465f5cf597ecc2b64069e0
Author: Pranil Dey 
Date:   Fri Aug 30 21:31:26 2024 +0530

Fixed some indentations and function names

1. Changed function name extract_exception_types_for_call to 
extract_types_for_call due to length of the name
2. Fixed space indentation in some places

Diff:
---
 gcc/tree-eh.cc | 32 
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
index 4d541b08c2fc..e7e4bd191628 100644
--- a/gcc/tree-eh.cc
+++ b/gcc/tree-eh.cc
@@ -2293,7 +2293,7 @@ same_or_derived_type (tree t1, tree t2)
 }
 
 // Check if a landing pad can handle any of the given exception types
-bool match_lp(eh_landing_pad lp, vec *exception_types) {
+bool match_lp (eh_landing_pad lp, vec *exception_types) {
 eh_region region = lp->region;
 
 // Ensure the region is of type ERT_TRY
@@ -2303,15 +2303,15 @@ bool match_lp(eh_landing_pad lp, vec 
*exception_types) {
 while (catch_handler) {
 tree type_list = catch_handler->type_list;
 
-if(type_list == NULL) {
+if (type_list == NULL) {
 return true;
 }
 
-for (tree t = type_list; t; t = TREE_CHAIN(t)) {
-tree type = TREE_VALUE(t);
-for (unsigned i = 0; i < exception_types->length(); ++i) {
+for (tree t = type_list; t; t = TREE_CHAIN (t)) {
+tree type = TREE_VALUE (t);
+for (unsigned i = 0; i < exception_types->length (); ++i) {
   // match found or a catch-all handler (NULL)
-if (!type || same_or_derived_type ((*exception_types)[i], 
type)) {
+if (!type || same_or_derived_type ( (*exception_types)[i], 
type)) {
 return true;
 }
 }
@@ -2323,18 +2323,18 @@ bool match_lp(eh_landing_pad lp, vec 
*exception_types) {
 }
 
 // Function to update landing pad in throw_stmt_table for a given statement
-void update_stmt_eh_region(gimple *stmt) {
+void update_stmt_eh_region (gimple *stmt) {
   auto_vec exception_types;
   if (!stmt_throw_types (cfun, stmt, &exception_types)) {
 return;
 }
 
-int lp_nr = lookup_stmt_eh_lp_fn(cfun, stmt);
+int lp_nr = lookup_stmt_eh_lp_fn (cfun, stmt);
 if (lp_nr <= 0) {
 return;
 }
 
-eh_landing_pad lp = get_eh_landing_pad_from_number(lp_nr);
+eh_landing_pad lp = get_eh_landing_pad_from_number (lp_nr);
 if (!lp) {
 return;
 }
@@ -2345,12 +2345,12 @@ void update_stmt_eh_region(gimple *stmt) {
 while (region) {
 switch (region->type) {
 case ERT_CLEANUP:
-*cfun->eh->throw_stmt_table->get(const_cast(stmt)) = 
lp->index;
+*cfun->eh->throw_stmt_table->get (const_cast (stmt)) 
= lp->index;
 return;
 
 case ERT_TRY:
-if (match_lp(lp, &exception_types)) {
-*cfun->eh->throw_stmt_table->get(const_cast(stmt)) = lp->index;
+if (match_lp (lp, &exception_types)) {
+*cfun->eh->throw_stmt_table->get (const_cast 
(stmt)) = lp->index;
 return;
 }
 break;
@@ -2360,7 +2360,7 @@ void update_stmt_eh_region(gimple *stmt) {
 return;
 
 case ERT_ALLOWED_EXCEPTIONS:
-if (!match_lp(lp, &exception_types)) {
+if (!match_lp (lp, &exception_types)) {
 return;
 }
 break;
@@ -2371,7 +2371,7 @@ void update_stmt_eh_region(gimple *stmt) {
 region = region->outer;
 }
 
-remove_stmt_from_eh_lp_fn(cfun, stmt);
+remove_stmt_from_eh_lp_fn (cfun, stmt);
 }
 
 /* Create the single EH edge from STMT to its nearest landing pad,
@@ -3016,7 +3016,7 @@ stmt_could_throw_1_p (gassign *stmt)
   return false;
 }
 
-void extract_exception_types_for_call (gcall *call_stmt, vec 
*ret_vector) {
+void extract_types_for_call (gcall *call_stmt, vec *ret_vector) {
 tree callee = gimple_call_fndecl (call_stmt);
 if (callee == NULL_TREE) {
 return;
@@ -3045,7 +3045,7 @@ bool stmt_throw_types (function *fun, gimple *stmt, 
vec *ret_vector) {
 
 switch (gimple_code (stmt)) {
 case GIMPLE_CALL:
-extract_exception_types_for_call (as_a (stmt), ret_vector);
+extract_types_for_call (as_a (stmt), ret_vector);
 return !ret_vector->is_empty ();
 
 default:


[gcc/devel/nothrow-detection] RESX statement processing functions added:

2024-09-30 Thread Pranil Dey via Gcc-cvs
https://gcc.gnu.org/g:d1a84d379d65c8d11a1f81e54f41d98cbce03cd7

commit d1a84d379d65c8d11a1f81e54f41d98cbce03cd7
Author: Pranil Dey 
Date:   Sat Sep 21 03:06:48 2024 +0530

RESX statement processing functions added:

1. extract_types_for_resx - Used as a helper for getting the types from a 
resx statement to use later in the extract_fun_resx_types
2. extract_fun_resx_types - Used for getting the types thrown and 
propagated outside a function

Diff:
---
 gcc/tree-eh.cc | 65 ++
 1 file changed, 65 insertions(+)

diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
index e7e4bd191628..121cbed505b8 100644
--- a/gcc/tree-eh.cc
+++ b/gcc/tree-eh.cc
@@ -3053,6 +3053,71 @@ bool stmt_throw_types (function *fun, gimple *stmt, 
vec *ret_vector) {
 }
 }
 
+// To get the all exception types from a resx stmt  
+void extract_types_for_resx (gimple *resx_stmt, vec *ret_vector) {
+   edge e;
+   edge_iterator ei;
+   
+  basic_block bb = gimple_bb (resx_stmt);
+   
+  // Iterate over edges to walk up the basic blocks
+  FOR_EACH_EDGE (e, ei, bb->pred)
+  {
+   // Get the last stmt of the basic block as it is an EH stmt
+   bb = e->src;
+   gimple_stmt_iterator gsi = gsi_last_bb (bb);
+ gimple *last_stmt = gsi_stmt (gsi);
+   
+ if (bb->aux)continue;
+ bb->aux = (void*)1;
+   
+ if (e->flags & EDGE_EH){
+  if (gimple_code (last_stmt) == GIMPLE_CALL) {
+// check if its a throw
+extract_types_for_call (as_a (last_stmt), ret_vector);
+continue;
+  }
+  else if (gimple_code(last_stmt) == GIMPLE_RESX){
+// Recursively processing resx
+extract_types_for_resx (last_stmt, ret_vector);
+continue;
+  }
+   
+}
+   else extract_types_for_resx (last_stmt, ret_vector);
+  }
+}
+
+// To get the types being thrown outside of a function
+void extract_fun_resx_types (function *fun){
+   basic_block bb;
+   gimple_stmt_iterator gsi;
+   vec *exception_types;
+
+   FOR_EACH_BB_FN (bb, fun)
+   {
+   bb->aux = (void*)1;
+   gsi = gsi_last_bb (bb);
+   gimple *stmt = gsi_stmt (gsi);
+   vec *ret_vector;
+
+   if (stmt_can_throw_external (stmt)){
+   if (gimple_code (stmt) == GIMPLE_RESX){
+   extract_types_for_resx (stmt, ret_vector);
+   }
+   
+   else if (gimple_code (stmt) == GIMPLE_CALL){
+   extract_types_for_call (as_a (stmt), 
ret_vector);
+   }
+   }
+
+   for (unsigned i = 0;ilength ();++i){
+   tree type = (*ret_vector)[i];
+   exception_types->safe_push (type);
+   }
+   }
+}
+
 /* Return true if statement STMT within FUN could throw an exception.  */
 
 bool


[gcc/devel/nothrow-detection] Added functions extract_fun_resx_types

2024-09-30 Thread Pranil Dey via Gcc-cvs
https://gcc.gnu.org/g:5f1a438ba69b855103cec32eecde60fd7e4415b0

commit 5f1a438ba69b855103cec32eecde60fd7e4415b0
Author: Pranil Dey 
Date:   Tue Oct 1 10:00:59 2024 +0530

Added functions extract_fun_resx_types

Diff:
---
 gcc/tree-eh.cc | 138 +
 1 file changed, 138 insertions(+)

diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
index 8e7629164b7d..89640c0faf6d 100644
--- a/gcc/tree-eh.cc
+++ b/gcc/tree-eh.cc
@@ -49,6 +49,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimplify.h"
 #include "print-tree.h"
 #include "ipa-utils.h"
+#include "print-tree.h"
+#include "ipa-utils.h"
 #include "hash-set.h"
 
 /* In some instances a tree and a gimple need to be stored in a same table,
@@ -2275,6 +2277,106 @@ make_eh_dispatch_edges (geh_dispatch *stmt)
 }
 bool
 same_or_derived_type (tree t1, tree t2)
+{
+  t1 = TYPE_MAIN_VARIANT (t1);
+  t2 = TYPE_MAIN_VARIANT (t2);
+  if (t1 == t2)
+return true;
+  while ((TREE_CODE (t1) == POINTER_TYPE || TREE_CODE (t1) == REFERENCE_TYPE)
+&& TREE_CODE (t1) == TREE_CODE (t2))
+  {
+t1 = TYPE_MAIN_VARIANT (TREE_TYPE (t1));
+t2 = TYPE_MAIN_VARIANT (TREE_TYPE (t2));
+  }
+  if (t1 == t2)
+return true;
+  if (!AGGREGATE_TYPE_P (t1) || !AGGREGATE_TYPE_P (t2))
+return false;
+  return odr_equivalent_or_derived_p (t1, t2);
+}
+
+// Check if a landing pad can handle any of the given exception types
+bool match_lp(eh_landing_pad lp, vec *exception_types) {
+eh_region region = lp->region;
+
+// Ensure the region is of type ERT_TRY
+if (region && region->type == ERT_TRY) {
+eh_catch_d *catch_handler = region->u.eh_try.first_catch;
+
+while (catch_handler) {
+tree type_list = catch_handler->type_list;
+
+   if (!type_list)
+ return true;
+
+for (tree t = type_list; t; t = TREE_CHAIN(t)) {
+tree type = TREE_VALUE(t);
+for (unsigned i = 0; i < exception_types->length(); ++i) {
+  // match found or a catch-all handler (NULL)
+if (!type || same_or_derived_type ((*exception_types)[i], 
type)) {
+return true;
+}
+}
+}
+catch_handler = catch_handler->next_catch;
+}
+}
+return false;
+}
+
+// Function to update landing pad in throw_stmt_table for a given statement
+void update_stmt_eh_region(gimple *stmt) {
+  auto_vec exception_types;
+  if (!stmt_throw_types (cfun, stmt, &exception_types)) {
+return;
+}
+
+int lp_nr = lookup_stmt_eh_lp_fn(cfun, stmt);
+if (lp_nr <= 0) {
+return;
+}
+
+eh_landing_pad lp = get_eh_landing_pad_from_number(lp_nr);
+if (!lp) {
+return;
+}
+
+eh_region region = lp->region;
+
+// Walk up the region tree
+while (region) {
+switch (region->type) {
+case ERT_CLEANUP:
+*cfun->eh->throw_stmt_table->get(const_cast(stmt)) = 
lp->index;
+return;
+
+case ERT_TRY:
+if (match_lp(lp, &exception_types)) {
+*cfun->eh->throw_stmt_table->get(const_cast(stmt)) = lp->index;
+return;
+}
+break;
+
+case ERT_MUST_NOT_THROW:
+// Undefined behavior, leave edge unchanged
+return;
+
+case ERT_ALLOWED_EXCEPTIONS:
+if (!match_lp(lp, &exception_types)) {
+return;
+}
+break;
+
+default:
+break;
+}
+region = region->outer;
+}
+
+remove_stmt_from_eh_lp_fn(cfun, stmt);
+}
+bool
+same_or_derived_type (tree t1, tree t2)
 {
   t1 = TYPE_MAIN_VARIANT (t1);
   t2 = TYPE_MAIN_VARIANT (t2);
@@ -3029,6 +3131,42 @@ stmt_could_throw_1_p (gassign *stmt)
   return false;
 }
 
+void extract_exception_types_for_call (gcall *call_stmt, vec 
*ret_vector) {
+tree callee = gimple_call_fndecl (call_stmt);
+if (callee == NULL_TREE) {
+return;
+  }
+  if (strcmp (IDENTIFIER_POINTER (DECL_NAME (callee)), "__cxa_throw") == 
0) {
+  // Extracting exception type
+  tree exception_type_info = gimple_call_arg (call_stmt, 1); 
+  if (exception_type_info && TREE_CODE (exception_type_info) == 
ADDR_EXPR) {
+  exception_type_info = TREE_OPERAND (exception_type_info, 0);
+  }
+  if (exception_type_info && TREE_CODE (exception_type_info) == 
VAR_DECL) {
+  // Converting the typeinfo to a compile-time type
+  tree exception_type = TREE_TYPE (exception_type_info);
+  if (exception_type) {
+  ret_vector->safe_push (exception_type);
+  }
+  }
+  }
+}
+
+// Determine which types can be thrown by a GIMPLE statement and convert them 
to compile-time types
+bool stmt_th

[gcc/devel/nothrow-detection] Added some functions and fixed some testcase failures

2024-09-30 Thread Pranil Dey via Gcc-cvs
https://gcc.gnu.org/g:ba70ece43622eb4da97455fb78c42c7e9c7f8ce6

commit ba70ece43622eb4da97455fb78c42c7e9c7f8ce6
Author: Pranil Dey 
Date:   Sun Aug 25 01:25:26 2024 +0530

Added some functions and fixed some testcase failures

1. odr_equivalent_or_derived_p in ipa-devirt.cc
2. same_or_derived_type in in tree-eh.cc
3. Fixed catch-all handling in match_lp function

Diff:
---
 gcc/ipa-devirt.cc | 24 
 gcc/ipa-utils.h   |  1 +
 gcc/tree-eh.cc| 27 ++-
 3 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/gcc/ipa-devirt.cc b/gcc/ipa-devirt.cc
index a7ce434bffb4..17271b089b74 100644
--- a/gcc/ipa-devirt.cc
+++ b/gcc/ipa-devirt.cc
@@ -1211,6 +1211,30 @@ skip_in_fields_list_p (tree t)
   return false;
 }
 
+/* Return true if T2 is derived form T1.  */
+
+bool
+odr_equivalent_or_derived_p (tree t1, tree t2)
+{
+  if (in_lto_p)
+{
+  if (odr_types_equivalent_p (t1, t2))
+   return true;
+}
+  else
+{
+  if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
+   return true;
+}
+  if (!TYPE_BINFO (t2))
+return false;
+  for (unsigned int i = 0; i < BINFO_N_BASE_BINFOS (TYPE_BINFO (t2)); i++)
+if (odr_equivalent_or_derived_p
+(t1, BINFO_TYPE (BINFO_BASE_BINFO (TYPE_BINFO (t2), i
+return true;
+  return false;
+}
+
 /* Compare T1 and T2, report ODR violations if WARN is true and set
WARNED to true if anything is reported.  Return true if types match.
If true is returned, the types are also compatible in the sense of
diff --git a/gcc/ipa-utils.h b/gcc/ipa-utils.h
index d1da9c31e09e..908b425e98c5 100644
--- a/gcc/ipa-utils.h
+++ b/gcc/ipa-utils.h
@@ -106,6 +106,7 @@ cgraph_node *try_speculative_devirtualization (tree, 
HOST_WIDE_INT,
 void warn_types_mismatch (tree t1, tree t2, location_t loc1 = UNKNOWN_LOCATION,
  location_t loc2 = UNKNOWN_LOCATION);
 bool odr_or_derived_type_p (const_tree t);
+bool odr_equivalent_or_derived_p (tree t1, tree t2);
 bool odr_types_equivalent_p (tree type1, tree type2);
 bool odr_type_violation_reported_p (tree type);
 tree prevailing_odr_type (tree type);
diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
index eec1e6af70d7..4d541b08c2fc 100644
--- a/gcc/tree-eh.cc
+++ b/gcc/tree-eh.cc
@@ -47,6 +47,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "attribs.h"
 #include "asan.h"
 #include "gimplify.h"
+#include "print-tree.h"
+#include "ipa-utils.h"
 
 /* In some instances a tree and a gimple need to be stored in a same table,
i.e. in hash tables. This is a structure to do this. */
@@ -2270,6 +2272,25 @@ make_eh_dispatch_edges (geh_dispatch *stmt)
 
   return true;
 }
+bool
+same_or_derived_type (tree t1, tree t2)
+{
+  t1 = TYPE_MAIN_VARIANT (t1);
+  t2 = TYPE_MAIN_VARIANT (t2);
+  if (t1 == t2)
+return true;
+  while ((TREE_CODE (t1) == POINTER_TYPE || TREE_CODE (t1) == REFERENCE_TYPE)
+&& TREE_CODE (t1) == TREE_CODE (t2))
+  {
+t1 = TYPE_MAIN_VARIANT (TREE_TYPE (t1));
+t2 = TYPE_MAIN_VARIANT (TREE_TYPE (t2));
+  }
+  if (t1 == t2)
+return true;
+  if (!AGGREGATE_TYPE_P (t1) || !AGGREGATE_TYPE_P (t2))
+return false;
+  return odr_equivalent_or_derived_p (t1, t2);
+}
 
 // Check if a landing pad can handle any of the given exception types
 bool match_lp(eh_landing_pad lp, vec *exception_types) {
@@ -2282,11 +2303,15 @@ bool match_lp(eh_landing_pad lp, vec 
*exception_types) {
 while (catch_handler) {
 tree type_list = catch_handler->type_list;
 
+if(type_list == NULL) {
+return true;
+}
+
 for (tree t = type_list; t; t = TREE_CHAIN(t)) {
 tree type = TREE_VALUE(t);
 for (unsigned i = 0; i < exception_types->length(); ++i) {
   // match found or a catch-all handler (NULL)
-if (type == (*exception_types)[i] || !type) {
+if (!type || same_or_derived_type ((*exception_types)[i], 
type)) {
 return true;
 }
 }


[gcc/devel/nothrow-detection] Updated parameters of functions and typecasted resx stmts

2024-09-30 Thread Pranil Dey via Gcc-cvs
https://gcc.gnu.org/g:079ca47d41e5030c63cca7f8ee679e7323a26d45

commit 079ca47d41e5030c63cca7f8ee679e7323a26d45
Author: Pranil Dey 
Date:   Tue Oct 1 09:46:48 2024 +0530

Updated parameters of functions and typecasted resx stmts

Diff:
---
 gcc/tree-eh.cc | 23 +--
 gcc/tree-eh.h  |  2 +-
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
index ea9a2ca6bb00..8e7629164b7d 100644
--- a/gcc/tree-eh.cc
+++ b/gcc/tree-eh.cc
@@ -2346,18 +2346,20 @@ void update_stmt_eh_region (gimple *stmt) {
 while (region) {
 switch (region->type) {
 case ERT_CLEANUP:
-if(gimple_code (stmt) == GIMPLE_RESX){
-  gimple_resx_set_region(stmt, region->index);
+if (gimple_code (stmt) == GIMPLE_RESX){
+  gresx *resx_stmt = as_a  (stmt);
+  gimple_resx_set_region (resx_stmt, region->index);
 }
-*cfun->eh->throw_stmt_table->get (const_cast (stmt)) 
= lp->index;
+else *cfun->eh->throw_stmt_table->get (const_cast 
(stmt)) = lp->index;
 return;
 
 case ERT_TRY:
 if (match_lp (lp, &exception_types)) {
-  if(gimple_code (stmt) == GIMPLE_RESX){
-gimple_resx_set_region(stmt, region->index);
+  if (gimple_code (stmt) == GIMPLE_RESX){
+gresx *resx_stmt = as_a  (stmt);
+gimple_resx_set_region (resx_stmt, region->index);
   }
-  *cfun->eh->throw_stmt_table->get (const_cast 
(stmt)) = lp->index;
+  else *cfun->eh->throw_stmt_table->get (const_cast 
(stmt)) = lp->index;
   return;
 }
 break;
@@ -2378,8 +2380,9 @@ void update_stmt_eh_region (gimple *stmt) {
 region = region->outer;
 }
 
-if(gimple_code (stmt) == GIMPLE_RESX){
-  gimple_resx_set_region(stmt, -1);
+if (gimple_code (stmt) == GIMPLE_RESX){
+  gresx *resx_stmt = as_a  (stmt);
+  gimple_resx_set_region (resx_stmt, 0);
 }
 else remove_stmt_from_eh_lp_fn (cfun, stmt);
 }
@@ -3075,7 +3078,7 @@ void extract_types_for_resx (gimple *resx_stmt, vec 
*ret_vector) {
   basic_block bb = gimple_bb (resx_stmt);

   // Iterate over edges to walk up the basic blocks
-  FOR_EACH_EDGE (e, ei, bb->pred)
+  FOR_EACH_EDGE (e, ei, bb->preds)
   {
// Get the last stmt of the basic block as it is an EH stmt
bb = e->src;
@@ -3115,7 +3118,7 @@ void extract_fun_resx_types (function *fun, vec 
*ret_vector) {
gimple *stmt = gsi_stmt (gsi);
vec *ret_vector;
 
-   if (stmt_can_throw_external (stmt)){
+   if (stmt_can_throw_external (fun, stmt)){
if (gimple_code (stmt) == GIMPLE_RESX){
extract_types_for_resx (stmt, ret_vector);
}
diff --git a/gcc/tree-eh.h b/gcc/tree-eh.h
index ea5cefc9fd29..4d816fd93c85 100644
--- a/gcc/tree-eh.h
+++ b/gcc/tree-eh.h
@@ -44,7 +44,7 @@ extern tree rewrite_to_non_trapping_overflow (tree);
 extern void extract_exception_types_for_call (gcall *, vec *);
 extern bool stmt_throw_types (function *, gimple *, vec *);
 extern void extract_types_for_resx (gimple *, vec *);
-extern void extract_fun_resx_types (function *);
+extern void extract_fun_resx_types (function *, vec *);
 extern bool stmt_could_throw_p (function *, gimple *);
 extern bool stmt_unremovable_because_of_non_call_eh_p (function *, gimple *);
 extern bool tree_could_throw_p (tree);


[gcc/devel/nothrow-detection] Reolved some conflicts

2024-09-30 Thread Pranil Dey via Gcc-cvs
https://gcc.gnu.org/g:97933e95963b2d91da147fb9e1639434f9a7a049

commit 97933e95963b2d91da147fb9e1639434f9a7a049
Author: Pranil Dey 
Date:   Tue Oct 1 10:03:43 2024 +0530

Reolved some conflicts

Diff:
---
 gcc/tree-eh.cc | 36 
 1 file changed, 36 deletions(-)

diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
index 89640c0faf6d..6ed705d6ebe9 100644
--- a/gcc/tree-eh.cc
+++ b/gcc/tree-eh.cc
@@ -3131,42 +3131,6 @@ stmt_could_throw_1_p (gassign *stmt)
   return false;
 }
 
-void extract_exception_types_for_call (gcall *call_stmt, vec 
*ret_vector) {
-tree callee = gimple_call_fndecl (call_stmt);
-if (callee == NULL_TREE) {
-return;
-  }
-  if (strcmp (IDENTIFIER_POINTER (DECL_NAME (callee)), "__cxa_throw") == 
0) {
-  // Extracting exception type
-  tree exception_type_info = gimple_call_arg (call_stmt, 1); 
-  if (exception_type_info && TREE_CODE (exception_type_info) == 
ADDR_EXPR) {
-  exception_type_info = TREE_OPERAND (exception_type_info, 0);
-  }
-  if (exception_type_info && TREE_CODE (exception_type_info) == 
VAR_DECL) {
-  // Converting the typeinfo to a compile-time type
-  tree exception_type = TREE_TYPE (exception_type_info);
-  if (exception_type) {
-  ret_vector->safe_push (exception_type);
-  }
-  }
-  }
-}
-
-// Determine which types can be thrown by a GIMPLE statement and convert them 
to compile-time types
-bool stmt_throw_types (function *fun, gimple *stmt, vec *ret_vector) {
-if (!flag_exceptions) {
-return false;
-}
-
-switch (gimple_code (stmt)) {
-case GIMPLE_CALL:
-extract_exception_types_for_call (as_a (stmt), ret_vector);
-return !ret_vector->is_empty ();
-
-default:
-return false;
-}
-}
 void extract_types_for_call (gcall *call_stmt, vec *ret_vector) {
 tree callee = gimple_call_fndecl (call_stmt);
 if (callee == NULL_TREE) {


[gcc/devel/nothrow-detection] Merge remote-tracking branch 'origin/devel/nothrow-detection' into devel/nothrow-detection

2024-09-30 Thread Pranil Dey via Gcc-cvs
https://gcc.gnu.org/g:6db81730ef66c0f557b78c9a67a33b6eec2f040e

commit 6db81730ef66c0f557b78c9a67a33b6eec2f040e
Merge: 079ca47d41e5 b602de4ed9f8
Author: Pranil Dey 
Date:   Tue Oct 1 10:00:26 2024 +0530

Merge remote-tracking branch 'origin/devel/nothrow-detection' into 
devel/nothrow-detection

Diff:

 gcc/ipa-devirt.cc | 4 ++--
 gcc/tree-eh.h | 3 +++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --cc gcc/tree-eh.h
index 4d816fd93c85,f3b2c16ed77e..4fa134b43ddc
--- a/gcc/tree-eh.h
+++ b/gcc/tree-eh.h
@@@ -23,6 -23,6 +23,7 @@@ along with GCC; see the file COPYING3
  
  typedef struct eh_region_d *eh_region;
  typedef struct eh_landing_pad_d *eh_landing_pad;
++typedef struct eh_landing_pad_d *eh_landing_pad;
  
  extern void using_eh_for_cleanups (void);
  extern void add_stmt_to_eh_lp (gimple *, int);
@@@ -33,6 -33,6 +34,8 @@@ extern int lookup_stmt_eh_lp (const gim
  extern bool make_eh_dispatch_edges (geh_dispatch *);
  extern bool match_lp (eh_landing_pad, vec *);
  extern void update_stmt_eh_region(gimple *);
++extern bool match_lp (eh_landing_pad, vec *);
++extern void update_stmt_eh_region(gimple *);
  extern edge make_eh_edge (gimple *);
  extern edge redirect_eh_edge (edge, basic_block);
  extern void redirect_eh_dispatch_edge (geh_dispatch *, edge, basic_block);


[gcc/devel/nothrow-detection] Added the previous functions to the tree-eh.h file

2024-09-30 Thread Pranil Dey via Gcc-cvs
https://gcc.gnu.org/g:47c2d0f6e02b3aed9f0cdbb27ae62bff4e707390

commit 47c2d0f6e02b3aed9f0cdbb27ae62bff4e707390
Author: Pranil Dey 
Date:   Sat Sep 21 03:13:43 2024 +0530

Added the previous functions to the tree-eh.h file

Functions added:
1. void extract_types_for_resx (gimple *, vec *);
2. void extract_fun_resx_types (function *);

Diff:
---
 gcc/tree-eh.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/tree-eh.h b/gcc/tree-eh.h
index f3b2c16ed77e..ea5cefc9fd29 100644
--- a/gcc/tree-eh.h
+++ b/gcc/tree-eh.h
@@ -43,6 +43,8 @@ extern bool tree_could_trap_p (tree);
 extern tree rewrite_to_non_trapping_overflow (tree);
 extern void extract_exception_types_for_call (gcall *, vec *);
 extern bool stmt_throw_types (function *, gimple *, vec *);
+extern void extract_types_for_resx (gimple *, vec *);
+extern void extract_fun_resx_types (function *);
 extern bool stmt_could_throw_p (function *, gimple *);
 extern bool stmt_unremovable_because_of_non_call_eh_p (function *, gimple *);
 extern bool tree_could_throw_p (tree);


[gcc/devel/nothrow-detection] removed conflicts

2024-09-30 Thread Pranil Dey via Gcc-cvs
https://gcc.gnu.org/g:5a924600ea2f5fc3aee95385117ffaf492fa9203

commit 5a924600ea2f5fc3aee95385117ffaf492fa9203
Author: Pranil Dey 
Date:   Tue Oct 1 10:10:17 2024 +0530

removed conflicts

Diff:
---
 gcc/tree-eh.cc | 99 --
 1 file changed, 99 deletions(-)

diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
index 6ed705d6ebe9..37eb6081eca9 100644
--- a/gcc/tree-eh.cc
+++ b/gcc/tree-eh.cc
@@ -2275,106 +2275,7 @@ make_eh_dispatch_edges (geh_dispatch *stmt)
 
   return true;
 }
-bool
-same_or_derived_type (tree t1, tree t2)
-{
-  t1 = TYPE_MAIN_VARIANT (t1);
-  t2 = TYPE_MAIN_VARIANT (t2);
-  if (t1 == t2)
-return true;
-  while ((TREE_CODE (t1) == POINTER_TYPE || TREE_CODE (t1) == REFERENCE_TYPE)
-&& TREE_CODE (t1) == TREE_CODE (t2))
-  {
-t1 = TYPE_MAIN_VARIANT (TREE_TYPE (t1));
-t2 = TYPE_MAIN_VARIANT (TREE_TYPE (t2));
-  }
-  if (t1 == t2)
-return true;
-  if (!AGGREGATE_TYPE_P (t1) || !AGGREGATE_TYPE_P (t2))
-return false;
-  return odr_equivalent_or_derived_p (t1, t2);
-}
-
-// Check if a landing pad can handle any of the given exception types
-bool match_lp(eh_landing_pad lp, vec *exception_types) {
-eh_region region = lp->region;
-
-// Ensure the region is of type ERT_TRY
-if (region && region->type == ERT_TRY) {
-eh_catch_d *catch_handler = region->u.eh_try.first_catch;
-
-while (catch_handler) {
-tree type_list = catch_handler->type_list;
-
-   if (!type_list)
- return true;
-
-for (tree t = type_list; t; t = TREE_CHAIN(t)) {
-tree type = TREE_VALUE(t);
-for (unsigned i = 0; i < exception_types->length(); ++i) {
-  // match found or a catch-all handler (NULL)
-if (!type || same_or_derived_type ((*exception_types)[i], 
type)) {
-return true;
-}
-}
-}
-catch_handler = catch_handler->next_catch;
-}
-}
-return false;
-}
-
-// Function to update landing pad in throw_stmt_table for a given statement
-void update_stmt_eh_region(gimple *stmt) {
-  auto_vec exception_types;
-  if (!stmt_throw_types (cfun, stmt, &exception_types)) {
-return;
-}
-
-int lp_nr = lookup_stmt_eh_lp_fn(cfun, stmt);
-if (lp_nr <= 0) {
-return;
-}
-
-eh_landing_pad lp = get_eh_landing_pad_from_number(lp_nr);
-if (!lp) {
-return;
-}
-
-eh_region region = lp->region;
-
-// Walk up the region tree
-while (region) {
-switch (region->type) {
-case ERT_CLEANUP:
-*cfun->eh->throw_stmt_table->get(const_cast(stmt)) = 
lp->index;
-return;
 
-case ERT_TRY:
-if (match_lp(lp, &exception_types)) {
-*cfun->eh->throw_stmt_table->get(const_cast(stmt)) = lp->index;
-return;
-}
-break;
-
-case ERT_MUST_NOT_THROW:
-// Undefined behavior, leave edge unchanged
-return;
-
-case ERT_ALLOWED_EXCEPTIONS:
-if (!match_lp(lp, &exception_types)) {
-return;
-}
-break;
-
-default:
-break;
-}
-region = region->outer;
-}
-
-remove_stmt_from_eh_lp_fn(cfun, stmt);
-}
 bool
 same_or_derived_type (tree t1, tree t2)
 {


[gcc/devel/nothrow-detection] Integrated the resx functions with stmt_throw_types

2024-09-30 Thread Pranil Dey via Gcc-cvs
https://gcc.gnu.org/g:7ec787200301f75109c41d7c4a82891971dbd62b

commit 7ec787200301f75109c41d7c4a82891971dbd62b
Author: Pranil Dey 
Date:   Mon Sep 30 18:39:14 2024 +0530

Integrated the resx functions with stmt_throw_types

update_stmt_eh_region updated for resx stmt support and 
extract_fun_resx_types fixed

Diff:
---
 gcc/tree-eh.cc | 34 +++---
 1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
index 121cbed505b8..ea9a2ca6bb00 100644
--- a/gcc/tree-eh.cc
+++ b/gcc/tree-eh.cc
@@ -49,6 +49,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimplify.h"
 #include "print-tree.h"
 #include "ipa-utils.h"
+#include "hash-set.h"
 
 /* In some instances a tree and a gimple need to be stored in a same table,
i.e. in hash tables. This is a structure to do this. */
@@ -2345,13 +2346,19 @@ void update_stmt_eh_region (gimple *stmt) {
 while (region) {
 switch (region->type) {
 case ERT_CLEANUP:
+if(gimple_code (stmt) == GIMPLE_RESX){
+  gimple_resx_set_region(stmt, region->index);
+}
 *cfun->eh->throw_stmt_table->get (const_cast (stmt)) 
= lp->index;
 return;
 
 case ERT_TRY:
 if (match_lp (lp, &exception_types)) {
-*cfun->eh->throw_stmt_table->get (const_cast 
(stmt)) = lp->index;
-return;
+  if(gimple_code (stmt) == GIMPLE_RESX){
+gimple_resx_set_region(stmt, region->index);
+  }
+  *cfun->eh->throw_stmt_table->get (const_cast 
(stmt)) = lp->index;
+  return;
 }
 break;
 
@@ -2371,7 +2378,10 @@ void update_stmt_eh_region (gimple *stmt) {
 region = region->outer;
 }
 
-remove_stmt_from_eh_lp_fn (cfun, stmt);
+if(gimple_code (stmt) == GIMPLE_RESX){
+  gimple_resx_set_region(stmt, -1);
+}
+else remove_stmt_from_eh_lp_fn (cfun, stmt);
 }
 
 /* Create the single EH edge from STMT to its nearest landing pad,
@@ -3044,10 +3054,14 @@ bool stmt_throw_types (function *fun, gimple *stmt, 
vec *ret_vector) {
 }
 
 switch (gimple_code (stmt)) {
+case GIMPLE_RESX:
+extract_fun_resx_types (fun, ret_vector);
+return !ret_vector->is_empty ();
+
 case GIMPLE_CALL:
 extract_types_for_call (as_a (stmt), ret_vector);
 return !ret_vector->is_empty ();
-
+  
 default:
 return false;
 }
@@ -3089,10 +3103,10 @@ void extract_types_for_resx (gimple *resx_stmt, 
vec *ret_vector) {
 }
 
 // To get the types being thrown outside of a function
-void extract_fun_resx_types (function *fun){
+void extract_fun_resx_types (function *fun, vec *ret_vector) {
basic_block bb;
gimple_stmt_iterator gsi;
-   vec *exception_types;
+  hash_set *types;
 
FOR_EACH_BB_FN (bb, fun)
{
@@ -3113,9 +3127,15 @@ void extract_fun_resx_types (function *fun){
 
for (unsigned i = 0;ilength ();++i){
tree type = (*ret_vector)[i];
-   exception_types->safe_push (type);
+ types->add (type);
}
}
+
+  for (auto it = types->begin(); it != types->end(); ++it) {
+ret_vector->safe_push(*it);
+  }
+
+  clear_aux_for_blocks ();
 }
 
 /* Return true if statement STMT within FUN could throw an exception.  */


[gcc/devel/nothrow-detection] resolved more conflicts

2024-09-30 Thread Pranil Dey via Gcc-cvs
https://gcc.gnu.org/g:27be11a6b2fe5c91f60460e01c30ca5c4fddf58a

commit 27be11a6b2fe5c91f60460e01c30ca5c4fddf58a
Author: Pranil Dey 
Date:   Tue Oct 1 10:12:35 2024 +0530

resolved more conflicts

Diff:
---
 gcc/tree-eh.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/gcc/tree-eh.h b/gcc/tree-eh.h
index 4fa134b43ddc..978bc6228bf0 100644
--- a/gcc/tree-eh.h
+++ b/gcc/tree-eh.h
@@ -34,8 +34,6 @@ extern int lookup_stmt_eh_lp (const gimple *);
 extern bool make_eh_dispatch_edges (geh_dispatch *);
 extern bool match_lp (eh_landing_pad, vec *);
 extern void update_stmt_eh_region(gimple *);
-extern bool match_lp (eh_landing_pad, vec *);
-extern void update_stmt_eh_region(gimple *);
 extern edge make_eh_edge (gimple *);
 extern edge redirect_eh_edge (edge, basic_block);
 extern void redirect_eh_dispatch_edge (geh_dispatch *, edge, basic_block);


[gcc r15-3959] middle-end: check explicitly for external or constants when checking for loop invariant [PR116817]

2024-09-30 Thread Tamar Christina via Gcc-cvs
https://gcc.gnu.org/g:87905f63a6521eef1f38082e2368e18c637ef092

commit r15-3959-g87905f63a6521eef1f38082e2368e18c637ef092
Author: Tamar Christina 
Date:   Mon Sep 30 13:06:24 2024 +0100

middle-end: check explicitly for external or constants when checking for 
loop invariant [PR116817]

The previous check if a value was external was checking
!vect_get_internal_def (vinfo, var) but this of course isn't completely 
right
as they could reductions etc.

This changes the check to just explicitly look at externals and constants.
Note that reductions remain unhandled here, but we don't support codegen of
boolean reductions today anyway.

So at the time we do then this would have the be handled as well in 
lowering.

gcc/ChangeLog:

PR tree-optimization/116817
* tree-vect-patterns.cc (vect_recog_bool_pattern): Check for const 
or
externals.

gcc/testsuite/ChangeLog:

PR tree-optimization/116817
* g++.dg/vect/pr116817.cc: New test.

Diff:
---
 gcc/testsuite/g++.dg/vect/pr116817.cc | 16 
 gcc/tree-vect-patterns.cc |  5 -
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/vect/pr116817.cc 
b/gcc/testsuite/g++.dg/vect/pr116817.cc
new file mode 100644
index ..7e28982fb138
--- /dev/null
+++ b/gcc/testsuite/g++.dg/vect/pr116817.cc
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-O3" } */
+
+int main_ulData0;
+unsigned *main_pSrcBuffer;
+int main(void) {
+  int iSrc = 0;
+  bool bData0;
+  for (; iSrc < 4; iSrc++) {
+if (bData0)
+  main_pSrcBuffer[iSrc] = main_ulData0;
+else
+  main_pSrcBuffer[iSrc] = 0;
+bData0 = !bData0;
+  }
+}
diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index e7e877dd2adb..b174ff1e705c 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -6062,12 +6062,15 @@ vect_recog_bool_pattern (vec_info *vinfo,
   if (get_vectype_for_scalar_type (vinfo, type) == NULL_TREE)
return NULL;
 
+  enum vect_def_type dt;
   if (check_bool_pattern (var, vinfo, bool_stmts))
var = adjust_bool_stmts (vinfo, bool_stmts, type, stmt_vinfo);
   else if (integer_type_for_mask (var, vinfo))
return NULL;
   else if (TREE_CODE (TREE_TYPE (var)) == BOOLEAN_TYPE
-  && !vect_get_internal_def (vinfo, var))
+  && vect_is_simple_use (var, vinfo, &dt)
+  && (dt == vect_external_def
+  || dt == vect_constant_def))
{
  /* If the condition is already a boolean then manually convert it to a
 mask of the given integer type but don't set a vectype.  */


[gcc r15-3960] tree-optimization/116879 - failure to recognize non-empty latch

2024-09-30 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:18e905b461a7138185cf4f0efde4a4e1214fb798

commit r15-3960-g18e905b461a7138185cf4f0efde4a4e1214fb798
Author: Richard Biener 
Date:   Mon Sep 30 13:38:28 2024 +0200

tree-optimization/116879 - failure to recognize non-empty latch

When we relaxed the vectorizers constraint on loop structure verifying
the emptiness of the latch became too lose as can be seen in the case
for PR116879 where the latch effectively contains two basic-blocks
which one being an unmerged forwarder that's not empty.

PR tree-optimization/116879
* tree-vect-loop.cc (vect_analyze_loop_form): Scan all
blocks that form the latch.

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

Diff:
---
 gcc/testsuite/gcc.dg/pr116879.c | 15 +++
 gcc/tree-vect-loop.cc   | 15 +++
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/pr116879.c b/gcc/testsuite/gcc.dg/pr116879.c
new file mode 100644
index ..73ddb2b658c9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr116879.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -ftree-vectorize -fallow-store-data-races -fno-tree-ch 
-ftree-loop-distribution" } */
+
+static int b;
+int *a, c, *d = &c;
+int main() {
+  int e = 0;
+  for (; e < 8; e = (char)(e + 1)) {
+int *f = &b, g[8], h = 0;
+for (; h < 8; h++)
+  g[h] = 0;
+--*f != (*d = g[0] || a);
+  }
+  return 0;
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 5cd4bdb32e04..0ce1bf8ebbac 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -1851,10 +1851,17 @@ vect_analyze_loop_form (class loop *loop, 
vect_loop_form_info *info)
   " too many incoming edges.\n");
 
   /* We assume that the latch is empty.  */
-  if (!empty_block_p (loop->latch)
-  || !gimple_seq_empty_p (phi_nodes (loop->latch)))
-return opt_result::failure_at (vect_location,
-  "not vectorized: latch block not empty.\n");
+  basic_block latch = loop->latch;
+  do
+{
+  if (!empty_block_p (latch)
+ || !gimple_seq_empty_p (phi_nodes (latch)))
+   return opt_result::failure_at (vect_location,
+  "not vectorized: latch block not "
+  "empty.\n");
+  latch = single_pred (latch);
+}
+  while (single_succ_p (latch));
 
   /* Make sure there is no abnormal exit.  */
   auto_vec exits = get_loop_exit_edges (loop);


[gcc/devel/nothrow-detection] Edge redirection for exceptions.

2024-09-30 Thread Pranil Dey via Gcc-cvs
https://gcc.gnu.org/g:9a70651a2126e4aceefd2ebec63c0cf15ce83695

commit 9a70651a2126e4aceefd2ebec63c0cf15ce83695
Author: Pranil Dey 
Date:   Tue Aug 20 22:07:57 2024 +0530

Edge redirection for exceptions.

 This commit is contains change in code for the tree-eh.cc, tree-eh.h, 
MAINTAINERS and tree-cfg.cc files.
 Specifically it contains four functions -
1. void extract_exception_types_for_call which extracts the exception types 
in a call stmt and adds them into a vector tree.
2. bool stmt_throw_types does the same as stmt_could_throw the difference 
being that it also gives the list of exception types as given by the
 extract_exception_types_for_call function.
3. bool match_lp checks if a landing pad can handle any of the exception 
types given as input parameters by looking into the catch handlers.
4. update_stmt_eh_region is the function that walks up the EH tree and 
changes the landing pad for the last statement in a basic block in the control
 flow graph so that when the edge by make_eh_edge is created it points to 
the correct handlers.

Further work to be done regarding RESX stmts.

Diff:
---
 gcc/tree-cfg.cc |   5 ++-
 gcc/tree-eh.cc  | 114 
 gcc/tree-eh.h   |   5 +++
 3 files changed, 122 insertions(+), 2 deletions(-)

diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
index fcb488d87113..964376d30dcc 100644
--- a/gcc/tree-cfg.cc
+++ b/gcc/tree-cfg.cc
@@ -855,11 +855,12 @@ make_edges_bb (basic_block bb, struct omp_region 
**pcur_region, int *pomp_index)
 
   if (!last)
 return ret;
-
+
+  update_stmt_eh_region(last);
   switch (gimple_code (last))
 {
 case GIMPLE_GOTO:
-  if (make_goto_expr_edges (bb))
+  if (make_goto_expr_edges (bb))  
ret = 1;
   fallthru = false;
   break;
diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
index 9609bdc0d9b7..eec1e6af70d7 100644
--- a/gcc/tree-eh.cc
+++ b/gcc/tree-eh.cc
@@ -2271,6 +2271,84 @@ make_eh_dispatch_edges (geh_dispatch *stmt)
   return true;
 }
 
+// Check if a landing pad can handle any of the given exception types
+bool match_lp(eh_landing_pad lp, vec *exception_types) {
+eh_region region = lp->region;
+
+// Ensure the region is of type ERT_TRY
+if (region && region->type == ERT_TRY) {
+eh_catch_d *catch_handler = region->u.eh_try.first_catch;
+
+while (catch_handler) {
+tree type_list = catch_handler->type_list;
+
+for (tree t = type_list; t; t = TREE_CHAIN(t)) {
+tree type = TREE_VALUE(t);
+for (unsigned i = 0; i < exception_types->length(); ++i) {
+  // match found or a catch-all handler (NULL)
+if (type == (*exception_types)[i] || !type) {
+return true;
+}
+}
+}
+catch_handler = catch_handler->next_catch;
+}
+}
+return false;
+}
+
+// Function to update landing pad in throw_stmt_table for a given statement
+void update_stmt_eh_region(gimple *stmt) {
+  auto_vec exception_types;
+  if (!stmt_throw_types (cfun, stmt, &exception_types)) {
+return;
+}
+
+int lp_nr = lookup_stmt_eh_lp_fn(cfun, stmt);
+if (lp_nr <= 0) {
+return;
+}
+
+eh_landing_pad lp = get_eh_landing_pad_from_number(lp_nr);
+if (!lp) {
+return;
+}
+
+eh_region region = lp->region;
+
+// Walk up the region tree
+while (region) {
+switch (region->type) {
+case ERT_CLEANUP:
+*cfun->eh->throw_stmt_table->get(const_cast(stmt)) = 
lp->index;
+return;
+
+case ERT_TRY:
+if (match_lp(lp, &exception_types)) {
+*cfun->eh->throw_stmt_table->get(const_cast(stmt)) = lp->index;
+return;
+}
+break;
+
+case ERT_MUST_NOT_THROW:
+// Undefined behavior, leave edge unchanged
+return;
+
+case ERT_ALLOWED_EXCEPTIONS:
+if (!match_lp(lp, &exception_types)) {
+return;
+}
+break;
+
+default:
+break;
+}
+region = region->outer;
+}
+
+remove_stmt_from_eh_lp_fn(cfun, stmt);
+}
+
 /* Create the single EH edge from STMT to its nearest landing pad,
if there is such a landing pad within the current function.  */
 
@@ -2913,6 +2991,42 @@ stmt_could_throw_1_p (gassign *stmt)
   return false;
 }
 
+void extract_exception_types_for_call (gcall *call_stmt, vec 
*ret_vector) {
+tree callee = gimple_call_fndecl (call_stmt);
+if (callee == NULL_TREE) {
+return;
+  }
+  if (strcmp (IDENTIFIER_POINTER (DECL_NAME (callee)), "__cxa_throw") == 
0) {
+  // Extracting exception type
+  tree exception_type_info = gimple_call_arg (call_stmt, 1); 
+

[gcc/devel/nothrow-detection] (34 commits) Reolved some conflicts

2024-09-30 Thread Pranil Dey via Gcc-cvs
The branch 'devel/nothrow-detection' was updated to point to:

 97933e95963b... Reolved some conflicts

It previously pointed to:

 b602de4ed9f8... Merge branch 'master' of git+ssh://gcc.gnu.org/git/gcc into

Diff:

Summary of changes (added commits):
---

  97933e9... Reolved some conflicts
  5f1a438... Added functions extract_fun_resx_types
  6db8173... Merge remote-tracking branch 'origin/devel/nothrow-detectio
  079ca47... Updated parameters of functions and typecasted resx stmts
  7ec7872... Integrated the resx functions with stmt_throw_types
  47c2d0f... Added the previous functions to the tree-eh.h file
  d1a84d3... RESX statement processing functions added:
  70505f5... Fixed some indentations and function names
  ba70ece... Added some functions and fixed some testcase failures
  9a70651... Edge redirection for exceptions.
  0939c8c... Daily bump. (*)
  b1696ff... libstdc++-v3: Fix signed-overflow warning for newlib/ctype_ (*)
  ab07db3... [testcase] Fix-absfloat16.c-testcase (*)
  4bcfaae... c++: concept in default argument [PR109859] (*)
  65073a5... Fix internal error during inlining after ICF pass (*)
  9c14f9a... diagnostics: return text buffer from test_show_locus [PR116 (*)
  e7a8fbe... diagnostics: require callers of diagnostic_show_locus to be (*)
  be02253... diagnostics: isolate diagnostic_context with interface clas (*)
  cce5286... diagnostics: avoid using diagnostic_context's m_printer [PR (*)
  3d3d20c... diagnostics: use "%e" to avoid intermediate strings [PR1166 (*)
  4c7a58a... diagnostics: add "dump" to pretty_printer and output_buffer (*)
  3286b67... diagnostics: fix typo in XHTML output [PR116792] (*)
  ab6c7a3... diagnostics: fix memory leak in SARIF selftests (*)
  8398ef9... autovectorizer: Test autovectorization of different dot-pro (*)
  fd35d99... c6x:  Adjust dot-product backend patterns (*)
  113e31c... rs6000: Adjust altivec dot-product backend patterns (*)
  d33786b... mips:  Adjust dot-product backend patterns (*)
  85a2ed0... arc: Adjust dot-product backend patterns (*)
  c45ef5e... i386: Fix dot_prod backend patterns for mmx and sse targets (*)
  bfa44e6... arm: Fix arm backend-use of (u|s|us)dot_prod patterns (*)
  0d0be1d... aarch64: Fix aarch64 backend-use of (u|s|us)dot_prod patter (*)
  c7fba0e... autovectorizer: Add basic support for convert optabs (*)
  2f68d69... optabs: Make all `*dot_prod_optab's modeled as conversions (*)
  18e905b... tree-optimization/116879 - failure to recognize non-empty l (*)

(*) This commit already exists in another branch.
Because the reference `refs/heads/devel/nothrow-detection' matches
your hooks.email-new-commits-only configuration,
no separate email is sent for this commit.


[gcc r15-3982] libstdc++-v3: Fix signed-overflow warning for newlib/ctype_base.h, PR116895

2024-09-30 Thread Hans-Peter Nilsson via Gcc-cvs
https://gcc.gnu.org/g:b1696ffd46872907b324996d4cdf28a2b9df209d

commit r15-3982-gb1696ffd46872907b324996d4cdf28a2b9df209d
Author: Hans-Peter Nilsson 
Date:   Sun Sep 29 05:47:03 2024 +0200

libstdc++-v3: Fix signed-overflow warning for newlib/ctype_base.h, PR116895

There are 100+ regressions when running the g++ testsuite for newlib
targets (probably excepting ARM-based ones) e.g cris-elf after commit
r15-3859-g63a598deb0c9fc "libstdc++: #ifdef out #pragma GCC
system_header", which effectively no longer silences warnings for
gcc-installed system headers.  Some of these regressions are fixed by
r15-3928.  For the remaining ones, there's in g++.log:

FAIL: g++.old-deja/g++.robertl/eb79.C  -std=c++26 (test for excess errors)
Excess errors:
/gccobj/cris-elf/libstdc++-v3/include/cris-elf/bits/ctype_base.h:50:53: \
 warning: overflow in conversion from 'int' to 'std::ctype_base::mask' \
 {aka 'char'} changes value from '151' to '-105' [-Woverflow]

This is because the _B macro in newlib's ctype.h (from where the
"_" macros come) is bit 7, the sign-bit of 8-bit types:

#define _B  0200

Using it in an int-expression that is then truncated to 8 bits will
"change" the value to negative for a default-signed char.  If this
code was created from scratch, it should have been an unsigned type,
however it's not advisable to change the type of mask as this affects
the API.  The least ugly option seems to be to silence the warning by
explict casts in the initializer, and for consistency, doing it for
all members.

PR libstdc++/116895
* config/os/newlib/ctype_base.h: Avoid signed-overflow warnings by
explicitly casting initializer expressions to mask.

Diff:
---
 libstdc++-v3/config/os/newlib/ctype_base.h | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/libstdc++-v3/config/os/newlib/ctype_base.h 
b/libstdc++-v3/config/os/newlib/ctype_base.h
index 309fdeea7731..5ec43a0c6803 100644
--- a/libstdc++-v3/config/os/newlib/ctype_base.h
+++ b/libstdc++-v3/config/os/newlib/ctype_base.h
@@ -41,19 +41,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 // NB: Offsets into ctype::_M_table force a particular size
 // on the mask type. Because of this, we don't use an enum.
 typedef char   mask;
-static const mask upper= _U;
-static const mask lower= _L;
-static const mask alpha= _U | _L;
-static const mask digit= _N;
-static const mask xdigit   = _X | _N;
-static const mask space= _S;
-static const mask print= _P | _U | _L | _N | _B;
-static const mask graph= _P | _U | _L | _N;
-static const mask cntrl= _C;
-static const mask punct= _P;
-static const mask alnum= _U | _L | _N;
+static const mask upper= mask (_U);
+static const mask lower= mask (_L);
+static const mask alpha= mask (_U | _L);
+static const mask digit= mask (_N);
+static const mask xdigit   = mask (_X | _N);
+static const mask space= mask (_S);
+static const mask print= mask (_P | _U | _L | _N | _B);
+static const mask graph= mask (_P | _U | _L | _N);
+static const mask cntrl= mask (_C);
+static const mask punct= mask (_P);
+static const mask alnum= mask (_U | _L | _N);
 #if __cplusplus >= 201103L
-static const mask blank= space;
+static const mask blank= mask (space);
 #endif
   };


[gcc(refs/users/meissner/heads/work179-vpair)] Remove re-inclusion support; Fix various typos; Spacing.

2024-09-30 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:16e02c32129462311803152925b59dfa73d81757

commit 16e02c32129462311803152925b59dfa73d81757
Author: Michael Meissner 
Date:   Mon Sep 30 15:15:38 2024 -0400

Remove re-inclusion support; Fix various typos; Spacing.

2024-09-30  Michael Meissner  

gcc/

* config/rs6000/vector-pair.h: Remove re-inclusion support; Fix 
various
typos; Spacing.

Diff:
---
 gcc/config/rs6000/vector-pair.h | 862 
 1 file changed, 347 insertions(+), 515 deletions(-)

diff --git a/gcc/config/rs6000/vector-pair.h b/gcc/config/rs6000/vector-pair.h
index 3443d32198df..e39e11fb3537 100644
--- a/gcc/config/rs6000/vector-pair.h
+++ b/gcc/config/rs6000/vector-pair.h
@@ -31,9 +31,6 @@
 #define _VECTOR_PAIR_H 1
 
 /* Union of the various vector pair types.  */
-#ifndef __VPAIR_UNION__
-#define __VPAIR_UNION__1
-
 union __vpair_union {
 
 #ifdef __MMA__
@@ -48,7 +45,6 @@ union __vpair_union {
 typedef union __vpair_unionvector_pair_t;
 typedef union __vpair_unionvector_pair_f64_t;
 typedef union __vpair_unionvector_pair_f32_t;
-#endif /* __VPAIR_UNION__.  */
 
 #if !__VPAIR_BUILTIN__ && !__VPAIR_ASM__ && !__VPAIR_NOP10__
 #if __MMA__ && __VPAIR__
@@ -68,147 +64,88 @@ typedef union __vpair_unionvector_pair_f32_t;
 
 #if __VPAIR_BUILTIN__ && __MMA__
 
-/* Allow vector-pair.h to be included multiple times during testing.  */
-#undef vpair_f64_abs
-#undef vpair_f64_add
-#undef vpair_f64_div
-#undef vpair_f64_fma
-#undef vpair_f64_fms
-#undef vpair_f64_max
-#undef vpair_f64_min
-#undef vpair_f64_mul
-#undef vpair_f64_nabs
-#undef vpair_f64_neg
-#undef vpair_f64_nfma
-#undef vpair_f64_nfms
-#undef vpair_f64_splat
-#undef vpair_f64_sqrt
-#undef vpair_f64_sub
-
-#undef vpair_f32_abs
-#undef vpair_f32_add
-#undef vpair_f32_div
-#undef vpair_f32_fma
-#undef vpair_f32_fms
-#undef vpair_f32_max
-#undef vpair_f32_min
-#undef vpair_f32_mul
-#undef vpair_f32_nabs
-#undef vpair_f32_neg
-#undef vpair_f32_nfma
-#undef vpair_f32_nfms
-#undef vpair_f32_splat
-#undef vpair_f32_sqrt
-#undef vpair_f32_sub
-
-#define vpair_f64_abs  __vpair_f64_abs_builtin
-#define vpair_f64_add  __vpair_f64_add_builtin
-#define vpair_f64_div  __vpair_f64_div_builtin
-#define vpair_f64_fma  __vpair_f64_fma_builtin
-#define vpair_f64_fms  __vpair_f64_fms_builtin
-#define vpair_f64_max  __vpair_f64_max_builtin
-#define vpair_f64_min  __vpair_f64_min_builtin
-#define vpair_f64_mul  __vpair_f64_mul_builtin
-#define vpair_f64_nabs __vpair_f64_nabs_builtin
-#define vpair_f64_neg  __vpair_f64_neg_builtin
-#define vpair_f64_nfma __vpair_f64_nfma_builtin
-#define vpair_f64_nfms __vpair_f64_nfms_builtin
-#define vpair_f64_splat__vpair_f64_splat_builtin
-#define vpair_f64_sqrt __vpair_f64_sqrt_builtin
-#define vpair_f64_sub  __vpair_f64_sub_builtin
-
-#define vpair_f32_abs  __vpair_f32_abs_builtin
-#define vpair_f32_add  __vpair_f32_add_builtin
-#define vpair_f32_div  __vpair_f32_div_builtin
-#define vpair_f32_fma  __vpair_f32_fma_builtin
-#define vpair_f32_fms  __vpair_f32_fms_builtin
-#define vpair_f32_max  __vpair_f32_max_builtin
-#define vpair_f32_min  __vpair_f32_min_builtin
-#define vpair_f32_mul  __vpair_f32_mul_builtin
-#define vpair_f32_nabs __vpair_f32_nabs_builtin
-#define vpair_f32_neg  __vpair_f32_neg_builtin
-#define vpair_f32_nfma __vpair_f32_nfma_builtin
-#define vpair_f32_nfms __vpair_f32_nfms_builtin
-#define vpair_f32_splat__vpair_f32_splat_builtin
-#define vpair_f32_sqrt __vpair_f32_sqrt_builtin
-#define vpair_f32_sub  __vpair_f32_sub_builtin
-
-/* vector pair double operations on power10/power11.  */
+/* vector pair double operations on power10/power11 with vector pair built-in
+   functions.  */
 static inline void
-vpair_f64_splat (vector_pair_f64_t *__r, double x)
+vpair_f64_splat (vector_pair_f64_t *__r,
+double __x)
 {
-  __r->__vpair = __builtin_vpair_f64_splat (x);
+  __r->__vpair = __builtin_vpair_f64_splat (__x);
 }
 
 static inline void
-vpair_f64_abs (vector_ptr_f64_t *__r, vector_pair_f64_t *__a)
+vpair_f64_abs (vector_pair_f64_t   *__r,
+  const vector_pair_f64_t *__a)
 {
-  __r->__vpair = __builtin_vpair_f64_abs (__a->_-vpair);
+  __r->__vpair = __builtin_vpair_f64_abs (__a->__vpair);
 }
 
 static inline void
-vpair_f64_nabs (vector_ptr_f64_t *__r, vector_pair_f64_t *__a)
+vpair_f64_nabs (vector_pair_f64_t   *__r,
+   const vector_pair_f64_t *__a)
 {
-  __r->__vpair = __builtin_vpair_f64_nabs (__a->_-vpair);
+  __r->__vpair = __builtin_vpair_f64_nabs (__a->__vpair);
 }
 
 static inline void
-vpair_f64_neg (vector_ptr_f64_t *__r, vector_pair_f64_t *__a)
+vpair_f64_neg (vector_pair_f64_t   *__r,
+  co

[gcc r15-3980] c++: concept in default argument [PR109859]

2024-09-30 Thread Marek Polacek via Gcc-cvs
https://gcc.gnu.org/g:4bcfaaed25b1b8ecc81f6a28d9ca76f00870dedf

commit r15-3980-g4bcfaaed25b1b8ecc81f6a28d9ca76f00870dedf
Author: Marek Polacek 
Date:   Wed Sep 18 15:44:31 2024 -0400

c++: concept in default argument [PR109859]

1) We're hitting the assert in cp_parser_placeholder_type_specifier.
It says that if it turns out to be false, we should do error() instead.
Do so, then.

2) lambda-targ8.C should compile fine, though.  The problem was that
local_variables_forbidden_p wasn't cleared when we're about to parse
the optional template-parameter-list for a lambda in a default argument.

PR c++/109859

gcc/cp/ChangeLog:

* parser.cc (cp_parser_lambda_declarator_opt): Temporarily clear
local_variables_forbidden_p.
(cp_parser_placeholder_type_specifier): Turn an assert into an
error.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/concepts-defarg3.C: New test.
* g++.dg/cpp2a/lambda-targ8.C: New test.

Reviewed-by: Jason Merrill 

Diff:
---
 gcc/cp/parser.cc  |  9 +++--
 gcc/testsuite/g++.dg/cpp2a/concepts-defarg3.C |  8 
 gcc/testsuite/g++.dg/cpp2a/lambda-targ8.C | 10 ++
 3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index f50534f5f395..0944827d777b 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -11891,6 +11891,11 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, 
tree lambda_expr)
 "lambda templates are only available with "
 "%<-std=c++20%> or %<-std=gnu++20%>");
 
+  /* Even though the whole lambda may be a default argument, its
+template-parameter-list is a context where it's OK to create
+new parameters.  */
+  auto lvf = make_temp_override (parser->local_variables_forbidden_p, 0u);
+
   cp_lexer_consume_token (parser->lexer);
 
   template_param_list = cp_parser_template_parameter_list (parser);
@@ -20989,8 +20994,8 @@ cp_parser_placeholder_type_specifier (cp_parser 
*parser, location_t loc,
   /* In a default argument we may not be creating new parameters.  */
   if (parser->local_variables_forbidden_p & LOCAL_VARS_FORBIDDEN)
{
- /* If this assert turns out to be false, do error() instead.  */
- gcc_assert (tentative);
+ if (!tentative)
+   error_at (loc, "invalid use of concept-name %qD", con);
  return error_mark_node;
}
   return build_constrained_parameter (con, proto, args);
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-defarg3.C 
b/gcc/testsuite/g++.dg/cpp2a/concepts-defarg3.C
new file mode 100644
index ..6fe82f91e434
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-defarg3.C
@@ -0,0 +1,8 @@
+// PR c++/109859
+// { dg-do compile { target c++20 } }
+
+template
+concept C = true;
+
+template  // { dg-error "invalid use of concept-name .C." }
+int f();
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-targ8.C 
b/gcc/testsuite/g++.dg/cpp2a/lambda-targ8.C
new file mode 100644
index ..3685b0ef880b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/lambda-targ8.C
@@ -0,0 +1,10 @@
+// PR c++/109859
+// { dg-do compile { target c++20 } }
+
+template
+concept A = true;
+
+template {}>
+int x;
+
+void g() { (void) x<>; }


[gcc r15-3979] Fix internal error during inlining after ICF pass

2024-09-30 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:65073a5b90c00a1c47efae8a67b9c754e2287ee0

commit r15-3979-g65073a5b90c00a1c47efae8a67b9c754e2287ee0
Author: Eric Botcazou 
Date:   Mon Sep 30 21:04:18 2024 +0200

Fix internal error during inlining after ICF pass

The problem is that the ICF pass identifies two functions, one of which has
a static chain while the other does not.  The fix is simply to prevent this
identification from occurring.

gcc/
PR ipa/113996
* ipa-icf.cc (sem_function::get_hash): Hash DECL_STATIC_CHAIN.
(sem_function::equals_wpa): Compare it.
(sem_function::equals_private): Likewise.

gcc/testsuite/
* gnat.dg/lto27.adb: New test.

Diff:
---
 gcc/ipa-icf.cc  | 11 +--
 gcc/testsuite/gnat.dg/lto27.adb | 18 ++
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/gcc/ipa-icf.cc b/gcc/ipa-icf.cc
index e84922c3ef87..6f9941522c8f 100644
--- a/gcc/ipa-icf.cc
+++ b/gcc/ipa-icf.cc
@@ -304,6 +304,7 @@ sem_function::get_hash (void)
   (TREE_OPTIMIZATION (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (decl;
   hstate.add_flag (DECL_CXX_CONSTRUCTOR_P (decl));
   hstate.add_flag (DECL_CXX_DESTRUCTOR_P (decl));
+  hstate.add_flag (DECL_STATIC_CHAIN (decl));
 
   set_hash (hstate.end ());
 }
@@ -655,7 +656,10 @@ sem_function::equals_wpa (sem_item *item,
 }
 
   if (list1 || list2)
-return return_false_with_msg ("Mismatched number of parameters");
+return return_false_with_msg ("mismatched number of parameters");
+
+  if (DECL_STATIC_CHAIN (decl) != DECL_STATIC_CHAIN (item->decl))
+return return_false_with_msg ("static chain mismatch");
 
   if (node->num_references () != item->node->num_references ())
 return return_false_with_msg ("different number of references");
@@ -876,7 +880,10 @@ sem_function::equals_private (sem_item *item)
 return return_false ();
 }
   if (arg1 || arg2)
-return return_false_with_msg ("Mismatched number of arguments");
+return return_false_with_msg ("mismatched number of arguments");
+
+ if (DECL_STATIC_CHAIN (decl) != DECL_STATIC_CHAIN (m_compared_func->decl))
+return return_false_with_msg ("static chain mismatch");
 
   if (!dyn_cast  (node)->has_gimple_body_p ())
 return true;
diff --git a/gcc/testsuite/gnat.dg/lto27.adb b/gcc/testsuite/gnat.dg/lto27.adb
new file mode 100644
index ..41049f7daf1d
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/lto27.adb
@@ -0,0 +1,18 @@
+-- { dg-do link }
+-- { dg-options "-O2 -gnatp -flto" { target lto } }
+
+with Ada.Containers.Hashed_Maps;
+with Ada.Strings.Hash;
+
+procedure Lto27 is
+   subtype Node_Name is String (1 .. 4);
+
+   package Node_Maps is new Ada.Containers.Hashed_Maps
+ (Key_Type=> Node_Name,
+  Element_Type=> Integer,
+  Hash=> Ada.Strings.Hash,
+  Equivalent_Keys => "=");
+
+begin
+   null;
+end;


[gcc r15-3981] [testcase] Fix-absfloat16.c-testcase

2024-09-30 Thread Kugan Vivekanandarajah via Gcc-cvs
https://gcc.gnu.org/g:ab07db3f24e203971c2190bdeec1732942f02bdd

commit r15-3981-gab07db3f24e203971c2190bdeec1732942f02bdd
Author: Kugan Vivekanandarajah 
Date:   Tue Oct 1 08:49:07 2024 +1000

[testcase] Fix-absfloat16.c-testcase

gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/absfloat16.c: Fix testcase.

Signed-off-by: Kugan Vivekanandarajah 

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

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/absfloat16.c 
b/gcc/testsuite/gcc.dg/tree-ssa/absfloat16.c
index a417fe281a90..c8eb985856ad 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/absfloat16.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/absfloat16.c
@@ -1,7 +1,7 @@
 /* { dg-do compile } */
-/* { dg-add-options float16 } */
 /* { dg-require-effective-target float16 } */
 /* { dg-options "-Ofast -fdump-tree-optimized" } */
+/* { dg-add-options float16 } */
 /* { dg-final { scan-tree-dump-times " = ABS_EXPR ;" 1 
"optimized" } } */
 
 _Float16  absfloat16(_Float16 x) {


[gcc(refs/users/meissner/heads/work179-vpair)] Update ChangeLog.*

2024-09-30 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:4d62173dbe7b74bc2512b9ed4c1aa6d4d6e83ace

commit 4d62173dbe7b74bc2512b9ed4c1aa6d4d6e83ace
Author: Michael Meissner 
Date:   Mon Sep 30 15:17:57 2024 -0400

Update ChangeLog.*

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

diff --git a/gcc/ChangeLog.vpair b/gcc/ChangeLog.vpair
index fdd35ca21cfc..9fec75006e9e 100644
--- a/gcc/ChangeLog.vpair
+++ b/gcc/ChangeLog.vpair
@@ -1,3 +1,14 @@
+ Branch work179-vpair, patch #307 
+
+Remove re-inclusion support; Fix various typos; Spacing.
+
+2024-09-30  Michael Meissner  
+
+gcc/
+
+   * config/rs6000/vector-pair.h: Remove re-inclusion support; Fix various
+   typos; Spacing.
+
  Branch work179-vpair, patch #306 
 
 Delete __vpair_ptr_t.