[PATCH v3] fold fold_truth_andor field merging into ifcombine

2024-12-08 Thread Alexandre Oliva


This patch introduces various improvements to the logic that merges
field compares, while moving it into ifcombine.

Before the patch, we could merge:

  (a.x1 EQNE b.x1)  ANDOR  (a.y1 EQNE b.y1)

into something like:

  (((type *)&a)[Na] & MASK) EQNE (((type *)&b)[Nb] & MASK)

if both of A's fields live within the same alignment boundaries, and
so do B's, at the same relative positions.  Constants may be used
instead of the object B.

The initial goal of this patch was to enable such combinations when a
field crossed alignment boundaries, e.g. for packed types.  We can't
generally access such fields with a single memory access, so when we
come across such a compare, we will attempt to combine each access
separately.

Some merging opportunities were missed because of right-shifts,
compares expressed as e.g. ((a.x1 ^ b.x1) & MASK) EQNE 0, and
narrowing conversions, especially after earlier merges.  This patch
introduces handlers for several cases involving these.

The merging of multiple field accesses into wider bitfield-like
accesses is undesirable to do too early in compilation, so we move it
from folding to ifcombine, and guard its warnings with
-Wtautological-compare, turned into a common flag.

When the second of a noncontiguous pair of compares is the first that
accesses a word, we may merge the first compare with part of the
second compare that refers to the same word, keeping the compare of
the remaining bits at the spot where the second compare used to be.

Handling compares with non-constant fields was somewhat generalized
from what fold used to do, now handling non-adjacent fields, even if a
field of one object crosses an alignment boundary but the other
doesn't.

Regstrapped on x86_64-linux-gnu.  Ok to install?

Changes from v2:

- fixed ICE when xor appeared only in the right-hand operand of a
  compare

- simplified the interface of decode_field_reference.  pand_mask can now
  be NULL, meaning mask operations are to be rejected, but this ended up
  unused.  It no longer rejects plain SSA names as the expr to be
  combined.

- drop unused variables from fold_truth_andor_for_ifcombine, and ensure
  right-hand masks are applied even on constants

- normalize width of masks and constants represented as wide_int, fixing
  regressions introduced by the transition to wide_int.  Don't bother to
  sign extend them, treat them as unsigned since it's all bitwise
  equality tests.

- more tests; fixed thinko in v2-added test

- guard warnings with -Wtautological-compares; made the option available
  on all languages

- backpedal from match.pd matchers to open-coded matchers

- improve vuse setting to avoid unwarranted assumptions about
  gimplification

- simplify selection of types for combined operands

- drop side effects tests not sensible in gimple

- explain apparent presence of TRUTH_*IF_EXPR in gimple

Changes from v1:

- Noncontiguous ifcombine split out and already installed.

- Do not attempt to place new loads next to the latest of the original
  loads.  Only check that loads have the same vuses, and place loads
  next to either one, even if that's suboptimal.

- Use gimple pattern matching.  It turned out not to be very useful, but
  it enabled the elimination of redundant auxiliary functions.

- Rewrote constants and masks using wide_int.

- Work harder to gather and reuse location_t.

- Rework BIT_XOR handling to avoid having to match patterns again.

- Distinguish the cases of contiguous and noncontiguous conditions.

- Comments, lots of comments.

- More tests.

- Dropped the warnings that were hitting i386 and rs6000 bootstraps.
  The new possibilities with ifcombine, noncontiguous at that, on top of
  more flexible field merging, made room for too many false positives.

Requested but unchanged from v1:

- fold_truth_andor_for_ifcombine (renamed from ...andor_maybe_separate)
still builds and returns generic expressions.  Since other
ifcombine_ifandif build generic exprs and have to go through
regimplification anyway, I failed to see the point.  Implementing that
change would require some more work in tree-ssa-ifcombine.cc to support.
I'd rather do that as a follow up if desired, please let me know.

- it also remains a single bulky function.  There's so much state that
breaking it up doesn't seem to be helpful.  Hopefully the added comments
will help despite making it even bigger.

- TBAA situation is unchanged, same as what's carried over from fold.
I'm not sure what the concerns in your mind are, but if there are actual
problems, they have long been there, and we'd better address them in
both fold and in this bit now moved to ifcombine, ideally in a separate
backportable patch.


for  gcc/ChangeLog

* fold-const.cc (make_bit_field): Export.
(unextend, all_ones_mask_p): Drop.
(decode_field_reference, fold_truth_andor_1): Move
field compare merging logic...
* gimple-fold.cc: (fold_truth_andor_for_ifcombine) ... here,
with -Wtautological-

Re: [PATCH v2] fold fold_truth_andor field merging into ifcombine

2024-12-08 Thread Alexandre Oliva
Here's yet another incremental patchlet, with the changes made in
response to your review to v2.

I'll post v3 containing it momentarily, but this incremental is supposed
to make it easier to review.

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 0d255561b1bdc..be7916e957d66 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -1477,10 +1477,6 @@ Wtemplates
 C++ ObjC++ Var(warn_templates) Warning
 Warn on primary template declaration.
 
-Wtautological-compare
-C ObjC C++ ObjC++ Var(warn_tautological_compare) Warning LangEnabledBy(C ObjC 
C++ ObjC++,Wall)
-Warn if a comparison always evaluates to true or false.
-
 Wtemplate-body
 C++ ObjC++ Var(warn_template_body) Warning Init(1)
 Diagnose errors when parsing a template.
diff --git a/gcc/common.opt b/gcc/common.opt
index bb226ac61e6a1..915ce5bffb4e0 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -812,6 +812,10 @@ Wsystem-headers
 Common Var(warn_system_headers) Warning
 Do not suppress warnings from system headers.
 
+Wtautological-compare
+Common Var(warn_tautological_compare) Warning LangEnabledBy(C ObjC C++ 
ObjC++,Wall)
+Warn if a comparison always evaluates to true or false.
+
 Wtrampolines
 Common Var(warn_trampolines) Warning
 Warn whenever a trampoline is generated.
diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 2c33cdfb1b29a..3ba4307769dd8 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -7439,6 +7439,53 @@ maybe_fold_comparisons_from_match_pd (tree type, enum 
tree_code code,
   return NULL_TREE;
 }
 
+/* Return TRUE and set op[0] if T, following all SSA edges, is a type
+   conversion.  */
+
+static bool
+gimple_fold_follow_convert (tree t, tree op[1])
+{
+  if (TREE_CODE (t) == SSA_NAME
+  && !SSA_NAME_IS_DEFAULT_DEF (t))
+if (gassign *def = dyn_cast  (SSA_NAME_DEF_STMT (t)))
+  switch (gimple_assign_rhs_code (def))
+   {
+   CASE_CONVERT:
+ op[0] = gimple_assign_rhs1 (def);
+ return true;
+   case VIEW_CONVERT_EXPR:
+ op[0] = TREE_OPERAND (gimple_assign_rhs1 (def), 0);
+ return true;
+   default:
+ break;
+   }
+  return false;
+}
+
+/* Return TRUE and set op[*] if T, following all SSA edges, resolves to a
+   binary expression with code CODE.  */
+
+static bool
+gimple_fold_binop_cst (enum tree_code code, tree t, tree op[2])
+{
+  if (TREE_CODE (t) == SSA_NAME
+  && !SSA_NAME_IS_DEFAULT_DEF (t))
+if (gimple *def = dyn_cast  (SSA_NAME_DEF_STMT (t)))
+  if (gimple_assign_rhs_code (def) == code)
+   {
+ tree op0 = gimple_assign_rhs1 (def);
+ tree op1 = gimple_assign_rhs2 (def);
+ if (tree_swap_operands_p (op0, op1))
+   std::swap (op0, op1);
+ if (uniform_integer_cst_p (op1))
+   {
+ op[0] = op0;
+ op[1] = op1;
+ return true;
+   }
+   }
+  return false;
+}
 /* Subroutine for fold_truth_andor_1: decode a field reference.
 
If *PEXP is a comparison reference, we return the innermost reference.
@@ -7478,12 +7525,6 @@ decode_field_reference (tree *pexp, HOST_WIDE_INT 
*pbitsize,
wide_int *pand_mask, bool *xor_p, tree *xor_cmp_op,
gimple **load, location_t loc[4])
 {
-  /* These are from match.pd.  */
-  extern bool gimple_any_convert (tree, tree *, tree (*)(tree));
-  extern bool gimple_bit_and_cst (tree, tree *, tree (*)(tree));
-  extern bool gimple_bit_xor_cst (tree, tree *, tree (*)(tree));
-  extern bool gimple_rshift_cst (tree, tree *, tree (*)(tree));
-
   tree exp = *pexp;
   tree outer_type = 0;
   wide_int and_mask;
@@ -7504,7 +7545,7 @@ decode_field_reference (tree *pexp, HOST_WIDE_INT 
*pbitsize,
  narrowing then widening casts, or vice-versa, for those that are not
  essential for the compare have already been optimized out at this
  point.  */
-  if (gimple_any_convert (exp, res_ops, follow_all_ssa_edges))
+  if (gimple_fold_follow_convert (exp, res_ops))
 {
   if (!outer_type)
{
@@ -7515,7 +7556,7 @@ decode_field_reference (tree *pexp, HOST_WIDE_INT 
*pbitsize,
 }
 
   /* Recognize and save a masking operation.  */
-  if (pand_mask && gimple_bit_and_cst (exp, res_ops, follow_all_ssa_edges))
+  if (pand_mask && gimple_fold_binop_cst (BIT_AND_EXPR, exp, res_ops))
 {
   loc[1] = gimple_location (SSA_NAME_DEF_STMT (exp));
   exp = res_ops[0];
@@ -7523,7 +7564,7 @@ decode_field_reference (tree *pexp, HOST_WIDE_INT 
*pbitsize,
 }
 
   /* Turn (a ^ b) [!]= 0 into a [!]= b.  */
-  if (xor_p && gimple_bit_xor_cst (exp, res_ops, follow_all_ssa_edges))
+  if (xor_p && gimple_fold_binop_cst (BIT_XOR_EXPR, exp, res_ops))
 {
   /* No location recorded for this one, it's entirely subsumed by the
 compare.  */
@@ -7545,7 +7586,7 @@ decode_field_reference (tree *pexp, HOST_WIDE_INT 
*pbitsize,
 }
 
   /* Another chance to drop conversions.  */
-  if (gimple_any_convert (exp, res_ops, follow_all_ssa_edges)

[committed] pru: Implement c and n asm operand modifiers

2024-12-08 Thread Dimitar Dimitrov
Fix c-c++-common/toplevel-asm-1.c failure for PRU backend, caused by
missing implementation of the "c" asm operand modifier.

Pushed to trunk.

gcc/ChangeLog:

* config/pru/pru.cc (pru_print_operand): Implement c and n
inline assembly operand modifiers.

gcc/testsuite/ChangeLog:

* gcc.target/pru/asm-op-modifier.c: New test.

Signed-off-by: Dimitar Dimitrov 
---
 gcc/config/pru/pru.cc | 12 ++-
 .../gcc.target/pru/asm-op-modifier.c  | 32 +++
 2 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/pru/asm-op-modifier.c

diff --git a/gcc/config/pru/pru.cc b/gcc/config/pru/pru.cc
index 3b9ab362993..5dd6391f340 100644
--- a/gcc/config/pru/pru.cc
+++ b/gcc/config/pru/pru.cc
@@ -1858,12 +1858,22 @@ pru_print_operand (FILE *file, rtx op, int letter)
  fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (op) & 0xff);
  return;
}
+  else if (letter == 'c')
+   {
+ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (op));
+ return;
+   }
+  else if (letter == 'n')
+   {
+ fprintf (file, HOST_WIDE_INT_PRINT_DEC, -INTVAL (op));
+ return;
+   }
   /* Else, fall through.  */
 
 case CONST:
 case LABEL_REF:
 case SYMBOL_REF:
-  if (letter == 0)
+  if (letter == 0 || letter == 'c')
{
  output_addr_const (file, op);
  return;
diff --git a/gcc/testsuite/gcc.target/pru/asm-op-modifier.c 
b/gcc/testsuite/gcc.target/pru/asm-op-modifier.c
new file mode 100644
index 000..6ace0311985
--- /dev/null
+++ b/gcc/testsuite/gcc.target/pru/asm-op-modifier.c
@@ -0,0 +1,32 @@
+/* Test ASM operand modifiers. */
+
+/* { dg-do compile } */
+/* { dg-options "-O1" } */
+
+struct S {
+  char b;
+  int a;
+  short c;
+};
+
+void
+test_const_int (void)
+{
+  /* { dg-final { scan-assembler "# printing 7 and -5" } } */
+  asm volatile ("# printing %c0 and %n1"
+: :
+"i" (sizeof(struct S)),
+"i" (__builtin_offsetof (struct S, c)));
+}
+
+extern int g;
+
+void
+test_sym (void)
+{
+  /* { dg-final { scan-assembler "# outputting g and test_sym" } } */
+  asm volatile ("# outputting %c0 and %c1"
+: :
+"i" (&g),
+"i" (&test_sym));
+}
-- 
2.47.1



[PATCH v1 2/6] RISC-V: Refine unsigned vector SAT_SUB testcase dump check to tree optimized

2024-12-08 Thread pan2 . li
From: Pan Li 

The sat alu related testcase check the rtl dump for the standard name
like .SAT_SUB exist or not.  But the rtl pass expand is somehow
impressionable by the middle-end change or debug information.  Like
below new appearance recently.

Replacing Expressions
_5 replace with --> _5 = .SAT_SUB (x_3(D), y_4(D)); [tail call]

After that we need to adjust the dump check time and again.  This
patch would like to switch to tree optimized pass for the standard
name check, which is more stable up to a point.

The below test suites are passed for this patch.
* The rv64gcv fully regression test.

It is test only patch and obvious up to a point, will commit it
directly if no comments in next 48H.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-1-u16.c: Take
tree-optimized pass for standard name check, and adjust the times.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-1-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-1-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-1-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-10-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-10-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-10-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-10-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-2-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-2-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-2-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-2-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-3-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-3-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-3-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-3-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-4-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-4-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-4-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-4-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-5-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-5-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-5-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-5-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-6-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-6-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-6-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-6-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-7-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-7-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-7-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-7-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-8-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-8-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-8-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-8-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-9-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-9-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-9-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-9-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub_imm-1-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub_imm-1-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub_imm-1-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub_imm-1-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub_trunc-1-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub_trunc-1-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub_trunc-1-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub_zip.c: Ditto.

Signed-off-by: Pan Li 
---
 .../riscv/rvv/autovec/sat/vec_sat_u_sub-1-u16.c   | 4 ++--
 .../riscv/rvv/autovec/sat/vec_sat_u_sub-1-u32.c   | 4 ++--
 .../riscv/rvv/autovec/sat/vec_sat_u_sub-1-u64.c   | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub-1-u8.c | 4 ++--
 .../riscv/rvv/autovec/sat/vec_sat_u_sub-10-u16.c  | 4 ++--
 .../riscv/rvv/autovec/sat/vec_sat_u_sub-10-u32.c  | 4 ++--
 .../riscv/rvv/autovec/sat/vec_sat_u_sub-10-u64.c  | 4 ++--
 .../riscv/rvv/autovec/sat/vec_sat_u_sub-10-u8.c   | 4 ++--
 .../riscv/rvv/autovec/sat/vec_sat_u_sub-2-u16.c   | 4 ++--
 .../riscv/rvv/autovec/

[PATCH v1 6/6] RISC-V: Refine signed vector SAT_TRUNC testcase dump check to tree optimized

2024-12-08 Thread pan2 . li
From: Pan Li 

The sat alu related testcase check the rtl dump for the standard name
like .SAT_TRUNC exist or not.  But the rtl pass expand is somehow
impressionable by the middle-end change or debug information.  Like
below new appearance recently.

Replacing Expressions
_5 replace with --> _5 = .SAT_TRUNC (x_3(D), y_4(D)); [tail call]

After that we need to adjust the dump check time and again.  This
patch would like to switch to tree optimized pass for the standard
name check, which is more stable up to a point.

The below test suites are passed for this patch.
* The rv64gcv fully regression test.

It is test only patch and obvious up to a point, will commit it
directly if no comments in next 48H.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-1-i16-to-i8.c: Take
tree-optimized pass for standard name check, and adjust the times.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-1-i32-to-i16.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-1-i32-to-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-1-i64-to-i16.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-1-i64-to-i32.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-1-i64-to-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-2-i16-to-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-2-i32-to-i16.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-2-i32-to-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-2-i64-to-i16.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-2-i64-to-i32.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-2-i64-to-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-3-i16-to-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-3-i32-to-i16.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-3-i32-to-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-3-i64-to-i16.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-3-i64-to-i32.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-3-i64-to-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-4-i16-to-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-4-i32-to-i16.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-4-i32-to-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-4-i64-to-i16.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-4-i64-to-i32.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-4-i64-to-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-5-i16-to-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-5-i32-to-i16.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-5-i32-to-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-5-i64-to-i16.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-5-i64-to-i32.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-5-i64-to-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-6-i16-to-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-6-i32-to-i16.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-6-i32-to-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-6-i64-to-i16.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-6-i64-to-i32.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-6-i64-to-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-7-i16-to-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-7-i32-to-i16.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-7-i32-to-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-7-i64-to-i16.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-7-i64-to-i32.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-7-i64-to-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-8-i16-to-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-8-i32-to-i16.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-8-i32-to-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-8-i64-to-i16.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-8-i64-to-i32.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_trunc-8-i64-to-i8.c: Ditto.

Signed-off-by: Pan Li 
---
 .../riscv/rvv/autovec/sat/vec_sat_s_trunc-1-i16-to-i8.c | 6 +++---
 .../riscv/rvv/autovec/sat/vec_sat_s_trunc-1-i32-to-i16.c| 4 ++--
 .../riscv/rvv/autovec/sat/vec_sat_s_trunc-1-i32-to-i8.c | 6 +++---
 .../riscv/

[PATCH v1 1/6] RISC-V: Refine unsigned vector SAT_ADD testcase dump check to tree optimized

2024-12-08 Thread pan2 . li
From: Pan Li 

The sat alu related testcase check the rtl dump for the standard name
like .SAT_ADD exist or not.  But the rtl pass expand is somehow
impressionable by the middle-end change or debug information.  Like
below new appearance recently.

Replacing Expressions
_5 replace with --> _5 = .SAT_ADD (x_3(D), y_4(D)); [tail call]

After that we need to adjust the dump check time and again.  This
patch would like to switch to tree optimized pass for the standard
name check, which is more stable up to a point.

The below test suites are passed for this patch.
* The rv64gcv fully regression test.

It is test only patch and obvious up to a point, will commit it
directly if no comments in next 48H.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-1-u16.c: Take
tree-optimized pass for standard name check, and adjust the times.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-1-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-1-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-1-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-2-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-2-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-2-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-2-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-3-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-3-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-3-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-3-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-4-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-4-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-4-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-4-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-5-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-5-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-5-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-5-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-6-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-6-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-6-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-6-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-7-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-7-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-7-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-7-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-8-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-8-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-8-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-8-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-1-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-1-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-1-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-1-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-2-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-2-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-2-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-2-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-3-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-3-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-3-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-3-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-4-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-4-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-4-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-4-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm_reconcile-1-u16.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm_reconcile-1-u32.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm_reconcile-1-u64.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm_reconcile-1-u8.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm_reconcile-2-u16.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm_reconcile-2-u32.c: 
Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm_reconcile-2-u64.c: 
Ditto.
* gcc.target/r

[PATCH v1 4/6] [PATCH] RISC-V: Refine signed vector SAT_ADD testcase dump check to tree optimized

2024-12-08 Thread pan2 . li
From: Pan Li 

The sat alu related testcase check the rtl dump for the standard name
like .SAT_ADD exist or not.  But the rtl pass expand is somehow
impressionable by the middle-end change or debug information.  Like
below new appearance recently.

Replacing Expressions
_5 replace with --> _5 = .SAT_ADD (x_3(D), y_4(D)); [tail call]

After that we need to adjust the dump check time and again.  This
patch would like to switch to tree optimized pass for the standard
name check, which is more stable up to a point.

The below test suites are passed for this patch.
* The rv64gcv fully regression test.

It is test only patch and obvious up to a point, will commit it
directly if no comments in next 48H.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-1-s16.c: Take
tree-optimized pass for standard name check, and adjust the times.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-1-s32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-1-s64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-1-s8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-2-s16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-2-s32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-2-s64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-2-s8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-3-s16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-3-s32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-3-s64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-3-s8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-4-s16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-4-s32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-4-s64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-4-s8.c: Ditto.

Signed-off-by: Pan Li 
---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-1-s16.c  | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-1-s32.c  | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-1-s64.c  | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-1-s8.c   | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-2-s16.c  | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-2-s32.c  | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-2-s64.c  | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-2-s8.c   | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-3-s16.c  | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-3-s32.c  | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-3-s64.c  | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-3-s8.c   | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-4-s16.c  | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-4-s32.c  | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-4-s64.c  | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-4-s8.c   | 6 +++---
 16 files changed, 48 insertions(+), 48 deletions(-)

diff --git 
a/gcc/testsuite/gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-1-s16.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-1-s16.c
index 6ef8ecbc170..6147e7ab56e 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-1-s16.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-1-s16.c
@@ -1,10 +1,10 @@
 /* { dg-do compile } */
-/* { dg-options "-march=rv64gcv -mabi=lp64d -ftree-vectorize 
-fdump-rtl-expand-details" } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -ftree-vectorize 
-fdump-tree-optimized" } */
 
 #include "vec_sat_arith.h"
 
 DEF_VEC_SAT_S_ADD_FMT_1(int16_t, uint16_t, INT16_MIN, INT16_MAX)
 
-/* { dg-final { scan-rtl-dump-times ".SAT_ADD " 2 "expand" { target { no-opts 
"-O2" } } } } */
-/* { dg-final { scan-rtl-dump-times ".SAT_ADD " 4 "expand" { target { no-opts 
"-O3" } } } } */
+/* { dg-final { scan-tree-dump-times ".SAT_ADD " 1 "optimized" { target { 
no-opts "-O2" } } } } */
+/* { dg-final { scan-tree-dump-times ".SAT_ADD " 2 "optimized" { target { 
no-opts "-O3" } } } } */
 /* { dg-final { scan-assembler-times {vsadd\.vv} 1 } } */
diff --git 
a/gcc/testsuite/gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-1-s32.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-1-s32.c
index 46a4b6fdbd0..2312b5b6074 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-1-s32.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/sat/vec_sat_s_add-1-s32.c
@@ -1,10 +1,10 @@
 /* { dg-do compile } */
-/* { dg-options "-march=rv64gcv -mabi=lp64d -ftree-vectorize 
-fdump-rtl-expand-details" } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -ftree-vectorize 
-fdump-tree-optimized" } */
 
 #include "vec_sat_arith.h"
 
 DEF_VEC_SAT_S_ADD_FMT_1(int32_t, uint32_t, INT32_MIN, INT32_MAX

[PATCH v1 3/6] RISC-V: Refine unsigned vector SAT_TRUNC testcase dump check to tree optimized

2024-12-08 Thread pan2 . li
From: Pan Li 

The sat alu related testcase check the rtl dump for the standard name
like .SAT_TRUNC exist or not.  But the rtl pass expand is somehow
impressionable by the middle-end change or debug information.  Like
below new appearance recently.

Replacing Expressions
_5 replace with --> _5 = .SAT_TRUNC (x_3(D), y_4(D)); [tail call]

After that we need to adjust the dump check time and again.  This
patch would like to switch to tree optimized pass for the standard
name check, which is more stable up to a point.

The below test suites are passed for this patch.
* The rv64gcv fully regression test.

It is test only patch and obvious up to a point, will commit it
directly if no comments in next 48H.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-1-u16.c: Take
tree-optimized pass for standard name check, and adjust the times.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-1-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-1-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-1-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-2-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-2-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-2-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-2-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-3-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-3-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-3-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-3-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-4-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-4-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-4-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-4-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-5-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-5-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-5-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-5-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-6-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-6-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-6-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-6-u8.c: Ditto.

Signed-off-by: Pan Li 
---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-1-u16.c  | 4 ++--
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-1-u32.c  | 4 ++--
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-1-u64.c  | 4 ++--
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-1-u8.c   | 4 ++--
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-2-u16.c  | 4 ++--
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-2-u32.c  | 4 ++--
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-2-u64.c  | 4 ++--
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-2-u8.c   | 4 ++--
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-3-u16.c  | 4 ++--
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-3-u32.c  | 4 ++--
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-3-u64.c  | 4 ++--
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-3-u8.c   | 4 ++--
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-4-u16.c  | 4 ++--
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-4-u32.c  | 4 ++--
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-4-u64.c  | 4 ++--
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-4-u8.c   | 4 ++--
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-5-u16.c  | 4 ++--
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-5-u32.c  | 4 ++--
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-5-u64.c  | 4 ++--
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-5-u8.c   | 4 ++--
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-6-u16.c  | 4 ++--
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-6-u32.c  | 4 ++--
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-6-u64.c  | 4 ++--
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-6-u8.c   | 4 ++--
 24 files changed, 48 insertions(+), 48 deletions(-)

diff --git 
a/gcc/testsuite/gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-1-u16.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-1-u16.c
index bf83a5cbe66..b3f4c33d813 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-1-u16.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/sat/vec_sat_u_trunc-1-u16.c
@@ -1,9 +1,9 @@
 /* { dg-do compile } */
-/* { dg-options "-march=rv64gcv -mabi=lp64d -ftree-vectorize 
-fdump-rtl-expand-details" } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -ftree-vectorize 
-fdump-tree-optimized" } */
 
 #inc

[PATCH v1 5/6] RISC-V: Refine signed vector SAT_SUB testcase dump check to tree optimized

2024-12-08 Thread pan2 . li
From: Pan Li 

The sat alu related testcase check the rtl dump for the standard name
like .SAT_SUB exist or not.  But the rtl pass expand is somehow
impressionable by the middle-end change or debug information.  Like
below new appearance recently.

Replacing Expressions
_5 replace with --> _5 = .SAT_SUB (x_3(D), y_4(D)); [tail call]

After that we need to adjust the dump check time and again.  This
patch would like to switch to tree optimized pass for the standard
name check, which is more stable up to a point.

The below test suites are passed for this patch.
* The rv64gcv fully regression test.

It is test only patch and obvious up to a point, will commit it
directly if no comments in next 48H.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-1-i16.c: Take
tree-optimized pass for standard name check, and adjust the times.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-1-i32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-1-i64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-1-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-2-i16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-2-i32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-2-i64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-2-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-3-i16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-3-i32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-3-i64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-3-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-4-i16.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-4-i32.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-4-i64.c: Ditto.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-4-i8.c: Ditto.

Signed-off-by: Pan Li 
---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-1-i16.c  | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-1-i32.c  | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-1-i64.c  | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-1-i8.c   | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-2-i16.c  | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-2-i32.c  | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-2-i64.c  | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-2-i8.c   | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-3-i16.c  | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-3-i32.c  | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-3-i64.c  | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-3-i8.c   | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-4-i16.c  | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-4-i32.c  | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-4-i64.c  | 6 +++---
 .../gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-4-i8.c   | 6 +++---
 16 files changed, 48 insertions(+), 48 deletions(-)

diff --git 
a/gcc/testsuite/gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-1-i16.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-1-i16.c
index 38d10575237..5ae4515d254 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-1-i16.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-1-i16.c
@@ -1,14 +1,14 @@
 /* { dg-do compile } */
-/* { dg-options "-march=rv64gcv -mabi=lp64d -ftree-vectorize 
-fdump-rtl-expand-details" } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -ftree-vectorize 
-fdump-tree-optimized" } */
 
 #include "vec_sat_arith.h"
 
 DEF_VEC_SAT_S_SUB_FMT_1(int16_t, uint16_t, INT16_MIN, INT16_MAX)
 
-/* { dg-final { scan-rtl-dump-times ".SAT_SUB " 2 "expand" { target { any-opts
+/* { dg-final { scan-tree-dump-times ".SAT_SUB " 1 "optimized" { target { 
any-opts
  "-O3"
} } } } */
-/* { dg-final { scan-rtl-dump-times ".SAT_SUB " 4 "expand" { target { any-opts
+/* { dg-final { scan-tree-dump-times ".SAT_SUB " 2 "optimized" { target { 
any-opts
  "-O2"
} } } } */
 /* { dg-final { scan-assembler-times {vssub\.vv} 1 } } */
diff --git 
a/gcc/testsuite/gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-1-i32.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-1-i32.c
index b1d0ad03dae..1f845791231 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-1-i32.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/sat/vec_sat_s_sub-1-i32.c
@@ -1,14 +1,14 @@
 /* { dg-do compile } */
-/* { dg-options "-march=rv64gcv -mabi=lp64d -ftree-vectorize 
-fdump-rtl-expand-details" } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -ftree-vectorize 
-fdump-tree-optimized" } */
 
 #include "vec_sat_arith.h"
 
 DEF_VEC_SAT_S_SUB_FMT_1(int32_t, uint32_t, INT32_MIN, INT32_MAX)
 
-/* { dg

Re: [PATCH] tree-eh: Don't crash on GIMPLE_TRY_FINALLY with empty cleanup sequence [PR117845]

2024-12-08 Thread Simon Martin
Hi Richard,

On 8 Dec 2024, at 10:27, Richard Biener wrote:

> On Sat, Dec 7, 2024 at 9:29 PM Simon Martin  
> wrote:
>>
>> The following valid code triggers an ICE with -fsanitize=address
>>
>> === cut here ===
>> void l() {
>> auto const ints = {0,1,2,3,4,5};
>> for (auto i : { 3 } ) {
>> __builtin_printf("%d ", i);
>> }
>> }
>> === cut here ===
>>
>> The problem is that honor_protect_cleanup_actions does not expect the

>> cleanup sequence of a GIMPLE_TRY_FINALLY to be empty. It is however 
>> the
>> case here since r14-8681-gceb242f5302027, because lower_stmt removes 
>> the
>> only statement in the sequence: a ASAN_MARK statement for the array 
>> that
>> backs the initializer_list).
>>
>> This patch simply checks that the finally block is not 0 before
>> accessing it in honor_protect_cleanup_actions.
>>
>> Successfully tested on x86_64-pc-linux-gnu. OK for trunk and gcc-14?
>>
>> PR c++/117845
>>
>> gcc/ChangeLog:
>>
>> * tree-eh.cc (honor_protect_cleanup_actions): Support empty
>> finally sequences.
>>
>> gcc/testsuite/ChangeLog:
>>
>> * g++.dg/asan/pr117845-2.C: New test.
>> * g++.dg/asan/pr117845.C: New test.
>>
>> ---
>>  gcc/testsuite/g++.dg/asan/pr117845-2.C | 12 
>>  gcc/testsuite/g++.dg/asan/pr117845.C   | 12 
>>  gcc/tree-eh.cc |  3 ++-
>>  3 files changed, 26 insertions(+), 1 deletion(-)
>>  create mode 100644 gcc/testsuite/g++.dg/asan/pr117845-2.C
>>  create mode 100644 gcc/testsuite/g++.dg/asan/pr117845.C
>>
>> diff --git a/gcc/testsuite/g++.dg/asan/pr117845-2.C 
>> b/gcc/testsuite/g++.dg/asan/pr117845-2.C
>> new file mode 100644
>> index 000..c0556397009
>> --- /dev/null
>> +++ b/gcc/testsuite/g++.dg/asan/pr117845-2.C
>> @@ -0,0 +1,12 @@
>> +// PR c++/117845 - Actually valid variant
>> +// { dg-do "compile" }
>> +// { dg-options "-fsanitize=address" }
>> +
>> +#include 
>> +
>> +void l() {
>> +auto const ints = {0,1,2,3,4,5};
>> +for (auto i : { 3 } ) {
>> +__builtin_printf("%d ", i);
>> +}
>> +}
>> diff --git a/gcc/testsuite/g++.dg/asan/pr117845.C 
>> b/gcc/testsuite/g++.dg/asan/pr117845.C
>> new file mode 100644
>> index 000..d90d351e270
>> --- /dev/null
>> +++ b/gcc/testsuite/g++.dg/asan/pr117845.C
>> @@ -0,0 +1,12 @@
>> +// PR c++/117845 - Initially reported case.
>> +// { dg-do "compile" }
>> +// { dg-options "-fsanitize=address" }
>> +
>> +#include 
>> +
>> +void l() {
>> +auto const ints = {0,1,2,3,4,5};
>> +for (int i : ints | h) { // { dg-error "was not declared" }
>> +__builtin_printf("%d ", i);
>> +}
>> +}
>> diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
>> index 769785fad2b..dc920de9b38 100644
>> --- a/gcc/tree-eh.cc
>> +++ b/gcc/tree-eh.cc
>> @@ -1026,7 +1026,8 @@ honor_protect_cleanup_actions (struct leh_state 
>> *outer_state,
>>  MUST_NOT_THROW filter.  */
>>gimple_stmt_iterator gsi = gsi_start (finally);
>>gimple *x = gsi_stmt (gsi);
>> -  if (gimple_code (x) == GIMPLE_TRY
>> +  if (x
>
> style-wise you should check for gsi_end_p (gsi) before
> calling gsi_stmt on the iterator.  Implementation-wise
> your patch has the same effect, of course.
>
> Can you still refactor it this way?
Sure, here’s the updated version that I’m currently testing. Ok for 
trunk and gcc-14 assuming the testing comes back all green?

Thanks!
   SimonFrom b7d2918b249b57e2ca236acac66cc3503f5bddeb Mon Sep 17 00:00:00 2001
From: Simon Martin 
Date: Fri, 6 Dec 2024 11:04:24 +0100
Subject: [PATCH] tree-eh: Don't crash on GIMPLE_TRY_FINALLY with empty cleanup
 sequence [PR117845]

The following valid code triggers an ICE with -fsanitize=address

=== cut here ===
void l() {
auto const ints = {0,1,2,3,4,5};
for (auto i : { 3 } ) {
__builtin_printf("%d ", i);
}
}
=== cut here ===

The problem is that honor_protect_cleanup_actions does not expect the
cleanup sequence of a GIMPLE_TRY_FINALLY to be empty. It is however the
case here since r14-8681-gceb242f5302027, because lower_stmt removes the
only statement in the sequence: a ASAN_MARK statement for the array that
backs the initializer_list).

This patch simply checks that the finally block is not 0 before
accessing it in honor_protect_cleanup_actions.

Successfully tested on x86_64-pc-linux-gnu. OK for trunk and gcc-14?

PR c++/117845

gcc/ChangeLog:

* tree-eh.cc (honor_protect_cleanup_actions): Support empty
finally sequences.

gcc/testsuite/ChangeLog:

* g++.dg/asan/pr117845-2.C: New test.
* g++.dg/asan/pr117845.C: New test.

---
 gcc/testsuite/g++.dg/asan/pr117845-2.C | 12 
 gcc/testsuite/g++.dg/asan/pr117845.C   | 12 
 gcc/tree-eh.cc |  5 +++--
 3 files changed, 27 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/asan/pr117845-2.C
 create mode 100644 gcc/testsuite/g++.dg/asan/pr117845.C

diff --git a/gcc/testsuite/g++.dg/asan/pr117

Re: [PATCH v6 1/7] Honor TARGET_PROMOTE_PROTOTYPES during RTL expand

2024-12-08 Thread H.J. Lu
On Sun, Dec 8, 2024, 5:25 PM Richard Biener 
wrote:

> On Sat, Dec 7, 2024 at 5:23 PM Jeff Law  wrote:
> >
> >
> >
> > On 12/6/24 5:39 AM, Richard Biener wrote:
> > > On Wed, Dec 4, 2024 at 9:48 PM H.J. Lu  wrote:
> > >>
> > >> Promote integer arguments smaller than int if
> TARGET_PROMOTE_PROTOTYPES
> > >> returns true.
> > >
> > > This is OK when 2/7 got no negative comments and Jeff doesn't have
> > > further input here.
> > Nothing specific.  I'm leery of the change, but that's as much a
> > function of being into stage3 as anything.
>
> I have no strong opinion here as I think it should be pretty safe (and
> it fixes a wrong-code
> bug).  But I think we can also live with pushing this to next stage1
> if HJ is fine with it.
>

It can wait for GCC 16.

Thanks.


> Richard.
>
> >
> > Jeff
>
>


Re: [PATCH] Invalid gimple __BB# accepted due to usage of atoi -> replace atoi with stroul in c_parser_gimple_parse_bb_spec [PR114541]

2024-12-08 Thread Richard Biener
On Sat, Dec 7, 2024 at 12:28 AM Heiko Eißfeldt  wrote:
>
> and here is the forgotten patch (it is late...)

Hmm.  While this might seem to be "good", the failure mode after fixing
the issue with atoi (or the alternate failure mode when using __BBB1234)
shows that we are missing handling in the GIMPLE frontend for
labels used that are not declared - lookup_label_for_goto tentatively
records a label.  I couldn't quickly find how the C frontend later discovers
used but not bound labels - in principle the GIMPLE FE would need sth
similar.

There's also missing support for indirect gotos it seems.

void foo(int x)
{
  void *l = &&lab;
lab:
  goto *l;
}

is, when in SSA form

void __GIMPLE (ssa)
foo (int x)
{
  void * gotovar.0;
  void * l;
  void * _2;

  __BB(2):
  l_1 = &lab;
  goto __BB3;

  __BB(3):
lab:
  _2 = l_1;
  goto __BB4;

  __BB(4):
  goto _2;

}

so you can see we have to support a non-__BB(N) goto even on GIMPLE
(labels shouldn't appear there - those are resolved to __BB(N)).

With your patch applied the following still ICEs in calc_dfs_tree for me
and no error is emitted:

void __GIMPLE (cfg)
foo (int x)
{
  void * gotovar;
  void * l;

  __BB(2):
lab:
  goto __BBB3;

  __BB(3):
  if (x != 0)
goto __BB5;
  else
goto __BB6;

  __BB(4):
  goto gotovar;

  __BB(5):
  gotovar = l;
  goto __BB4;

  __BB(6):
  return;

}

Note you picked a difficult patch - as said, the atoi fix looks OK to
me, even if
it doesn't solve downstream issues.  Can you split that out so I can
approve that
separately?

The GIMPLE FE is really not meant to parse arbitrary errorneous input - the ICEs
you run into should be viewed as error reporting (even if not exactly
helpful in this case).

That said, we should emit helpful errors for feeding
-fdump-tree-X-gimple output into
the GIMPLE FE since the dump output you get is not yet parseable without manual
editing.  "Fuzzing" attempts shouldn't be considered priority when fixing.

Thanks,
Richard.


Re: [PATCH v6 2/7] Drop targetm.promote_prototypes from C, C++ and Ada frontends

2024-12-08 Thread Richard Biener
On Sat, Dec 7, 2024 at 5:22 PM Jeff Law  wrote:
>
>
>
> On 12/7/24 8:38 AM, Jason Merrill wrote:
> > On 12/6/24 7:37 AM, Richard Biener wrote:
> >> On Wed, Dec 4, 2024 at 9:48 PM H.J. Lu  wrote:
> >>>
> >>> Remove the targetm.calls.promote_prototypes call from C, C++ and Ada
> >>> frontends.
> >>
> >> I'm conditionally approving this unless FE maintainers complain before
> >> holidays
> >> (the effect of the hook is re-instantiated during RTL expansion in 1/7).
> >>
> >> I've added the FE maintainers to CC
> >
> > I'm not entirely clear why this patch series isn't an ABI break, but
> > trust you to have considered that.  I have no C++-specific objection.
> That's my generic concern anytime we change these code paths.
>
> I Richi's position would be that the promote_prototypes call being used
> by the front-ends is fundamenally broken and I would generally agree.
> In theory the actions it's taking are supposed to be addressed by a
> later patch in the series.

Let me add that targetm.calls.promote_prototypes is _not_ part of the ABI.
Even when we'd drop it entirely this shouldn't have any effect -- unless
there are targets who fail to implement TARGET_PROMOTE_FUNCTION_MODE
and friends correctly.

That said, the first patch in the series ensures TARGET_PROMOTE_PROTOTYPES
is applied later during RTL expansion (where also TARGET_PROMOTE_FUNCTION_MODE
is applied).

Richard.

>
> Jeff
>
>


Re: [PATCH v6 1/7] Honor TARGET_PROMOTE_PROTOTYPES during RTL expand

2024-12-08 Thread Richard Biener
On Sat, Dec 7, 2024 at 5:23 PM Jeff Law  wrote:
>
>
>
> On 12/6/24 5:39 AM, Richard Biener wrote:
> > On Wed, Dec 4, 2024 at 9:48 PM H.J. Lu  wrote:
> >>
> >> Promote integer arguments smaller than int if TARGET_PROMOTE_PROTOTYPES
> >> returns true.
> >
> > This is OK when 2/7 got no negative comments and Jeff doesn't have
> > further input here.
> Nothing specific.  I'm leery of the change, but that's as much a
> function of being into stage3 as anything.

I have no strong opinion here as I think it should be pretty safe (and
it fixes a wrong-code
bug).  But I think we can also live with pushing this to next stage1
if HJ is fine with it.

Richard.

>
> Jeff


Re: [PATCH] tree-eh: Don't crash on GIMPLE_TRY_FINALLY with empty cleanup sequence [PR117845]

2024-12-08 Thread Richard Biener
On Sat, Dec 7, 2024 at 9:29 PM Simon Martin  wrote:
>
> The following valid code triggers an ICE with -fsanitize=address
>
> === cut here ===
> void l() {
> auto const ints = {0,1,2,3,4,5};
> for (auto i : { 3 } ) {
> __builtin_printf("%d ", i);
> }
> }
> === cut here ===
>
> The problem is that honor_protect_cleanup_actions does not expect the
> cleanup sequence of a GIMPLE_TRY_FINALLY to be empty. It is however the
> case here since r14-8681-gceb242f5302027, because lower_stmt removes the
> only statement in the sequence: a ASAN_MARK statement for the array that
> backs the initializer_list).
>
> This patch simply checks that the finally block is not 0 before
> accessing it in honor_protect_cleanup_actions.
>
> Successfully tested on x86_64-pc-linux-gnu. OK for trunk and gcc-14?
>
> PR c++/117845
>
> gcc/ChangeLog:
>
> * tree-eh.cc (honor_protect_cleanup_actions): Support empty
> finally sequences.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/asan/pr117845-2.C: New test.
> * g++.dg/asan/pr117845.C: New test.
>
> ---
>  gcc/testsuite/g++.dg/asan/pr117845-2.C | 12 
>  gcc/testsuite/g++.dg/asan/pr117845.C   | 12 
>  gcc/tree-eh.cc |  3 ++-
>  3 files changed, 26 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/g++.dg/asan/pr117845-2.C
>  create mode 100644 gcc/testsuite/g++.dg/asan/pr117845.C
>
> diff --git a/gcc/testsuite/g++.dg/asan/pr117845-2.C 
> b/gcc/testsuite/g++.dg/asan/pr117845-2.C
> new file mode 100644
> index 000..c0556397009
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/asan/pr117845-2.C
> @@ -0,0 +1,12 @@
> +// PR c++/117845 - Actually valid variant
> +// { dg-do "compile" }
> +// { dg-options "-fsanitize=address" }
> +
> +#include 
> +
> +void l() {
> +auto const ints = {0,1,2,3,4,5};
> +for (auto i : { 3 } ) {
> +__builtin_printf("%d ", i);
> +}
> +}
> diff --git a/gcc/testsuite/g++.dg/asan/pr117845.C 
> b/gcc/testsuite/g++.dg/asan/pr117845.C
> new file mode 100644
> index 000..d90d351e270
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/asan/pr117845.C
> @@ -0,0 +1,12 @@
> +// PR c++/117845 - Initially reported case.
> +// { dg-do "compile" }
> +// { dg-options "-fsanitize=address" }
> +
> +#include 
> +
> +void l() {
> +auto const ints = {0,1,2,3,4,5};
> +for (int i : ints | h) { // { dg-error "was not declared" }
> +__builtin_printf("%d ", i);
> +}
> +}
> diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
> index 769785fad2b..dc920de9b38 100644
> --- a/gcc/tree-eh.cc
> +++ b/gcc/tree-eh.cc
> @@ -1026,7 +1026,8 @@ honor_protect_cleanup_actions (struct leh_state 
> *outer_state,
>  MUST_NOT_THROW filter.  */
>gimple_stmt_iterator gsi = gsi_start (finally);
>gimple *x = gsi_stmt (gsi);
> -  if (gimple_code (x) == GIMPLE_TRY
> +  if (x

style-wise you should check for gsi_end_p (gsi) before
calling gsi_stmt on the iterator.  Implementation-wise
your patch has the same effect, of course.

Can you still refactor it this way?

Thanks,
Richard.

> + && gimple_code (x) == GIMPLE_TRY
>   && gimple_try_kind (x) == GIMPLE_TRY_CATCH
>   && gimple_try_catch_is_cleanup (x))
> {
> --
> 2.44.0
>


Re: [PATCH] tree-eh: Don't crash on GIMPLE_TRY_FINALLY with empty cleanup sequence [PR117845]

2024-12-08 Thread Richard Biener



> Am 08.12.2024 um 18:11 schrieb Simon Martin :
> 
> On 8 Dec 2024, at 11:10, Simon Martin wrote:
> 
>> Hi Richard,
>> 
>>> On 8 Dec 2024, at 10:27, Richard Biener wrote:
>>> 
>>> On Sat, Dec 7, 2024 at 9:29 PM Simon Martin 
>>> wrote:
 
 The following valid code triggers an ICE with -fsanitize=address
 
 === cut here ===
 void l() {
auto const ints = {0,1,2,3,4,5};
for (auto i : { 3 } ) {
__builtin_printf("%d ", i);
}
 }
 === cut here ===
 
 The problem is that honor_protect_cleanup_actions does not expect the
>> 
 cleanup sequence of a GIMPLE_TRY_FINALLY to be empty. It is however
 the
 case here since r14-8681-gceb242f5302027, because lower_stmt removes
 the
 only statement in the sequence: a ASAN_MARK statement for the array
 that
 backs the initializer_list).
 
 This patch simply checks that the finally block is not 0 before
 accessing it in honor_protect_cleanup_actions.
 
 Successfully tested on x86_64-pc-linux-gnu. OK for trunk and gcc-14?
 
PR c++/117845
 
 gcc/ChangeLog:
 
* tree-eh.cc (honor_protect_cleanup_actions): Support empty
finally sequences.
 
 gcc/testsuite/ChangeLog:
 
* g++.dg/asan/pr117845-2.C: New test.
* g++.dg/asan/pr117845.C: New test.
 
 ---
 gcc/testsuite/g++.dg/asan/pr117845-2.C | 12 
 gcc/testsuite/g++.dg/asan/pr117845.C   | 12 
 gcc/tree-eh.cc |  3 ++-
 3 files changed, 26 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/asan/pr117845-2.C
 create mode 100644 gcc/testsuite/g++.dg/asan/pr117845.C
 
 diff --git a/gcc/testsuite/g++.dg/asan/pr117845-2.C
 b/gcc/testsuite/g++.dg/asan/pr117845-2.C
 new file mode 100644
 index 000..c0556397009
 --- /dev/null
 +++ b/gcc/testsuite/g++.dg/asan/pr117845-2.C
 @@ -0,0 +1,12 @@
 +// PR c++/117845 - Actually valid variant
 +// { dg-do "compile" }
 +// { dg-options "-fsanitize=address" }
 +
 +#include 
 +
 +void l() {
 +auto const ints = {0,1,2,3,4,5};
 +for (auto i : { 3 } ) {
 +__builtin_printf("%d ", i);
 +}
 +}
 diff --git a/gcc/testsuite/g++.dg/asan/pr117845.C
 b/gcc/testsuite/g++.dg/asan/pr117845.C
 new file mode 100644
 index 000..d90d351e270
 --- /dev/null
 +++ b/gcc/testsuite/g++.dg/asan/pr117845.C
 @@ -0,0 +1,12 @@
 +// PR c++/117845 - Initially reported case.
 +// { dg-do "compile" }
 +// { dg-options "-fsanitize=address" }
 +
 +#include 
 +
 +void l() {
 +auto const ints = {0,1,2,3,4,5};
 +for (int i : ints | h) { // { dg-error "was not declared" }
 +__builtin_printf("%d ", i);
 +}
 +}
 diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
 index 769785fad2b..dc920de9b38 100644
 --- a/gcc/tree-eh.cc
 +++ b/gcc/tree-eh.cc
 @@ -1026,7 +1026,8 @@ honor_protect_cleanup_actions (struct leh_state
 *outer_state,
 MUST_NOT_THROW filter.  */
   gimple_stmt_iterator gsi = gsi_start (finally);
   gimple *x = gsi_stmt (gsi);
 -  if (gimple_code (x) == GIMPLE_TRY
 +  if (x
>>> 
>>> style-wise you should check for gsi_end_p (gsi) before
>>> calling gsi_stmt on the iterator.  Implementation-wise
>>> your patch has the same effect, of course.
>>> 
>>> Can you still refactor it this way?
>> Sure, here’s the updated version that I’m currently testing. Ok for
>> trunk and gcc-14 assuming the testing comes back all green?
> FYI the testing on x86_64-pc-linux-gnu of the updated patch was successful.

Ok

Richard 

> Simon
> 


[PATCH] testsuite/gcc.dg/tree-ssa/pr111456-1.c: Handle fallout

2024-12-08 Thread Hans-Peter Nilsson
Forcing a fail and marking as xfail is IMHO better than
passing --param=logical-op-non-short-circuit=0 or #pragma
GCC unroll, making the test pass.  To wit, this makes it
observable when it's fixed.

Ok to commit?
-- >8 --
This is expected fallout from r15-5646-gd1cf0d7a0f27fd as
described by that commit.

PR tree-ssa/117954
* gcc.dg/tree-ssa/pr111456-1.c: Xfail and pass
--param=logical-op-non-short-circuit=0.
---
 gcc/testsuite/gcc.dg/tree-ssa/pr111456-1.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr111456-1.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr111456-1.c
index 664a1afa..24984cd6c6b7 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr111456-1.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr111456-1.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-options "-O2 -fdump-tree-optimized --param 
logical-op-non-short-circuit=0" } */
 /* PR tree-optimization/111456 */
 
 void foo(void);
@@ -38,6 +38,6 @@ static signed char k(signed char m, short n) {
 int main() { k(0 <= 0 > *j, i); }
 
 
-/* { dg-final { scan-tree-dump-not "foo " "optimized" } } */
+/* { dg-final { scan-tree-dump-not "foo " "optimized" { xfail *-*-* } } } */
 /* { dg-final { scan-tree-dump "return 0;" "optimized" } } */
 
-- 
2.30.2



Re: [PATCH v2] testsuite/gcc.dg/tree-ssa/pr111456-1.c: Handle fallout

2024-12-08 Thread Hans-Peter Nilsson
> From: Sam James 
> Date: Sun, 08 Dec 2024 19:06:12 +

> Hans-Peter Nilsson  writes:
> 
> > v2: oops, typo: component is tree-optimization, not tree-ssa.
> > Resent for the benefit of autotesters that don't yet
> > understand natural language.
> >
> > Forcing a fail and marking as xfail is IMHO better than
> > passing --param=logical-op-non-short-circuit=0 or #pragma
> 
> "better than ...=1", right?

You are correct.  I have to fill my quota of at least one
typo per mssage. :)

At least that one was above the scissors-line.

brgds, H-P


> 
> > GCC unroll, making the test pass.  To wit, this makes it
> > observable when it's fixed.
> >
> > Ok to commit?
> > -- >8 --
> > This is expected fallout from r15-5646-gd1cf0d7a0f27fd as
> > described by that commit.
> >
> > PR tree-optimization/117954
> > * gcc.dg/tree-ssa/pr111456-1.c: Xfail and pass
> > --param=logical-op-non-short-circuit=0.
> > ---
> >  gcc/testsuite/gcc.dg/tree-ssa/pr111456-1.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr111456-1.c 
> > b/gcc/testsuite/gcc.dg/tree-ssa/pr111456-1.c
> > index 664a1afa..24984cd6c6b7 100644
> > --- a/gcc/testsuite/gcc.dg/tree-ssa/pr111456-1.c
> > +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr111456-1.c
> > @@ -1,5 +1,5 @@
> >  /* { dg-do compile } */
> > -/* { dg-options "-O2 -fdump-tree-optimized" } */
> > +/* { dg-options "-O2 -fdump-tree-optimized --param 
> > logical-op-non-short-circuit=0" } */
> >  /* PR tree-optimization/111456 */
> >  
> >  void foo(void);
> > @@ -38,6 +38,6 @@ static signed char k(signed char m, short n) {
> >  int main() { k(0 <= 0 > *j, i); }
> >  
> >  
> > -/* { dg-final { scan-tree-dump-not "foo " "optimized" } } */
> > +/* { dg-final { scan-tree-dump-not "foo " "optimized" { xfail *-*-* } } } 
> > */
> >  /* { dg-final { scan-tree-dump "return 0;" "optimized" } } */
> 


Re: [PATCH v2] testsuite/gcc.dg/tree-ssa/pr111456-1.c: Handle fallout

2024-12-08 Thread Sam James
Hans-Peter Nilsson  writes:

> v2: oops, typo: component is tree-optimization, not tree-ssa.
> Resent for the benefit of autotesters that don't yet
> understand natural language.
>
> Forcing a fail and marking as xfail is IMHO better than
> passing --param=logical-op-non-short-circuit=0 or #pragma

"better than ...=1", right?

> GCC unroll, making the test pass.  To wit, this makes it
> observable when it's fixed.
>
> Ok to commit?
> -- >8 --
> This is expected fallout from r15-5646-gd1cf0d7a0f27fd as
> described by that commit.
>
>   PR tree-optimization/117954
>   * gcc.dg/tree-ssa/pr111456-1.c: Xfail and pass
>   --param=logical-op-non-short-circuit=0.
> ---
>  gcc/testsuite/gcc.dg/tree-ssa/pr111456-1.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr111456-1.c 
> b/gcc/testsuite/gcc.dg/tree-ssa/pr111456-1.c
> index 664a1afa..24984cd6c6b7 100644
> --- a/gcc/testsuite/gcc.dg/tree-ssa/pr111456-1.c
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr111456-1.c
> @@ -1,5 +1,5 @@
>  /* { dg-do compile } */
> -/* { dg-options "-O2 -fdump-tree-optimized" } */
> +/* { dg-options "-O2 -fdump-tree-optimized --param 
> logical-op-non-short-circuit=0" } */
>  /* PR tree-optimization/111456 */
>  
>  void foo(void);
> @@ -38,6 +38,6 @@ static signed char k(signed char m, short n) {
>  int main() { k(0 <= 0 > *j, i); }
>  
>  
> -/* { dg-final { scan-tree-dump-not "foo " "optimized" } } */
> +/* { dg-final { scan-tree-dump-not "foo " "optimized" { xfail *-*-* } } } */
>  /* { dg-final { scan-tree-dump "return 0;" "optimized" } } */


[PATCH] gm2: fix bad programming practice warning

2024-12-08 Thread Wilken Gottwalt
Fix identifier names to be too similar to Modula-2 keywords and causing
warnings coming from Modula-2's own libraries.

m2/m2log/InOut.mod:51:18: note: In implementation module ‘InOut’:
either the identifier has the same name as a keyword or alternatively a
keyword has the wrong case (‘IN’ and ‘in’)
   51 |in, out: File ;

m2/m2log/InOut.mod:51:18: note: the symbol name ‘in’ is legal as an
identifier, however as such it might cause confusion and is considered
bad programming practice

gcc/gm2:
* gm2-libs-log/InOut.mod: Fix bad identifier warning.

Signed-off-by: Wilken Gottwalt 
---
 gcc/m2/gm2-libs-log/InOut.mod | 53 +--
 1 file changed, 26 insertions(+), 27 deletions(-)

diff --git a/gcc/m2/gm2-libs-log/InOut.mod b/gcc/m2/gm2-libs-log/InOut.mod
index 6e21fdcb6c1..12fdfe6b753 100644
--- a/gcc/m2/gm2-libs-log/InOut.mod
+++ b/gcc/m2/gm2-libs-log/InOut.mod
@@ -48,9 +48,8 @@ TYPE
CharSet = SET OF CHAR ;
 
 VAR
-   in, out: File ;
-   inUsed,
-   outUsed: BOOLEAN ;
+   inFile, outFile: File ;
+   inUsed, outUsed: BOOLEAN ;
 
 
 (*
@@ -71,8 +70,8 @@ BEGIN
END ;
IF SFIO.Exists(s)
THEN
-  in := SFIO.OpenToRead(s) ;
-  Done := FIO.IsNoError(in) ;
+  inFile := SFIO.OpenToRead(s) ;
+  Done := FIO.IsNoError(inFile) ;
   inUsed := TRUE
ELSE
   Done := FALSE ;
@@ -91,8 +90,8 @@ PROCEDURE CloseInput ;
 BEGIN
IF inUsed
THEN
-  FIO.Close(in) ;
-  in := StdIn ;
+  FIO.Close(inFile) ;
+  inFile := StdIn ;
   inUsed := FALSE
END
 END CloseInput ;
@@ -116,8 +115,8 @@ BEGIN
END ;
IF SFIO.Exists(s)
THEN
-  out := SFIO.OpenToWrite(s) ;
-  Done := FIO.IsNoError(out) ;
+  outFile := SFIO.OpenToWrite(s) ;
+  Done := FIO.IsNoError(outFile) ;
   outUsed := TRUE
ELSE
   Done := FALSE ;
@@ -136,8 +135,8 @@ PROCEDURE CloseOutput ;
 BEGIN
IF outUsed
THEN
-  FIO.Close(out) ;
-  out := StdOut ;
+  FIO.Close(outFile) ;
+  outFile := StdOut ;
   outUsed := FALSE
END
 END CloseOutput ;
@@ -149,8 +148,8 @@ END CloseOutput ;
 
 PROCEDURE LocalRead (VAR ch: CHAR) ;
 BEGIN
-   ch := FIO.ReadChar(in) ;
-   Done := FIO.IsNoError(in) AND (NOT FIO.EOF(in))
+   ch := FIO.ReadChar(inFile) ;
+   Done := FIO.IsNoError(inFile) AND (NOT FIO.EOF(inFile))
 END LocalRead ;
 
 
@@ -246,8 +245,8 @@ END ReadString ;
 
 PROCEDURE WriteString (s: ARRAY OF CHAR) ;
 BEGIN
-   FIO.WriteString(out, s) ;
-   Done := FIO.IsNoError(out)
+   FIO.WriteString(outFile, s) ;
+   Done := FIO.IsNoError(outFile)
 END WriteString ;
 
 
@@ -257,13 +256,13 @@ END WriteString ;
 
 PROCEDURE LocalWrite (ch: CHAR) ;
 BEGIN
-   FIO.WriteChar(out, ch) ;
-   Done := FIO.IsNoError(out)
+   FIO.WriteChar(outFile, ch) ;
+   Done := FIO.IsNoError(outFile)
 (*
IF outUsed
THEN
-  FIO.WriteChar(out, ch) ;
-  Done := FIO.IsNoError(out)
+  FIO.WriteChar(outFile, ch) ;
+  Done := FIO.IsNoError(outFile)
ELSE
   Done := (write(stdout, ADR(ch), 1) = 1)
END
@@ -308,8 +307,8 @@ PROCEDURE WriteLn ;
 BEGIN
IF outUsed
THEN
-  FIO.WriteLine(out) ;
-  Done := FIO.IsNoError(out)
+  FIO.WriteLine(outFile) ;
+  Done := FIO.IsNoError(outFile)
ELSE
   Terminal.WriteLn
END
@@ -366,7 +365,7 @@ END ReadCard ;
 
 PROCEDURE WriteCard (x, n: CARDINAL) ;
 BEGIN
-   IF KillString(SFIO.WriteS(out, ctos(x, n, ' ')))=NIL
+   IF KillString(SFIO.WriteS(outFile, ctos(x, n, ' ')))=NIL
THEN
END
 END WriteCard ;
@@ -380,7 +379,7 @@ END WriteCard ;
 
 PROCEDURE WriteInt (x: INTEGER; n: CARDINAL) ;
 BEGIN
-   IF KillString(SFIO.WriteS(out, itos(x, n, ' ', FALSE)))=NIL
+   IF KillString(SFIO.WriteS(outFile, itos(x, n, ' ', FALSE)))=NIL
THEN
END
 END WriteInt ;
@@ -394,7 +393,7 @@ END WriteInt ;
 
 PROCEDURE WriteOct (x, n: CARDINAL) ;
 BEGIN
-   IF KillString(SFIO.WriteS(out, CardinalToString(x, n, ' ', 8, FALSE)))=NIL
+   IF KillString(SFIO.WriteS(outFile, CardinalToString(x, n, ' ', 8, 
FALSE)))=NIL
THEN
END
 END WriteOct ;
@@ -408,7 +407,7 @@ END WriteOct ;
 
 PROCEDURE WriteHex (x, n: CARDINAL) ;
 BEGIN
-   IF KillString(SFIO.WriteS(out, CardinalToString(x, n, ' ', 16, TRUE)))=NIL
+   IF KillString(SFIO.WriteS(outFile, CardinalToString(x, n, ' ', 16, 
TRUE)))=NIL
THEN
END
 END WriteHex ;
@@ -420,8 +419,8 @@ END WriteHex ;
 
 PROCEDURE Init ;
 BEGIN
-   in := FIO.StdIn ;
-   out := FIO.StdOut ;
+   inFile := FIO.StdIn ;
+   outFile := FIO.StdOut ;
inUsed := FALSE ;
outUsed := FALSE ;
AssignRead(LocalRead, LocalStatus, Done) ;
-- 
2.47.1



[r15-6016 Regression] FAIL: gfortran.dg/sizeof_6.f90 -O1 execution test on Linux/x86_64

2024-12-08 Thread haochen.jiang
On Linux/x86_64,

d9cdc500c1e86b1218a24d1e8469930f000528d0 is the first bad commit
commit d9cdc500c1e86b1218a24d1e8469930f000528d0
Author: Lewis Hyatt 
Date:   Sat Nov 16 13:45:22 2024 -0500

Support for 64-bit location_t: Activate 64-bit location_t

caused

FAIL: gfortran.dg/sizeof_6.f90   -O1  execution test

with GCC configured with

../../gcc/configure 
--prefix=/export/users/haochenj/src/gcc-bisect/master/master/r15-6016/usr 
--enable-clocale=gnu --with-system-zlib --with-demangler-in-ld 
--with-fpmath=sse --enable-languages=c,c++,fortran --enable-cet --without-isl 
--enable-libmpx x86_64-linux --disable-bootstrap

To reproduce:

$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="dg.exp=gfortran.dg/sizeof_6.f90 --target_board='unix{-m64\ 
-march=cascadelake}'"

(Please do not reply to this email, for question about this report, contact me 
at haochen dot jiang at intel.com.)
(If you met problems with cascadelake related, disabling AVX512F in command 
line might save that.)
(However, please make sure that there is no potential problems with AVX512.)


[PATCH] Fortran: fix two minor front-end GMP memleaks

2024-12-08 Thread Harald Anlauf
Dear all,

while looking at testcases with inquiry refs, I encountered two minor
GMP memleaks due to double-initialization of GMP variables.  Easily
plugged by the attached patch.

Regtested on x86_64-pc-linux-gnu.

I intend to commit as obvious within 24h unless there are objections.

Thanks,
Harald

From a299b38fa34869b19f5e11bcc389cd78c877c319 Mon Sep 17 00:00:00 2001
From: Harald Anlauf 
Date: Sun, 8 Dec 2024 22:30:32 +0100
Subject: [PATCH] Fortran: fix two minor front-end GMP memleaks

gcc/fortran/ChangeLog:

	* expr.cc (find_array_section): Do not initialize GMP variables
	twice.
---
 gcc/fortran/expr.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index a997bdae726..a349d989d6c 100644
--- a/gcc/fortran/expr.cc
+++ b/gcc/fortran/expr.cc
@@ -1613,7 +1613,7 @@ find_array_section (gfc_expr *expr, gfc_ref *ref)
 	  /* Zero-sized arrays have no shape and no elements, stop early.  */
 	  if (!begin->shape)
 	{
-	  mpz_init_set_ui (nelts, 0);
+	  mpz_set_ui (nelts, 0);
 	  break;
 	}

@@ -1714,7 +1714,7 @@ find_array_section (gfc_expr *expr, gfc_ref *ref)
  constructor.  */
   for (idx = 0; idx < (int) mpz_get_si (nelts); idx++)
 {
-  mpz_init_set_ui (ptr, 0);
+  mpz_set_ui (ptr, 0);

   incr_ctr = true;
   for (d = 0; d < rank; d++)
--
2.35.3



Re: [PATCH] AIX Build failure with default -std=gnu23.

2024-12-08 Thread David Edelsohn
This revised patch is okay.

You are listed in the FSF copyrights file for GCC GDB GLIBC BINUTILS, but
do you have write privileges for the GCC repo?  You are not listed in
gcc/MAINTAINERS for write-after-approval.

Thanks, David

On Sun, Dec 8, 2024 at 10:49 AM swamy sangamesh 
wrote:

> Thank you all for the review and comments.
>
> David, I have tested the changes against the latest master and ran default
> test cases.
> I have also built and ran the default test cases on RHEL9.0 ppc64le.
> Please let me know if any other testing needs to be covered.
>
> Please find the latest patch attached.
>
>
>
> On Sat, Dec 7, 2024 at 2:31 AM David Edelsohn  wrote:
>
>> On Fri, Dec 6, 2024 at 2:17 PM Ian Lance Taylor  wrote:
>>
>>> David Edelsohn  writes:
>>>
>>> > On Fri, Dec 6, 2024 at 12:25 PM Rainer Orth <
>>> r...@cebitec.uni-bielefeld.de>
>>> > wrote:
>>> >
>>> >> Hi David,
>>> >>
>>> >> > No objection from me, but Ian is the maintainer of libiberty, so
>>> I'll
>>> >> defer
>>> >> > to him, especially about style and overall software engineering.
>>> >> >
>>> >> > The C23 change presumably will break on Alpha OSF/1 as well.  Does
>>> GCC
>>> >> > still support OSF/1?  It might be preferred to delete the block
>>> entirely
>>> >> > instead of #ifndef _AIX.
>>> >>
>>> >> GCC 4.7 was the last release to support Tru64 UNIX (ex-OSF/1).
>>> However,
>>> >> libiberty is also used outside of the toolchain, so that may affect
>>> the
>>> >> decision.
>>> >>
>>> >> However, IMO the Tru64 UNIX support can go for good now.
>>> >>
>>> >
>>> > Hi, Rainer
>>> >
>>> > Thanks for taking a look and commenting.
>>> >
>>> > It seems we both agree that it would be better to remove the entire
>>> block
>>> > defining _NO_PROTO because both of the systems are no longer supported.
>>> >
>>> > I'll give Ian the opportunity to comment.
>>>
>>> Looks good to me.  Thanks.
>>>
>>> Ian
>>>
>>
>> Sangamesh,
>>
>> Can you respin and test a revised patch that removes the conditional
>> _NO_PROTO definition instead of adding #ifndef _AIX?  I think that is what
>> Rainer and I would prefer because neither of the OSes is supported and we
>> don't need a fragile work-around.
>>
>> Thanks, David
>>
>>
>
> --
> Thanks & Regards,
> Sangamesh
>


[PATCH v2] testsuite/gcc.dg/tree-ssa/pr111456-1.c: Handle fallout

2024-12-08 Thread Hans-Peter Nilsson
v2: oops, typo: component is tree-optimization, not tree-ssa.
Resent for the benefit of autotesters that don't yet
understand natural language.

Forcing a fail and marking as xfail is IMHO better than
passing --param=logical-op-non-short-circuit=0 or #pragma
GCC unroll, making the test pass.  To wit, this makes it
observable when it's fixed.

Ok to commit?
-- >8 --
This is expected fallout from r15-5646-gd1cf0d7a0f27fd as
described by that commit.

PR tree-optimization/117954
* gcc.dg/tree-ssa/pr111456-1.c: Xfail and pass
--param=logical-op-non-short-circuit=0.
---
 gcc/testsuite/gcc.dg/tree-ssa/pr111456-1.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr111456-1.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr111456-1.c
index 664a1afa..24984cd6c6b7 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr111456-1.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr111456-1.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-options "-O2 -fdump-tree-optimized --param 
logical-op-non-short-circuit=0" } */
 /* PR tree-optimization/111456 */
 
 void foo(void);
@@ -38,6 +38,6 @@ static signed char k(signed char m, short n) {
 int main() { k(0 <= 0 > *j, i); }
 
 
-/* { dg-final { scan-tree-dump-not "foo " "optimized" } } */
+/* { dg-final { scan-tree-dump-not "foo " "optimized" { xfail *-*-* } } } */
 /* { dg-final { scan-tree-dump "return 0;" "optimized" } } */
 
-- 
2.30.2



Re: [PATCH] Fix type compatibility for types with flexible array member [PR113688,PR114014,PR117724]

2024-12-08 Thread Sam James
Martin Uecker  writes:

> Hi Richard,
>
> this is another version.  It now adds an "ignore_size" flag
> to gimple_canonical_types_compatible_p and uses this instead
> of having the complicated special case for arrays at the
> end.  Also zero-sized members are now ignored again, except
> if they are arrays at the end where then only the size is
> ignored.  This can still be stricter than before for the 
> case where there are zero-sized arrays at the end (e.g.
> before element type could differ). 
>
> Martin
>
>
> Bootstrapped and regression tested on x86_64.
> [...]
>  
> diff --git a/gcc/testsuite/gcc.dg/pr112716.c b/gcc/testsuite/gcc.dg/pr112716.c
> new file mode 100644
> index 000..109dd252f0d
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pr112716.c
> @@ -0,0 +1,40 @@
> +/* { dg-do compile } */
> +/* { dg-options "-lfto -O2" } */

-flto, but need to use dg-require-effective-target lto too then.

> [...]

thanks,
sam


Re: [PATCH] tree-eh: Don't crash on GIMPLE_TRY_FINALLY with empty cleanup sequence [PR117845]

2024-12-08 Thread Simon Martin
On 8 Dec 2024, at 11:10, Simon Martin wrote:

> Hi Richard,
>
> On 8 Dec 2024, at 10:27, Richard Biener wrote:
>
>> On Sat, Dec 7, 2024 at 9:29 PM Simon Martin 
>> wrote:
>>>
>>> The following valid code triggers an ICE with -fsanitize=address
>>>
>>> === cut here ===
>>> void l() {
>>> auto const ints = {0,1,2,3,4,5};
>>> for (auto i : { 3 } ) {
>>> __builtin_printf("%d ", i);
>>> }
>>> }
>>> === cut here ===
>>>
>>> The problem is that honor_protect_cleanup_actions does not expect the
>
>>> cleanup sequence of a GIMPLE_TRY_FINALLY to be empty. It is however
>>> the
>>> case here since r14-8681-gceb242f5302027, because lower_stmt removes
>>> the
>>> only statement in the sequence: a ASAN_MARK statement for the array
>>> that
>>> backs the initializer_list).
>>>
>>> This patch simply checks that the finally block is not 0 before
>>> accessing it in honor_protect_cleanup_actions.
>>>
>>> Successfully tested on x86_64-pc-linux-gnu. OK for trunk and gcc-14?
>>>
>>> PR c++/117845
>>>
>>> gcc/ChangeLog:
>>>
>>> * tree-eh.cc (honor_protect_cleanup_actions): Support empty
>>> finally sequences.
>>>
>>> gcc/testsuite/ChangeLog:
>>>
>>> * g++.dg/asan/pr117845-2.C: New test.
>>> * g++.dg/asan/pr117845.C: New test.
>>>
>>> ---
>>>  gcc/testsuite/g++.dg/asan/pr117845-2.C | 12 
>>>  gcc/testsuite/g++.dg/asan/pr117845.C   | 12 
>>>  gcc/tree-eh.cc |  3 ++-
>>>  3 files changed, 26 insertions(+), 1 deletion(-)
>>>  create mode 100644 gcc/testsuite/g++.dg/asan/pr117845-2.C
>>>  create mode 100644 gcc/testsuite/g++.dg/asan/pr117845.C
>>>
>>> diff --git a/gcc/testsuite/g++.dg/asan/pr117845-2.C
>>> b/gcc/testsuite/g++.dg/asan/pr117845-2.C
>>> new file mode 100644
>>> index 000..c0556397009
>>> --- /dev/null
>>> +++ b/gcc/testsuite/g++.dg/asan/pr117845-2.C
>>> @@ -0,0 +1,12 @@
>>> +// PR c++/117845 - Actually valid variant
>>> +// { dg-do "compile" }
>>> +// { dg-options "-fsanitize=address" }
>>> +
>>> +#include 
>>> +
>>> +void l() {
>>> +auto const ints = {0,1,2,3,4,5};
>>> +for (auto i : { 3 } ) {
>>> +__builtin_printf("%d ", i);
>>> +}
>>> +}
>>> diff --git a/gcc/testsuite/g++.dg/asan/pr117845.C
>>> b/gcc/testsuite/g++.dg/asan/pr117845.C
>>> new file mode 100644
>>> index 000..d90d351e270
>>> --- /dev/null
>>> +++ b/gcc/testsuite/g++.dg/asan/pr117845.C
>>> @@ -0,0 +1,12 @@
>>> +// PR c++/117845 - Initially reported case.
>>> +// { dg-do "compile" }
>>> +// { dg-options "-fsanitize=address" }
>>> +
>>> +#include 
>>> +
>>> +void l() {
>>> +auto const ints = {0,1,2,3,4,5};
>>> +for (int i : ints | h) { // { dg-error "was not declared" }
>>> +__builtin_printf("%d ", i);
>>> +}
>>> +}
>>> diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
>>> index 769785fad2b..dc920de9b38 100644
>>> --- a/gcc/tree-eh.cc
>>> +++ b/gcc/tree-eh.cc
>>> @@ -1026,7 +1026,8 @@ honor_protect_cleanup_actions (struct leh_state
>>> *outer_state,
>>>  MUST_NOT_THROW filter.  */
>>>gimple_stmt_iterator gsi = gsi_start (finally);
>>>gimple *x = gsi_stmt (gsi);
>>> -  if (gimple_code (x) == GIMPLE_TRY
>>> +  if (x
>>
>> style-wise you should check for gsi_end_p (gsi) before
>> calling gsi_stmt on the iterator.  Implementation-wise
>> your patch has the same effect, of course.
>>
>> Can you still refactor it this way?
> Sure, here’s the updated version that I’m currently testing. Ok for
> trunk and gcc-14 assuming the testing comes back all green?
FYI the testing on x86_64-pc-linux-gnu of the updated patch was successful.

Simon



Re: [PATCH] Fortran: fix two minor front-end GMP memleaks

2024-12-08 Thread Jerry Delisle
Looks good, OK to push.

On Sun, Dec 8, 2024, 1:39 PM Harald Anlauf  wrote:

> Dear all,
>
> while looking at testcases with inquiry refs, I encountered two minor
> GMP memleaks due to double-initialization of GMP variables.  Easily
> plugged by the attached patch.
>
> Regtested on x86_64-pc-linux-gnu.
>
> I intend to commit as obvious within 24h unless there are objections.
>
> Thanks,
> Harald
>
>


[PATCH] Fix type compatibility for types with flexible array member [PR113688,PR114014,PR117724]

2024-12-08 Thread Martin Uecker


Hi Richard,

this is another version.  It now adds an "ignore_size" flag
to gimple_canonical_types_compatible_p and uses this instead
of having the complicated special case for arrays at the
end.  Also zero-sized members are now ignored again, except
if they are arrays at the end where then only the size is
ignored.  This can still be stricter than before for the 
case where there are zero-sized arrays at the end (e.g.
before element type could differ). 

Martin


Bootstrapped and regression tested on x86_64.



Fix type compatibility for types with flexible array member 
[PR113688,PR114014,PR117724]

verify_type checks the compatibility of TYPE_CANONICAL using
gimple_canonical_types_compatible_p.   But it is stricter than what the
C standard requires and therefor inconsistent with how TYPE_CANONICAL is set
in the C FE.  Here, the logic is changed to ignore the array size when it
is the last element of a structure or union.  To not get errors because of
an inconsistent number of members, zero-sized arrays which are the last
element are not ignored anymore when checking the fields of a struct (which
in this particular case is stricter than what was done before).  Finally,
exceptions are added that allow the TYPE_MODE of a type with an array as
last member and of such arrays to differ from another compatible type.

PR c/112716
PR c/113688
PR c/114014
PR c/117724

gcc/ChangeLog:
* tree.cc (gimple_canonical_types_compatible_p): Add
  `ignore_size' parameter and revise logic.
(verify_type): Add exceptions.

gcc/lto/ChangeLog:
* lto-common.cc (hash_canonical_type): Add exceptions.

gcc/testsuite/ChangeLog:
* gcc.dg/pr112716.c: New test.
* gcc.dg/pr113688.c: New test.
* gcc.dg/pr114014.c: New test.
* gcc.dg/pr117724.c: New test.

diff --git a/gcc/lto/lto-common.cc b/gcc/lto/lto-common.cc
index 86a309f92b4..f65a9d1c7b6 100644
--- a/gcc/lto/lto-common.cc
+++ b/gcc/lto/lto-common.cc
@@ -254,7 +254,8 @@ hash_canonical_type (tree type)
  checked.  */
   code = tree_code_for_canonical_type_merging (TREE_CODE (type));
   hstate.add_int (code);
-  hstate.add_int (TYPE_MODE (type));
+  if (!RECORD_OR_UNION_TYPE_P (type))
+hstate.add_int (TYPE_MODE (type));
 
   /* Incorporate common features of numerical types.  */
   if (INTEGRAL_TYPE_P (type)
@@ -332,7 +333,11 @@ hash_canonical_type (tree type)
&& (! DECL_SIZE (f)
|| ! integer_zerop (DECL_SIZE (f
  {
-   iterative_hash_canonical_type (TREE_TYPE (f), hstate);
+   tree t = TREE_TYPE (f);
+   if (!TREE_CHAIN (f)
+   && TREE_CODE (t) == ARRAY_TYPE)
+ t = TREE_TYPE  (t);
+   iterative_hash_canonical_type (t, hstate);
nf++;
  }
 
diff --git a/gcc/testsuite/gcc.dg/pr112716.c b/gcc/testsuite/gcc.dg/pr112716.c
new file mode 100644
index 000..109dd252f0d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr112716.c
@@ -0,0 +1,40 @@
+/* { dg-do compile } */
+/* { dg-options "-lfto -O2" } */
+
+#define T1 int[n]
+#define T2 int[n]
+
+// TU 1
+void bar(void*);
+
+[[gnu::noinline,gnu::noipa]]
+int foo(void *p, void *q)
+{
+   int n = 5;
+   struct foo { int x; typeof(T1) y; } *p2 = p;
+   p2->x = 1;
+   bar(q);
+   return p2->x;
+}
+
+int main()
+{
+   int n = 5;
+   void *p = __builtin_malloc(sizeof(struct foo { int x; typeof(T1) y; }));
+
+   if (!p)
+   return 0;
+
+   if (2 != foo(p, p))
+   __builtin_abort();
+
+   return 0;
+}
+// TU 2
+void bar(void* q)
+{
+   int n = 5;
+   struct foo { int x; typeof(T2) y; } *q2 = q;
+   q2->x = 2;
+}
+
diff --git a/gcc/testsuite/gcc.dg/pr113688.c b/gcc/testsuite/gcc.dg/pr113688.c
new file mode 100644
index 000..8dee8c86f1b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr113688.c
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-g" } */
+
+struct S{int x,y[1];}*a;
+int main(void){
+   struct S{int x,y[];};
+}
+
diff --git a/gcc/testsuite/gcc.dg/pr114014.c b/gcc/testsuite/gcc.dg/pr114014.c
new file mode 100644
index 000..1531ffab1b7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr114014.c
@@ -0,0 +1,14 @@
+/* PR c/114014
+ * { dg-do compile }
+ * { dg-options "-std=gnu23 -g" } */
+
+struct r {
+  int a;
+  char b[];
+};
+struct r {
+  int a;
+  char b[0];
+};
+
+
diff --git a/gcc/testsuite/gcc.dg/pr117724.c b/gcc/testsuite/gcc.dg/pr117724.c
new file mode 100644
index 000..d631daeb644
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr117724.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-g" } */
+
+struct {
+  unsigned long len;
+  unsigned long size;
+  char data[];
+}; /* { dg-warning "unnamed struct" } */
+struct {
+  struct {
+unsigned long len;
+unsigned long size

Re: 'gcc/config/nvptx/gen-multilib-matches.sh': Support '--selftest'

2024-12-08 Thread Sam James
Thomas Schwinge  writes:

> Hi Sam!

Hi!
>
> On 2024-12-06T09:34:32+, Sam James  wrote:
>> The script has #!/bin/sh shebang (and hence must have POSIX shell
>> compatibility), but the patch introduces uses of the 'local' keyword
>> which isn't in POSIX.
>>
>> While many shells do have the 'local' keyword, its behaviour isn't
>> portable across those either, which is why it's likely it'll never
>> be added to POSIX :(
>
> Right, but I intentionally picked the form that I thought was supported
> by all reasonable '/bin/sh's: 'local [name]', without any further
> adornement.  For example, per :
>
> | 'local' is mandated by the LSB and Debian policy specifications, though 
> only the 'local varname' (not 'local var=value') syntax is specified.
>
> Portable, reliable shell programming is a nice idea, but then, reality
> check...

Yeah, that's fair enough. (I just noticed by chance as I was looking at
my other issue; I didn't hit an actual problem with this at all.)

>
> (Don't ask me how much time I already spent on this simple script, to get
> it into its current form -- and I'd consider myself well-versed in shell
> programming...)
>
> I was inclined to just rewrite it in Python, what do you think?  In my
> opinion, a GCC-build-time Python dependency is not a problem for
> '--target=nvptx-none', as that one's not in the bootstrapping chain?

I think that should be fine and far less error prone. Certainly not a
problem for us and I can't imagine it is for the others.

>
>
> Grüße
>  Thomas

thanks,
sam


Re: [PATCH] Add fancy pointer support in std::map/set

2024-12-08 Thread François Dumont


On 04/12/2024 22:48, Jonathan Wakely wrote:

On 04/12/24 19:27 +0100, François Dumont wrote:

Hi

I've completed the synchronization with your equivalent PR for 
std::list so here is the updated patch.


PR updated a couple of days ago.

Note that I've started to rework the patch for the same in _Hashtable.


Great, thanks.



#if __cplusplus < 201103L
  void
-  _M_construct_node(_Link_type __node, const value_type& __x)
+  _M_construct_node(_Base_ptr __p, const value_type& __x)


And can this be left as _Node_ptr instead of changed to _Base_ptr?
Then it wouldn't need the static_cast, and the callers wouldn't need
to use _M_base_ptr().

Logically, it has to be a _Node_ptr or the cast isn't valid anyway.

There seem to be several places like this where we're giving up
valuable type information by using _base_ptr instead of _Node_ptr.

Is that really necessary? If we have a _Node_ptr we can always get a
_Base_ptr easily by calling _M_base_ptr().

Is it a constness thing, because _M_begin() const was changed to
return _Base_ptr instead of _Const_link_ptr?

No, just me being lazy and considering that as we store _Base_ptr we can 
also use it everywhere.


In this new version I've preserved _Node_ptr almost everywhere.

But _M_begin() is still returning a _Base_ptr and I've introduced 
_M_begin_node() for rare occasions when a _Node_ptr is needed.


Note that I've hesitated to add a _S_nullptr() to get a _Base_ptr null 
pointer. Is default constructor on fancy pointer type mandatory ? I fear 
that only constructor from nullptr is mandatory.


I've forced push on:

https://forge.sourceware.org/gcc/gcc-TEST/pulls/27

François

diff --git a/libstdc++-v3/include/bits/stl_tree.h 
b/libstdc++-v3/include/bits/stl_tree.h
index bc27e191e8b..c5539371628 100644
--- a/libstdc++-v3/include/bits/stl_tree.h
+++ b/libstdc++-v3/include/bits/stl_tree.h
@@ -66,6 +66,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #if __cplusplus >= 201103L
 # include 
@@ -74,6 +75,13 @@
 # include 
 #endif
 
+#if __cplusplus < 201103L
+# undef _GLIBCXX_USE_ALLOC_PTR_FOR_RB_TREE
+# define _GLIBCXX_USE_ALLOC_PTR_FOR_RB_TREE 0
+#elif ! defined _GLIBCXX_USE_ALLOC_PTR_FOR_RB_TREE
+# define _GLIBCXX_USE_ALLOC_PTR_FOR_RB_TREE 1
+#endif
+
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -99,7 +107,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   struct _Rb_tree_node_base
   {
 typedef _Rb_tree_node_base* _Base_ptr;
-typedef const _Rb_tree_node_base* _Const_Base_ptr;
 
 _Rb_tree_color _M_color;
 _Base_ptr  _M_parent;
@@ -113,13 +120,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   return __x;
 }
 
-static _Const_Base_ptr
-_S_minimum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
-{
-  while (__x->_M_left != 0) __x = __x->_M_left;
-  return __x;
-}
-
 static _Base_ptr
 _S_maximum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
 {
@@ -127,12 +127,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   return __x;
 }
 
-static _Const_Base_ptr
-_S_maximum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
-{
-  while (__x->_M_right != 0) __x = __x->_M_right;
-  return __x;
-}
+// This is not const-correct, but it's only used in a const access path
+// by std::_Rb_tree::_M_end() where the pointer is used to initialize a
+// const_iterator and so constness is restored.
+_Base_ptr
+_M_base_ptr() const _GLIBCXX_NOEXCEPT
+{ return const_cast<_Rb_tree_node_base*>(this); }
+
+template
+  _NodePtr
+  _M_node_ptr() _GLIBCXX_NOEXCEPT
+  { return static_cast<_NodePtr>(this); }
   };
 
   // Helper type offering value initialization guarantee on the compare 
functor.
@@ -213,8 +218,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 struct _Rb_tree_node : public _Rb_tree_node_base
 {
-  typedef _Rb_tree_node<_Val>* _Link_type;
-
 #if __cplusplus < 201103L
   _Val _M_value_field;
 
@@ -238,18 +241,135 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
 };
 
+#if _GLIBCXX_USE_ALLOC_PTR_FOR_RB_TREE
+namespace __rb_tree
+{
+  template
+struct _Node_base
+{
+  using _Base_ptr = __ptr_rebind<_VoidPtr, _Node_base>;
+
+  _Rb_tree_color   _M_color;
+  _Base_ptr_M_parent;
+  _Base_ptr_M_left;
+  _Base_ptr_M_right;
+
+  static _Base_ptr
+  _S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
+  {
+   while (__x->_M_left) __x = __x->_M_left;
+   return __x;
+  }
+
+  static _Base_ptr
+  _S_maximum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
+  {
+   while (__x->_M_right) __x = __x->_M_right;
+   return __x;
+  }
+
+  // This is not const-correct, but it's only used in a const access path
+  // by std::_Rb_tree::_M_end() where the pointer is used to initialize a
+  // const_iterator and so constness is restored.
+  _Base_ptr
+  _M_base_ptr() const
+  {
+   return pointer_traits<_Base_ptr>::pointer_to
+  

RE: [PATCH v1] RISC-V: Fix incorrect optimization options passing to partial

2024-12-08 Thread Li, Pan2
Thanks Kito, all issues like below of rvv.exp are fixed.

Pan

-Original Message-
From: Kito Cheng  
Sent: Monday, December 9, 2024 2:58 PM
To: Li, Pan2 
Cc: gcc-patches@gcc.gnu.org; juzhe.zh...@rivai.ai; jeffreya...@gmail.com; 
rdapp@gmail.com
Subject: Re: [PATCH v1] RISC-V: Fix incorrect optimization options passing to 
partial

ok

On Mon, Dec 9, 2024 at 2:13 PM  wrote:
>
> From: Pan Li 
>
> Like the strided load/store, the testcases of vector partial
> are designed to pick up different sorts of optimization options but
> actually these option are ignored according to the Execution log of
> the gcc.log.
>
> This patch would like to make it correct almost the same as how we
> fixed for strided load/store.
>
> The below test suites are passed for this patch.
> * The rv64gcv fully regression test.
>
> It is test only patch and obvious up to a point, will commit it
> directly if no comments in next 48H.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/riscv/rvv/rvv.exp: Fix the incorrect optimization
> options passing to testcases.
>
> Signed-off-by: Pan Li 
> ---
>  gcc/testsuite/gcc.target/riscv/rvv/rvv.exp | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/rvv.exp 
> b/gcc/testsuite/gcc.target/riscv/rvv/rvv.exp
> index 98759865fb5..1278f23e8ea 100644
> --- a/gcc/testsuite/gcc.target/riscv/rvv/rvv.exp
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/rvv.exp
> @@ -61,7 +61,7 @@ set AUTOVEC_TEST_OPTS [list \
>{-ftree-vectorize -O2 -mrvv-max-lmul=dynamic} ]
>  foreach op $AUTOVEC_TEST_OPTS {
>dg-runtest [lsort [glob -nocomplain 
> $srcdir/$subdir/autovec/partial/*.\[cS\]]] \
> -"" "$op"
> +"$op" ""
>dg-runtest [lsort [glob -nocomplain 
> $srcdir/$subdir/autovec/binop/*.\[cS\]]] \
>  "$op" ""
>dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/autovec/cmp/*.\[cS\]]] 
> \
> --
> 2.43.0
>


Re: [PATCH v1] RISC-V: Fix incorrect optimization options passing to partial

2024-12-08 Thread Kito Cheng
ok

On Mon, Dec 9, 2024 at 2:13 PM  wrote:
>
> From: Pan Li 
>
> Like the strided load/store, the testcases of vector partial
> are designed to pick up different sorts of optimization options but
> actually these option are ignored according to the Execution log of
> the gcc.log.
>
> This patch would like to make it correct almost the same as how we
> fixed for strided load/store.
>
> The below test suites are passed for this patch.
> * The rv64gcv fully regression test.
>
> It is test only patch and obvious up to a point, will commit it
> directly if no comments in next 48H.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/riscv/rvv/rvv.exp: Fix the incorrect optimization
> options passing to testcases.
>
> Signed-off-by: Pan Li 
> ---
>  gcc/testsuite/gcc.target/riscv/rvv/rvv.exp | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/rvv.exp 
> b/gcc/testsuite/gcc.target/riscv/rvv/rvv.exp
> index 98759865fb5..1278f23e8ea 100644
> --- a/gcc/testsuite/gcc.target/riscv/rvv/rvv.exp
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/rvv.exp
> @@ -61,7 +61,7 @@ set AUTOVEC_TEST_OPTS [list \
>{-ftree-vectorize -O2 -mrvv-max-lmul=dynamic} ]
>  foreach op $AUTOVEC_TEST_OPTS {
>dg-runtest [lsort [glob -nocomplain 
> $srcdir/$subdir/autovec/partial/*.\[cS\]]] \
> -"" "$op"
> +"$op" ""
>dg-runtest [lsort [glob -nocomplain 
> $srcdir/$subdir/autovec/binop/*.\[cS\]]] \
>  "$op" ""
>dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/autovec/cmp/*.\[cS\]]] 
> \
> --
> 2.43.0
>


[PATCH v1] RISC-V: Fix incorrect optimization options passing to partial

2024-12-08 Thread pan2 . li
From: Pan Li 

Like the strided load/store, the testcases of vector partial
are designed to pick up different sorts of optimization options but
actually these option are ignored according to the Execution log of
the gcc.log.

This patch would like to make it correct almost the same as how we
fixed for strided load/store.

The below test suites are passed for this patch.
* The rv64gcv fully regression test.

It is test only patch and obvious up to a point, will commit it
directly if no comments in next 48H.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/rvv.exp: Fix the incorrect optimization
options passing to testcases.

Signed-off-by: Pan Li 
---
 gcc/testsuite/gcc.target/riscv/rvv/rvv.exp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/rvv.exp 
b/gcc/testsuite/gcc.target/riscv/rvv/rvv.exp
index 98759865fb5..1278f23e8ea 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/rvv.exp
+++ b/gcc/testsuite/gcc.target/riscv/rvv/rvv.exp
@@ -61,7 +61,7 @@ set AUTOVEC_TEST_OPTS [list \
   {-ftree-vectorize -O2 -mrvv-max-lmul=dynamic} ]
 foreach op $AUTOVEC_TEST_OPTS {
   dg-runtest [lsort [glob -nocomplain 
$srcdir/$subdir/autovec/partial/*.\[cS\]]] \
-"" "$op"
+"$op" ""
   dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/autovec/binop/*.\[cS\]]] 
\
 "$op" ""
   dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/autovec/cmp/*.\[cS\]]] \
-- 
2.43.0



Re: [PATCH v1 1/6] RISC-V: Refine unsigned vector SAT_ADD testcase dump check to tree optimized

2024-12-08 Thread Kito Cheng
This patch series is LGTM :)

On Sun, Dec 8, 2024 at 8:01 PM  wrote:
>
> From: Pan Li 
>
> The sat alu related testcase check the rtl dump for the standard name
> like .SAT_ADD exist or not.  But the rtl pass expand is somehow
> impressionable by the middle-end change or debug information.  Like
> below new appearance recently.
>
> Replacing Expressions
> _5 replace with --> _5 = .SAT_ADD (x_3(D), y_4(D)); [tail call]
>
> After that we need to adjust the dump check time and again.  This
> patch would like to switch to tree optimized pass for the standard
> name check, which is more stable up to a point.
>
> The below test suites are passed for this patch.
> * The rv64gcv fully regression test.
>
> It is test only patch and obvious up to a point, will commit it
> directly if no comments in next 48H.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-1-u16.c: Take
> tree-optimized pass for standard name check, and adjust the times.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-1-u32.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-1-u64.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-1-u8.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-2-u16.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-2-u32.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-2-u64.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-2-u8.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-3-u16.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-3-u32.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-3-u64.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-3-u8.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-4-u16.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-4-u32.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-4-u64.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-4-u8.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-5-u16.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-5-u32.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-5-u64.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-5-u8.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-6-u16.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-6-u32.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-6-u64.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-6-u8.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-7-u16.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-7-u32.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-7-u64.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-7-u8.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-8-u16.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-8-u32.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-8-u64.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add-8-u8.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-1-u16.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-1-u32.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-1-u64.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-1-u8.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-2-u16.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-2-u32.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-2-u64.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-2-u8.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-3-u16.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-3-u32.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-3-u64.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-3-u8.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-4-u16.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-4-u32.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-4-u64.c: Ditto.
> * gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm-4-u8.c: Ditto.
> * 
> gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm_reconcile-1-u16.c: Ditto.
> * 
> gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm_reconcile-1-u32.c: Ditto.
> * 
> gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm_reconcile-1-u64.c: Ditto.
> * 
> gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_imm_reconcile-1-u8.c: Ditto.
> * 
> gcc.target/riscv/rvv/autovec/sat/vec_sat_u_add_im

Re: [PATCH] AIX Build failure with default -std=gnu23.

2024-12-08 Thread swamy sangamesh
Hi  David,

I don't have write privileges for GCC repo.
I have raised a request for write access and provided your email address as
approver.
Please approve the request.

Thanks,
Sangamesh


On Mon, Dec 9, 2024 at 3:17 AM David Edelsohn  wrote:

> This revised patch is okay.
>
> You are listed in the FSF copyrights file for GCC GDB GLIBC BINUTILS, but
> do you have write privileges for the GCC repo?  You are not listed in
> gcc/MAINTAINERS for write-after-approval.
>
> Thanks, David
>
> On Sun, Dec 8, 2024 at 10:49 AM swamy sangamesh 
> wrote:
>
>> Thank you all for the review and comments.
>>
>> David, I have tested the changes against the latest master and ran
>> default test cases.
>> I have also built and ran the default test cases on RHEL9.0 ppc64le.
>> Please let me know if any other testing needs to be covered.
>>
>> Please find the latest patch attached.
>>
>>
>>
>> On Sat, Dec 7, 2024 at 2:31 AM David Edelsohn  wrote:
>>
>>> On Fri, Dec 6, 2024 at 2:17 PM Ian Lance Taylor  wrote:
>>>
 David Edelsohn  writes:

 > On Fri, Dec 6, 2024 at 12:25 PM Rainer Orth <
 r...@cebitec.uni-bielefeld.de>
 > wrote:
 >
 >> Hi David,
 >>
 >> > No objection from me, but Ian is the maintainer of libiberty, so
 I'll
 >> defer
 >> > to him, especially about style and overall software engineering.
 >> >
 >> > The C23 change presumably will break on Alpha OSF/1 as well.  Does
 GCC
 >> > still support OSF/1?  It might be preferred to delete the block
 entirely
 >> > instead of #ifndef _AIX.
 >>
 >> GCC 4.7 was the last release to support Tru64 UNIX (ex-OSF/1).
 However,
 >> libiberty is also used outside of the toolchain, so that may affect
 the
 >> decision.
 >>
 >> However, IMO the Tru64 UNIX support can go for good now.
 >>
 >
 > Hi, Rainer
 >
 > Thanks for taking a look and commenting.
 >
 > It seems we both agree that it would be better to remove the entire
 block
 > defining _NO_PROTO because both of the systems are no longer
 supported.
 >
 > I'll give Ian the opportunity to comment.

 Looks good to me.  Thanks.

 Ian

>>>
>>> Sangamesh,
>>>
>>> Can you respin and test a revised patch that removes the conditional
>>> _NO_PROTO definition instead of adding #ifndef _AIX?  I think that is what
>>> Rainer and I would prefer because neither of the OSes is supported and we
>>> don't need a fragile work-around.
>>>
>>> Thanks, David
>>>
>>>
>>
>> --
>> Thanks & Regards,
>> Sangamesh
>>
>

-- 
Thanks & Regards,
Sangamesh


Re: [PATCH v2] fold fold_truth_andor field merging into ifcombine

2024-12-08 Thread Richard Biener
On Sun, Dec 8, 2024 at 11:17 AM Alexandre Oliva  wrote:
>
> Here's yet another incremental patchlet, with the changes made in
> response to your review to v2.
>
> I'll post v3 containing it momentarily, but this incremental is supposed
> to make it easier to review.
>
> diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
> index 0d255561b1bdc..be7916e957d66 100644
> --- a/gcc/c-family/c.opt
> +++ b/gcc/c-family/c.opt
> @@ -1477,10 +1477,6 @@ Wtemplates
>  C++ ObjC++ Var(warn_templates) Warning
>  Warn on primary template declaration.
>
> -Wtautological-compare
> -C ObjC C++ ObjC++ Var(warn_tautological_compare) Warning LangEnabledBy(C 
> ObjC C++ ObjC++,Wall)
> -Warn if a comparison always evaluates to true or false.
> -
>  Wtemplate-body
>  C++ ObjC++ Var(warn_template_body) Warning Init(1)
>  Diagnose errors when parsing a template.
> diff --git a/gcc/common.opt b/gcc/common.opt
> index bb226ac61e6a1..915ce5bffb4e0 100644
> --- a/gcc/common.opt
> +++ b/gcc/common.opt
> @@ -812,6 +812,10 @@ Wsystem-headers
>  Common Var(warn_system_headers) Warning
>  Do not suppress warnings from system headers.
>
> +Wtautological-compare
> +Common Var(warn_tautological_compare) Warning LangEnabledBy(C ObjC C++ 
> ObjC++,Wall)
> +Warn if a comparison always evaluates to true or false.
> +
>  Wtrampolines
>  Common Var(warn_trampolines) Warning
>  Warn whenever a trampoline is generated.
> diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
> index 2c33cdfb1b29a..3ba4307769dd8 100644
> --- a/gcc/gimple-fold.cc
> +++ b/gcc/gimple-fold.cc
> @@ -7439,6 +7439,53 @@ maybe_fold_comparisons_from_match_pd (tree type, enum 
> tree_code code,
>return NULL_TREE;
>  }
>
> +/* Return TRUE and set op[0] if T, following all SSA edges, is a type
> +   conversion.  */
> +

Like below, gimple_convert_def_p ().

> +static bool
> +gimple_fold_follow_convert (tree t, tree op[1])
> +{
> +  if (TREE_CODE (t) == SSA_NAME
> +  && !SSA_NAME_IS_DEFAULT_DEF (t))
> +if (gassign *def = dyn_cast  (SSA_NAME_DEF_STMT (t)))
> +  switch (gimple_assign_rhs_code (def))
> +   {
> +   CASE_CONVERT:
> + op[0] = gimple_assign_rhs1 (def);
> + return true;
> +   case VIEW_CONVERT_EXPR:
> + op[0] = TREE_OPERAND (gimple_assign_rhs1 (def), 0);
> + return true;
> +   default:
> + break;
> +   }
> +  return false;
> +}
> +
> +/* Return TRUE and set op[*] if T, following all SSA edges, resolves to a
> +   binary expression with code CODE.  */
> +
> +static bool
> +gimple_fold_binop_cst (enum tree_code code, tree t, tree op[2])

Since it doesn't actually fold - can you name it

static bool
gimple_binop_def_p (...)

and ...

> +{
> +  if (TREE_CODE (t) == SSA_NAME
> +  && !SSA_NAME_IS_DEFAULT_DEF (t))
> +if (gimple *def = dyn_cast  (SSA_NAME_DEF_STMT (t)))
> +  if (gimple_assign_rhs_code (def) == code)
> +   {
> + tree op0 = gimple_assign_rhs1 (def);
> + tree op1 = gimple_assign_rhs2 (def);
> + if (tree_swap_operands_p (op0, op1))
> +   std::swap (op0, op1);

All stmts are canonical, you shouldn't need to swap operands here.

> + if (uniform_integer_cst_p (op1))

... put this in the caller so it could be made more universal eventually?

Otherwise the incremental patch looks OK.

Richard.

> +   {
> + op[0] = op0;
> + op[1] = op1;
> + return true;
> +   }
> +   }
> +  return false;
> +}
>  /* Subroutine for fold_truth_andor_1: decode a field reference.
>
> If *PEXP is a comparison reference, we return the innermost reference.
> @@ -7478,12 +7525,6 @@ decode_field_reference (tree *pexp, HOST_WIDE_INT 
> *pbitsize,
> wide_int *pand_mask, bool *xor_p, tree *xor_cmp_op,
> gimple **load, location_t loc[4])
>  {
> -  /* These are from match.pd.  */
> -  extern bool gimple_any_convert (tree, tree *, tree (*)(tree));
> -  extern bool gimple_bit_and_cst (tree, tree *, tree (*)(tree));
> -  extern bool gimple_bit_xor_cst (tree, tree *, tree (*)(tree));
> -  extern bool gimple_rshift_cst (tree, tree *, tree (*)(tree));
> -
>tree exp = *pexp;
>tree outer_type = 0;
>wide_int and_mask;
> @@ -7504,7 +7545,7 @@ decode_field_reference (tree *pexp, HOST_WIDE_INT 
> *pbitsize,
>   narrowing then widening casts, or vice-versa, for those that are not
>   essential for the compare have already been optimized out at this
>   point.  */
> -  if (gimple_any_convert (exp, res_ops, follow_all_ssa_edges))
> +  if (gimple_fold_follow_convert (exp, res_ops))
>  {
>if (!outer_type)
> {
> @@ -7515,7 +7556,7 @@ decode_field_reference (tree *pexp, HOST_WIDE_INT 
> *pbitsize,
>  }
>
>/* Recognize and save a masking operation.  */
> -  if (pand_mask && gimple_bit_and_cst (exp, res_ops, follow_all_ssa_edges))
> +  if (pand_mask && gimple_fold_binop_cst (BIT_AND_EXPR, exp, res_ops))
>  {
>loc[1] = gimple_locat

Re: [patch, avr] Assert minimal required bit width of section_common::flags.

2024-12-08 Thread Denis Chertykov
сб, 7 дек. 2024 г. в 17:39, Georg-Johann Lay :
>
> ...the patch
>
> Am 07.12.24 um 14:36 schrieb Georg-Johann Lay:
> > This patch implements an alarm should we ever run out of
> > section flags bits.
> >
> > Ok for trunk?

Ok.

Denis


Re: [RFC 0/4] Hard Register Constraints

2024-12-08 Thread Georg-Johann Lay




Am 07.12.24 um 22:25 schrieb Stefan Schulze Frielinghaus:

On Sat, Dec 07, 2024 at 08:49:20AM +0100, Georg-Johann Lay wrote:

Is there a PR for this feature?  (Just to make sure that I don't
miss progress on this I could CC to the PR).


No.  However, I can CC you in case of further patch revisions.

Cheers,
Stefan


Yes, thanks.  That would be nice.

Johann


Am 10.09.24 um 16:20 schrieb Stefan Schulze Frielinghaus:

This series introduces hard register constraints.  The first patch
enables hard register constraints for asm statements and for
machine descriptions.  The subsequent patch adds some basic error
handling for asm statements.  The third patch adds some verification of
register names used in machine description.  The fourth and last patch
adds the feature of rewriting local register asm into hard register
constraints.

This series was bootstrapped and regtested on s390.  Furthermore, the
new dg-compile tests were verified via cross compilers for the enabled
targets.  There is still some fallout if -fdemote-register-asm is used
since a couple of features are missing as e.g. erroring out during
gimplification if the clobber set of registers intersects with
input/output registers.

As a larger test vehicle I've compiled and regtested glibc on s390 using
-fdemote-register-asm without any fallout.  On x86_64 this fails due to
the limitation that fixed registers are currently not supported for hard
register constraints (see commit message of the first patch).  This is
also the reason why I'm posting this series already since I was hoping
to get some feedback about this limitation.

Furthermore, I've compiled the Linux kernel on s390 and x86_64 with
-fdemote-register-asm.  Interestingly, the Linux kernel for x86_64 makes
use of the following asm statement:

#define call_on_stack(stack, func, asm_call, argconstr...)  \
{   \
  register void *tos asm("r11");  \
  \
  tos = ((void *)(stack));\
  \
  asm_inline volatile(\
  "movq   %%rsp, (%[tos]) \n" \
  "movq   %[tos], %%rsp   \n" \
  \
  asm_call\
  \
  "popq   %%rsp   \n" \
  \
  : "+r" (tos), ASM_CALL_CONSTRAINT   \
  : [__func] "i" (func), [tos] "r" (tos) argconstr\
  : "cc", "rax", "rcx", "rdx", "rsi", "rdi", "r8", "r9", "r10",   \
"memory"  \
  );  \
}

Note the output
"+r" (tos)
and the input
[tos] "r" (tos)
Currently I error out for this since I consider this as two inputs using
the same hard register.  One time an implicit input via '+' and a second
time via the explicit input.  Thus, actually I would expect a '='
instead of a '+' for the output constraint since the input is explicitly
mentioned, or remove the input entirely and just use the inoutput
 [tos] "+r" (tos)
If you consider this valid asm I would have to adjust the error
handling.  Either way, this is just about error handling and doesn't
really affect code generation.

Stefan Schulze Frielinghaus (4):
Hard register constraints
Error handling for hard register constraints
genoutput: Verify hard register constraints
Rewrite register asm into hard register constraints

   gcc/cfgexpand.cc  |  42 ---
   gcc/common.opt|   4 +
   gcc/function.cc   | 116 
   gcc/genoutput.cc  |  60 
   gcc/genpreds.cc   |   4 +-
   gcc/gimplify.cc   | 151 +-
   gcc/gimplify_reg_info.h   | 130 +
   gcc/ira.cc|  79 +-
   gcc/lra-constraints.cc|  13 +
   gcc/output.h  |   2 +
   gcc/recog.cc  |  11 +-
   gcc/stmt.cc   | 268 +-
   gcc/stmt.h|   9 +-
   gcc/testsuite/gcc.dg/asm-hard-reg-1.c |  85 ++
   gcc/testsuite/gcc.dg/asm-hard-reg-2.c |  33 +++
   gcc/testsuite/gcc.dg/a

Re: [PATCH v3 5/7] Support for 64-bit location_t: Activate 64-bit location_t

2024-12-08 Thread Lewis Hyatt
On Tue, Dec 3, 2024 at 7:33 AM Richard Biener
 wrote:
>
> On Mon, Dec 2, 2024 at 1:50 AM Lewis Hyatt  wrote:
> >
> > With the codebase having already been prepared to handle it, change
> > location_t to be a 64-bit integer instead of a 32-bit integer.
>
> OK if there's no comments from others within 48h.
>
> Thanks,
> Richard.

This is now pushed as r15-6016-gd9cdc500c1e86b. Thanks again for all the help.

-Lewis


libstdc++: Optimize std::vector

2024-12-08 Thread Jan Hubicka
Hi,
std::vector has independent implementation for bool which has its won
size/capacity functions.  I updated them to add __builtin_unreachable to
announce that size is never more than max_size.  However while testing the code
I noticed that even construction of unused copy is not optimized out.  Main
problem is that the vector copying loops copies the tail of vector using loop
that copies bit by bit.  We eventually pattern match it to bit operations (that
surprises me) but we need to unroll it and run through loop optimization that
happens late.

This patch also updates copy_aglined to use bit operations. However for = 
operation
we can do better since it is not necessary to preserve original bits (those are
undefined anyway). So I added copy_aglined_trail (better name would be welcome)
that does not care about trailing bits of the copied block.

As a result the following functions are optimized to empty functions:
#include 
bool
empty(std::vector src)
{
std::vector  data=src;
return false;
}
bool
empty2(std::vector src)
{
std::vector  data;
data.reserve(1);
return data.size ();
}
bool
empty3()
{
std::vector  data;
data.push_back (true);
return data[0];
}

Finally I mirrored changes to push_back from normal vectors to bit vectors.
This involve separating append from insert and breaking out the resizing (and
cold) path to separate function. 

Here are two little benchmarks on push_back:

#include 

__attribute__ ((noipa))
std::vector
test()
{
std::vector  t;
t.push_back (1);
t.push_back (2);
return t;
}
int
main()
{
for (int i = 0; i < 1; i++)
{
test();
}
return 0;
}

 runtime(s) .text size of a.out
gcc -O2 1.041606
gcc -O2 + patch 0.981315
gcc -O3 0.981249
gcc -O3 + patch 0.961138
gcc -O3 + patch --param max-inline-insns-auto=5000  0.961138
clang -O2   1.561823
clang -O3   1.561839
clang -O2 + libc++  2.314272
clang -O3 + libc++  2.764262

push_back is still too large to inline fully at -O3.  If parameters are bumped 
up
for small vectors this makes it possible to propagate bit positions.
This variant of benchmark

#include 

__attribute__ ((noipa))
std::vector
test()
{
std::vector  t;
t.push_back (1);
t.push_back (2);
return t;
}
int
main()
{
for (int i = 0; i < 1; i++)
{
test();
}
return 0;
}


 runtime(s) .text size of a.out
gcc -O2 1.481574
gcc -O2 + patch 1.301177
gcc -O3 1.461515
gcc -O3 + patch 1.271069
gcc -O3 + patch --param max-inline-insns-auto=5000  1.10388
clang -O2   1.481823
clang -O3   1.461711
clang -O2 + libc++  1.201001
clang -O3 + libc++  1.171001

Note that clang does not suport noipa attribute, so it has some advantage here.
Bootstrapped/regtested x86_64-linux, OK?

libstdc++-v3/ChangeLog:

* include/bits/stl_bvector.h (vector::operator=): Use
_M_copy_aligned_trail.
(vector::copy_aglined_trail): New function.
(vector::copy_aglined): Implement copying of tail 
manually.
(vector::size,vector::capacity): Add check
that size is at most max_size.
(vector::size,vector::push_back): Use
_M_append_aux.
(vector::size,vector::_M_append_aux): 
Declare.
(vector::size,vector::_M_realloc_append_aux): Declare.
(vector::size,vector::_M_realloc_insert_aux): Declare.
* include/bits/vector.tcc
(vector::size,vector::_M_append_aux): 
Implement.
(vector::size,vector::_M_realloc_append_aux): Implement.
(vector::size,vector::_M_realloc_insert_aux): Break out from ...
(vector::size,vector::_M_insert_aux): ... 
here.

gcc/testsuite/ChangeLog:

* g++.dg/tree-ssa/bvector-1.C: New test.

diff --git a/gcc/testsuite/g++.dg/tree-ssa/bvector-1.C 
b/gcc/testsuite/g++.dg/tree-ssa/bvector-1.C
new file mode 100644
index 000..4197ff8c4b8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/tree-ssa/bvector-1.C
@@ -0,0 +1,28 @@
+// { dg-do compile }
+// { dg-options "-O2 -fdump-tree-optimized"  }
+// { dg-skip-if "requires hosted libstdc++ for vector" { ! hostedlib } }
+#include 
+bool
+empty(std:

Re: [PATCH] AIX Build failure with default -std=gnu23.

2024-12-08 Thread swamy sangamesh
Thank you all for the review and comments.

David, I have tested the changes against the latest master and ran default
test cases.
I have also built and ran the default test cases on RHEL9.0 ppc64le.
Please let me know if any other testing needs to be covered.

Please find the latest patch attached.



On Sat, Dec 7, 2024 at 2:31 AM David Edelsohn  wrote:

> On Fri, Dec 6, 2024 at 2:17 PM Ian Lance Taylor  wrote:
>
>> David Edelsohn  writes:
>>
>> > On Fri, Dec 6, 2024 at 12:25 PM Rainer Orth <
>> r...@cebitec.uni-bielefeld.de>
>> > wrote:
>> >
>> >> Hi David,
>> >>
>> >> > No objection from me, but Ian is the maintainer of libiberty, so I'll
>> >> defer
>> >> > to him, especially about style and overall software engineering.
>> >> >
>> >> > The C23 change presumably will break on Alpha OSF/1 as well.  Does
>> GCC
>> >> > still support OSF/1?  It might be preferred to delete the block
>> entirely
>> >> > instead of #ifndef _AIX.
>> >>
>> >> GCC 4.7 was the last release to support Tru64 UNIX (ex-OSF/1).
>> However,
>> >> libiberty is also used outside of the toolchain, so that may affect the
>> >> decision.
>> >>
>> >> However, IMO the Tru64 UNIX support can go for good now.
>> >>
>> >
>> > Hi, Rainer
>> >
>> > Thanks for taking a look and commenting.
>> >
>> > It seems we both agree that it would be better to remove the entire
>> block
>> > defining _NO_PROTO because both of the systems are no longer supported.
>> >
>> > I'll give Ian the opportunity to comment.
>>
>> Looks good to me.  Thanks.
>>
>> Ian
>>
>
> Sangamesh,
>
> Can you respin and test a revised patch that removes the conditional
> _NO_PROTO definition instead of adding #ifndef _AIX?  I think that is what
> Rainer and I would prefer because neither of the OSes is supported and we
> don't need a fragile work-around.
>
> Thanks, David
>
>

-- 
Thanks & Regards,
Sangamesh


0001-aix-Resolve-build-failure-with-default-C23.patch
Description: Binary data