[gcc r15-7007] testsuite: Make embed-10.c test more robust

2025-01-17 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:d8a31b5bead0c64d7e4a59d6834bc649f68de765

commit r15-7007-gd8a31b5bead0c64d7e4a59d6834bc649f68de765
Author: Jakub Jelinek 
Date:   Fri Jan 17 21:00:50 2025 +0100

testsuite: Make embed-10.c test more robust

With the https://gcc.gnu.org/pipermail/gcc-patches/2025-January/673945.html
hack we get slightly different error wording in one of the errors, given 
that
the test actually does use #embed, I think both wordings are just fine and
we should accept them.

2025-01-17  Jakub Jelinek  

* c-c++-common/cpp/embed-10.c: Allow a different error wording for
C++.

Diff:
---
 gcc/testsuite/c-c++-common/cpp/embed-10.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/c-c++-common/cpp/embed-10.c 
b/gcc/testsuite/c-c++-common/cpp/embed-10.c
index a358384ae3d4..e797f795ea57 100644
--- a/gcc/testsuite/c-c++-common/cpp/embed-10.c
+++ b/gcc/testsuite/c-c++-common/cpp/embed-10.c
@@ -7,4 +7,4 @@ const char *p =
 /* { dg-error "makes pointer from integer without a cast" "" { target c } .-2 
} */
 /* { dg-error "expected identifier" "" { target c } .-3 } */
 /* { dg-error "invalid conversion" "" { target c++ } .-4 } */
-/* { dg-error "expected unqualified-id before numeric constant" "" { target 
c++ } .-5 } */
+/* { dg-error "expected unqualified-id before (?:numeric constant|'#embed')" 
"" { target c++ } .-5 } */


[gcc r12-10915] Fix setting of call graph node AutoFDO count

2025-01-17 Thread Eugene Rozenfeld via Gcc-cvs
https://gcc.gnu.org/g:d180e392d7a8ba1346bfe7580de953234f0c2f9d

commit r12-10915-gd180e392d7a8ba1346bfe7580de953234f0c2f9d
Author: Eugene Rozenfeld 
Date:   Fri Jan 10 19:48:52 2025 -0800

Fix setting of call graph node AutoFDO count

We are initializing both the call graph node count and
the entry block count of the function with the head_count value
from the profile.

Count propagation algorithm may refine the entry block count
and we may end up with a case where the call graph node count
is set to zero but the entry block count is non-zero. That becomes
a problem because we have this code in execute_fixup_cfg:

 profile_count num = node->count;
 profile_count den = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
 bool scale = num.initialized_p () && !(num == den);

Here if num is 0 but den is not 0, scale becomes true and we
lose the counts in

if (scale)
  bb->count = bb->count.apply_scale (num, den);

This is what happened in the issue reported in PR116743
(a 10% regression in MySQL HAMMERDB tests).
3d9e6767939e9658260e2506e81ec32b37cba041 made an improvement in
AutoFDO count propagation, which caused a mismatch between
the call graph node count (zero) and the entry block count (non-zero)
and subsequent loss of counts as described above.

The fix is to update the call graph node count once we've done count 
propagation.

Tested on x86_64-pc-linux-gnu.

gcc/ChangeLog:
PR gcov-profile/116743
* auto-profile.cc (afdo_annotate_cfg): Fix mismatch between the 
call graph node count
and the entry block count.

(cherry picked from commit e683c6b029f809c7a1981b4341c95d9652c22e18)

Diff:
---
 gcc/auto-profile.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/auto-profile.cc b/gcc/auto-profile.cc
index 2b34b80b82d2..89dd05252c25 100644
--- a/gcc/auto-profile.cc
+++ b/gcc/auto-profile.cc
@@ -1537,8 +1537,6 @@ afdo_annotate_cfg (const stmt_set &promoted_stmts)
 
   if (s == NULL)
 return;
-  cgraph_node::get (current_function_decl)->count
- = profile_count::from_gcov_type (s->head_count ()).afdo ();
   ENTRY_BLOCK_PTR_FOR_FN (cfun)->count
  = profile_count::from_gcov_type (s->head_count ()).afdo ();
   EXIT_BLOCK_PTR_FOR_FN (cfun)->count = profile_count::zero ().afdo ();
@@ -1577,6 +1575,8 @@ afdo_annotate_cfg (const stmt_set &promoted_stmts)
   /* Calculate, propagate count and probability information on CFG.  */
   afdo_calculate_branch_prob (&annotated_bb);
 }
+  cgraph_node::get(current_function_decl)->count
+  = ENTRY_BLOCK_PTR_FOR_FN(cfun)->count;
   update_max_bb_count ();
   profile_status_for_fn (cfun) = PROFILE_READ;
   if (flag_value_profile_transformations)


[gcc(refs/users/aoliva/heads/testme)] [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

2025-01-17 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:458997f785630c5390f7833e88e53fddf3a3f8b8

commit 458997f785630c5390f7833e88e53fddf3a3f8b8
Author: Alexandre Oliva 
Date:   Fri Jan 17 16:47:25 2025 -0300

[ifcombine] out-of-bounds bitfield refs can trap [PR118514]

Diff:
---
 gcc/gimple-fold.cc| 27 +++
 gcc/testsuite/gcc.dg/field-merge-23.c | 19 +++
 gcc/tree-eh.cc| 30 +-
 3 files changed, 71 insertions(+), 5 deletions(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 3c971a29ef04..8e3bb5c74f79 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -7815,6 +7815,20 @@ compute_split_boundary_from_align (HOST_WIDE_INT align,
   return boundary;
 }
 
+/* Return true iff REF and the LOADed expression both trap, or neither do.  */
+
+static inline bool
+still_trap_p (gimple *load, const_tree ref)
+{
+  const_tree before = gimple_assign_rhs1 (load);
+  const_tree now = ref;
+
+  STRIP_NOPS (before);
+  STRIP_NOPS (now);
+
+  return (tree_could_trap_p (before) == tree_could_trap_p (now));
+}
+
 /* Make a bit_field_ref.  If POINT is NULL, return the BIT_FIELD_REF.
Otherwise, build and insert a load stmt before POINT, and return
the SSA_NAME.  ???  Rewrite LOAD in terms of the bitfield?  */
@@ -7836,11 +7850,16 @@ make_bit_field_load (location_t loc, tree inner, tree 
orig_inner, tree type,
 
   /* If we're remaking the same load, reuse the SSA NAME it is already loaded
  into.  */
-  if (gimple_assign_load_p (point)
-  && operand_equal_p (ref, gimple_assign_rhs1 (point)))
+  if (gimple_assign_load_p (point))
 {
-  gcc_checking_assert (TREE_CODE (gimple_assign_lhs (point)) == SSA_NAME);
-  return gimple_assign_lhs (point);
+  if (operand_equal_p (ref, gimple_assign_rhs1 (point)))
+   {
+ gcc_checking_assert (TREE_CODE (gimple_assign_lhs (point))
+  == SSA_NAME);
+ return gimple_assign_lhs (point);
+   }
+  else
+   gcc_checking_assert (still_trap_p (point, ref));
 }
 
   gimple_seq stmts = NULL;
diff --git a/gcc/testsuite/gcc.dg/field-merge-23.c 
b/gcc/testsuite/gcc.dg/field-merge-23.c
new file mode 100644
index ..d60f76206ebe
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/field-merge-23.c
@@ -0,0 +1,19 @@
+/* { dg-do run } */
+/* { dg-options "-O" } */
+
+/* PR tree-optimization/118514 */
+
+/* Check that we don't pull optimized references that could trap out of
+   loops.  */
+
+int a, c = 1;
+unsigned char b[1], d;
+int main() {
+  while (a || !c) {
+signed char e = b[10];
+d = e < 0 || b[10] > 1;
+if (d)
+  __builtin_abort ();
+  }
+  return 0;
+}
diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
index 1033b124e4df..a92eccb4bb6d 100644
--- a/gcc/tree-eh.cc
+++ b/gcc/tree-eh.cc
@@ -2646,6 +2646,30 @@ range_in_array_bounds_p (tree ref)
   return true;
 }
 
+/* Return true iff EXPR, a BIT_FIELD_REF, accesses a bit range that is known to
+   be in bounds for the referred operand type.  */
+
+static bool
+bit_field_ref_in_bounds_p (tree expr)
+{
+  tree size_tree;
+  poly_uint64 size_max, min, wid, max;
+
+  size_tree = TYPE_SIZE (TREE_TYPE (TREE_OPERAND (expr, 0)));
+  if (!size_tree
+  || !poly_int_tree_p (size_tree, &size_max)
+  || !poly_int_tree_p (TREE_OPERAND (expr, 2), &min)
+  || !poly_int_tree_p (TREE_OPERAND (expr, 1), &wid))
+return false;
+
+  max = min + wid;
+  if (maybe_lt (max, min)
+  || maybe_lt (size_max, max))
+return false;
+
+  return true;
+}
+
 /* Return true if EXPR can trap, as in dereferencing an invalid pointer
location or floating point arithmetic.  C.f. the rtl version, may_trap_p.
This routine expects only GIMPLE lhs or rhs input.  */
@@ -2688,10 +2712,14 @@ tree_could_trap_p (tree expr)
  restart:
   switch (code)
 {
+case BIT_FIELD_REF:
+  if (!bit_field_ref_in_bounds_p (expr))
+   return true;
+  /* Fall through.  */
+
 case COMPONENT_REF:
 case REALPART_EXPR:
 case IMAGPART_EXPR:
-case BIT_FIELD_REF:
 case VIEW_CONVERT_EXPR:
 case WITH_SIZE_EXPR:
   expr = TREE_OPERAND (expr, 0);


[gcc/aoliva/heads/testme] [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

2025-01-17 Thread Alexandre Oliva via Gcc-cvs
The branch 'aoliva/heads/testme' was updated to point to:

 458997f78563... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

It previously pointed to:

 53d5a650fd72... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

Diff:

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

  53d5a65... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]


Summary of changes (added commits):
---

  458997f... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]


[gcc(refs/users/aoliva/heads/testme)] [ifcombine] avoid dropping tree_could_trap_p [PR118514]

2025-01-17 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:49b5606e0e8d0b133227071c9d39582e8734aead

commit 49b5606e0e8d0b133227071c9d39582e8734aead
Author: Alexandre Oliva 
Date:   Sat Jan 18 00:40:51 2025 -0300

[ifcombine] avoid dropping tree_could_trap_p [PR118514]

Unlike other access patterns, BIT_FIELD_REFs aren't regarded as
possibly-trapping out of referencing out-of-bounds bits.

So, if decode_field_reference finds a load that could trap, but whose
inner object doesn't, bail out if the accesses past the inner object's
size.

This may drop some optimizations in VLAs, that could be safe if we
managed to reuse the same pre-existing load for both compares, but
those get optimized later (as in the new testcase).  The cases of most
interest are those that merge separate fields, and they necessarily
involve new BIT_FIELD_REFs loads.


for  gcc/ChangeLog

PR tree-optimization/118514
* gimple-fold.cc (decode_field_reference): Refuse to consider
BIT_FIELD_REF of non-trapping object if the original load
could trap for being out-of-bounds.
(make_bit_field_ref): Check that replacement loads could trap
as much as the original loads.

for  gcc/testsuite/ChangeLog

PR tree-optimization/118514
* gcc.dg/field-merge-23.c: New.

Diff:
---
 gcc/gimple-fold.cc| 19 +++
 gcc/testsuite/gcc.dg/field-merge-23.c | 19 +++
 2 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 3c971a29ef04..41b21ecd58a3 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -7686,10 +7686,16 @@ decode_field_reference (tree *pexp, HOST_WIDE_INT 
*pbitsize,
   || bs <= shiftrt
   || offset != 0
   || TREE_CODE (inner) == PLACEHOLDER_EXPR
-  /* Reject out-of-bound accesses (PR79731).  */
-  || (! AGGREGATE_TYPE_P (TREE_TYPE (inner))
- && compare_tree_int (TYPE_SIZE (TREE_TYPE (inner)),
-  bp + bs) < 0)
+  /* Reject out-of-bound accesses (PR79731).  BIT_FIELD_REFs aren't flagged
+as tree_could_trap_p just because of out-of-range bits, so don't even
+try to optimize loads that could trap if they access out-of-range bits
+of an object that could not trap (PR118514).  */
+  || ((! AGGREGATE_TYPE_P (TREE_TYPE (inner))
+  || (load && tree_could_trap_p (gimple_assign_rhs1 (load))
+  & !tree_could_trap_p (inner)))
+ && (!tree_fits_uhwi_p (TYPE_SIZE (TREE_TYPE (inner)))
+ || compare_tree_int (TYPE_SIZE (TREE_TYPE (inner)),
+  bp + bs) < 0))
   || (INTEGRAL_TYPE_P (TREE_TYPE (inner))
  && !type_has_mode_precision_p (TREE_TYPE (inner
 return NULL_TREE;
@@ -7859,6 +7865,11 @@ make_bit_field_load (location_t loc, tree inner, tree 
orig_inner, tree type,
   gimple *new_stmt = gsi_stmt (i);
   if (gimple_has_mem_ops (new_stmt))
gimple_set_vuse (new_stmt, reaching_vuse);
+  gcc_checking_assert (! (gimple_assign_load_p (point)
+ && gimple_assign_load_p (new_stmt))
+  || (tree_could_trap_p (gimple_assign_rhs1 (point))
+  == tree_could_trap_p (gimple_assign_rhs1
+(new_stmt;
 }
 
   gimple_stmt_iterator gsi = gsi_for_stmt (point);
diff --git a/gcc/testsuite/gcc.dg/field-merge-23.c 
b/gcc/testsuite/gcc.dg/field-merge-23.c
new file mode 100644
index ..96604d43c9de
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/field-merge-23.c
@@ -0,0 +1,19 @@
+/* { dg-do run } */
+/* { dg-options "-O" } */
+
+/* PR tree-optimization/118514 */
+
+/* Check that we don't create BIT_FIELD_REFs that could trap, because they are
+   assumed not to trap and could be pulled out of loops.  */
+
+int a, c = 1;
+unsigned char b[1], d;
+int main() {
+  while (a || !c) {
+signed char e = b[10];
+d = e < 0 || b[10] > 1;
+if (d)
+  __builtin_abort ();
+  }
+  return 0;
+}


[gcc/aoliva/heads/testme] [ifcombine] avoid dropping tree_could_trap_p [PR118514]

2025-01-17 Thread Alexandre Oliva via Gcc-cvs
The branch 'aoliva/heads/testme' was updated to point to:

 49b5606e0e8d... [ifcombine] avoid dropping tree_could_trap_p [PR118514]

It previously pointed to:

 58dbf143f4d7... [ifcombine] avoid bitfield refs that could trap [PR118514]

Diff:

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

  58dbf14... [ifcombine] avoid bitfield refs that could trap [PR118514]


Summary of changes (added commits):
---

  49b5606... [ifcombine] avoid dropping tree_could_trap_p [PR118514]


[gcc(refs/users/aoliva/heads/testme)] [ifcombine] avoid bitfield refs that could trap [PR118514]

2025-01-17 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:58dbf143f4d724222c754766d4957f5e099244d9

commit 58dbf143f4d724222c754766d4957f5e099244d9
Author: Alexandre Oliva 
Date:   Sat Jan 18 00:40:51 2025 -0300

[ifcombine] avoid bitfield refs that could trap [PR118514]

Diff:
---
 gcc/gimple-fold.cc| 13 +
 gcc/testsuite/gcc.dg/field-merge-23.c | 19 +++
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 3c971a29ef04..612810c35b08 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -7686,10 +7686,10 @@ decode_field_reference (tree *pexp, HOST_WIDE_INT 
*pbitsize,
   || bs <= shiftrt
   || offset != 0
   || TREE_CODE (inner) == PLACEHOLDER_EXPR
-  /* Reject out-of-bound accesses (PR79731).  */
-  || (! AGGREGATE_TYPE_P (TREE_TYPE (inner))
- && compare_tree_int (TYPE_SIZE (TREE_TYPE (inner)),
-  bp + bs) < 0)
+  /* Reject out-of-bound accesses (PR79731, PR118514).  */
+  || !tree_fits_uhwi_p (TYPE_SIZE (TREE_TYPE (inner)))
+  || compare_tree_int (TYPE_SIZE (TREE_TYPE (inner)),
+  bp + bs) < 0
   || (INTEGRAL_TYPE_P (TREE_TYPE (inner))
  && !type_has_mode_precision_p (TREE_TYPE (inner
 return NULL_TREE;
@@ -7859,6 +7859,11 @@ make_bit_field_load (location_t loc, tree inner, tree 
orig_inner, tree type,
   gimple *new_stmt = gsi_stmt (i);
   if (gimple_has_mem_ops (new_stmt))
gimple_set_vuse (new_stmt, reaching_vuse);
+  gcc_checking_assert (! (gimple_assign_load_p (point)
+ && gimple_assign_load_p (new_stmt))
+  || (tree_could_trap_p (gimple_assign_rhs1 (point))
+  == tree_could_trap_p (gimple_assign_rhs1
+(new_stmt;
 }
 
   gimple_stmt_iterator gsi = gsi_for_stmt (point);
diff --git a/gcc/testsuite/gcc.dg/field-merge-23.c 
b/gcc/testsuite/gcc.dg/field-merge-23.c
new file mode 100644
index ..96604d43c9de
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/field-merge-23.c
@@ -0,0 +1,19 @@
+/* { dg-do run } */
+/* { dg-options "-O" } */
+
+/* PR tree-optimization/118514 */
+
+/* Check that we don't create BIT_FIELD_REFs that could trap, because they are
+   assumed not to trap and could be pulled out of loops.  */
+
+int a, c = 1;
+unsigned char b[1], d;
+int main() {
+  while (a || !c) {
+signed char e = b[10];
+d = e < 0 || b[10] > 1;
+if (d)
+  __builtin_abort ();
+  }
+  return 0;
+}


[gcc/aoliva/heads/testme] [ifcombine] avoid bitfield refs that could trap [PR118514]

2025-01-17 Thread Alexandre Oliva via Gcc-cvs
The branch 'aoliva/heads/testme' was updated to point to:

 58dbf143f4d7... [ifcombine] avoid bitfield refs that could trap [PR118514]

It previously pointed to:

 a823af078547... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

Diff:

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

  a823af0... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]


Summary of changes (added commits):
---

  58dbf14... [ifcombine] avoid bitfield refs that could trap [PR118514]


[gcc r15-7012] LoongArch: Fix cost model for alsl

2025-01-17 Thread Xi Ruoyao via Gcc-cvs
https://gcc.gnu.org/g:ce36692f8e10a619563938851f507cdb15567cf8

commit r15-7012-gce36692f8e10a619563938851f507cdb15567cf8
Author: Xi Ruoyao 
Date:   Fri Sep 6 00:34:55 2024 +0800

LoongArch: Fix cost model for alsl

Our cost model for alsl was wrong: it matches (a + b * imm) where imm is
1, 2, 3, or 4 (should be 2, 4, 8, or 16), and it does not match
(a + (b << imm)) at all.  For the test case:

a += c << 3;
b += c << 3;

it caused the compiler to perform a CSE and make one slli and two add,
but we just want two alsl.

Also add a "code == PLUS" check to prevent matching a - (b << imm) as we
don't have any "slsl" instruction.

gcc/ChangeLog:

* config/loongarch/loongarch.cc (loongarch_rtx_costs): Fix the
cost for (a + b * imm) and (a + (b << imm)) which can be
implemented with a single alsl instruction.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/alsl-cost.c: New test.

Diff:
---
 gcc/config/loongarch/loongarch.cc  | 27 +-
 gcc/testsuite/gcc.target/loongarch/alsl-cost.c | 14 +
 2 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/gcc/config/loongarch/loongarch.cc 
b/gcc/config/loongarch/loongarch.cc
index 9d97f0216f0d..3a8e1297bd3c 100644
--- a/gcc/config/loongarch/loongarch.cc
+++ b/gcc/config/loongarch/loongarch.cc
@@ -3929,14 +3929,31 @@ loongarch_rtx_costs (rtx x, machine_mode mode, int 
outer_code,
 
   /* If it's an add + mult (which is equivalent to shift left) and
 it's immediate operand satisfies const_immalsl_operand predicate.  */
-  if ((mode == SImode || (TARGET_64BIT && mode == DImode))
- && GET_CODE (XEXP (x, 0)) == MULT)
+  if (code == PLUS
+ && (mode == SImode || (TARGET_64BIT && mode == DImode)))
{
- rtx op2 = XEXP (XEXP (x, 0), 1);
- if (const_immalsl_operand (op2, mode))
+ HOST_WIDE_INT shamt = -1;
+ rtx lhs = XEXP (x, 0);
+ rtx_code code_lhs = GET_CODE (lhs);
+
+ switch (code_lhs)
+   {
+   case ASHIFT:
+ if (CONST_INT_P (XEXP (lhs, 1)))
+   shamt = INTVAL (XEXP (lhs, 1));
+ break;
+   case MULT:
+ if (CONST_INT_P (XEXP (lhs, 1)))
+   shamt = exact_log2 (INTVAL (XEXP (lhs, 1)));
+ break;
+   default:
+ break;
+   }
+
+ if (IN_RANGE (shamt, 1, 4))
{
  *total = (COSTS_N_INSNS (1)
-   + set_src_cost (XEXP (XEXP (x, 0), 0), mode, speed)
+   + set_src_cost (XEXP (lhs, 0), mode, speed)
+ set_src_cost (XEXP (x, 1), mode, speed));
  return true;
}
diff --git a/gcc/testsuite/gcc.target/loongarch/alsl-cost.c 
b/gcc/testsuite/gcc.target/loongarch/alsl-cost.c
new file mode 100644
index ..a182279015c4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/alsl-cost.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mtune=loongarch64" } */
+/* { dg-final { scan-assembler-times "alsl\\\.\[wd\]" 2 } } */
+
+struct P
+{
+  long a, b;
+};
+
+struct P
+t (struct P x, long n)
+{
+  return (struct P){.a = x.a + n * 8, .b = x.b + n * 8};
+}


[gcc r15-7011] LoongArch: Add alsl.wu

2025-01-17 Thread Xi Ruoyao via Gcc-cvs
https://gcc.gnu.org/g:cc6176a921cbe3b9db323b1cd557efe4f299171a

commit r15-7011-gcc6176a921cbe3b9db323b1cd557efe4f299171a
Author: Xi Ruoyao 
Date:   Fri Sep 6 03:27:19 2024 +0800

LoongArch: Add alsl.wu

On 64-bit capable LoongArch hardware, alsl.wu is similar to alsl.w but
zero-extending the 32-bit result.

gcc/ChangeLog:

* config/loongarch/loongarch.md (alslsi3_extend): Add alsl.wu.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/alsl_wu.c: New test.

Diff:
---
 gcc/config/loongarch/loongarch.md| 8 
 gcc/testsuite/gcc.target/loongarch/alsl_wu.c | 9 +
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/gcc/config/loongarch/loongarch.md 
b/gcc/config/loongarch/loongarch.md
index 59f457703110..1b46e8e4af0d 100644
--- a/gcc/config/loongarch/loongarch.md
+++ b/gcc/config/loongarch/loongarch.md
@@ -3143,15 +3143,15 @@
   [(set_attr "type" "arith")
(set_attr "mode" "")])
 
-(define_insn "alslsi3_extend"
+(define_insn "*alslsi3_extend"
   [(set (match_operand:DI 0 "register_operand" "=r")
-   (sign_extend:DI
+   (any_extend:DI
  (plus:SI
(ashift:SI (match_operand:SI 1 "register_operand" "r")
   (match_operand 2 "const_immalsl_operand" ""))
(match_operand:SI 3 "register_operand" "r"]
-  ""
-  "alsl.w\t%0,%1,%3,%2"
+  "TARGET_64BIT"
+  "alsl.w\t%0,%1,%3,%2"
   [(set_attr "type" "arith")
(set_attr "mode" "SI")])
 
diff --git a/gcc/testsuite/gcc.target/loongarch/alsl_wu.c 
b/gcc/testsuite/gcc.target/loongarch/alsl_wu.c
new file mode 100644
index ..65f55e629ddb
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/alsl_wu.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-march=loongarch64 -mabi=lp64d -O2" } */
+/* { dg-final { scan-assembler "alsl\\.wu" } } */
+
+unsigned long
+test (unsigned int a, unsigned int b)
+{
+  return (a << 2) + b;
+}


[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Factorisation set descriptor with shape

2025-01-17 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:cd8c9a96d23badcdfb0b2dc88765ef18f883e837

commit cd8c9a96d23badcdfb0b2dc88765ef18f883e837
Author: Mikael Morin 
Date:   Fri Jan 17 21:46:27 2025 +0100

Factorisation set descriptor with shape

Diff:
---
 gcc/fortran/trans-array.cc | 78 ++
 gcc/fortran/trans-array.h  |  2 ++
 gcc/fortran/trans-intrinsic.cc | 76 +++-
 3 files changed, 85 insertions(+), 71 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 88a2509a5246..b05f69fdd874 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -1566,6 +1566,84 @@ copy_descriptor (stmtblock_t *block, tree dest, tree src,
   gfc_conv_descriptor_span_set (block, dest, tmp);
 }
 
+
+void
+gfc_set_descriptor_with_shape (stmtblock_t *block, tree desc,
+  tree ptr, gfc_expr *shape,
+  locus *where)
+{
+  /* Set the span field.  */
+  tree tmp = TYPE_SIZE_UNIT (gfc_get_element_type (TREE_TYPE (desc)));
+  tmp = fold_convert (gfc_array_index_type, tmp);
+  gfc_conv_descriptor_span_set (block, desc, tmp);
+
+  /* Set data value, dtype, and offset.  */
+  tmp = GFC_TYPE_ARRAY_DATAPTR_TYPE (TREE_TYPE (desc));
+  gfc_conv_descriptor_data_set (block, desc, fold_convert (tmp, ptr));
+  gfc_add_modify (block, gfc_conv_descriptor_dtype (desc),
+ gfc_get_dtype (TREE_TYPE (desc)));
+
+  /* Start scalarization of the bounds, using the shape argument.  */
+
+  gfc_ss *shape_ss = gfc_walk_expr (shape);
+  gcc_assert (shape_ss != gfc_ss_terminator);
+  gfc_se shapese;
+  gfc_init_se (&shapese, NULL);
+
+  gfc_loopinfo loop;
+  gfc_init_loopinfo (&loop);
+  gfc_add_ss_to_loop (&loop, shape_ss);
+  gfc_conv_ss_startstride (&loop);
+  gfc_conv_loop_setup (&loop, where);
+  gfc_mark_ss_chain_used (shape_ss, 1);
+
+  gfc_copy_loopinfo_to_se (&shapese, &loop);
+  shapese.ss = shape_ss;
+
+  tree stride = gfc_create_var (gfc_array_index_type, "stride");
+  tree offset = gfc_create_var (gfc_array_index_type, "offset");
+  gfc_add_modify (block, stride, gfc_index_one_node);
+  gfc_add_modify (block, offset, gfc_index_zero_node);
+
+  /* Loop body.  */
+  stmtblock_t body;
+  gfc_start_scalarized_body (&loop, &body);
+
+  tree dim = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
+ loop.loopvar[0], loop.from[0]);
+
+  /* Set bounds and stride.  */
+  gfc_conv_descriptor_lbound_set (&body, desc, dim, gfc_index_one_node);
+  gfc_conv_descriptor_stride_set (&body, desc, dim, stride);
+
+  gfc_conv_expr (&shapese, shape);
+  gfc_add_block_to_block (&body, &shapese.pre);
+  gfc_conv_descriptor_ubound_set (&body, desc, dim, shapese.expr);
+  gfc_add_block_to_block (&body, &shapese.post);
+
+  /* Calculate offset.  */
+  gfc_add_modify (&body, offset,
+ fold_build2_loc (input_location, PLUS_EXPR,
+  gfc_array_index_type, offset, stride));
+  /* Update stride.  */
+  gfc_add_modify (&body, stride,
+ fold_build2_loc (input_location, MULT_EXPR,
+  gfc_array_index_type, stride,
+  fold_convert (gfc_array_index_type,
+shapese.expr)));
+  /* Finish scalarization loop.  */
+  gfc_trans_scalarizing_loops (&loop, &body);
+  gfc_add_block_to_block (block, &loop.pre);
+  gfc_add_block_to_block (block, &loop.post);
+  gfc_cleanup_loop (&loop);
+
+  gfc_add_modify (block, offset,
+ fold_build1_loc (input_location, NEGATE_EXPR,
+  gfc_array_index_type, offset));
+  gfc_conv_descriptor_offset_set (block, desc, offset);
+}
+
+
 /* Obtain offsets for trans-types.cc(gfc_get_array_descr_info).  */
 
 void
diff --git a/gcc/fortran/trans-array.h b/gcc/fortran/trans-array.h
index 3f39845c898f..05ea68d531ac 100644
--- a/gcc/fortran/trans-array.h
+++ b/gcc/fortran/trans-array.h
@@ -145,6 +145,8 @@ void gfc_clear_descriptor (stmtblock_t *block, gfc_symbol 
*, tree);
 void gfc_nullify_descriptor (stmtblock_t *block, gfc_expr *, tree);
 void gfc_clear_descriptor (stmtblock_t *block, gfc_symbol *, gfc_expr *, tree);
 void gfc_set_scalar_descriptor (stmtblock_t *block, tree, gfc_symbol *, 
gfc_expr *, tree);
+void gfc_set_descriptor_with_shape (stmtblock_t *, tree, tree,
+   gfc_expr *, locus *);
 
 /* Get a single array element.  */
 void gfc_conv_array_ref (gfc_se *, gfc_array_ref *, gfc_expr *, locus *);
diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index b6900d734afd..5d77f3d768a6 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -10482,11 +10482,8 @@ conv_isocbinding_subroutine (gfc_code *code)
   gfc_se se;
   gfc_se cptrse;
   gfc_se fptrse;
-  gfc_se shapese;
-  gfc_ss *shape_ss;
-  tree desc, dim, tmp, stride, offset;
-  stmtbl

[gcc/aoliva/heads/testme] [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

2025-01-17 Thread Alexandre Oliva via Gcc-cvs
The branch 'aoliva/heads/testme' was updated to point to:

 80670982ddfe... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

It previously pointed to:

 7164ecf0... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

Diff:

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

  716... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]


Summary of changes (added commits):
---

  8067098... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]


[gcc(refs/users/aoliva/heads/testme)] [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

2025-01-17 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:80670982ddfeb70e10f255fb59a58d71fab48ed1

commit 80670982ddfeb70e10f255fb59a58d71fab48ed1
Author: Alexandre Oliva 
Date:   Fri Jan 17 16:47:25 2025 -0300

[ifcombine] out-of-bounds bitfield refs can trap [PR118514]

Diff:
---
 gcc/gimple-fold.cc|  2 ++
 gcc/testsuite/gcc.dg/field-merge-23.c | 19 +++
 gcc/tree-eh.cc| 30 +-
 3 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 3c971a29ef04..5f1d69c19fe4 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -7834,6 +7834,8 @@ make_bit_field_load (location_t loc, tree inner, tree 
orig_inner, tree type,
   if (!point)
 return ref;
 
+  gcc_checking_assert (gimple_could_trap_p (point) == tree_could_trap_p (ref));
+
   /* If we're remaking the same load, reuse the SSA NAME it is already loaded
  into.  */
   if (gimple_assign_load_p (point)
diff --git a/gcc/testsuite/gcc.dg/field-merge-23.c 
b/gcc/testsuite/gcc.dg/field-merge-23.c
new file mode 100644
index ..d60f76206ebe
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/field-merge-23.c
@@ -0,0 +1,19 @@
+/* { dg-do run } */
+/* { dg-options "-O" } */
+
+/* PR tree-optimization/118514 */
+
+/* Check that we don't pull optimized references that could trap out of
+   loops.  */
+
+int a, c = 1;
+unsigned char b[1], d;
+int main() {
+  while (a || !c) {
+signed char e = b[10];
+d = e < 0 || b[10] > 1;
+if (d)
+  __builtin_abort ();
+  }
+  return 0;
+}
diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
index 1033b124e4df..a92eccb4bb6d 100644
--- a/gcc/tree-eh.cc
+++ b/gcc/tree-eh.cc
@@ -2646,6 +2646,30 @@ range_in_array_bounds_p (tree ref)
   return true;
 }
 
+/* Return true iff EXPR, a BIT_FIELD_REF, accesses a bit range that is known to
+   be in bounds for the referred operand type.  */
+
+static bool
+bit_field_ref_in_bounds_p (tree expr)
+{
+  tree size_tree;
+  poly_uint64 size_max, min, wid, max;
+
+  size_tree = TYPE_SIZE (TREE_TYPE (TREE_OPERAND (expr, 0)));
+  if (!size_tree
+  || !poly_int_tree_p (size_tree, &size_max)
+  || !poly_int_tree_p (TREE_OPERAND (expr, 2), &min)
+  || !poly_int_tree_p (TREE_OPERAND (expr, 1), &wid))
+return false;
+
+  max = min + wid;
+  if (maybe_lt (max, min)
+  || maybe_lt (size_max, max))
+return false;
+
+  return true;
+}
+
 /* Return true if EXPR can trap, as in dereferencing an invalid pointer
location or floating point arithmetic.  C.f. the rtl version, may_trap_p.
This routine expects only GIMPLE lhs or rhs input.  */
@@ -2688,10 +2712,14 @@ tree_could_trap_p (tree expr)
  restart:
   switch (code)
 {
+case BIT_FIELD_REF:
+  if (!bit_field_ref_in_bounds_p (expr))
+   return true;
+  /* Fall through.  */
+
 case COMPONENT_REF:
 case REALPART_EXPR:
 case IMAGPART_EXPR:
-case BIT_FIELD_REF:
 case VIEW_CONVERT_EXPR:
 case WITH_SIZE_EXPR:
   expr = TREE_OPERAND (expr, 0);


[gcc(refs/users/aoliva/heads/testme)] [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

2025-01-17 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:a823af07854747028d8c2b5672e3c8bdf5d95be1

commit a823af07854747028d8c2b5672e3c8bdf5d95be1
Author: Alexandre Oliva 
Date:   Fri Jan 17 16:47:25 2025 -0300

[ifcombine] out-of-bounds bitfield refs can trap [PR118514]

Diff:
---
 gcc/gimple-fold.cc| 14 ++
 gcc/testsuite/gcc.dg/field-merge-23.c | 19 +++
 gcc/tree-eh.cc| 32 +++-
 3 files changed, 60 insertions(+), 5 deletions(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 3c971a29ef04..147a70894f48 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -7836,11 +7836,17 @@ make_bit_field_load (location_t loc, tree inner, tree 
orig_inner, tree type,
 
   /* If we're remaking the same load, reuse the SSA NAME it is already loaded
  into.  */
-  if (gimple_assign_load_p (point)
-  && operand_equal_p (ref, gimple_assign_rhs1 (point)))
+  if (gimple_assign_load_p (point))
 {
-  gcc_checking_assert (TREE_CODE (gimple_assign_lhs (point)) == SSA_NAME);
-  return gimple_assign_lhs (point);
+  if (operand_equal_p (ref, gimple_assign_rhs1 (point)))
+   {
+ gcc_checking_assert (TREE_CODE (gimple_assign_lhs (point))
+  == SSA_NAME);
+ return gimple_assign_lhs (point);
+   }
+  else
+   gcc_checking_assert (tree_could_trap_p (gimple_assign_rhs1 (point))
+== tree_could_trap_p (ref));
 }
 
   gimple_seq stmts = NULL;
diff --git a/gcc/testsuite/gcc.dg/field-merge-23.c 
b/gcc/testsuite/gcc.dg/field-merge-23.c
new file mode 100644
index ..d60f76206ebe
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/field-merge-23.c
@@ -0,0 +1,19 @@
+/* { dg-do run } */
+/* { dg-options "-O" } */
+
+/* PR tree-optimization/118514 */
+
+/* Check that we don't pull optimized references that could trap out of
+   loops.  */
+
+int a, c = 1;
+unsigned char b[1], d;
+int main() {
+  while (a || !c) {
+signed char e = b[10];
+d = e < 0 || b[10] > 1;
+if (d)
+  __builtin_abort ();
+  }
+  return 0;
+}
diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
index 1033b124e4df..178f20add56c 100644
--- a/gcc/tree-eh.cc
+++ b/gcc/tree-eh.cc
@@ -2646,6 +2646,30 @@ range_in_array_bounds_p (tree ref)
   return true;
 }
 
+/* Return true iff EXPR, a BIT_FIELD_REF, accesses a bit range that is known to
+   be in bounds for the referred operand type.  */
+
+static bool
+bit_field_ref_in_bounds_p (tree expr)
+{
+  tree size_tree;
+  poly_uint64 size_max, min, wid, max;
+
+  size_tree = TYPE_SIZE (TREE_TYPE (TREE_OPERAND (expr, 0)));
+  if (!size_tree
+  || !poly_int_tree_p (size_tree, &size_max)
+  || !poly_int_tree_p (TREE_OPERAND (expr, 2), &min)
+  || !poly_int_tree_p (TREE_OPERAND (expr, 1), &wid))
+return false;
+
+  max = min + wid;
+  if (maybe_lt (max, min)
+  || maybe_lt (size_max, max))
+return false;
+
+  return true;
+}
+
 /* Return true if EXPR can trap, as in dereferencing an invalid pointer
location or floating point arithmetic.  C.f. the rtl version, may_trap_p.
This routine expects only GIMPLE lhs or rhs input.  */
@@ -2688,10 +2712,16 @@ tree_could_trap_p (tree expr)
  restart:
   switch (code)
 {
+case BIT_FIELD_REF:
+  if (!bit_field_ref_in_bounds_p (expr))
+   return true;
+  /* Fall through.  */
+
 case COMPONENT_REF:
 case REALPART_EXPR:
 case IMAGPART_EXPR:
-case BIT_FIELD_REF:
+case NOP_EXPR:
+case CONVERT_EXPR:
 case VIEW_CONVERT_EXPR:
 case WITH_SIZE_EXPR:
   expr = TREE_OPERAND (expr, 0);


[gcc r15-7013] RISC-V: Remove unused variable in riscv_file_end function.

2025-01-17 Thread Monk Chiang via Gcc-cvs
https://gcc.gnu.org/g:3c34cea666c6fffc3959b8e1a4bbc4afdbd7009f

commit r15-7013-g3c34cea666c6fffc3959b8e1a4bbc4afdbd7009f
Author: Monk Chiang 
Date:   Sat Jan 18 15:32:26 2025 +0800

RISC-V: Remove unused variable in riscv_file_end function.

gcc/ChangeLog:
* config/riscv/riscv.cc: Remove unused variable.

Diff:
---
 gcc/config/riscv/riscv.cc | 1 -
 1 file changed, 1 deletion(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index aa5cb8af682b..9a1db2d2b380 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -10337,7 +10337,6 @@ void
 riscv_file_end ()
 {
   file_end_indicate_exec_stack ();
-  long GNU_PROPERTY_RISCV_FEATURE_1_AND  = 0;
   unsigned long feature_1_and = 0;
 
   if (is_zicfilp_p ())


[gcc(refs/users/aoliva/heads/testme)] [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

2025-01-17 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:01891eefc637741f8aa2db04378bedfc4fb818b0

commit 01891eefc637741f8aa2db04378bedfc4fb818b0
Author: Alexandre Oliva 
Date:   Fri Jan 17 16:47:25 2025 -0300

[ifcombine] out-of-bounds bitfield refs can trap [PR118514]

Diff:
---
 gcc/gimple-fold.cc| 27 +++
 gcc/testsuite/gcc.dg/field-merge-23.c | 19 +++
 gcc/tree-eh.cc| 30 +-
 3 files changed, 71 insertions(+), 5 deletions(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 3c971a29ef04..cb00e83ad31c 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -7815,6 +7815,20 @@ compute_split_boundary_from_align (HOST_WIDE_INT align,
   return boundary;
 }
 
+/* Return true iff REF and the LOADed expression both trap, or neither do.  */
+
+static inline bool
+still_trap_p (gimple *load, tree ref)
+{
+  tree before = gimple_assign_rhs1 (load);
+  tree now = ref;
+
+  STRIP_NOPS (before);
+  STRIP_NOPS (now);
+
+  return (tree_could_trap_p (before) == tree_could_trap_p (now));
+}
+
 /* Make a bit_field_ref.  If POINT is NULL, return the BIT_FIELD_REF.
Otherwise, build and insert a load stmt before POINT, and return
the SSA_NAME.  ???  Rewrite LOAD in terms of the bitfield?  */
@@ -7836,11 +7850,16 @@ make_bit_field_load (location_t loc, tree inner, tree 
orig_inner, tree type,
 
   /* If we're remaking the same load, reuse the SSA NAME it is already loaded
  into.  */
-  if (gimple_assign_load_p (point)
-  && operand_equal_p (ref, gimple_assign_rhs1 (point)))
+  if (gimple_assign_load_p (point))
 {
-  gcc_checking_assert (TREE_CODE (gimple_assign_lhs (point)) == SSA_NAME);
-  return gimple_assign_lhs (point);
+  if (operand_equal_p (ref, gimple_assign_rhs1 (point)))
+   {
+ gcc_checking_assert (TREE_CODE (gimple_assign_lhs (point))
+  == SSA_NAME);
+ return gimple_assign_lhs (point);
+   }
+  else
+   gcc_checking_assert (still_trap_p (point, ref));
 }
 
   gimple_seq stmts = NULL;
diff --git a/gcc/testsuite/gcc.dg/field-merge-23.c 
b/gcc/testsuite/gcc.dg/field-merge-23.c
new file mode 100644
index ..d60f76206ebe
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/field-merge-23.c
@@ -0,0 +1,19 @@
+/* { dg-do run } */
+/* { dg-options "-O" } */
+
+/* PR tree-optimization/118514 */
+
+/* Check that we don't pull optimized references that could trap out of
+   loops.  */
+
+int a, c = 1;
+unsigned char b[1], d;
+int main() {
+  while (a || !c) {
+signed char e = b[10];
+d = e < 0 || b[10] > 1;
+if (d)
+  __builtin_abort ();
+  }
+  return 0;
+}
diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
index 1033b124e4df..a92eccb4bb6d 100644
--- a/gcc/tree-eh.cc
+++ b/gcc/tree-eh.cc
@@ -2646,6 +2646,30 @@ range_in_array_bounds_p (tree ref)
   return true;
 }
 
+/* Return true iff EXPR, a BIT_FIELD_REF, accesses a bit range that is known to
+   be in bounds for the referred operand type.  */
+
+static bool
+bit_field_ref_in_bounds_p (tree expr)
+{
+  tree size_tree;
+  poly_uint64 size_max, min, wid, max;
+
+  size_tree = TYPE_SIZE (TREE_TYPE (TREE_OPERAND (expr, 0)));
+  if (!size_tree
+  || !poly_int_tree_p (size_tree, &size_max)
+  || !poly_int_tree_p (TREE_OPERAND (expr, 2), &min)
+  || !poly_int_tree_p (TREE_OPERAND (expr, 1), &wid))
+return false;
+
+  max = min + wid;
+  if (maybe_lt (max, min)
+  || maybe_lt (size_max, max))
+return false;
+
+  return true;
+}
+
 /* Return true if EXPR can trap, as in dereferencing an invalid pointer
location or floating point arithmetic.  C.f. the rtl version, may_trap_p.
This routine expects only GIMPLE lhs or rhs input.  */
@@ -2688,10 +2712,14 @@ tree_could_trap_p (tree expr)
  restart:
   switch (code)
 {
+case BIT_FIELD_REF:
+  if (!bit_field_ref_in_bounds_p (expr))
+   return true;
+  /* Fall through.  */
+
 case COMPONENT_REF:
 case REALPART_EXPR:
 case IMAGPART_EXPR:
-case BIT_FIELD_REF:
 case VIEW_CONVERT_EXPR:
 case WITH_SIZE_EXPR:
   expr = TREE_OPERAND (expr, 0);


[gcc/aoliva/heads/testme] [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

2025-01-17 Thread Alexandre Oliva via Gcc-cvs
The branch 'aoliva/heads/testme' was updated to point to:

 01891eefc637... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

It previously pointed to:

 458997f78563... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

Diff:

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

  458997f... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]


Summary of changes (added commits):
---

  01891ee... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]


[gcc r15-7008] [PR118067][LRA]: Check secondary memory mode for the reg class

2025-01-17 Thread Vladimir Makarov via Gcc-cvs
https://gcc.gnu.org/g:9f009e8865cda01310c52f7ec8bdaa3c557a2745

commit r15-7008-g9f009e8865cda01310c52f7ec8bdaa3c557a2745
Author: Vladimir N. Makarov 
Date:   Fri Jan 17 15:56:29 2025 -0500

[PR118067][LRA]: Check secondary memory mode for the reg class

  This is the second patch for the PR for the new test.  The patch
solves problem in the case when secondary memory mode (SImode in the
PR test) returned by hook secondary_memory_needed_mode can not be used
for reg class (ALL_MASK_REGS) involved in secondary memory moves.  The
patch uses reg mode instead of one returned by
secondary_memory_needed_mode in this case.

gcc/ChangeLog:

PR rtl-optimization/118067
* lra-constraints.cc (invalid_mode_reg_p): New function.
(curr_insn_transform): Use it to check mode returned by target
secondary_memory_needed_mode.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr118067-2.c: New.

Diff:
---
 gcc/lra-constraints.cc | 17 +
 gcc/testsuite/gcc.target/i386/pr118067-2.c | 16 
 2 files changed, 33 insertions(+)

diff --git a/gcc/lra-constraints.cc b/gcc/lra-constraints.cc
index 3d5abcfaeb0b..cd19da294db3 100644
--- a/gcc/lra-constraints.cc
+++ b/gcc/lra-constraints.cc
@@ -4129,6 +4129,19 @@ swap_operands (int nop)
   lra_update_dup (curr_id, nop + 1);
 }
 
+/* Return TRUE if X is a (subreg of) reg and there are no hard regs of X class
+   which can contain value of MODE.  */
+static bool invalid_mode_reg_p (enum machine_mode mode, rtx x)
+{
+  if (SUBREG_P (x))
+x = SUBREG_REG (x);
+  if (! REG_P (x))
+return false;
+  enum reg_class rclass = get_reg_class (REGNO (x));
+  return hard_reg_set_subset_p (ira_prohibited_class_mode_regs[rclass][mode],
+   reg_class_contents[rclass]);
+}
+
 /* Main entry point of the constraint code: search the body of the
current insn to choose the best alternative.  It is mimicking insn
alternative cost calculation model of former reload pass.  That is
@@ -4389,6 +4402,10 @@ curr_insn_transform (bool check_only_p)
   rld = partial_subreg_p (GET_MODE (src), GET_MODE (dest)) ? src : dest;
   rld_mode = GET_MODE (rld);
   sec_mode = targetm.secondary_memory_needed_mode (rld_mode);
+  if (rld_mode != sec_mode
+ && (invalid_mode_reg_p (sec_mode, dest)
+ || invalid_mode_reg_p (sec_mode, src)))
+   sec_mode = rld_mode;
   new_reg = lra_create_new_reg (sec_mode, NULL_RTX, NO_REGS, NULL,
"secondary");
   /* If the mode is changed, it should be wider.  */
diff --git a/gcc/testsuite/gcc.target/i386/pr118067-2.c 
b/gcc/testsuite/gcc.target/i386/pr118067-2.c
new file mode 100644
index ..831871db0b43
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr118067-2.c
@@ -0,0 +1,16 @@
+/* { dg-do compile { target { ! ia32 } } } */
+/* { dg-options "-O -fno-split-wide-types -mavx512f -mcpu=k8" } */
+
+typedef unsigned short U __attribute__((__vector_size__(64)));
+typedef int V __attribute__((__vector_size__(64)));
+typedef __int128 W __attribute__((__vector_size__(64)));
+
+W
+foo(U u, V v)
+{
+  W w;
+  /* __asm__ volatile ("" : "=v"(w)); prevents the -Wuninitialized warning */
+  u[0] >>= 1;
+  v %= (V)w;
+  return (W)u + (W)v;
+}


[gcc/aoliva/heads/testme] [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

2025-01-17 Thread Alexandre Oliva via Gcc-cvs
The branch 'aoliva/heads/testme' was updated to point to:

 057671e7d5c8... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

It previously pointed to:

 80670982ddfe... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

Diff:

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

  8067098... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]


Summary of changes (added commits):
---

  057671e... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]


[gcc(refs/users/aoliva/heads/testme)] [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

2025-01-17 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:057671e7d5c8ed1b8dd43525268f6bf831cd0f1e

commit 057671e7d5c8ed1b8dd43525268f6bf831cd0f1e
Author: Alexandre Oliva 
Date:   Fri Jan 17 16:47:25 2025 -0300

[ifcombine] out-of-bounds bitfield refs can trap [PR118514]

Diff:
---
 gcc/gimple-fold.cc| 18 ++
 gcc/testsuite/gcc.dg/field-merge-23.c | 19 +++
 gcc/tree-eh.cc| 30 +-
 3 files changed, 62 insertions(+), 5 deletions(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 3c971a29ef04..9cb0925a75d0 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -7836,11 +7836,21 @@ make_bit_field_load (location_t loc, tree inner, tree 
orig_inner, tree type,
 
   /* If we're remaking the same load, reuse the SSA NAME it is already loaded
  into.  */
-  if (gimple_assign_load_p (point)
-  && operand_equal_p (ref, gimple_assign_rhs1 (point)))
+  if (gimple_assign_load_p (point))
 {
-  gcc_checking_assert (TREE_CODE (gimple_assign_lhs (point)) == SSA_NAME);
-  return gimple_assign_lhs (point);
+  if (operand_equal_p (ref, gimple_assign_rhs1 (point)))
+   {
+ gcc_checking_assert (TREE_CODE (gimple_assign_lhs (point))
+  == SSA_NAME);
+ return gimple_assign_lhs (point);
+   }
+  else
+   {
+ tree chk = ref;
+ STRIP_NOPS (chk);
+ gcc_checking_assert (tree_could_trap_p (gimple_assign_rhs1 (point))
+  == tree_could_trap_p (chk));
+   }
 }
 
   gimple_seq stmts = NULL;
diff --git a/gcc/testsuite/gcc.dg/field-merge-23.c 
b/gcc/testsuite/gcc.dg/field-merge-23.c
new file mode 100644
index ..d60f76206ebe
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/field-merge-23.c
@@ -0,0 +1,19 @@
+/* { dg-do run } */
+/* { dg-options "-O" } */
+
+/* PR tree-optimization/118514 */
+
+/* Check that we don't pull optimized references that could trap out of
+   loops.  */
+
+int a, c = 1;
+unsigned char b[1], d;
+int main() {
+  while (a || !c) {
+signed char e = b[10];
+d = e < 0 || b[10] > 1;
+if (d)
+  __builtin_abort ();
+  }
+  return 0;
+}
diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
index 1033b124e4df..a92eccb4bb6d 100644
--- a/gcc/tree-eh.cc
+++ b/gcc/tree-eh.cc
@@ -2646,6 +2646,30 @@ range_in_array_bounds_p (tree ref)
   return true;
 }
 
+/* Return true iff EXPR, a BIT_FIELD_REF, accesses a bit range that is known to
+   be in bounds for the referred operand type.  */
+
+static bool
+bit_field_ref_in_bounds_p (tree expr)
+{
+  tree size_tree;
+  poly_uint64 size_max, min, wid, max;
+
+  size_tree = TYPE_SIZE (TREE_TYPE (TREE_OPERAND (expr, 0)));
+  if (!size_tree
+  || !poly_int_tree_p (size_tree, &size_max)
+  || !poly_int_tree_p (TREE_OPERAND (expr, 2), &min)
+  || !poly_int_tree_p (TREE_OPERAND (expr, 1), &wid))
+return false;
+
+  max = min + wid;
+  if (maybe_lt (max, min)
+  || maybe_lt (size_max, max))
+return false;
+
+  return true;
+}
+
 /* Return true if EXPR can trap, as in dereferencing an invalid pointer
location or floating point arithmetic.  C.f. the rtl version, may_trap_p.
This routine expects only GIMPLE lhs or rhs input.  */
@@ -2688,10 +2712,14 @@ tree_could_trap_p (tree expr)
  restart:
   switch (code)
 {
+case BIT_FIELD_REF:
+  if (!bit_field_ref_in_bounds_p (expr))
+   return true;
+  /* Fall through.  */
+
 case COMPONENT_REF:
 case REALPART_EXPR:
 case IMAGPART_EXPR:
-case BIT_FIELD_REF:
 case VIEW_CONVERT_EXPR:
 case WITH_SIZE_EXPR:
   expr = TREE_OPERAND (expr, 0);


[gcc(refs/users/aoliva/heads/testme)] [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

2025-01-17 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:53d5a650fd7270e931680b62bb055a36faa3bdb0

commit 53d5a650fd7270e931680b62bb055a36faa3bdb0
Author: Alexandre Oliva 
Date:   Fri Jan 17 16:47:25 2025 -0300

[ifcombine] out-of-bounds bitfield refs can trap [PR118514]

Diff:
---
 gcc/gimple-fold.cc| 25 +
 gcc/testsuite/gcc.dg/field-merge-23.c | 19 +++
 gcc/tree-eh.cc| 30 +-
 3 files changed, 69 insertions(+), 5 deletions(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 3c971a29ef04..7efc02d5a7ae 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -7815,6 +7815,18 @@ compute_split_boundary_from_align (HOST_WIDE_INT align,
   return boundary;
 }
 
+/* Return true iff REF and the LOADed expression both trap, or neither do.  */
+
+static inline bool
+still_trap_p (gimple *load, const_tree ref)
+{
+  tree bef = gimple_assign_rhs1 (load);
+  tree now = ref;
+  STRIP_NOPS (bef);
+  STRIP_NOPS (now);
+  return (tree_could_trap_p (bef) == tree_could_trap_p (now));
+}
+
 /* Make a bit_field_ref.  If POINT is NULL, return the BIT_FIELD_REF.
Otherwise, build and insert a load stmt before POINT, and return
the SSA_NAME.  ???  Rewrite LOAD in terms of the bitfield?  */
@@ -7836,11 +7848,16 @@ make_bit_field_load (location_t loc, tree inner, tree 
orig_inner, tree type,
 
   /* If we're remaking the same load, reuse the SSA NAME it is already loaded
  into.  */
-  if (gimple_assign_load_p (point)
-  && operand_equal_p (ref, gimple_assign_rhs1 (point)))
+  if (gimple_assign_load_p (point))
 {
-  gcc_checking_assert (TREE_CODE (gimple_assign_lhs (point)) == SSA_NAME);
-  return gimple_assign_lhs (point);
+  if (operand_equal_p (ref, gimple_assign_rhs1 (point)))
+   {
+ gcc_checking_assert (TREE_CODE (gimple_assign_lhs (point))
+  == SSA_NAME);
+ return gimple_assign_lhs (point);
+   }
+  else
+   gcc_checking_assert (still_trap_p (point, ref));
 }
 
   gimple_seq stmts = NULL;
diff --git a/gcc/testsuite/gcc.dg/field-merge-23.c 
b/gcc/testsuite/gcc.dg/field-merge-23.c
new file mode 100644
index ..d60f76206ebe
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/field-merge-23.c
@@ -0,0 +1,19 @@
+/* { dg-do run } */
+/* { dg-options "-O" } */
+
+/* PR tree-optimization/118514 */
+
+/* Check that we don't pull optimized references that could trap out of
+   loops.  */
+
+int a, c = 1;
+unsigned char b[1], d;
+int main() {
+  while (a || !c) {
+signed char e = b[10];
+d = e < 0 || b[10] > 1;
+if (d)
+  __builtin_abort ();
+  }
+  return 0;
+}
diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
index 1033b124e4df..a92eccb4bb6d 100644
--- a/gcc/tree-eh.cc
+++ b/gcc/tree-eh.cc
@@ -2646,6 +2646,30 @@ range_in_array_bounds_p (tree ref)
   return true;
 }
 
+/* Return true iff EXPR, a BIT_FIELD_REF, accesses a bit range that is known to
+   be in bounds for the referred operand type.  */
+
+static bool
+bit_field_ref_in_bounds_p (tree expr)
+{
+  tree size_tree;
+  poly_uint64 size_max, min, wid, max;
+
+  size_tree = TYPE_SIZE (TREE_TYPE (TREE_OPERAND (expr, 0)));
+  if (!size_tree
+  || !poly_int_tree_p (size_tree, &size_max)
+  || !poly_int_tree_p (TREE_OPERAND (expr, 2), &min)
+  || !poly_int_tree_p (TREE_OPERAND (expr, 1), &wid))
+return false;
+
+  max = min + wid;
+  if (maybe_lt (max, min)
+  || maybe_lt (size_max, max))
+return false;
+
+  return true;
+}
+
 /* Return true if EXPR can trap, as in dereferencing an invalid pointer
location or floating point arithmetic.  C.f. the rtl version, may_trap_p.
This routine expects only GIMPLE lhs or rhs input.  */
@@ -2688,10 +2712,14 @@ tree_could_trap_p (tree expr)
  restart:
   switch (code)
 {
+case BIT_FIELD_REF:
+  if (!bit_field_ref_in_bounds_p (expr))
+   return true;
+  /* Fall through.  */
+
 case COMPONENT_REF:
 case REALPART_EXPR:
 case IMAGPART_EXPR:
-case BIT_FIELD_REF:
 case VIEW_CONVERT_EXPR:
 case WITH_SIZE_EXPR:
   expr = TREE_OPERAND (expr, 0);


[gcc/aoliva/heads/testme] [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

2025-01-17 Thread Alexandre Oliva via Gcc-cvs
The branch 'aoliva/heads/testme' was updated to point to:

 53d5a650fd72... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

It previously pointed to:

 057671e7d5c8... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

Diff:

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

  057671e... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]


Summary of changes (added commits):
---

  53d5a65... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]


[gcc r14-11223] d: Fix ICE in expand_d_format when diagnosing empty enum [PR117115]

2025-01-17 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:4abeaeba435054ad0ab59cf570620b37c06ffcc4

commit r14-11223-g4abeaeba435054ad0ab59cf570620b37c06ffcc4
Author: Iain Buclaw 
Date:   Fri Jan 17 20:10:39 2025 +0100

d: Fix ICE in expand_d_format when diagnosing empty enum [PR117115]

This was fixed in upstream dmd, and merged in r15-6824. Backport the
individual fix from the upstream merge for releases/gcc-14.

PR d/117115

gcc/testsuite/ChangeLog:

* gdc.dg/pr117115.d: New test.

(cherry picked from commit 975c4f1a5de4ede89ee9499cd1a73d613a4aeae4)

Diff:
---
 gcc/d/dmd/enumsem.d | 2 +-
 gcc/testsuite/gdc.dg/pr117115.d | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/d/dmd/enumsem.d b/gcc/d/dmd/enumsem.d
index 3886ca25e97b..06683b254907 100644
--- a/gcc/d/dmd/enumsem.d
+++ b/gcc/d/dmd/enumsem.d
@@ -186,7 +186,7 @@ void enumSemantic(Scope* sc, EnumDeclaration ed)
 
 if (ed.members.length == 0)
 {
-.error(ed.loc, "%s `%s enum `%s` must have at least one member", 
ed.kind, ed.toPrettyChars, ed.toChars());
+.error(ed.loc, "%s `%s` enum `%s` must have at least one member", 
ed.kind, ed.toPrettyChars, ed.toChars());
 ed.errors = true;
 ed.semanticRun = PASS.semanticdone;
 return;
diff --git a/gcc/testsuite/gdc.dg/pr117115.d b/gcc/testsuite/gdc.dg/pr117115.d
new file mode 100644
index ..b012268b509e
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr117115.d
@@ -0,0 +1,3 @@
+// { dg-do compile }
+
+enum E117115 {} // { dg-error "must have at least one member" }


[gcc/aoliva/heads/testme] (85 commits) [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

2025-01-17 Thread Alexandre Oliva via Gcc-cvs
The branch 'aoliva/heads/testme' was updated to point to:

 7164ecf0... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

It previously pointed to:

 cfff1937f515... [testsuite] [arm] adjust wmul expectations [PR113560]

Diff:

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

  cfff193... [testsuite] [arm] adjust wmul expectations [PR113560]
  05289ed... [testsuite] [arm] multilibs.exp: adjust float abi opt match
  447aaef... [testsuite] drop explicit run overrider in more dfp tests
  3b49119... [testsuite] skip test on non-hosted libstdc++ [PR113994]
  c32ef7c... [testsuite] rearrange requirements for dfp bitint run tests


Summary of changes (added commits):
---

  716... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]
  15a7544... c++: RESULT_DECL replacement w/ non-reduced ctx->object [PR (*)
  fed57c8... [testsuite] [arm] adjust wmul expectations [PR113560] (*)
  bc6e3a0... [testsuite] [arm] multilibs.exp: adjust float abi opt match (*)
  def933a... [testsuite] skip test on non-hosted libstdc++ [PR113994] (*)
  4fc3bf9... [testsuite] drop explicit run overrider in more dfp tests (*)
  22f9ccf... [testsuite] rearrange requirements for dfp bitint run tests (*)
  f5409d7... Fortran/OpenMP: Fix declare_variant's 'adjust_args' mishand (*)
  62daa81... c++: explicit spec of constrained member tmpl [PR107522] (*)
  d72e5b7... c++: pack expansion arg vs non-pack parm checking ICE [PR11 (*)
  232d3a7... c++: make finish_pseudo_destructor_expr SFINAE-aware [PR116 (*)
  37f38b0... c++: Make sure fold_sizeof_expr returns the correct type [P (*)
  99bcce0... libfortran: fix conversion of UNSIGNED(kind=16) to decimal  (*)
  1ff85af... AArch64: have -mcpu=native detect architecture extensions f (*)
  773beea... AArch64: don't override march to assembler with mcpu if mar (*)
  d983582... [PR118067][LRA]: Use the right mode to evaluate secondary m (*)
  c158f36... Allow CFI_cdesc_t in argument lists with -fc-prototypes. (*)
  7f8bb64... OpenMP: Improve error message for invalid directive in "ass (*)
  c7dab40... d: Add testcase for fixed PR116373 (*)
  3c8df36... OpenMP: Update "declare target"/OpenMP context interaction (*)
  fdeceba... OpenMP: Shared metadirective/dynamic selector tests for C a (*)
  677e452... OpenMP: C++ support for metadirectives and dynamic selector (*)
  4e20914... OpenMP: Add C support for metadirectives and dynamic select (*)
  0696af7... rs6000: Fix ICE for invalid constants in built-in functions (*)
  1a2d63a... rs6000: Fix loop limit for built-in constant checking (*)
  3191d74... c++: Fix up reshape_* RAW_DATA_CST handling [PR118214] (*)
  03e0bf3... c++: Change c++2b and gnu++2b to c++23 and gnu++23 in C++ d (*)
  80b5230... middle-end: Add early break conditions to vect-switch-searc (*)
  3d678ad... Extend OpenACC 'serial' testing, compiler-side (*)
  97aae0f... [OpenACC/Fortran testsuite] Use relative line numbers for a (*)
  c5a8e22... Fortran: Create fresh ts.u.cl for result in gfc_get_symbol_ (*)
  462a7f4... libstdc++: Move std::basic_ostream to new internal header [ (*)
  301a961... libstdc++: Implement LWG 2937 for std::filesystem::equivale (*)
  408f5b8... libstdc++: Check feature test macro for associative contain (*)
  8682fcb... RISC-V: Update Xsfvqmacc and Xsfvfnrclip's testcases (*)
  030aaea... RISC-V: Update Xsfvfnrclip implementation. (*)
  b42eeef... forwprop: Ensure that shuffle masks are VECTOR_CSTs (*)
  57de373... forwprop: Eliminate redundant calls to to_constant() (*)
  ea1deef... tree-optimization/115494 - PRE PHI translation and ranges (*)
  7f5adfd... tree-ssa-propagate: Special case lhs of musttail calls in m (*)
  9c4397c... tailc: Virtually undo IPA-VRP return value optimization for (*)
  015ec11... docs: Fix up inline asm documentation (*)
  43f4d44... vec.h: Properly destruct elements in auto_vec auto storage  (*)
  3872daa... Fix typo to avoid ICE. (*)
  1b5d2cc... tree-optimization/115895 - overrun with masked loop (*)
  cf9de71... lm32: In va_arg, skip to stack args with too few remaining  (*)
  423e9a8... lm32: Compute pretend_size in setup_incoming_varargs even i (*)
  6e593fc... lm32: Skip last named param when computing save varargs reg (*)
  3184f6a... lm32: Args with arg.named false still get passed in regs (*)
  efd00e3... Fix an incorrect file header comment for the core2 scheduli (*)
  e683c6b... Fix setting of call graph node AutoFDO count (*)
  14f337e... Daily bump. (*)
  79d5504... libstdc++: Fix use of internal feature test macro in test (*)
  f079fee... libstdc++: Fix fancy pointer test for std::set (*)
  903ab91... match: Simplify `1 >> x` into `x == 0` [PR102705] (*)
  c340ff2... doc: cleanup trailing whitespace (*)
  d8e5244... doc: trivial grammar fix (*)
  6f85a97... libstdc++: Fix reversed args in unreachable assumption [PR1 (*)
  8923099... Fortran: reject NULL as source-expr in ALLO

[gcc/aoliva/heads/testbase] (84 commits) c++: RESULT_DECL replacement w/ non-reduced ctx->object [PR

2025-01-17 Thread Alexandre Oliva via Gcc-cvs
The branch 'aoliva/heads/testbase' was updated to point to:

 15a7544e09d8... c++: RESULT_DECL replacement w/ non-reduced ctx->object [PR

It previously pointed to:

 5006b9d810b1... [ifcombine] robustify decode_field_reference

Diff:

Summary of changes (added commits):
---

  15a7544... c++: RESULT_DECL replacement w/ non-reduced ctx->object [PR (*)
  fed57c8... [testsuite] [arm] adjust wmul expectations [PR113560] (*)
  bc6e3a0... [testsuite] [arm] multilibs.exp: adjust float abi opt match (*)
  def933a... [testsuite] skip test on non-hosted libstdc++ [PR113994] (*)
  4fc3bf9... [testsuite] drop explicit run overrider in more dfp tests (*)
  22f9ccf... [testsuite] rearrange requirements for dfp bitint run tests (*)
  f5409d7... Fortran/OpenMP: Fix declare_variant's 'adjust_args' mishand (*)
  62daa81... c++: explicit spec of constrained member tmpl [PR107522] (*)
  d72e5b7... c++: pack expansion arg vs non-pack parm checking ICE [PR11 (*)
  232d3a7... c++: make finish_pseudo_destructor_expr SFINAE-aware [PR116 (*)
  37f38b0... c++: Make sure fold_sizeof_expr returns the correct type [P (*)
  99bcce0... libfortran: fix conversion of UNSIGNED(kind=16) to decimal  (*)
  1ff85af... AArch64: have -mcpu=native detect architecture extensions f (*)
  773beea... AArch64: don't override march to assembler with mcpu if mar (*)
  d983582... [PR118067][LRA]: Use the right mode to evaluate secondary m (*)
  c158f36... Allow CFI_cdesc_t in argument lists with -fc-prototypes. (*)
  7f8bb64... OpenMP: Improve error message for invalid directive in "ass (*)
  c7dab40... d: Add testcase for fixed PR116373 (*)
  3c8df36... OpenMP: Update "declare target"/OpenMP context interaction (*)
  fdeceba... OpenMP: Shared metadirective/dynamic selector tests for C a (*)
  677e452... OpenMP: C++ support for metadirectives and dynamic selector (*)
  4e20914... OpenMP: Add C support for metadirectives and dynamic select (*)
  0696af7... rs6000: Fix ICE for invalid constants in built-in functions (*)
  1a2d63a... rs6000: Fix loop limit for built-in constant checking (*)
  3191d74... c++: Fix up reshape_* RAW_DATA_CST handling [PR118214] (*)
  03e0bf3... c++: Change c++2b and gnu++2b to c++23 and gnu++23 in C++ d (*)
  80b5230... middle-end: Add early break conditions to vect-switch-searc (*)
  3d678ad... Extend OpenACC 'serial' testing, compiler-side (*)
  97aae0f... [OpenACC/Fortran testsuite] Use relative line numbers for a (*)
  c5a8e22... Fortran: Create fresh ts.u.cl for result in gfc_get_symbol_ (*)
  462a7f4... libstdc++: Move std::basic_ostream to new internal header [ (*)
  301a961... libstdc++: Implement LWG 2937 for std::filesystem::equivale (*)
  408f5b8... libstdc++: Check feature test macro for associative contain (*)
  8682fcb... RISC-V: Update Xsfvqmacc and Xsfvfnrclip's testcases (*)
  030aaea... RISC-V: Update Xsfvfnrclip implementation. (*)
  b42eeef... forwprop: Ensure that shuffle masks are VECTOR_CSTs (*)
  57de373... forwprop: Eliminate redundant calls to to_constant() (*)
  ea1deef... tree-optimization/115494 - PRE PHI translation and ranges (*)
  7f5adfd... tree-ssa-propagate: Special case lhs of musttail calls in m (*)
  9c4397c... tailc: Virtually undo IPA-VRP return value optimization for (*)
  015ec11... docs: Fix up inline asm documentation (*)
  43f4d44... vec.h: Properly destruct elements in auto_vec auto storage  (*)
  3872daa... Fix typo to avoid ICE. (*)
  1b5d2cc... tree-optimization/115895 - overrun with masked loop (*)
  cf9de71... lm32: In va_arg, skip to stack args with too few remaining  (*)
  423e9a8... lm32: Compute pretend_size in setup_incoming_varargs even i (*)
  6e593fc... lm32: Skip last named param when computing save varargs reg (*)
  3184f6a... lm32: Args with arg.named false still get passed in regs (*)
  efd00e3... Fix an incorrect file header comment for the core2 scheduli (*)
  e683c6b... Fix setting of call graph node AutoFDO count (*)
  14f337e... Daily bump. (*)
  79d5504... libstdc++: Fix use of internal feature test macro in test (*)
  f079fee... libstdc++: Fix fancy pointer test for std::set (*)
  903ab91... match: Simplify `1 >> x` into `x == 0` [PR102705] (*)
  c340ff2... doc: cleanup trailing whitespace (*)
  d8e5244... doc: trivial grammar fix (*)
  6f85a97... libstdc++: Fix reversed args in unreachable assumption [PR1 (*)
  8923099... Fortran: reject NULL as source-expr in ALLOCATE with SOURCE (*)
  2619413... c++: Handle RAW_DATA_CST in unify [PR118390] (*)
  4ce502f... AArch64: Update neoverse512tvb tuning (*)
  2713f6b... AArch64: Add FULLY_PIPELINED_FMA to tune baseline (*)
  625ea3c... AArch64: Deprecate -mabi=ilp32 (*)
  01c37f9... bpf: set index entry for a VAR_DECL in CO-RE relocs (*)
  42786cc... bpf: calls do not promote attr access_index on lhs (*)
  d30def0... bpf: make sure CO-RE relocs are typed with struct BTF_KIND_ (*)
  8d9d583... c++: Implement mangling of RAW_DATA_CST [PR118278] (*)
  1bc474f... c++: handle decltype in n

[gcc(refs/users/aoliva/heads/testme)] [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

2025-01-17 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:7164ecf0de0abfa7b419317d55ab6bb94fa2

commit 7164ecf0de0abfa7b419317d55ab6bb94fa2
Author: Alexandre Oliva 
Date:   Fri Jan 17 16:47:25 2025 -0300

[ifcombine] out-of-bounds bitfield refs can trap [PR118514]

Diff:
---
 gcc/gimple-fold.cc|  2 ++
 gcc/testsuite/gcc.dg/field-merge-23.c | 19 +++
 gcc/tree-eh.cc| 28 +++-
 3 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 3c971a29ef04..5f1d69c19fe4 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -7834,6 +7834,8 @@ make_bit_field_load (location_t loc, tree inner, tree 
orig_inner, tree type,
   if (!point)
 return ref;
 
+  gcc_checking_assert (gimple_could_trap_p (point) == tree_could_trap_p (ref));
+
   /* If we're remaking the same load, reuse the SSA NAME it is already loaded
  into.  */
   if (gimple_assign_load_p (point)
diff --git a/gcc/testsuite/gcc.dg/field-merge-23.c 
b/gcc/testsuite/gcc.dg/field-merge-23.c
new file mode 100644
index ..d60f76206ebe
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/field-merge-23.c
@@ -0,0 +1,19 @@
+/* { dg-do run } */
+/* { dg-options "-O" } */
+
+/* PR tree-optimization/118514 */
+
+/* Check that we don't pull optimized references that could trap out of
+   loops.  */
+
+int a, c = 1;
+unsigned char b[1], d;
+int main() {
+  while (a || !c) {
+signed char e = b[10];
+d = e < 0 || b[10] > 1;
+if (d)
+  __builtin_abort ();
+  }
+  return 0;
+}
diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
index 1033b124e4df..57b14a606c12 100644
--- a/gcc/tree-eh.cc
+++ b/gcc/tree-eh.cc
@@ -2646,6 +2646,28 @@ range_in_array_bounds_p (tree ref)
   return true;
 }
 
+/* Return true iff EXPR, a BIT_FIELD_REF, accesses a bit range that is known to
+   be in bounds for the referred operand type.  */
+
+static bool
+bit_field_ref_in_bounds_p (tree expr)
+{
+  tree size_tree;
+  poly_uint64 size_max, min, wid, max;
+
+  size_tree = TYPE_SIZE (TREE_TYPE (TREE_OPERAND (expr, 0)));
+  if (!size_tree || !poly_int_tree_p (size_tree, &size_max)
+  || !poly_int_tree_p (TREE_OPERAND (expr, 2), &min)
+  || !poly_int_tree_p (TREE_OPERAND (expr, 1), &wid))
+return false;
+
+  max = min + wid;
+  if (known_lt (max, min) || maybe_le (size_max, max))
+return false;
+  
+  return true;
+}
+
 /* Return true if EXPR can trap, as in dereferencing an invalid pointer
location or floating point arithmetic.  C.f. the rtl version, may_trap_p.
This routine expects only GIMPLE lhs or rhs input.  */
@@ -2688,10 +2710,14 @@ tree_could_trap_p (tree expr)
  restart:
   switch (code)
 {
+case BIT_FIELD_REF:
+  if (!bit_field_ref_in_bounds_p (expr))
+   return true;
+  /* Fall through.  */
+
 case COMPONENT_REF:
 case REALPART_EXPR:
 case IMAGPART_EXPR:
-case BIT_FIELD_REF:
 case VIEW_CONVERT_EXPR:
 case WITH_SIZE_EXPR:
   expr = TREE_OPERAND (expr, 0);


[gcc r15-7009] libfortran: G formatting for UNSIGNED [PR118536]

2025-01-17 Thread Harald Anlauf via Gcc-cvs
https://gcc.gnu.org/g:ca2681d45a45077010bcc5a4547450044bdd6d78

commit r15-7009-gca2681d45a45077010bcc5a4547450044bdd6d78
Author: Harald Anlauf 
Date:   Fri Jan 17 21:20:31 2025 +0100

libfortran: G formatting for UNSIGNED [PR118536]

PR libfortran/118536

libgfortran/ChangeLog:

* io/transfer.c (formatted_transfer_scalar_write): Handle UNSIGNED
in G formatting.

gcc/testsuite/ChangeLog:

* gfortran.dg/unsigned_write_2.f90: New test.

Diff:
---
 gcc/testsuite/gfortran.dg/unsigned_write_2.f90 | 30 ++
 libgfortran/io/transfer.c  |  3 +++
 2 files changed, 33 insertions(+)

diff --git a/gcc/testsuite/gfortran.dg/unsigned_write_2.f90 
b/gcc/testsuite/gfortran.dg/unsigned_write_2.f90
new file mode 100644
index ..091e9b99f107
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/unsigned_write_2.f90
@@ -0,0 +1,30 @@
+! { dg-do  run }
+! This is a libgfortran (runtime library) test, need to run only once!
+!
+! { dg-additional-options "-funsigned" }
+!
+! PR libfortran/118536 - G formatting for UNSIGNED
+
+program print_unsigned_g_formatted
+  character(21) :: s1, s2
+  unsigned(1)  :: u1 = huge(0U_1)
+  unsigned(2)  :: u2 = huge(0U_2)
+  unsigned(4)  :: u4 = huge(0U_4)
+  unsigned(8)  :: u8 = huge(0U_8)
+
+  write(s1,'(i0)') u1
+  write(s2,'(g0)') u1
+  if (s1 /= s2) stop 1
+
+  write(s1,'(i0)') u2
+  write(s2,'(g0)') u2
+  if (s1 /= s2) stop 2
+
+  write(s1,'(i0)') u4
+  write(s2,'(g0)') u4
+  if (s1 /= s2) stop 3
+
+  write(s1,'(i0)') u8
+  write(s2,'(g0)') u8
+  if (s1 /= s2) stop 4
+end
diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c
index 0177e0520628..b3b72f39c5b1 100644
--- a/libgfortran/io/transfer.c
+++ b/libgfortran/io/transfer.c
@@ -2365,6 +2365,9 @@ formatted_transfer_scalar_write (st_parameter_dt *dtp, bt 
type, void *p, int kin
  case BT_INTEGER:
write_i (dtp, f, p, kind);
break;
+ case BT_UNSIGNED:
+   write_iu (dtp, f, p, kind);
+   break;
  case BT_LOGICAL:
write_l (dtp, f, p, kind);
break;


[gcc/aoliva/heads/testme] [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

2025-01-17 Thread Alexandre Oliva via Gcc-cvs
The branch 'aoliva/heads/testme' was updated to point to:

 a823af078547... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

It previously pointed to:

 01891eefc637... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]

Diff:

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

  01891ee... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]


Summary of changes (added commits):
---

  a823af0... [ifcombine] out-of-bounds bitfield refs can trap [PR118514]


[gcc r15-6991] c++: Friend classes don't shadow enclosing template class paramater [PR118255]

2025-01-17 Thread Simon Martin via Gcc-cvs
https://gcc.gnu.org/g:b5a069203fc074ab75d994c4a7e0f2db6a0a00fd

commit r15-6991-gb5a069203fc074ab75d994c4a7e0f2db6a0a00fd
Author: Simon Martin 
Date:   Sun Jan 5 10:36:47 2025 +0100

c++: Friend classes don't shadow enclosing template class paramater 
[PR118255]

We currently reject the following code

=== code here ===
template  struct S { friend class non_template; };
class non_template {};
S<0> s;
=== code here ===

While EDG agrees with the current behaviour, clang and MSVC don't (see
https://godbolt.org/z/69TGaabhd), and I believe that this code is valid,
since the friend clause does not actually declare a type, so it cannot
shadow anything. The fact that we didn't error out if the non_template
class was declared before S backs this up as well.

This patch fixes this by skipping the call to check_template_shadow for
hidden bindings.

PR c++/118255

gcc/cp/ChangeLog:

* name-lookup.cc (pushdecl): Don't call check_template_shadow
for hidden bindings.

gcc/testsuite/ChangeLog:

* g++.dg/lookup/pr99116-1.C: Adjust test expectation.
* g++.dg/template/friend84.C: New test.

Diff:
---
 gcc/cp/name-lookup.cc|  5 -
 gcc/testsuite/g++.dg/lookup/pr99116-1.C  |  2 +-
 gcc/testsuite/g++.dg/template/friend84.C | 26 ++
 3 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index 0e185d3ef426..d1abb205bc7f 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -4040,7 +4040,10 @@ pushdecl (tree decl, bool hiding)
   if (old && anticipated_builtin_p (old))
old = OVL_CHAIN (old);
 
-  check_template_shadow (decl);
+  if (hiding)
+   ; /* Hidden bindings don't shadow anything.  */
+  else
+   check_template_shadow (decl);
 
   if (DECL_DECLARES_FUNCTION_P (decl))
{
diff --git a/gcc/testsuite/g++.dg/lookup/pr99116-1.C 
b/gcc/testsuite/g++.dg/lookup/pr99116-1.C
index 01b483ea9153..efee3e4aca36 100644
--- a/gcc/testsuite/g++.dg/lookup/pr99116-1.C
+++ b/gcc/testsuite/g++.dg/lookup/pr99116-1.C
@@ -2,7 +2,7 @@
 
 template struct Z {
 
-  friend struct T; // { dg-error "shadows template parameter" }
+  friend struct T; // { dg-bogus "shadows template parameter" }
 };
 
 struct Y {
diff --git a/gcc/testsuite/g++.dg/template/friend84.C 
b/gcc/testsuite/g++.dg/template/friend84.C
new file mode 100644
index ..64ea41a552ba
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/friend84.C
@@ -0,0 +1,26 @@
+// PR c++/118255
+// { dg-do "compile" }
+
+// The PR's case, that used to error out.
+template 
+struct S {
+  friend class non_template; // { dg-bogus "shadows template parameter" }
+};
+
+class non_template {};
+S<0> s;
+
+// We already accepted cases where the friend is already declared.
+template 
+struct T {
+  friend class non_template;
+};
+T<0> t;
+
+// We should reject (re)declarations.
+template 
+struct U {
+  class non_template {};  // { dg-error "shadows template parameter" }
+  void non_template () {} // { dg-error "shadows template parameter" }
+};
+U<0> u;


[gcc r12-10908] middle-end/116891 - fix (negate (IFN_FNMS@3 @0 @1 @2)) -> (IFN_FMA @0 @1 @2)

2025-01-17 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:c0c5db68331ea8814db45ecd90ba842818e623fa

commit r12-10908-gc0c5db68331ea8814db45ecd90ba842818e623fa
Author: Richard Biener 
Date:   Mon Oct 14 08:11:22 2024 +0200

middle-end/116891 - fix (negate (IFN_FNMS@3 @0 @1 @2)) -> (IFN_FMA @0 @1 @2)

Transforming -fma (-a, b, -c) to fma (a, b, c) is only valid when
not rounding towards -inf or +inf as the sign of the multiplication
changes.

PR middle-end/116891
* match.pd ((negate (IFN_FNMS@3 @0 @1 @2)) -> (IFN_FMA @0 @1 @2)):
Only enable for !HONOR_SIGN_DEPENDENT_ROUNDING.

(cherry picked from commit c53bd48c6920bc1f4039b6682aafbf414a600e47)

Diff:
---
 gcc/match.pd | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 45ed34205106..d32338c27801 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -7083,7 +7083,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (IFN_FMA @0 @1 @2))
  (simplify
   (negate (IFN_FNMS@3 @0 @1 @2))
-  (if (single_use (@3))
+  (if (!HONOR_SIGN_DEPENDENT_ROUNDING (type) && single_use (@3))
(IFN_FMA @0 @1 @2
 
 /* CLZ simplifications.  */


[gcc r12-10909] match.pd: Further fma negation fixes [PR116891]

2025-01-17 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:3af4410b7aed19e4fdcfef1bc669d067e51342b3

commit r12-10909-g3af4410b7aed19e4fdcfef1bc669d067e51342b3
Author: Jakub Jelinek 
Date:   Tue Oct 15 19:38:46 2024 +0200

match.pd: Further fma negation fixes [PR116891]

On Mon, Oct 14, 2024 at 08:53:29AM +0200, Jakub Jelinek wrote:
> > PR middle-end/116891
> > * match.pd ((negate (IFN_FNMS@3 @0 @1 @2)) -> (IFN_FMA @0 @1 @2)):
> > Only enable for !HONOR_SIGN_DEPENDENT_ROUNDING.
>
> Guess it would be nice to have a testcase which FAILs without the patch 
and
> PASSes with it, but it can be added later.

I've added such a testcase now, and additionally found the fix only fixed
one of the 4 problematic similar cases.

Here is a patch which fixes the others too and adds the testcases.
fma-pr116891.c FAILed without your patch, FAILs with your patch too (but
only due to the bar/baz/qux checks) and PASSes with the patch.

2024-10-15  Jakub Jelinek  

PR middle-end/116891
* match.pd ((negate (fmas@3 @0 @1 @2)) -> (IFN_FNMS @0 @1 @2)):
Only enable for !HONOR_SIGN_DEPENDENT_ROUNDING.
((negate (IFN_FMS@3 @0 @1 @2)) -> (IFN_FNMA @0 @1 @2)): Likewise.
((negate (IFN_FNMA@3 @0 @1 @2)) -> (IFN_FMS @0 @1 @2)): Likewise.

* gcc.dg/pr116891.c: New test.
* gcc.target/i386/fma-pr116891.c: New test.

(cherry picked from commit 4366f0c7e296ea0d7279343c9b0a1d597588a1da)

Diff:
---
 gcc/match.pd |  6 ++--
 gcc/testsuite/gcc.dg/pr116891.c  | 47 
 gcc/testsuite/gcc.target/i386/fma-pr116891.c | 19 +++
 3 files changed, 69 insertions(+), 3 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index d32338c27801..06149a740868 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -7041,7 +7041,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(IFN_FNMS @0 @1 @2))
   (simplify
(negate (fmas@3 @0 @1 @2))
-   (if (single_use (@3))
+   (if (!HONOR_SIGN_DEPENDENT_ROUNDING (type) && single_use (@3))
 (IFN_FNMS @0 @1 @2
 
  (simplify
@@ -7055,7 +7055,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (IFN_FNMA @0 @1 @2))
  (simplify
   (negate (IFN_FMS@3 @0 @1 @2))
-   (if (single_use (@3))
+   (if (!HONOR_SIGN_DEPENDENT_ROUNDING (type) && single_use (@3))
 (IFN_FNMA @0 @1 @2)))
 
  (simplify
@@ -7069,7 +7069,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (IFN_FMS @0 @1 @2))
  (simplify
   (negate (IFN_FNMA@3 @0 @1 @2))
-  (if (single_use (@3))
+  (if (!HONOR_SIGN_DEPENDENT_ROUNDING (type) && single_use (@3))
(IFN_FMS @0 @1 @2)))
 
  (simplify
diff --git a/gcc/testsuite/gcc.dg/pr116891.c b/gcc/testsuite/gcc.dg/pr116891.c
new file mode 100644
index ..446e5ec5a4aa
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr116891.c
@@ -0,0 +1,47 @@
+/* PR middle-end/116891 */
+/* { dg-do run } */
+/* { dg-require-effective-target fenv } */
+/* { dg-require-effective-target hard_float } */
+/* { dg-require-effective-target c99_runtime } */
+/* { dg-options "-O2 -frounding-math" } */
+
+#include 
+
+__attribute__((noipa)) double
+foo (double x, double y, double z)
+{
+  return -__builtin_fma (-x, y, -z);
+}
+
+__attribute__((noipa)) double
+bar (double x, double y, double z)
+{
+  return -__builtin_fma (-x, y, z);
+}
+
+__attribute__((noipa)) double
+baz (double x, double y, double z)
+{
+  return -__builtin_fma (x, y, -z);
+}
+
+__attribute__((noipa)) double
+qux (double x, double y, double z)
+{
+  return -__builtin_fma (x, y, z);
+}
+
+int
+main ()
+{
+#if defined (FE_DOWNWARD) && __DBL_MANT_DIG__ == 53 && __DBL_MAX_EXP__ == 1024
+  fesetround (FE_DOWNWARD);
+  double a = foo (-0x1.p256, 0x1.p256, 0x1.p-256);
+  if (a != -__builtin_nextafter (0x1p256 * 0x1p256, 0.))
+__builtin_abort ();
+  if (a != bar (-0x1.p256, 0x1.p256, -0x1.p-256)
+  || a != baz (0x1.p256, 0x1.p256, 0x1.p-256)
+  || a != qux (0x1.p256, 0x1.p256, -0x1.p-256))
+__builtin_abort ();
+#endif
+}
diff --git a/gcc/testsuite/gcc.target/i386/fma-pr116891.c 
b/gcc/testsuite/gcc.target/i386/fma-pr116891.c
new file mode 100644
index ..34689f44c419
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/fma-pr116891.c
@@ -0,0 +1,19 @@
+/* PR middle-end/116891 */
+/* { dg-do run } */
+/* { dg-require-effective-target fenv } */
+/* { dg-require-effective-target hard_float } */
+/* { dg-require-effective-target c99_runtime } */
+/* { dg-require-effective-target fma } */
+/* { dg-options "-O2 -mfma -frounding-math" } */
+
+#include 
+#include "fma-check.h"
+
+#define main() do_main ()
+#include "../../gcc.dg/pr116891.c"
+
+static void
+fma_test (void)
+{
+  do_main ();
+}


[gcc r12-10911] tree-optimization/117254 - ICE with access diangostics

2025-01-17 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:2b12998ff9370f4a0aa8c0562f933c2e7efdb41d

commit r12-10911-g2b12998ff9370f4a0aa8c0562f933c2e7efdb41d
Author: Richard Biener 
Date:   Tue Oct 22 11:46:47 2024 +0200

tree-optimization/117254 - ICE with access diangostics

The diagnostics code fails to handle non-constant domain max.

PR tree-optimization/117254
* gimple-ssa-warn-access.cc (maybe_warn_nonstring_arg):
Check the array domain max is constant before using it.

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

(cherry picked from commit d464a52d0678dfea523a60efe8b792ba1b8d40db)

Diff:
---
 gcc/gimple-ssa-warn-access.cc   |  3 ++-
 gcc/testsuite/gcc.dg/pr117254.c | 10 ++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc
index e70a6f1fb877..8e12e49816f9 100644
--- a/gcc/gimple-ssa-warn-access.cc
+++ b/gcc/gimple-ssa-warn-access.cc
@@ -604,7 +604,8 @@ maybe_warn_nonstring_arg (tree fndecl, GimpleOrTree exp)
{
  if (tree arrbnd = TYPE_DOMAIN (type))
{
- if ((arrbnd = TYPE_MAX_VALUE (arrbnd)))
+ if ((arrbnd = TYPE_MAX_VALUE (arrbnd))
+ && TREE_CODE (arrbnd) == INTEGER_CST)
{
  asize = wi::to_offset (arrbnd) + 1;
  known_size = true;
diff --git a/gcc/testsuite/gcc.dg/pr117254.c b/gcc/testsuite/gcc.dg/pr117254.c
new file mode 100644
index ..c7a510677f13
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr117254.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+int g;
+void e(int s) {
+  struct {
+__attribute__((nonstring)) char bn[g];
+  } f;
+  __builtin_strncpy (f.bn, f.bn, s);
+}


[gcc r12-10910] tree-optimization/117104 - add missed guards to max(a, b) != a simplification

2025-01-17 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:72d7bdbdd9fe1e575b7ad6da0fd7587627912ddb

commit r12-10910-g72d7bdbdd9fe1e575b7ad6da0fd7587627912ddb
Author: Richard Biener 
Date:   Sat Oct 12 14:51:37 2024 +0200

tree-optimization/117104 - add missed guards to max(a,b) != a simplification

For vector types we have to make sure the comparison result is a vector
type and the resulting compare operation is supported.  As the resulting
compare is never an equality compare I didn't bother to check for the
cbranch case.

PR tree-optimization/117104
* match.pd ((cmp:c (minmax:c @0 @1) @0) -> (out @0 @1)): Properly
guard the vector case.

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

(cherry picked from commit f54d42e7e7a558b273d87f95b3e5b1938f5a)

Diff:
---
 gcc/match.pd|  6 +-
 gcc/testsuite/gcc.dg/pr117104.c | 12 
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 06149a740868..9b7c9f3f0d59 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3255,7 +3255,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  out(le  gt  ge  lt )
  (simplify
   (cmp:c (minmax:c @0 @1) @0)
-  (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0)))
+  (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
+   && (!VECTOR_TYPE_P (TREE_TYPE (@0))
+  || (VECTOR_TYPE_P (type)
+  && (!expand_vec_cmp_expr_p (TREE_TYPE (@0), type, cmp)
+  || expand_vec_cmp_expr_p (TREE_TYPE (@0), type, out)
(out @0 @1
 /* MIN (X, 5) == 0 -> X == 0
MIN (X, 5) == 7 -> false  */
diff --git a/gcc/testsuite/gcc.dg/pr117104.c b/gcc/testsuite/gcc.dg/pr117104.c
new file mode 100644
index ..9aa5734f7927
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr117104.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-vect-cost-model" } */
+/* { dg-additional-options "-mavx" { target { x86_64-*-* i?86-*-* } } } */
+
+void g();
+void f(long *a)
+{
+  long b0 = a[0] > 0 ? a[0] : 0;
+  long b1 = a[1] > 0 ? a[1] : 0;
+  if ((b0|b1) == 0)
+g();
+}


[gcc r12-10913] tree-optimization/117417 - ICE with complex load optimization

2025-01-17 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:a5d05111bde1e07824fd85d3a97785022ae30b8a

commit r12-10913-ga5d05111bde1e07824fd85d3a97785022ae30b8a
Author: Richard Biener 
Date:   Tue Nov 12 11:15:15 2024 +0100

tree-optimization/117417 - ICE with complex load optimization

When we decompose a complex load only used as real and imaginary
parts we fail to honor IL constraints which are that a BIT_FIELD_REF
of register type should be outermost in a ref.  The following
simply avoids the transform when the complex load has such a
BIT_FIELD_REF.

PR tree-optimization/117417
* tree-ssa-forwprop.cc (pass_forwprop::execute): Avoid
decomposing BIT_FIELD_REF complex load.

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

(cherry picked from commit d976daa931642d940b7b27032ca6139210c07eed)

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr117417.c | 16 
 gcc/tree-ssa-forwprop.cc|  6 +++---
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr117417.c 
b/gcc/testsuite/gcc.dg/torture/pr117417.c
new file mode 100644
index ..2c80dd5d77cd
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr117417.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+
+typedef __attribute__((__vector_size__ (8))) double V;
+int bar (int a, V *p)
+{
+  V v;
+  v = *p;
+  a += *(_Complex short *) &v;
+  return a;
+}
+V x;
+int
+foo ()
+{
+  return bar (0, &x);
+}
diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index 062f5667f14a..1b36ffb0bbe7 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -3542,9 +3542,9 @@ pass_forwprop::execute (function *fun)
  else if (TREE_CODE (TREE_TYPE (lhs)) == COMPLEX_TYPE
   && gimple_assign_load_p (stmt)
   && !gimple_has_volatile_ops (stmt)
-  && (TREE_CODE (gimple_assign_rhs1 (stmt))
-  != TARGET_MEM_REF)
-  && !stmt_can_throw_internal (cfun, stmt))
+  && TREE_CODE (rhs) != TARGET_MEM_REF
+  && TREE_CODE (rhs) != BIT_FIELD_REF
+  && !stmt_can_throw_internal (fun, stmt))
{
  /* Rewrite loads used only in real/imagpart extractions to
 component-wise loads.  */


[gcc r15-6994] testsuite/117958 - ifcombine differences on aarch64 vs rest

2025-01-17 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:3347ac3cbc7704c7f1d69b6875b65129c6d7dae5

commit r15-6994-g3347ac3cbc7704c7f1d69b6875b65129c6d7dae5
Author: Richard Biener 
Date:   Fri Jan 17 13:18:11 2025 +0100

testsuite/117958 - ifcombine differences on aarch64 vs rest

ifcombine depends on BRANCH_COST and the testcase relies on ifcombine
to fully optimize the function.  But the important parts are optimized
everywhere, so the following delectively XFAILs the less important part.

PR testsuite/117958
* g++.dg/tree-ssa/pr117123.C: XFAIL parts on aarch64-*-*.

Diff:
---
 gcc/testsuite/g++.dg/tree-ssa/pr117123.C | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr117123.C 
b/gcc/testsuite/g++.dg/tree-ssa/pr117123.C
index 2aa2810de952..29b69dfa432c 100644
--- a/gcc/testsuite/g++.dg/tree-ssa/pr117123.C
+++ b/gcc/testsuite/g++.dg/tree-ssa/pr117123.C
@@ -49,4 +49,6 @@ int patatino(int a) {
 }
 
 // { dg-final { scan-tree-dump-not "dont_be_here" "optimized" } }
-// { dg-final { scan-tree-dump-times "if " 3 "optimized" } }
+// Depending on LOGICAL_OP_NON_SHORT_CIRCUIT (or BRANCH_COST) this might
+// or might not be optimized fully
+// { dg-final { scan-tree-dump-times "if " 3 "optimized" { xfail { aarch64-*-* 
} } } }


[gcc r15-6995] c++: Allow pragmas in NSDMIs [PR118147]

2025-01-17 Thread Nathaniel Shead via Gcc-cvs
https://gcc.gnu.org/g:f3ccc57e5f044031a1b07e79330de9220e93afe7

commit r15-6995-gf3ccc57e5f044031a1b07e79330de9220e93afe7
Author: Nathaniel Shead 
Date:   Fri Dec 20 22:09:39 2024 +1100

c++: Allow pragmas in NSDMIs [PR118147]

This patch removes the (unnecessary) CPP_PRAGMA_EOL case from
cp_parser_cache_defarg, which currently has the result that any pragmas
in the NSDMI cause an error.

PR c++/118147

gcc/cp/ChangeLog:

* parser.cc (cp_parser_cache_defarg): Don't error when
CPP_PRAGMA_EOL.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/nsdmi-defer7.C: New test.

Signed-off-by: Nathaniel Shead 

Diff:
---
 gcc/cp/parser.cc  |  1 -
 gcc/testsuite/g++.dg/cpp0x/nsdmi-defer7.C | 13 +
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index c030a18689e0..ff58a8ec98e4 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -36264,7 +36264,6 @@ cp_parser_cache_defarg (cp_parser *parser, bool nsdmi)
 
  /* If we run out of tokens, issue an error message.  */
case CPP_EOF:
-   case CPP_PRAGMA_EOL:
  error_at (token->location, "file ends in default argument");
  return error_mark_node;
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer7.C 
b/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer7.C
new file mode 100644
index ..3bef636ccbd2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer7.C
@@ -0,0 +1,13 @@
+// PR c++/118147
+// { dg-do compile { target c++11 } }
+
+struct F {
+  int i = []{
+#pragma message "test"  // { dg-message "test" }
+return 1;
+  }();
+};
+
+struct G {
+  int i =
+#pragma GCC diagnostic push  // { dg-error "file ends in default 
argument|expected" }


[gcc r14-11221] c++: Allow pragmas in NSDMIs [PR118147]

2025-01-17 Thread Nathaniel Shead via Gcc-cvs
https://gcc.gnu.org/g:f400d065a2ecda19b46fc0f7ec0a1fe6d7dd597e

commit r14-11221-gf400d065a2ecda19b46fc0f7ec0a1fe6d7dd597e
Author: Nathaniel Shead 
Date:   Fri Dec 20 22:09:39 2024 +1100

c++: Allow pragmas in NSDMIs [PR118147]

This patch removes the (unnecessary) CPP_PRAGMA_EOL case from
cp_parser_cache_defarg, which currently has the result that any pragmas
in the NSDMI cause an error.

PR c++/118147

gcc/cp/ChangeLog:

* parser.cc (cp_parser_cache_defarg): Don't error when
CPP_PRAGMA_EOL.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/nsdmi-defer7.C: New test.

Signed-off-by: Nathaniel Shead 
(cherry picked from commit f3ccc57e5f044031a1b07e79330de9220e93afe7)

Diff:
---
 gcc/cp/parser.cc  |  1 -
 gcc/testsuite/g++.dg/cpp0x/nsdmi-defer7.C | 13 +
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 725b5ef4ad66..5bfbdf85f152 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -35674,7 +35674,6 @@ cp_parser_cache_defarg (cp_parser *parser, bool nsdmi)
 
  /* If we run out of tokens, issue an error message.  */
case CPP_EOF:
-   case CPP_PRAGMA_EOL:
  error_at (token->location, "file ends in default argument");
  return error_mark_node;
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer7.C 
b/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer7.C
new file mode 100644
index ..3bef636ccbd2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer7.C
@@ -0,0 +1,13 @@
+// PR c++/118147
+// { dg-do compile { target c++11 } }
+
+struct F {
+  int i = []{
+#pragma message "test"  // { dg-message "test" }
+return 1;
+  }();
+};
+
+struct G {
+  int i =
+#pragma GCC diagnostic push  // { dg-error "file ends in default 
argument|expected" }


[gcc r15-6996] OpenMP/C++: Fix declare_variant's 'adjust_args' if there is a 'this' pointer [PR118321]

2025-01-17 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:5e91be6f8ce978e1d30c8a958072545002168ed1

commit r15-6996-g5e91be6f8ce978e1d30c8a958072545002168ed1
Author: Tobias Burnus 
Date:   Fri Jan 17 14:25:18 2025 +0100

OpenMP/C++: Fix declare_variant's 'adjust_args' if there is a 'this' 
pointer [PR118321]

The adjust_args clause is internally store as the i-th argument to the 
function,
which fails if hidden arguments come before. This commit handles the C++ 
'this'
pointer by shifting the internal arg index by one.

PR fortran/118321

gcc/cp/ChangeLog:

* decl.cc (omp_declare_variant_finalize_one): Shift adjust_args 
index
by one for non-static class function's 'this' pointer.

gcc/testsuite/ChangeLog:

* g++.dg/gomp/adjust-args-4.C: New test.

Diff:
---
 gcc/cp/decl.cc| 19 --
 gcc/testsuite/g++.dg/gomp/adjust-args-4.C | 60 +++
 2 files changed, 76 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index ef887915ff1d..af1b89fb8c9b 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -8629,9 +8629,22 @@ omp_declare_variant_finalize_one (tree decl, tree attr)
  // Prepend adjust_args list to variant attributes
  tree adjust_args_list = TREE_CHAIN (TREE_CHAIN (chain));
  if (adjust_args_list != NULL_TREE)
-   DECL_ATTRIBUTES (variant) = tree_cons (
- get_identifier ("omp declare variant variant args"),
- TREE_VALUE (adjust_args_list), DECL_ATTRIBUTES (variant));
+   {
+ if (DECL_NONSTATIC_MEMBER_P (variant)
+ && TREE_VALUE (adjust_args_list))
+   {
+ /* Shift arg position for the added 'this' pointer.  */
+ /* Handle need_device_ptr  */
+ for (tree t = TREE_PURPOSE (TREE_VALUE (adjust_args_list));
+  t; t = TREE_CHAIN (t))
+   TREE_VALUE (t)
+ = build_int_cst (TREE_TYPE (t),
+  tree_to_uhwi (TREE_VALUE (t)) + 1);
+   }
+ DECL_ATTRIBUTES (variant) = tree_cons (
+   get_identifier ("omp declare variant variant args"),
+   TREE_VALUE (adjust_args_list), DECL_ATTRIBUTES (variant));
+   }
}
 }
   else if (!processing_template_decl)
diff --git a/gcc/testsuite/g++.dg/gomp/adjust-args-4.C 
b/gcc/testsuite/g++.dg/gomp/adjust-args-4.C
new file mode 100644
index ..83100457e3e8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/gomp/adjust-args-4.C
@@ -0,0 +1,60 @@
+/* { dg-additional-options "-fdump-tree-gimple" }  */
+
+/* PR fortran/118321.  */
+
+/* Check that adjust_args applies to the right argument,
+   if C++ inserts a 'this' pointer.  */
+
+struct t1 {
+  void f1(int *x, int *y, int *z);
+  #pragma omp declare variant(f1) match(construct={dispatch}) \
+  adjust_args(need_device_ptr : y)
+  void g1(int *x, int *y, int *z);
+};
+
+struct t2 {
+  void f2(int *x, int *y, int *z);
+  #pragma omp declare variant(f2) match(construct={dispatch}) \
+  adjust_args(need_device_ptr : x, y, z)
+  void g2(int *x, int *y, int *z);
+};
+
+struct t3 {
+  void f3(int *x, int *y, int *z);
+  #pragma omp declare variant(f3) match(construct={dispatch}) \
+  adjust_args(nothing : x, y, z)
+  void g3(int *x, int *y, int *z);
+};
+
+
+void test(int *a1, int *b1, int *c1,
+  int *a2, int *b2, int *c2,
+  int *a3, int *b3, int *c3)
+{
+  struct t1 s1;
+  struct t2 s2;
+  struct t3 s3;
+
+  #pragma omp dispatch
+   s1.g1 (a1, b1, c1);
+  #pragma omp dispatch
+   s2.g2 (a2, b2, c2);
+  #pragma omp dispatch
+   s3.g3 (a3, b3, c3);
+}
+
+
+/* { dg-final { scan-tree-dump-times "D\.\[0-9\]+ = 
__builtin_omp_get_default_device \\(\\);" 2 "gimple" } }  */
+
+/* { dg-final { scan-tree-dump-times "__builtin_omp_get_mapped_ptr" 4 "gimple" 
} }  */
+
+/* { dg-final { scan-tree-dump "D\.\[0-9\]+ = __builtin_omp_get_mapped_ptr 
\\(b1, D\.\[0-9\]+\\);" "gimple" } }  */
+/* { dg-final { scan-tree-dump "t1::f1 \\(&s1, a1, D\.\[0-9\]+, c1\\);" 
"gimple" } }  */
+
+
+/* { dg-final { scan-tree-dump "D\.\[0-9\]+ = __builtin_omp_get_mapped_ptr 
\\(c2, D\.\[0-9\]+\\);" "gimple" } }  */
+/* { dg-final { scan-tree-dump "D\.\[0-9\]+ = __builtin_omp_get_mapped_ptr 
\\(b2, D\.\[0-9\]+\\);" "gimple" } }  */
+/* { dg-final { scan-tree-dump "D\.\[0-9\]+ = __builtin_omp_get_mapped_ptr 
\\(a2, D\.\[0-9\]+\\);" "gimple" } }  */
+/* { dg-final { scan-tree-dump "t2::f2 \\(&s2, D\.\[0-9\]+, D\.\[0-9\]+, 
D\.\[0-9\]+\\);" "gimple" } }  */
+
+/* { dg-final { scan-tree-dump "t3::f3 \\(&s3, a3, b3, c3\\);" "gimple" } }  */


[gcc r12-10914] c++: Allow pragmas in NSDMIs [PR118147]

2025-01-17 Thread Nathaniel Shead via Gcc-cvs
https://gcc.gnu.org/g:9d2f4c8b0f849839ff1b9b7d5f9e734271c03634

commit r12-10914-g9d2f4c8b0f849839ff1b9b7d5f9e734271c03634
Author: Nathaniel Shead 
Date:   Fri Dec 20 22:09:39 2024 +1100

c++: Allow pragmas in NSDMIs [PR118147]

This patch removes the (unnecessary) CPP_PRAGMA_EOL case from
cp_parser_cache_defarg, which currently has the result that any pragmas
in the NSDMI cause an error.

PR c++/118147

gcc/cp/ChangeLog:

* parser.cc (cp_parser_cache_defarg): Don't error when
CPP_PRAGMA_EOL.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/nsdmi-defer7.C: New test.

Signed-off-by: Nathaniel Shead 
(cherry picked from commit f3ccc57e5f044031a1b07e79330de9220e93afe7)

Diff:
---
 gcc/cp/parser.cc  |  1 -
 gcc/testsuite/g++.dg/cpp0x/nsdmi-defer7.C | 13 +
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 9c1bd32cff1c..64cefb6b4e40 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -34110,7 +34110,6 @@ cp_parser_cache_defarg (cp_parser *parser, bool nsdmi)
 
  /* If we run out of tokens, issue an error message.  */
case CPP_EOF:
-   case CPP_PRAGMA_EOL:
  error_at (token->location, "file ends in default argument");
  return error_mark_node;
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer7.C 
b/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer7.C
new file mode 100644
index ..3bef636ccbd2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer7.C
@@ -0,0 +1,13 @@
+// PR c++/118147
+// { dg-do compile { target c++11 } }
+
+struct F {
+  int i = []{
+#pragma message "test"  // { dg-message "test" }
+return 1;
+  }();
+};
+
+struct G {
+  int i =
+#pragma GCC diagnostic push  // { dg-error "file ends in default 
argument|expected" }


[gcc r13-9330] c++: Allow pragmas in NSDMIs [PR118147]

2025-01-17 Thread Nathaniel Shead via Gcc-cvs
https://gcc.gnu.org/g:9f29e23fc2c34a776620f43d95982f0df6e93bf0

commit r13-9330-g9f29e23fc2c34a776620f43d95982f0df6e93bf0
Author: Nathaniel Shead 
Date:   Fri Dec 20 22:09:39 2024 +1100

c++: Allow pragmas in NSDMIs [PR118147]

This patch removes the (unnecessary) CPP_PRAGMA_EOL case from
cp_parser_cache_defarg, which currently has the result that any pragmas
in the NSDMI cause an error.

PR c++/118147

gcc/cp/ChangeLog:

* parser.cc (cp_parser_cache_defarg): Don't error when
CPP_PRAGMA_EOL.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/nsdmi-defer7.C: New test.

Signed-off-by: Nathaniel Shead 
(cherry picked from commit f3ccc57e5f044031a1b07e79330de9220e93afe7)

Diff:
---
 gcc/cp/parser.cc  |  1 -
 gcc/testsuite/g++.dg/cpp0x/nsdmi-defer7.C | 13 +
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index d25ceff9ec38..fe4a63ea9e4c 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -34949,7 +34949,6 @@ cp_parser_cache_defarg (cp_parser *parser, bool nsdmi)
 
  /* If we run out of tokens, issue an error message.  */
case CPP_EOF:
-   case CPP_PRAGMA_EOL:
  error_at (token->location, "file ends in default argument");
  return error_mark_node;
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer7.C 
b/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer7.C
new file mode 100644
index ..3bef636ccbd2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer7.C
@@ -0,0 +1,13 @@
+// PR c++/118147
+// { dg-do compile { target c++11 } }
+
+struct F {
+  int i = []{
+#pragma message "test"  // { dg-message "test" }
+return 1;
+  }();
+};
+
+struct G {
+  int i =
+#pragma GCC diagnostic push  // { dg-error "file ends in default 
argument|expected" }


[gcc r15-6997] c++/modules: Propagate FNDECL_USED_AUTO when propagating deduced return types [PR118049]

2025-01-17 Thread Nathaniel Shead via Gcc-cvs
https://gcc.gnu.org/g:f054c36c4fcb693e04411dc691ef4172479143d6

commit r15-6997-gf054c36c4fcb693e04411dc691ef4172479143d6
Author: Nathaniel Shead 
Date:   Fri Jan 17 21:29:08 2025 +1100

c++/modules: Propagate FNDECL_USED_AUTO when propagating deduced return 
types [PR118049]

In the linked testcase, we're erroring because the declared return types
of the functions do not appear to match.  This is because when merging
the deduced return types for 'foo' in 'auto-5_b.C', we overwrote the
return type for the declaration with the deduced return type from
'auto-5_a.C' but neglected to track that we were originally declared
with 'auto'.

As a drive-by improvement to QOI, also add checks for if the deduced
return types do not match; this is currently useful because we do not
check the equivalence of the bodies of functions yet.

PR c++/118049

gcc/cp/ChangeLog:

* module.cc (trees_in::is_matching_decl): Propagate
FNDECL_USED_AUTO as well.

gcc/testsuite/ChangeLog:

* g++.dg/modules/auto-5_a.C: New test.
* g++.dg/modules/auto-5_b.C: New test.
* g++.dg/modules/auto-5_c.C: New test.
* g++.dg/modules/auto-6_a.H: New test.
* g++.dg/modules/auto-6_b.C: New test.

Signed-off-by: Nathaniel Shead 

Diff:
---
 gcc/cp/module.cc|  5 +
 gcc/testsuite/g++.dg/modules/auto-5_a.C | 10 ++
 gcc/testsuite/g++.dg/modules/auto-5_b.C | 14 ++
 gcc/testsuite/g++.dg/modules/auto-5_c.C |  4 
 gcc/testsuite/g++.dg/modules/auto-6_a.H |  5 +
 gcc/testsuite/g++.dg/modules/auto-6_b.C |  6 ++
 6 files changed, 44 insertions(+)

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 61116fe76693..6fe64bb538c2 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -11902,8 +11902,13 @@ trees_in::is_matching_decl (tree existing, tree decl, 
bool is_typedef)
{
  dump (dumper::MERGE)
&& dump ("Propagating deduced return type to %N", existing);
+ FNDECL_USED_AUTO (e_inner) = true;
+ DECL_SAVED_AUTO_RETURN_TYPE (existing) = TREE_TYPE (e_type);
  TREE_TYPE (existing) = change_return_type (TREE_TYPE (d_type), 
e_type);
}
+  else if (type_uses_auto (d_ret)
+  && !same_type_p (TREE_TYPE (d_type), TREE_TYPE (e_type)))
+   goto mismatch;
 }
   else if (is_typedef)
 {
diff --git a/gcc/testsuite/g++.dg/modules/auto-5_a.C 
b/gcc/testsuite/g++.dg/modules/auto-5_a.C
new file mode 100644
index ..fcab6f301e1c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/auto-5_a.C
@@ -0,0 +1,10 @@
+// PR c++/118049
+// { dg-additional-options "-fmodules -Wno-global-module" }
+// { dg-module-cmi A }
+
+module;
+template  struct S {
+  auto foo() {}
+};
+export module A;
+template struct S;
diff --git a/gcc/testsuite/g++.dg/modules/auto-5_b.C 
b/gcc/testsuite/g++.dg/modules/auto-5_b.C
new file mode 100644
index ..f75ed2d0f0cb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/auto-5_b.C
@@ -0,0 +1,14 @@
+// PR c++/118049
+// { dg-additional-options "-fmodules -Wno-global-module" }
+// { dg-module-cmi B }
+
+module;
+template  struct S {
+  auto foo() {}
+};
+template struct S;
+export module B;
+import A;
+template  void x() {
+  S{}.foo();
+}
diff --git a/gcc/testsuite/g++.dg/modules/auto-5_c.C 
b/gcc/testsuite/g++.dg/modules/auto-5_c.C
new file mode 100644
index ..f351c2b1ae45
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/auto-5_c.C
@@ -0,0 +1,4 @@
+// PR c++/118049
+// { dg-additional-options "-fmodules -fno-module-lazy 
-fdump-lang-module-alias" }
+
+import B;
diff --git a/gcc/testsuite/g++.dg/modules/auto-6_a.H 
b/gcc/testsuite/g++.dg/modules/auto-6_a.H
new file mode 100644
index ..3ad08ab81ce4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/auto-6_a.H
@@ -0,0 +1,5 @@
+// { dg-additional-options "-fmodule-header" }
+
+inline auto foo() {
+  return 1;
+}
diff --git a/gcc/testsuite/g++.dg/modules/auto-6_b.C 
b/gcc/testsuite/g++.dg/modules/auto-6_b.C
new file mode 100644
index ..aab7be4e5301
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/auto-6_b.C
@@ -0,0 +1,6 @@
+// { dg-additional-options "-fmodules-ts -fno-module-lazy" }
+
+inline auto foo() {  // { dg-error "conflicting" }
+  return 1.0;
+}
+import "auto-6_a.H";


[gcc r15-6998] AVR: Add "const" attribute to avr built-in functions if possible.

2025-01-17 Thread Georg-Johann Lay via Gcc-cvs
https://gcc.gnu.org/g:6a9086b6f4d58065e717e7cfabe156419cd8cb99

commit r15-6998-g6a9086b6f4d58065e717e7cfabe156419cd8cb99
Author: Georg-Johann Lay 
Date:   Fri Jan 17 13:14:51 2025 +0100

AVR: Add "const" attribute to avr built-in functions if possible.

gcc/
* config/avr/avr-c.cc (DEF_BUILTIN): Add ATTRS argument to macro
definition.
* config/avr/avr.cc: Same.
(avr_init_builtins) : New variable that can be used
as ATTRS argument in DEF_BUILTIN.
* config/avr/builtins.def (DEF_BUILTIN): Add ATTRS parameter
to all definitions.

Diff:
---
 gcc/config/avr/avr-c.cc |   4 +-
 gcc/config/avr/avr.cc   |  27 +++
 gcc/config/avr/builtins.def | 184 ++--
 3 files changed, 109 insertions(+), 106 deletions(-)

diff --git a/gcc/config/avr/avr-c.cc b/gcc/config/avr/avr-c.cc
index 67a97fa445c0..53f15f2be7b3 100644
--- a/gcc/config/avr/avr-c.cc
+++ b/gcc/config/avr/avr-c.cc
@@ -36,7 +36,7 @@
 
 enum avr_builtin_id
   {
-#define DEF_BUILTIN(NAME, N_ARGS, TYPE, CODE, LIBNAME)  \
+#define DEF_BUILTIN(NAME, N_ARGS, TYPE, CODE, LIBNAME, ATTRS) \
 AVR_BUILTIN_ ## NAME,
 #include "builtins.def"
 #undef DEF_BUILTIN
@@ -499,7 +499,7 @@ avr_cpu_cpp_builtins (cpp_reader *pfile)
   /* Define builtin macros so that the user can easily query whether or
  not a specific builtin is available. */
 
-#define DEF_BUILTIN(NAME, N_ARGS, TYPE, CODE, LIBNAME)  \
+#define DEF_BUILTIN(NAME, N_ARGS, TYPE, CODE, LIBNAME, ATTRS) \
   cpp_define (pfile, "__BUILTIN_AVR_" #NAME);
 #include "builtins.def"
 #undef DEF_BUILTIN
diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc
index c44ed7424538..ce1a375ce92c 100644
--- a/gcc/config/avr/avr.cc
+++ b/gcc/config/avr/avr.cc
@@ -15291,7 +15291,7 @@ avr_out_insert_bits (rtx *op, int *plen)
 
 enum avr_builtin_id
   {
-#define DEF_BUILTIN(NAME, N_ARGS, TYPE, CODE, LIBNAME)  \
+#define DEF_BUILTIN(NAME, N_ARGS, TYPE, CODE, LIBNAME, ATTRS) \
 AVR_BUILTIN_ ## NAME,
 #include "builtins.def"
 #undef DEF_BUILTIN
@@ -15314,7 +15314,7 @@ struct GTY(()) avr_builtin_description
 static GTY(()) avr_builtin_description
 avr_bdesc[AVR_BUILTIN_COUNT] =
   {
-#define DEF_BUILTIN(NAME, N_ARGS, TYPE, ICODE, LIBNAME) \
+#define DEF_BUILTIN(NAME, N_ARGS, TYPE, ICODE, LIBNAME, ATTRS) \
 { (enum insn_code) CODE_FOR_ ## ICODE, N_ARGS, NULL_TREE },
 #include "builtins.def"
 #undef DEF_BUILTIN
@@ -15514,17 +15514,18 @@ avr_init_builtins (void)
   FX_FTYPE_INTX (ul);
   FX_FTYPE_INTX (ull);
 
-
-#define DEF_BUILTIN(NAME, N_ARGS, TYPE, CODE, LIBNAME)  \
-  { \
-int id = AVR_BUILTIN_ ## NAME;  \
-const char *Name = "__builtin_avr_" #NAME;  \
-char *name = (char *) alloca (1 + strlen (Name));   \
-\
-gcc_assert (id < AVR_BUILTIN_COUNT);\
-avr_bdesc[id].fndecl\
-  = add_builtin_function (avr_tolower (name, Name), TYPE, id,   \
- BUILT_IN_MD, LIBNAME, NULL_TREE); \
+  tree attr_const = tree_cons (get_identifier ("const"), NULL, NULL);
+
+#define DEF_BUILTIN(NAME, N_ARGS, TYPE, CODE, LIBNAME, ATTRS)  \
+  {\
+int id = AVR_BUILTIN_ ## NAME; \
+const char *Name = "__builtin_avr_" #NAME; \
+char *name = (char *) alloca (1 + strlen (Name));  \
+   \
+gcc_assert (id < AVR_BUILTIN_COUNT);   \
+avr_bdesc[id].fndecl   \
+  = add_builtin_function (avr_tolower (name, Name), TYPE, id,  \
+ BUILT_IN_MD, LIBNAME, ATTRS); \
   }
 #include "builtins.def"
 #undef DEF_BUILTIN
diff --git a/gcc/config/avr/builtins.def b/gcc/config/avr/builtins.def
index eeffb6866319..61dbc3a6c1be 100644
--- a/gcc/config/avr/builtins.def
+++ b/gcc/config/avr/builtins.def
@@ -20,7 +20,7 @@
builtins defined in the AVR part of the GNU compiler.
Befor including this file, define a macro
 
-   DEF_BUILTIN(NAME, N_ARGS, TYPE, ICODE, LIBNAME)
+   DEF_BUILTIN(NAME, N_ARGS, TYPE, ICODE, LIBNAME, ATTRS)
 
NAME:`__builtin_avr_name' will be the user-level name of the builtin.
 `AVR_BUILTIN_NAME' will be the internal builtin's id.
@@ -30,31 +30,33 @@
ICODE:   Name of attached insn or expander.  If special treatment in avr.cc
 is needed to expand the built-in, use `nothing'.
LIBNAME: Name of the attached implementation in libgcc which is used if
- 

[gcc r14-11222] AVR: Use INT_N to built-in define __int24.

2025-01-17 Thread Georg-Johann Lay via Gcc-cvs
https://gcc.gnu.org/g:1ba0d18323f4ddacc3dfd218287b7904f80034fe

commit r14-11222-g1ba0d18323f4ddacc3dfd218287b7904f80034fe
Author: Georg-Johann Lay 
Date:   Thu Jan 16 19:43:27 2025 +0100

AVR: Use INT_N to built-in define __int24.

This patch uses the INT_N interface to define __int24 in avr-modes.def.

Since the testsuite uses -Wpedantic and __int24 is a C/C++ extension,
uses of __int24 and __uint24 is now marked as __extension__.

PR target/118329
gcc/
* config/avr/avr-modes.def: Add INT_N (PSI, 24).
* config/avr/avr.cc (avr_init_builtin_int24)
<__int24>: Remove definition.
<__uint24>: Adjust definition to INT_N interface.
gcc/testsuite/
* gcc.target/avr/torture/get-mem.c: (__int24, __uint24):
Add __extension__ to respective typedefs.
* gcc.target/avr/torture/set-mem.c: Same.
* gcc.target/avr/torture/int24-mul.c: Same.
* gcc.target/avr/torture/pr109907-2.c: Same.
* gcc.target/avr/torture/pr61443.c: Same.
* gcc.target/avr/torture/pr63633-ice-mult.c: Same.

(cherry picked from commit 6580b89957ccabbb5aaf43736b36b9bd399fbc13)

Diff:
---
 gcc/config/avr/avr-modes.def|  1 +
 gcc/config/avr/avr.cc   | 12 +++-
 gcc/testsuite/gcc.target/avr/torture/get-mem.c  |  2 +-
 gcc/testsuite/gcc.target/avr/torture/int24-mul.c|  9 ++---
 gcc/testsuite/gcc.target/avr/torture/pr109907-2.c   |  2 +-
 gcc/testsuite/gcc.target/avr/torture/pr61443.c  | 16 +---
 gcc/testsuite/gcc.target/avr/torture/pr63633-ice-mult.c | 12 +++-
 gcc/testsuite/gcc.target/avr/torture/set-mem.c  |  2 +-
 8 files changed, 33 insertions(+), 23 deletions(-)

diff --git a/gcc/config/avr/avr-modes.def b/gcc/config/avr/avr-modes.def
index e0633d680d54..6b1c11a40d3b 100644
--- a/gcc/config/avr/avr-modes.def
+++ b/gcc/config/avr/avr-modes.def
@@ -17,6 +17,7 @@
.  */
 
 FRACTIONAL_INT_MODE (PSI, 24, 3);
+INT_N (PSI, 24);
 
 /* Make TA and UTA 64 bits wide.
128 bit wide modes would be insane on a 8-bit machine.
diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc
index 32b43be1bc35..461776d45c95 100644
--- a/gcc/config/avr/avr.cc
+++ b/gcc/config/avr/avr.cc
@@ -15651,11 +15651,13 @@ avr_builtin_decl (unsigned id, bool /*initialize_p*/)
 static void
 avr_init_builtin_int24 (void)
 {
-  tree int24_type  = make_signed_type (GET_MODE_BITSIZE (PSImode));
-  tree uint24_type = make_unsigned_type (GET_MODE_BITSIZE (PSImode));
-
-  lang_hooks.types.register_builtin_type (int24_type, "__int24");
-  lang_hooks.types.register_builtin_type (uint24_type, "__uint24");
+  for (int i = 0; i < NUM_INT_N_ENTS; ++i)
+if (int_n_data[i].bitsize == 24)
+  {
+   tree uint24_type = int_n_trees[i].unsigned_type;
+   lang_hooks.types.register_builtin_type (uint24_type, "__uint24");
+   break;
+  }
 }
 
 
diff --git a/gcc/testsuite/gcc.target/avr/torture/get-mem.c 
b/gcc/testsuite/gcc.target/avr/torture/get-mem.c
index 46f47f10429e..a71d03aee565 100644
--- a/gcc/testsuite/gcc.target/avr/torture/get-mem.c
+++ b/gcc/testsuite/gcc.target/avr/torture/get-mem.c
@@ -4,7 +4,7 @@
 
 typedef __INT8_TYPE__ s8;
 typedef __INT16_TYPE__ s16;
-typedef __int24 s24;
+__extension__ typedef __int24 s24;
 typedef __INT32_TYPE__ s32;
 
 static const s8 arr8[] = { 12, 23, 34 };
diff --git a/gcc/testsuite/gcc.target/avr/torture/int24-mul.c 
b/gcc/testsuite/gcc.target/avr/torture/int24-mul.c
index 9b29763738cc..98df1d0d3c30 100644
--- a/gcc/testsuite/gcc.target/avr/torture/int24-mul.c
+++ b/gcc/testsuite/gcc.target/avr/torture/int24-mul.c
@@ -7,7 +7,10 @@
 #define __flash /* empty */
 #endif
 
-const __flash __int24 vals[] =
+__extension__ typedef __uint24 uint24_t;
+__extension__ typedef __int24 int24_t;
+
+const __flash int24_t vals[] =
   {
 0, 1, 2, 3, -1, -2, -3, 0xff, 0x100, 0x101,
 0xffL * 0xff, 0xfffL * 0xfff, 0x101010L, 0xaaL
@@ -17,7 +20,7 @@ void test_u (void)
 {
   unsigned int i;
   unsigned long la, lb, lc;
-  __uint24 a, b, c;
+  uint24_t a, b, c;
 
   int S = sizeof (vals) / sizeof (*vals);
 
@@ -58,7 +61,7 @@ void test_nu (void)
   unsigned long la;
   unsigned int i;
   int S = sizeof (vals) / sizeof (*vals);
-  __uint24 a;
+  uint24_t a;
   
   for (i = 0; i < 500; i++)
 {
diff --git a/gcc/testsuite/gcc.target/avr/torture/pr109907-2.c 
b/gcc/testsuite/gcc.target/avr/torture/pr109907-2.c
index db0cc72e590a..26cce5d5a426 100644
--- a/gcc/testsuite/gcc.target/avr/torture/pr109907-2.c
+++ b/gcc/testsuite/gcc.target/avr/torture/pr109907-2.c
@@ -5,7 +5,7 @@
 
 typedef __UINT8_TYPE__ uint8_t;
 typedef __UINT16_TYPE__ uint16_t;
-typedef __uint24 uint24_t;
+__extension__ typedef __uint24 uint24_t;
 typedef __UINT32_TYPE__ uint32_t;
 
 typedef __INT32_TYPE__ int32_t;
diff --git a/gcc/testsuite/gcc.target/av

[gcc r14-11220] c++: Make sure fold_sizeof_expr returns the correct type [PR117775]

2025-01-17 Thread Simon Martin via Gcc-cvs
https://gcc.gnu.org/g:b4578c16a45756144f48f0f03ebe77b61762a022

commit r14-11220-gb4578c16a45756144f48f0f03ebe77b61762a022
Author: Simon Martin 
Date:   Thu Jan 16 16:27:06 2025 +0100

c++: Make sure fold_sizeof_expr returns the correct type [PR117775]

We currently ICE upon the following code, that is valid under
-Wno-pointer-arith:

=== cut here ===
int main() {
  decltype( [](auto) { return sizeof(void); } ) x;
  return x.operator()(0);
}
=== cut here ===

The problem is that "fold_sizeof_expr (sizeof(void))" returns
size_one_node, that has a different TREE_TYPE from that of the sizeof
expression, which later triggers an assert in cxx_eval_store_expression.

This patch makes sure that fold_sizeof_expr always returns a tree with
the size_type_node type.

PR c++/117775

gcc/cp/ChangeLog:

* decl.cc (fold_sizeof_expr): Make sure the folded result has
type size_type_node.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/constexpr-117775.C: New test.

(cherry picked from commit 37f38b0f97374476a4818b68c8df991886428787)

Diff:
---
 gcc/cp/decl.cc|  1 +
 gcc/testsuite/g++.dg/cpp2a/constexpr-117775.C | 13 +
 2 files changed, 14 insertions(+)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 02119105058e..529bfadf2e7d 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -11502,6 +11502,7 @@ fold_sizeof_expr (tree t)
false, false);
   if (r == error_mark_node)
 r = size_one_node;
+  r = cp_fold_convert (size_type_node, r);
   return r;
 }
 
diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-117775.C 
b/gcc/testsuite/g++.dg/cpp2a/constexpr-117775.C
new file mode 100644
index ..59fc0d332b92
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-117775.C
@@ -0,0 +1,13 @@
+// PR c++/117775
+// Check that we don't ICE and have sizeof(void)==1 under -Wno-pointer-arith
+// { dg-do run { target c++20 } }
+// { dg-additional-options "-Wno-pointer-arith" }
+
+int main() {
+  struct why :
+decltype( [](auto) {
+   return sizeof(void);
+ })
+  {} x;
+  return 1 - x.operator()(0);
+}


[gcc r13-9328] Fix setting of call graph node AutoFDO count

2025-01-17 Thread Eugene Rozenfeld via Gcc-cvs
https://gcc.gnu.org/g:a71505ad9c2cc6463525b822959c407095a76c15

commit r13-9328-ga71505ad9c2cc6463525b822959c407095a76c15
Author: Eugene Rozenfeld 
Date:   Fri Jan 10 19:48:52 2025 -0800

Fix setting of call graph node AutoFDO count

We are initializing both the call graph node count and
the entry block count of the function with the head_count value
from the profile.

Count propagation algorithm may refine the entry block count
and we may end up with a case where the call graph node count
is set to zero but the entry block count is non-zero. That becomes
a problem because we have this code in execute_fixup_cfg:

 profile_count num = node->count;
 profile_count den = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
 bool scale = num.initialized_p () && !(num == den);

Here if num is 0 but den is not 0, scale becomes true and we
lose the counts in

if (scale)
  bb->count = bb->count.apply_scale (num, den);

This is what happened in the issue reported in PR116743
(a 10% regression in MySQL HAMMERDB tests).
3d9e6767939e9658260e2506e81ec32b37cba041 made an improvement in
AutoFDO count propagation, which caused a mismatch between
the call graph node count (zero) and the entry block count (non-zero)
and subsequent loss of counts as described above.

The fix is to update the call graph node count once we've done count 
propagation.

Tested on x86_64-pc-linux-gnu.

gcc/ChangeLog:
PR gcov-profile/116743
* auto-profile.cc (afdo_annotate_cfg): Fix mismatch between the 
call graph node count
and the entry block count.

(cherry picked from commit e683c6b029f809c7a1981b4341c95d9652c22e18)

Diff:
---
 gcc/auto-profile.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/auto-profile.cc b/gcc/auto-profile.cc
index f88d00934e1a..0447d4ec45cb 100644
--- a/gcc/auto-profile.cc
+++ b/gcc/auto-profile.cc
@@ -1536,8 +1536,6 @@ afdo_annotate_cfg (const stmt_set &promoted_stmts)
 
   if (s == NULL)
 return;
-  cgraph_node::get (current_function_decl)->count
- = profile_count::from_gcov_type (s->head_count ()).afdo ();
   ENTRY_BLOCK_PTR_FOR_FN (cfun)->count
  = profile_count::from_gcov_type (s->head_count ()).afdo ();
   EXIT_BLOCK_PTR_FOR_FN (cfun)->count = profile_count::zero ().afdo ();
@@ -1576,6 +1574,8 @@ afdo_annotate_cfg (const stmt_set &promoted_stmts)
   /* Calculate, propagate count and probability information on CFG.  */
   afdo_calculate_branch_prob (&annotated_bb);
 }
+  cgraph_node::get(current_function_decl)->count
+  = ENTRY_BLOCK_PTR_FOR_FN(cfun)->count;
   update_max_bb_count ();
   profile_status_for_fn (cfun) = PROFILE_READ;
   if (flag_value_profile_transformations)


[gcc r15-6999] rs6000, fix test builtins-1-p10-runnable.c

2025-01-17 Thread Carl Love via Gcc-cvs
https://gcc.gnu.org/g:5d779765b0123cc64c1e6af2656a20979ecaaf96

commit r15-6999-g5d779765b0123cc64c1e6af2656a20979ecaaf96
Author: Carl Love 
Date:   Wed Oct 2 21:05:08 2024 -0400

rs6000, fix test builtins-1-p10-runnable.c

The test has two issues:

1) The test should generate execute abort() if an error is found.
However, the test contains a #define 0 which actually enables the
error prints not exectuting void() because the debug code is protected
by an #ifdef not #if.  The #define DEBUG needs to be removed to so the
test will abort on an error.

2) The vec_i_expected output was tweeked to test that it would fail.
The test value was not removed.

By removing the #define DEBUG, the test fails and reports 1 failure.
Removing the intentionally wrong expected value results in the test
passing with no errors as expected.

gcc/testsuite/ChangeLog:
* gcc.target/powerpc/builtins-1-p10-runnable.c: Remove #define
DEBUG.  Replace vec_i_expected value with correct value.

Diff:
---
 gcc/testsuite/gcc.target/powerpc/builtins-1-p10-runnable.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/gcc/testsuite/gcc.target/powerpc/builtins-1-p10-runnable.c 
b/gcc/testsuite/gcc.target/powerpc/builtins-1-p10-runnable.c
index 222c8b3a409c..3e8a1c736e33 100644
--- a/gcc/testsuite/gcc.target/powerpc/builtins-1-p10-runnable.c
+++ b/gcc/testsuite/gcc.target/powerpc/builtins-1-p10-runnable.c
@@ -25,8 +25,6 @@
 #include 
 #include 
 
-#define DEBUG 0
-
 #ifdef DEBUG
 #include 
 #endif
@@ -281,8 +279,7 @@ int main()
 /* Signed word multiply high */
 i_arg1 = (vector int){ 2147483648, 2147483648, 2147483648, 2147483648 };
 i_arg2 = (vector int){ 2, 3, 4, 5};
-//vec_i_expected = (vector int){-1, -2, -2, -3};
-vec_i_expected = (vector int){1, -2, -2, -3};
+vec_i_expected = (vector int){-1, -2, -2, -3};
 
 vec_i_result = vec_mulh (i_arg1, i_arg2);


[gcc r15-7002] rs6000, Remove redundant built-in __builtin_vsx_xvcvuxwdp

2025-01-17 Thread Carl Love via Gcc-cvs
https://gcc.gnu.org/g:7a47e480390f9087ee75adbba8aaff2022244b2b

commit r15-7002-g7a47e480390f9087ee75adbba8aaff2022244b2b
Author: Carl Love 
Date:   Thu Aug 1 18:33:42 2024 -0400

rs6000, Remove redundant built-in __builtin_vsx_xvcvuxwdp

The built-in __builtin_vsx_xvcvuxwdp can be covered with PVIPR
function vec_doubleo on LE and vec_doublee on BE.  There are no test
cases or documentation for __builtin_vsx_xvcvuxwdp.  This patch
removes the redundant built-in.

gcc/ChangeLog:
* config/rs6000/rs6000-builtins.def (__builtin_vsx_xvcvuxwdp):
Remove built-in definition.

Diff:
---
 gcc/config/rs6000/rs6000-builtins.def | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/gcc/config/rs6000/rs6000-builtins.def 
b/gcc/config/rs6000/rs6000-builtins.def
index 6c455b91e147..555d7d589506 100644
--- a/gcc/config/rs6000/rs6000-builtins.def
+++ b/gcc/config/rs6000/rs6000-builtins.def
@@ -1616,9 +1616,6 @@
   const vf __builtin_vsx_xvcvuxdsp (vull);
 XVCVUXDSP vsx_xvcvuxdsp {}
 
-  const vd __builtin_vsx_xvcvuxwdp (vsi);
-XVCVUXWDP vsx_xvcvuxwdp {}
-
   const vf __builtin_vsx_xvcvuxwsp (vsi);
 XVCVUXWSP vsx_floatunsv4siv4sf2 {}


[gcc r15-7001] rs6000, remove built-ins __builtin_vsx_vperm_8hi and __builtin_vsx_vperm_8hi_uns

2025-01-17 Thread Carl Love via Gcc-cvs
https://gcc.gnu.org/g:38e862a6aa1b8ed209100a28f754f53cb10207de

commit r15-7001-g38e862a6aa1b8ed209100a28f754f53cb10207de
Author: Carl Love 
Date:   Wed Jul 31 16:40:34 2024 -0400

rs6000, remove built-ins __builtin_vsx_vperm_8hi and 
__builtin_vsx_vperm_8hi_uns

The two built-ins __builtin_vsx_vperm_8hi and __builtin_vsx_vperm_8hi_uns
are redundant. The are covered by the overloaded vec_perm built-in.  The
built-ins are not documented and do not have test cases.

The removal of these built-ins was missed in commit gcc r15-1923 on
7/9/2024.

This patch removes the redundant built-ins.

gcc/ChangeLog:
* config/rs6000/rs6000-builtins.def (__builtin_vsx_vperm_8hi,
__builtin_vsx_vperm_8hi_uns): Remove built-in definitions.

Diff:
---
 gcc/config/rs6000/rs6000-builtins.def | 6 --
 1 file changed, 6 deletions(-)

diff --git a/gcc/config/rs6000/rs6000-builtins.def 
b/gcc/config/rs6000/rs6000-builtins.def
index 3ca63739d317..6c455b91e147 100644
--- a/gcc/config/rs6000/rs6000-builtins.def
+++ b/gcc/config/rs6000/rs6000-builtins.def
@@ -1472,12 +1472,6 @@
   const vf __builtin_vsx_uns_floato_v2di (vsll);
 UNS_FLOATO_V2DI unsfloatov2di {}
 
-  const vss __builtin_vsx_vperm_8hi (vss, vss, vuc);
-VPERM_8HI_X altivec_vperm_v8hi {}
-
-  const vus __builtin_vsx_vperm_8hi_uns (vus, vus, vuc);
-VPERM_8HI_UNS_X altivec_vperm_v8hi_uns {}
-
   const vsll __builtin_vsx_vsigned_v2df (vd);
 VEC_VSIGNED_V2DF vsx_xvcvdpsxds {}


[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Factorisation set_contiguous_array

2025-01-17 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:be6b3df59a79a889095b9757159d87a3976794ef

commit be6b3df59a79a889095b9757159d87a3976794ef
Author: Mikael Morin 
Date:   Fri Jan 17 17:25:59 2025 +0100

Factorisation set_contiguous_array

Diff:
---
 gcc/fortran/trans-array.cc | 57 +++---
 1 file changed, 29 insertions(+), 28 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 4f066680dff0..76668d8a3ef1 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -10685,6 +10685,23 @@ gfc_caf_is_dealloc_only (int caf_mode)
 }
 
 
+static void
+set_contiguous_array (stmtblock_t *block, tree desc, tree size, tree data_ptr)
+{
+  gfc_add_modify (block, gfc_conv_descriptor_dtype (desc),
+ gfc_get_dtype_rank_type (1, TREE_TYPE (desc)));
+  gfc_conv_descriptor_lbound_set (block, desc,
+ gfc_index_zero_node,
+ gfc_index_one_node);
+  gfc_conv_descriptor_stride_set (block, desc,
+ gfc_index_zero_node,
+ gfc_index_one_node);
+  gfc_conv_descriptor_ubound_set (block, desc,
+ gfc_index_zero_node, size);
+  gfc_conv_descriptor_data_set (block, desc, data_ptr);
+}
+
+
 /* Recursively traverse an object of derived type, generating code to
deallocate, nullify or copy allocatable components.  This is the work horse
function for the functions named in this enum.  */
@@ -10945,32 +10962,6 @@ structure_alloc_comps (gfc_symbol * der_type, tree 
decl, tree dest,
  ubound = build_int_cst (gfc_array_index_type, 1);
}
 
- /* Treat strings like arrays.  Or the other way around, do not
-  * generate an additional array layer for scalar components.  */
- if (attr->dimension || c->ts.type == BT_CHARACTER)
-   {
- cdesc = gfc_get_array_type_bounds (tmp, 1, 0, &gfc_index_one_node,
-&ubound, 1,
-GFC_ARRAY_ALLOCATABLE, false);
-
- cdesc = gfc_create_var (cdesc, "cdesc");
- DECL_ARTIFICIAL (cdesc) = 1;
-
- gfc_add_modify (&tmpblock, gfc_conv_descriptor_dtype (cdesc),
- gfc_get_dtype_rank_type (1, tmp));
- gfc_conv_descriptor_lbound_set (&tmpblock, cdesc,
- gfc_index_zero_node,
- gfc_index_one_node);
- gfc_conv_descriptor_stride_set (&tmpblock, cdesc,
- gfc_index_zero_node,
- gfc_index_one_node);
- gfc_conv_descriptor_ubound_set (&tmpblock, cdesc,
- gfc_index_zero_node, ubound);
-   }
- else
-   /* Prevent warning.  */
-   cdesc = NULL_TREE;
-
  if (attr->dimension)
{
  if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (comp)))
@@ -10993,13 +10984,23 @@ structure_alloc_comps (gfc_symbol * der_type, tree 
decl, tree dest,
  gfc_add_block_to_block (&tmpblock, &se.pre);
}
 
+ /* Treat strings like arrays.  Or the other way around, do not
+  * generate an additional array layer for scalar components.  */
  if (attr->dimension || c->ts.type == BT_CHARACTER)
-   gfc_conv_descriptor_data_set (&tmpblock, cdesc, comp);
+   {
+ cdesc = gfc_get_array_type_bounds (tmp, 1, 0, &gfc_index_one_node,
+&ubound, 1,
+GFC_ARRAY_ALLOCATABLE, false);
+
+ cdesc = gfc_create_var (cdesc, "cdesc");
+ DECL_ARTIFICIAL (cdesc) = 1;
+
+ set_contiguous_array (&tmpblock, cdesc, ubound, comp);
+   }
  else
cdesc = comp;
 
  tree fndecl;
-
  fndecl = build_call_expr_loc (input_location,
gfor_fndecl_co_broadcast, 5,
gfc_build_addr_expr 
(pvoid_type_node,cdesc),


[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Factorisation set_contiguous_array

2025-01-17 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:a5897ea8217697e80d15fc11bec14e179ffbeebf

commit a5897ea8217697e80d15fc11bec14e179ffbeebf
Author: Mikael Morin 
Date:   Fri Jan 17 17:48:42 2025 +0100

Factorisation set_contiguous_array

Diff:
---
 gcc/fortran/trans-array.cc | 13 +
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 76668d8a3ef1..88a2509a5246 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -11148,21 +11148,10 @@ structure_alloc_comps (gfc_symbol * der_type, tree 
decl, tree dest,
  cdesc = gfc_create_var (cdesc, "cdesc");
  DECL_ARTIFICIAL (cdesc) = 1;
 
- gfc_add_modify (&dealloc_block, gfc_conv_descriptor_dtype (cdesc),
- gfc_get_dtype_rank_type (1, tmp));
- gfc_conv_descriptor_lbound_set (&dealloc_block, cdesc,
- gfc_index_zero_node,
- gfc_index_one_node);
- gfc_conv_descriptor_stride_set (&dealloc_block, cdesc,
- gfc_index_zero_node,
- gfc_index_one_node);
- gfc_conv_descriptor_ubound_set (&dealloc_block, cdesc,
- gfc_index_zero_node, ubound);
-
  if (attr->dimension)
comp = gfc_conv_descriptor_data_get (comp);
 
- gfc_conv_descriptor_data_set (&dealloc_block, cdesc, comp);
+ set_contiguous_array (&dealloc_block, cdesc, ubound, comp);
 
  /* Now call the deallocator.  */
  vtab = gfc_find_vtab (&c->ts);


[gcc r15-7000] rs6000, add testcases to the overloaded vec_perm built-in

2025-01-17 Thread Carl Love via Gcc-cvs
https://gcc.gnu.org/g:bc5753332649c5bcb31cbf6763207d8a9495b77b

commit r15-7000-gbc5753332649c5bcb31cbf6763207d8a9495b77b
Author: Carl Love 
Date:   Wed Jul 31 16:31:34 2024 -0400

rs6000, add testcases to the overloaded vec_perm built-in

The overloaded vec_perm built-in supports permuting signed and unsigned
vectors of char, bool char, short int, short bool, int, bool, long long
int, long long bool, int128, float and double.  However, not all of the
supported arguments are included in the test cases.  This patch adds
the missing test cases.

Additionally, in the 128-bit debug print statements the expected result and
the result need to be cast to unsigned long long to print correctly.  The
patch makes this additional change to the print statements.

gcc/ChangeLog:
* doc/extend.texi: Fix spelling mistake in description of the
vec_sel built-in.  Add documentation of the 128-bit vec_perm
instance.

gcc/testsuite/ChangeLog:
* gcc.target/powerpc/vsx-builtin-3.c: Add vec_perm test cases for
arguments of type vector signed long long int, long long bool,
bool, bool short, bool char and pixel, vector unsigned long long
int, unsigned int, unsigned short int, unsigned char.  Cast
arguments for debug prints to unsigned long long.
* gcc.target/powerpc/builtins-4-int128-runnable.c: Add vec_perm
test cases for signed and unsigned int128 arguments.

Diff:
---
 gcc/doc/extend.texi|  12 ++-
 .../powerpc/builtins-4-int128-runnable.c   | 108 ++---
 gcc/testsuite/gcc.target/powerpc/vsx-builtin-3.c   |  14 ++-
 3 files changed, 116 insertions(+), 18 deletions(-)

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index beaf67e59a1b..dd9a8d2f8ba5 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -21852,9 +21852,19 @@ vector bool __int128 vec_sel (vector bool __int128,
vector bool __int128, vector unsigned __int128);
 @end smallexample
 
-The instance is an extension of the exiting overloaded built-in @code{vec_sel}
+The instance is an extension of the existing overloaded built-in @code{vec_sel}
 that is documented in the PVIPR.
 
+@smallexample
+vector signed __int128 vec_perm (vector signed __int128,
+   vector signed __int128);
+vector unsigned __int128 vec_perm (vector unsigned __int128,
+   vector unsigned __int128);
+@end smallexample
+
+The instance is an extension of the existing overloaded built-in
+@code{vec_perm} that is documented in the PVIPR.
+
 @node Basic PowerPC Built-in Functions Available on ISA 2.06
 @subsubsection Basic PowerPC Built-in Functions Available on ISA 2.06
 
diff --git a/gcc/testsuite/gcc.target/powerpc/builtins-4-int128-runnable.c 
b/gcc/testsuite/gcc.target/powerpc/builtins-4-int128-runnable.c
index 62c11132cf33..c61b0ecb854b 100644
--- a/gcc/testsuite/gcc.target/powerpc/builtins-4-int128-runnable.c
+++ b/gcc/testsuite/gcc.target/powerpc/builtins-4-int128-runnable.c
@@ -18,6 +18,16 @@ int main() {
   __uint128_t data_u128[100];
   __int128_t data_128[100];
 
+#ifdef __BIG_ENDIAN__
+  vector unsigned char vuc = {0xC, 0xD, 0xE, 0xF, 0x8, 0x9, 0xA, 0xB,
+  0x1C, 0x1D, 0x1E, 0x1F, 0x18, 0x19, 0x1A, 0x1B};
+#else
+  vector unsigned char vuc = {0x4, 0x5, 0x6, 0x7, 0x0, 0x1, 0x2, 0x3, 
+ 0x14, 0x15, 0x16, 0x17, 0x10, 0x11, 0x12, 0x13};
+#endif
+  
+  vector __int128_t vec_128_arg1, vec_128_arg2;
+  vector __uint128_t vec_u128_arg1, vec_u128_arg2;
   vector __int128_t vec_128_expected1, vec_128_result1;
   vector __uint128_t vec_u128_expected1, vec_u128_result1;
   signed long long zero = (signed long long) 0;
@@ -37,11 +47,13 @@ int main() {
 {
 #ifdef DEBUG
printf("Error: vec_xl(), vec_128_result1[0] = %lld %llu; ",
-  vec_128_result1[0] >> 64,
-  vec_128_result1[0] & (__int128_t)0x);
+  (unsigned long long)(vec_128_result1[0] >> 64),
+  (unsigned long long)(vec_128_result1[0]
+   & (__int128_t)0x));
printf("vec_128_expected1[0] = %lld %llu\n",
-  vec_128_expected1[0] >> 64,
-  vec_128_expected1[0] & (__int128_t)0x);
+  (unsigned long long)(vec_128_expected1[0] >> 64),
+  (unsigned long long)(vec_128_expected1[0]
+   & (__int128_t)0x));
 #else
abort ();
 #endif
@@ -53,11 +65,13 @@ int main() {
 {
 #ifdef DEBUG
printf("Error: vec_xl(), vec_u128_result1[0] = %lld; ",
-  vec_u128_result1[0] >> 64,
-  vec_u128_result1[0] & (__int128_t)0x);
+  (unsigned long long)(vec_u128_result1[0] >> 64),
+  (unsigned long long)(vec_u128_result1[0]
+  

[gcc r15-7003] AArch64: Use standard names for saturating arithmetic

2025-01-17 Thread Tamar Christina via Gcc-cvs
https://gcc.gnu.org/g:5f5833a4107ddfbcd87651bf140151de043f4c36

commit r15-7003-g5f5833a4107ddfbcd87651bf140151de043f4c36
Author: Tamar Christina 
Date:   Fri Jan 17 17:43:49 2025 +

AArch64: Use standard names for saturating arithmetic

This renames the existing {s,u}q{add,sub} instructions to use the
standard names {s,u}s{add,sub}3 which are used by IFN_SAT_ADD and
IFN_SAT_SUB.

The NEON intrinsics for saturating arithmetic and their corresponding
builtins are changed to use these standard names too.

Using the standard names for the instructions causes 32 and 64-bit
unsigned scalar saturating arithmetic to use the NEON instructions,
resulting in an additional (and inefficient) FMOV to be generated when
the original operands are in GP registers. This patch therefore also
restores the original behaviour of using the adds/subs instructions
in this circumstance.

Additional tests are written for the scalar and Adv. SIMD cases to
ensure that the correct instructions are used. The NEON intrinsics are
already tested elsewhere.

gcc/ChangeLog:

* config/aarch64/aarch64-builtins.cc: Expand iterators.
* config/aarch64/aarch64-simd-builtins.def: Use standard names
* config/aarch64/aarch64-simd.md: Use standard names, split insn
definitions on signedness of operator and type of operands.
* config/aarch64/arm_neon.h: Use standard builtin names.
* config/aarch64/iterators.md: Add VSDQ_I_QI_HI iterator to
simplify splitting of insn for unsigned scalar arithmetic.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/scalar_intrinsics.c: Update testcases.
* 
gcc.target/aarch64/advsimd-intrinsics/saturating_arithmetic_autovect.inc:
Template file for unsigned vector saturating arithmetic tests.
* 
gcc.target/aarch64/advsimd-intrinsics/saturating_arithmetic_autovect_1.c:
8-bit vector type tests.
* 
gcc.target/aarch64/advsimd-intrinsics/saturating_arithmetic_autovect_2.c:
16-bit vector type tests.
* 
gcc.target/aarch64/advsimd-intrinsics/saturating_arithmetic_autovect_3.c:
32-bit vector type tests.
* 
gcc.target/aarch64/advsimd-intrinsics/saturating_arithmetic_autovect_4.c:
64-bit vector type tests.
* gcc.target/aarch64/saturating_arithmetic.inc: Template file
for scalar saturating arithmetic tests.
* gcc.target/aarch64/saturating_arithmetic_1.c: 8-bit tests.
* gcc.target/aarch64/saturating_arithmetic_2.c: 16-bit tests.
* gcc.target/aarch64/saturating_arithmetic_3.c: 32-bit tests.
* gcc.target/aarch64/saturating_arithmetic_4.c: 64-bit tests.

Co-authored-by: Tamar Christina 

Diff:
---
 gcc/config/aarch64/aarch64-builtins.cc |  12 +
 gcc/config/aarch64/aarch64-simd-builtins.def   |   8 +-
 gcc/config/aarch64/aarch64-simd.md | 207 +++-
 gcc/config/aarch64/arm_neon.h  |  96 
 gcc/config/aarch64/iterators.md|   4 +
 .../saturating_arithmetic_autovect.inc |  58 +
 .../saturating_arithmetic_autovect_1.c |  79 ++
 .../saturating_arithmetic_autovect_2.c |  79 ++
 .../saturating_arithmetic_autovect_3.c |  75 ++
 .../saturating_arithmetic_autovect_4.c |  77 ++
 .../aarch64/saturating-arithmetic-signed.c | 270 +
 .../gcc.target/aarch64/saturating_arithmetic.inc   |  39 +++
 .../gcc.target/aarch64/saturating_arithmetic_1.c   |  36 +++
 .../gcc.target/aarch64/saturating_arithmetic_2.c   |  36 +++
 .../gcc.target/aarch64/saturating_arithmetic_3.c   |  30 +++
 .../gcc.target/aarch64/saturating_arithmetic_4.c   |  30 +++
 .../gcc.target/aarch64/scalar_intrinsics.c |  32 +--
 17 files changed, 1096 insertions(+), 72 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-builtins.cc 
b/gcc/config/aarch64/aarch64-builtins.cc
index 86eebc168859..6d5479c2e449 100644
--- a/gcc/config/aarch64/aarch64-builtins.cc
+++ b/gcc/config/aarch64/aarch64-builtins.cc
@@ -5039,6 +5039,18 @@ aarch64_general_gimple_fold_builtin (unsigned int fcode, 
gcall *stmt,
  new_stmt = gimple_build_assign (gimple_call_lhs (stmt),
  LSHIFT_EXPR, args[0], args[1]);
break;
+  /* lower saturating add/sub neon builtins to gimple.  */
+  BUILTIN_VSDQ_I (BINOP, ssadd, 3, DEFAULT)
+  BUILTIN_VSDQ_I (BINOPU, usadd, 3, DEFAULT)
+   new_stmt = gimple_build_call_internal (IFN_SAT_ADD, 2, args[0], 
args[1]);
+   gimple_call_set_lhs (new_stmt, gimple_call_lhs (stmt));
+   break;
+  BUILTIN_VSDQ_I (BINOP, sssub, 3, DEFAULT)
+  BUILTIN_VSDQ_I (BINOPU, ussub, 3, DEFAULT)
+   new_stmt = gimple_build_call_in

[gcc r15-7004] AArch64: Use standard names for SVE saturating arithmetic

2025-01-17 Thread Tamar Christina via Gcc-cvs
https://gcc.gnu.org/g:26b2d9f27ca24f0705641a85f29d179fa0600869

commit r15-7004-g26b2d9f27ca24f0705641a85f29d179fa0600869
Author: Tamar Christina 
Date:   Fri Jan 17 17:44:23 2025 +

AArch64: Use standard names for SVE saturating arithmetic

Rename the existing SVE unpredicated saturating arithmetic instructions
to use standard names which are used by IFN_SAT_ADD and IFN_SAT_SUB.

gcc/ChangeLog:

* config/aarch64/aarch64-sve.md: Rename insns

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/sve/saturating_arithmetic.inc:
Template file for auto-vectorizer tests.
* gcc.target/aarch64/sve/saturating_arithmetic_1.c:
Instantiate 8-bit vector tests.
* gcc.target/aarch64/sve/saturating_arithmetic_2.c:
Instantiate 16-bit vector tests.
* gcc.target/aarch64/sve/saturating_arithmetic_3.c:
Instantiate 32-bit vector tests.
* gcc.target/aarch64/sve/saturating_arithmetic_4.c:
Instantiate 64-bit vector tests.

Diff:
---
 gcc/config/aarch64/aarch64-sve.md  |  4 +-
 .../aarch64/sve/saturating_arithmetic.inc  | 68 ++
 .../aarch64/sve/saturating_arithmetic_1.c  | 60 +++
 .../aarch64/sve/saturating_arithmetic_2.c  | 60 +++
 .../aarch64/sve/saturating_arithmetic_3.c  | 62 
 .../aarch64/sve/saturating_arithmetic_4.c  | 62 
 6 files changed, 314 insertions(+), 2 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-sve.md 
b/gcc/config/aarch64/aarch64-sve.md
index ba4b4d904c77..e975286a0190 100644
--- a/gcc/config/aarch64/aarch64-sve.md
+++ b/gcc/config/aarch64/aarch64-sve.md
@@ -4449,7 +4449,7 @@
 ;; -
 
 ;; Unpredicated saturating signed addition and subtraction.
-(define_insn "@aarch64_sve_"
+(define_insn "s3"
   [(set (match_operand:SVE_FULL_I 0 "register_operand")
(SBINQOPS:SVE_FULL_I
  (match_operand:SVE_FULL_I 1 "register_operand")
@@ -4465,7 +4465,7 @@
 )
 
 ;; Unpredicated saturating unsigned addition and subtraction.
-(define_insn "@aarch64_sve_"
+(define_insn "s3"
   [(set (match_operand:SVE_FULL_I 0 "register_operand")
(UBINQOPS:SVE_FULL_I
  (match_operand:SVE_FULL_I 1 "register_operand")
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/saturating_arithmetic.inc 
b/gcc/testsuite/gcc.target/aarch64/sve/saturating_arithmetic.inc
new file mode 100644
index ..0b3ebbcb0d6f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sve/saturating_arithmetic.inc
@@ -0,0 +1,68 @@
+/* Template file for vector saturating arithmetic validation.
+
+   This file defines saturating addition and subtraction functions for a given
+   scalar type, testing the auto-vectorization of these two operators. This
+   type, along with the corresponding minimum and maximum values for that type,
+   must be defined by any test file which includes this template file.  */
+
+#ifndef SAT_ARIT_AUTOVEC_INC
+#define SAT_ARIT_AUTOVEC_INC
+
+#include 
+#include 
+
+#ifndef UT
+#define UT uint32_t
+#define UMAX UINT_MAX
+#define UMIN 0
+#endif
+
+void uaddq (UT *out, UT *a, UT *b, int n)
+{
+  for (int i = 0; i < n; i++)
+{
+  UT sum = a[i] + b[i];
+  out[i] = sum < a[i] ? UMAX : sum;
+}
+}
+
+void uaddq2 (UT *out, UT *a, UT *b, int n)
+{
+  for (int i = 0; i < n; i++)
+{
+  UT sum;
+  if (!__builtin_add_overflow(a[i], b[i], &sum))
+   out[i] = sum;
+  else
+   out[i] = UMAX;
+}
+}
+
+void uaddq_imm (UT *out, UT *a, int n)
+{
+  for (int i = 0; i < n; i++)
+{
+  UT sum = a[i] + 50;
+  out[i] = sum < a[i] ? UMAX : sum;
+}
+}
+
+void usubq (UT *out, UT *a, UT *b, int n)
+{
+  for (int i = 0; i < n; i++)
+{
+  UT sum = a[i] - b[i];
+  out[i] = sum > a[i] ? UMIN : sum;
+}
+}
+
+void usubq_imm (UT *out, UT *a, int n)
+{
+  for (int i = 0; i < n; i++)
+{
+  UT sum = a[i] - 50;
+  out[i] = sum > a[i] ? UMIN : sum;
+}
+}
+
+#endif
\ No newline at end of file
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/saturating_arithmetic_1.c 
b/gcc/testsuite/gcc.target/aarch64/sve/saturating_arithmetic_1.c
new file mode 100644
index ..6936e9a27044
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sve/saturating_arithmetic_1.c
@@ -0,0 +1,60 @@
+/* { dg-do compile { target { aarch64*-*-* } } } */
+/* { dg-options "-O2 --save-temps -ftree-vectorize" } */
+/* { dg-final { check-function-bodies "**" "" "" } } */
+
+/*
+** uaddq:
+** ...
+** ld1b\tz([0-9]+)\.b, .*
+** ld1b\tz([0-9]+)\.b, .*
+** uqadd\tz\2.b, z\1\.b, z\2\.b
+** ...
+** ldr\tb([0-9]+), .*
+** ldr\tb([0-9]+), .*
+** uqadd\tb\4, b\3, b\4
+** ...
+*/
+/*
+** uaddq2:
+** ...
+** ld1b\tz([0-9]+)\.b, .*
+** ld1b\tz([0-9]+)\.b, .*
+** uqadd\tz\2.b, z\1\

[gcc r15-7005] s390: Replace some checking assertions with output_operand_lossage [PR118511]

2025-01-17 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:71280df05f28fd568f8b863dd700c0be2f2443a8

commit r15-7005-g71280df05f28fd568f8b863dd700c0be2f2443a8
Author: Jakub Jelinek 
Date:   Fri Jan 17 19:27:59 2025 +0100

s390: Replace some checking assertions with output_operand_lossage 
[PR118511]

r15-2002 s390: Fully exploit vgm, vgbm, vrepi change added
some code to print_operand and added gcc_checking_asserts in there.
But print_operand ideally should have no assertions in it, as most
of the assumptions can be easily violated by people using it in
inline asm.
This issue in particular was seen by failure to compile s390-tools,
which had in its extended inline asm uses of %r1 and %r2.
I really don't know if they meant %%r1 and %%r2 or %1 and %2 and
will leave that decision to the maintainers, but the thing is that
%r1 and %r2 used to expand like %1 and %2 in GCC 14 and earlier,
now in checking build it ICEs and in --enable-checking=release build
fails to assemble (the checking assert is ignored and the compiler just uses
some uninitialized variables to emit something arbitrary).

With the following patch it is diagnosed as error consistently
regardless if it is release checking or no checking or checking compiler.

Note, I see also
  else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLSLDM)
{
  fprintf (file, "%s", ":tls_ldcall:");
  const char *name = get_some_local_dynamic_name ();
  gcc_assert (name);
  assemble_name (file, name);
}
in print_operand, maybe that isn't a big deal because it might be
impossible to construct inline asm argument which is UNSPEC_TLSLDM.
And then there is
case 'e': case 'f':
case 's': case 't':
  {
int start, end;
int len;
bool ok;

len = (code == 's' || code == 'e' ? 64 : 32);
ok = s390_contiguous_bitmask_p (ival, true, len, &start, &end);
gcc_assert (ok);
if (code == 's' || code == 't')
  ival = start;
else
  ival = end;
  }
  break;
which likely should be also output_operand_lossage but I haven't tried
to reproduce that.

2025-01-17  Jakub Jelinek  

PR target/118511
* config/s390/s390.cc (print_operand) : Use
output_operand_lossage instead of gcc_checking_assert.
(print_operand) : Likewise.
(print_operand) : Likewise.

* gcc.target/s390/pr118511.c: New test.

Diff:
---
 gcc/config/s390/s390.cc  | 24 ++--
 gcc/testsuite/gcc.target/s390/pr118511.c | 11 +++
 2 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/gcc/config/s390/s390.cc b/gcc/config/s390/s390.cc
index a98e067bb06f..f166a8a07dd9 100644
--- a/gcc/config/s390/s390.cc
+++ b/gcc/config/s390/s390.cc
@@ -8688,8 +8688,12 @@ print_operand (FILE *file, rtx x, int code)
   {
machine_mode mode;
short imm;
-   bool b = s390_constant_via_vrepi_p (x, &mode, &imm);
-   gcc_checking_assert (b);
+   if (!s390_constant_via_vrepi_p (x, &mode, &imm))
+ {
+   output_operand_lossage ("invalid constant for output "
+   "modifier '%c'", code);
+   return;
+ }
switch (mode)
  {
  case QImode:
@@ -8714,8 +8718,12 @@ print_operand (FILE *file, rtx x, int code)
   {
machine_mode mode;
int start, end;
-   bool b = s390_constant_via_vgm_p (x, &mode, &start, &end);
-   gcc_checking_assert (b);
+   if (!s390_constant_via_vgm_p (x, &mode, &start, &end))
+ {
+   output_operand_lossage ("invalid constant for output "
+   "modifier '%c'", code);
+   return;
+ }
switch (mode)
  {
  case QImode:
@@ -8739,8 +8747,12 @@ print_operand (FILE *file, rtx x, int code)
 case 'r':
   {
unsigned mask;
-   bool b = s390_constant_via_vgbm_p (x, &mask);
-   gcc_checking_assert (b);
+   if (!s390_constant_via_vgbm_p (x, &mask))
+ {
+   output_operand_lossage ("invalid constant for output "
+   "modifier '%c'", code);
+   return;
+ }
fprintf (file, "%u", mask);
   }
   return;
diff --git a/gcc/testsuite/gcc.target/s390/pr118511.c 
b/gcc/testsuite/gcc.target/s390/pr118511.c
new file mode 100644
index ..67448e718051
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/pr118511.c
@@ -0,0 +1,11 @@
+/* PR target/118511 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+void
+foo (void)
+{
+  asm volatile ("# %p0" : : "d" (1));  /* { dg-error "invalid 'asm': invalid 
constant for output modifier 'p'" }

[gcc r13-9329] c++: Make sure fold_sizeof_expr returns the correct type [PR117775]

2025-01-17 Thread Simon Martin via Gcc-cvs
https://gcc.gnu.org/g:fa248a92134c0681719702e60c369b916d4f8bf9

commit r13-9329-gfa248a92134c0681719702e60c369b916d4f8bf9
Author: Simon Martin 
Date:   Thu Jan 16 16:27:06 2025 +0100

c++: Make sure fold_sizeof_expr returns the correct type [PR117775]

We currently ICE upon the following code, that is valid under
-Wno-pointer-arith:

=== cut here ===
int main() {
  decltype( [](auto) { return sizeof(void); } ) x;
  return x.operator()(0);
}
=== cut here ===

The problem is that "fold_sizeof_expr (sizeof(void))" returns
size_one_node, that has a different TREE_TYPE from that of the sizeof
expression, which later triggers an assert in cxx_eval_store_expression.

This patch makes sure that fold_sizeof_expr always returns a tree with
the size_type_node type.

PR c++/117775

gcc/cp/ChangeLog:

* decl.cc (fold_sizeof_expr): Make sure the folded result has
type size_type_node.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/constexpr-117775.C: New test.

(cherry picked from commit 37f38b0f97374476a4818b68c8df991886428787)

Diff:
---
 gcc/cp/decl.cc|  1 +
 gcc/testsuite/g++.dg/cpp2a/constexpr-117775.C | 13 +
 2 files changed, 14 insertions(+)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index dbd1ee664c60..8f902fb1d114 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -11210,6 +11210,7 @@ fold_sizeof_expr (tree t)
false, false);
   if (r == error_mark_node)
 r = size_one_node;
+  r = cp_fold_convert (size_type_node, r);
   return r;
 }
 
diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-117775.C 
b/gcc/testsuite/g++.dg/cpp2a/constexpr-117775.C
new file mode 100644
index ..59fc0d332b92
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-117775.C
@@ -0,0 +1,13 @@
+// PR c++/117775
+// Check that we don't ICE and have sizeof(void)==1 under -Wno-pointer-arith
+// { dg-do run { target c++20 } }
+// { dg-additional-options "-Wno-pointer-arith" }
+
+int main() {
+  struct why :
+decltype( [](auto) {
+   return sizeof(void);
+ })
+  {} x;
+  return 1 - x.operator()(0);
+}


[gcc r15-6992] match.pd: Fix (FTYPE) N CMP (FTYPE) M optimization for GENERIC [PR118522]

2025-01-17 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:3ab9eb6946f7b832834b3d808c5617935e0be727

commit r15-6992-g3ab9eb6946f7b832834b3d808c5617935e0be727
Author: Jakub Jelinek 
Date:   Fri Jan 17 11:30:07 2025 +0100

match.pd: Fix (FTYPE) N CMP (FTYPE) M optimization for GENERIC [PR118522]

The last case of this optimization assumes that if 2 integral types
have same precision and TYPE_UNSIGNED, then they are uselessly convertible.
While that is very likely the case for GIMPLE, it is not the case for
GENERIC, so the following patch adds there a convert so that the
optimization produces also valid GENERIC.  Without it we got
(int) p == b where b had _BitInt(32) type, so incompatible types.

2025-01-17  Jakub Jelinek  

PR tree-optimization/118522
* match.pd ((FTYPE) N CMP (FTYPE) M): Add convert, as in GENERIC
integral types with the same precision and sign might actually not
be compatible types.

* gcc.dg/bitint-120.c: New test.

Diff:
---
 gcc/match.pd  |  2 +-
 gcc/testsuite/gcc.dg/bitint-120.c | 11 +++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index b6cbb851897d..f4359d3a005a 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -7253,7 +7253,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (icmp (convert:type2 @1) @2)
  (if (TYPE_PRECISION (type1) == TYPE_PRECISION (type2)
   && type1_signed_p == type2_signed_p)
- (icmp @1 @2))
+ (icmp @1 (convert @2)))
 
 /* Optimize various special cases of (FTYPE) N CMP CST.  */
 (for cmp  (lt le eq ne ge gt)
diff --git a/gcc/testsuite/gcc.dg/bitint-120.c 
b/gcc/testsuite/gcc.dg/bitint-120.c
new file mode 100644
index ..51098881e140
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/bitint-120.c
@@ -0,0 +1,11 @@
+/* PR tree-optimization/118522 */
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-O2" } */
+
+_BitInt(32) b;
+
+int
+foo (unsigned short p)
+{
+  return p == (double) b;
+}


[gcc r12-10907] tree-optimization/116768 - wrong dependence analysis

2025-01-17 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:4e5e70e645f02bc956e1ac529ec6498eb281ec26

commit r12-10907-g4e5e70e645f02bc956e1ac529ec6498eb281ec26
Author: Richard Biener 
Date:   Thu Sep 19 14:58:18 2024 +0200

tree-optimization/116768 - wrong dependence analysis

The following reverts a bogus fix done for PR101009 and instead makes
sure we get into the same_access_functions () case when computing
the distance vector for g[1] and g[1] where the constants ended up
having different types.  The generic code doesn't seem to handle
loop invariant dependences.  The special case gets us both
( 0 ) and ( 1 ) as distance vectors while formerly we got ( 1 ),
which the PR101009 fix changed to ( 0 ) with bad effects on other
cases as shown in this PR.

PR tree-optimization/116768
* tree-data-ref.cc (build_classic_dist_vector_1): Revert
PR101009 change.
* tree-chrec.cc (eq_evolutions_p): Make sure (sizetype)1
and (int)1 compare equal.

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

(cherry picked from commit 5b5a36b122e1205449f1512bf39521b669e713ef)

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr116768.c | 32 
 gcc/tree-chrec.cc   |  4 ++--
 gcc/tree-data-ref.cc|  2 --
 3 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr116768.c 
b/gcc/testsuite/gcc.dg/torture/pr116768.c
new file mode 100644
index ..57b5d00e7b71
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr116768.c
@@ -0,0 +1,32 @@
+/* { dg-do run } */
+
+#define numwords 2
+
+typedef struct {
+  unsigned words[numwords];
+} Child;
+
+typedef struct {
+  Child child;
+} Parent;
+
+Parent my_or(Parent x, const Parent *y) {
+  const Child *y_child = &y->child;
+  for (int i = 0; i < numwords; i++) {
+x.child.words[i] |= y_child->words[i];
+  }
+  return x;
+}
+
+int main() {
+  Parent bs[4];
+  __builtin_memset(bs, 0, sizeof(bs));
+
+  bs[0].child.words[0] = 1;
+  for (int i = 1; i <= 3; i++) {
+bs[i] = my_or(bs[i], &bs[i - 1]);
+  }
+  if (bs[2].child.words[0] != 1)
+__builtin_abort ();
+  return 0;
+}
diff --git a/gcc/tree-chrec.cc b/gcc/tree-chrec.cc
index c44cea754344..685e975cf2bc 100644
--- a/gcc/tree-chrec.cc
+++ b/gcc/tree-chrec.cc
@@ -1594,7 +1594,7 @@ eq_evolutions_p (const_tree chrec0, const_tree chrec1)
   || TREE_CODE (chrec0) != TREE_CODE (chrec1))
 return false;
 
-  if (chrec0 == chrec1)
+  if (operand_equal_p (chrec0, chrec1, 0))
 return true;
 
   if (! types_compatible_p (TREE_TYPE (chrec0), TREE_TYPE (chrec1)))
@@ -1621,7 +1621,7 @@ eq_evolutions_p (const_tree chrec0, const_tree chrec1)
  TREE_OPERAND (chrec1, 0));
 
 default:
-  return operand_equal_p (chrec0, chrec1, 0);
+  return false;
 }
 }
 
diff --git a/gcc/tree-data-ref.cc b/gcc/tree-data-ref.cc
index b7bca6a9d064..ea55f81a92fc 100644
--- a/gcc/tree-data-ref.cc
+++ b/gcc/tree-data-ref.cc
@@ -5168,8 +5168,6 @@ build_classic_dist_vector_1 (struct 
data_dependence_relation *ddr,
  non_affine_dependence_relation (ddr);
  return false;
}
-  else
-   *init_b = true;
 }
 
   return true;


[gcc r12-10912] tree-optimization/117307 - STMT_VINFO_SLP_VECT_ONLY mis-computation

2025-01-17 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:39d3c3f06f969b6dbe5c50596c060d1210f8c9f0

commit r12-10912-g39d3c3f06f969b6dbe5c50596c060d1210f8c9f0
Author: Richard Biener 
Date:   Mon Oct 28 09:52:08 2024 +0100

tree-optimization/117307 - STMT_VINFO_SLP_VECT_ONLY mis-computation

STMT_VINFO_SLP_VECT_ONLY isn't properly computed as union of all
group members and when the group is later split due to duplicates
not all sub-groups inherit the flag.

PR tree-optimization/117307
* tree-vect-data-refs.cc (vect_analyze_data_ref_accesses):
Properly compute STMT_VINFO_SLP_VECT_ONLY.  Set it on all
parts of a split group.

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

(cherry picked from commit 19722308a286d9a00eead8ac82b948da8c4ca38b)

Diff:
---
 gcc/testsuite/gcc.dg/vect/pr117307.c | 17 +
 gcc/tree-vect-data-refs.cc   | 19 +--
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/vect/pr117307.c 
b/gcc/testsuite/gcc.dg/vect/pr117307.c
new file mode 100644
index ..dc853d617065
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr117307.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-march=x86-64-v4" { target { x86_64-*-* i?86-*-* } 
} } */
+
+int a;
+float *b, *c;
+float d;
+void e() {
+  for (; a; a++) {
+if (d) {
+  c[0] = b[0];
+  c[1] = b[1];
+} else if (b[1])
+  c[0] = b[0] * 0;
+b += 2;
+c += 2;
+  }
+}
diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc
index b47d0122aec5..7af01c6806e3 100644
--- a/gcc/tree-vect-data-refs.cc
+++ b/gcc/tree-vect-data-refs.cc
@@ -3255,12 +3255,15 @@ vect_analyze_data_ref_accesses (vec_info *vinfo,
  DR_GROUP_NEXT_ELEMENT (lastinfo) = stmtinfo_b;
  lastinfo = stmtinfo_b;
 
- STMT_VINFO_SLP_VECT_ONLY (stmtinfo_a)
-   = !can_group_stmts_p (stmtinfo_a, stmtinfo_b, false);
+ if (! STMT_VINFO_SLP_VECT_ONLY (stmtinfo_a))
+   {
+ STMT_VINFO_SLP_VECT_ONLY (stmtinfo_a)
+   = !can_group_stmts_p (stmtinfo_a, stmtinfo_b, false);
 
- if (dump_enabled_p () && STMT_VINFO_SLP_VECT_ONLY (stmtinfo_a))
-   dump_printf_loc (MSG_NOTE, vect_location,
-"Load suitable for SLP vectorization only.\n");
+ if (dump_enabled_p () && STMT_VINFO_SLP_VECT_ONLY (stmtinfo_a))
+   dump_printf_loc (MSG_NOTE, vect_location,
+"Load suitable for SLP vectorization only.\n");
+   }
 
  if (init_b == init_prev
  && !to_fixup.add (DR_GROUP_FIRST_ELEMENT (stmtinfo_a))
@@ -3304,7 +3307,11 @@ vect_analyze_data_ref_accesses (vec_info *vinfo,
{
  DR_GROUP_NEXT_ELEMENT (g) = DR_GROUP_NEXT_ELEMENT (next);
  if (!newgroup)
-   newgroup = next;
+   {
+ newgroup = next;
+ STMT_VINFO_SLP_VECT_ONLY (newgroup)
+   = STMT_VINFO_SLP_VECT_ONLY (grp);
+   }
  else
DR_GROUP_NEXT_ELEMENT (ng) = next;
  ng = next;


[gcc r12-10905] middle-end/69482 - not preserving volatile accesses

2025-01-17 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:3fd1c1a8640bf84c32695531a3ed81d4338409aa

commit r12-10905-g3fd1c1a8640bf84c32695531a3ed81d4338409aa
Author: Richard Biener 
Date:   Mon Jan 9 12:46:28 2023 +0100

middle-end/69482 - not preserving volatile accesses

The following addresses a long standing issue with not preserving
accesses to non-volatile objects through volatile qualified
pointers in the case that object gets expanded to a register.  The
fix is to treat accesses to an object with a volatile qualified
access as forcing that object to memory.  This issue got more
exposed recently so it regressed more since GCC 11.

PR middle-end/69482
* cfgexpand.cc (discover_nonconstant_array_refs_r): Volatile
qualified accesses also force objects to memory.

* gcc.target/i386/pr69482-1.c: New testcase.
* gcc.target/i386/pr69482-2.c: Likewise.

(cherry picked from commit a5a8242153d078f1ebe60f00409415da260a29ee)

Diff:
---
 gcc/cfgexpand.cc  |  9 +
 gcc/testsuite/gcc.target/i386/pr69482-1.c | 16 
 gcc/testsuite/gcc.target/i386/pr69482-2.c | 10 ++
 3 files changed, 35 insertions(+)

diff --git a/gcc/cfgexpand.cc b/gcc/cfgexpand.cc
index eadec9a2bfd2..006f46fa9db3 100644
--- a/gcc/cfgexpand.cc
+++ b/gcc/cfgexpand.cc
@@ -6311,6 +6311,15 @@ discover_nonconstant_array_refs_r (tree * tp, int 
*walk_subtrees,
 
   if (IS_TYPE_OR_DECL_P (t))
 *walk_subtrees = 0;
+  else if (REFERENCE_CLASS_P (t) && TREE_THIS_VOLATILE (t))
+{
+  t = get_base_address (t);
+  if (t && DECL_P (t)
+ && DECL_MODE (t) != BLKmode
+ && !TREE_ADDRESSABLE (t))
+   bitmap_set_bit (forced_stack_vars, DECL_UID (t));
+  *walk_subtrees = 0;
+}
   else if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF)
 {
   while (((TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF)
diff --git a/gcc/testsuite/gcc.target/i386/pr69482-1.c 
b/gcc/testsuite/gcc.target/i386/pr69482-1.c
new file mode 100644
index ..7ef0e71b17c8
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr69482-1.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -fno-stack-protector -fomit-frame-pointer" } */
+
+static inline void memset_s(void* s, int n) {
+  volatile unsigned char * p = s;
+  for(int i = 0; i < n; ++i) {
+p[i] = 0;
+  }
+}
+
+void test() {
+  unsigned char x[4];
+  memset_s(x, sizeof x);
+}
+
+/* { dg-final { scan-assembler-times "mov" 4 } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr69482-2.c 
b/gcc/testsuite/gcc.target/i386/pr69482-2.c
new file mode 100644
index ..6aabe4fb3939
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr69482-2.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fomit-frame-pointer" } */
+
+void bar ()
+{
+  int j;
+  *(volatile int *)&j = 0;
+}
+
+/* { dg-final { scan-assembler-times "mov" 1 } } */


[gcc r12-10906] tree-optimization/116290 - fix compare-debug issue in ldist

2025-01-17 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:567547a89763b583e8b829b81f1db9053c246b96

commit r12-10906-g567547a89763b583e8b829b81f1db9053c246b96
Author: Richard Biener 
Date:   Sun Oct 13 15:12:44 2024 +0200

tree-optimization/116290 - fix compare-debug issue in ldist

Loop distribution does different analysis with -g0/-g due to counting
a debug stmt starting a BB against a limit which will everntually
lead to different IVOPTs choices.  I've fixed a possible IVOPTs
issue on the way even though it doesn't make a difference here.

PR tree-optimization/116290
* tree-loop-distribution.cc (determine_reduction_stmt_1): PHIs
have no debug variants.  Start with first non-debug real stmt.
* tree-ssa-loop-ivopts.cc (find_givs_in_bb): Do not analyze
debug stmts.

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

(cherry picked from commit 566740013b3445162b8c4bc2205e4e568d014968)

Diff:
---
 gcc/testsuite/gcc.dg/pr116290.c | 18 ++
 gcc/tree-loop-distribution.cc   |  6 +++---
 gcc/tree-ssa-loop-ivopts.cc |  3 ++-
 3 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/pr116290.c b/gcc/testsuite/gcc.dg/pr116290.c
new file mode 100644
index ..97b946bda893
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr116290.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-g -O2 -fcompare-debug" } */
+
+char *camel_message_info_class_intern_init_part;
+void g_once_init_enter();
+void camel_message_info_class_intern_init() {
+  int ii;
+  char *label;
+  for (; camel_message_info_class_intern_init_part[ii]; ii++)
+if (camel_message_info_class_intern_init_part) {
+  if (label && *label)
+g_once_init_enter();
+  label = &camel_message_info_class_intern_init_part[ii + 1];
+  camel_message_info_class_intern_init_part[ii] = ' ';
+}
+  if (label)
+g_once_init_enter();
+}
diff --git a/gcc/tree-loop-distribution.cc b/gcc/tree-loop-distribution.cc
index 1b7d2a1ea7d2..449b9ffd4389 100644
--- a/gcc/tree-loop-distribution.cc
+++ b/gcc/tree-loop-distribution.cc
@@ -3492,7 +3492,7 @@ determine_reduction_stmt_1 (const loop_p loop, const 
basic_block *bbs)
   basic_block bb = bbs[i];
 
   for (gphi_iterator bsi = gsi_start_phis (bb); !gsi_end_p (bsi);
-  gsi_next_nondebug (&bsi))
+  gsi_next (&bsi))
{
  gphi *phi = bsi.phi ();
  if (virtual_operand_p (gimple_phi_result (phi)))
@@ -3505,8 +3505,8 @@ determine_reduction_stmt_1 (const loop_p loop, const 
basic_block *bbs)
}
}
 
-  for (gimple_stmt_iterator bsi = gsi_start_bb (bb); !gsi_end_p (bsi);
-  gsi_next_nondebug (&bsi), ++ninsns)
+  for (gimple_stmt_iterator bsi = gsi_start_nondebug_bb (bb);
+  !gsi_end_p (bsi); gsi_next_nondebug (&bsi), ++ninsns)
{
  /* Bail out early for loops which are unlikely to match.  */
  if (ninsns > 16)
diff --git a/gcc/tree-ssa-loop-ivopts.cc b/gcc/tree-ssa-loop-ivopts.cc
index eb4d8388906f..597c4b0e8a67 100644
--- a/gcc/tree-ssa-loop-ivopts.cc
+++ b/gcc/tree-ssa-loop-ivopts.cc
@@ -1458,7 +1458,8 @@ find_givs_in_bb (struct ivopts_data *data, basic_block bb)
   gimple_stmt_iterator bsi;
 
   for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi))
-find_givs_in_stmt (data, gsi_stmt (bsi));
+if (!is_gimple_debug (gsi_stmt (bsi)))
+  find_givs_in_stmt (data, gsi_stmt (bsi));
 }
 
 /* Finds general ivs.  */


[gcc r15-6993] AVR: Use INT_N to built-in define __int24.

2025-01-17 Thread Georg-Johann Lay via Gcc-cvs
https://gcc.gnu.org/g:6580b89957ccabbb5aaf43736b36b9bd399fbc13

commit r15-6993-g6580b89957ccabbb5aaf43736b36b9bd399fbc13
Author: Georg-Johann Lay 
Date:   Thu Jan 16 19:43:27 2025 +0100

AVR: Use INT_N to built-in define __int24.

This patch uses the INT_N interface to define __int24 in avr-modes.def.

Since the testsuite uses -Wpedantic and __int24 is a C/C++ extension,
uses of __int24 and __uint24 is now marked as __extension__.

PR target/118329
gcc/
* config/avr/avr-modes.def: Add INT_N (PSI, 24).
* config/avr/avr.cc (avr_init_builtin_int24)
<__int24>: Remove definition.
<__uint24>: Adjust definition to INT_N interface.
gcc/testsuite/
* gcc.target/avr/pr115830-add.c (__int24, __uint24): Add 
__extension__
to respective typedefs.
* gcc.target/avr/pr115830-sub-ext.c: Same.
* gcc.target/avr/pr115830-sub.c: Same.
* gcc.target/avr/torture/get-mem.c: Same.
* gcc.target/avr/torture/set-mem.c: Same.
* gcc.target/avr/torture/ifelse-c.h: Same.
* gcc.target/avr/torture/ifelse-d.h: Same.
* gcc.target/avr/torture/ifelse-q.h: Same.
* gcc.target/avr/torture/ifelse-r.h: Same.
* gcc.target/avr/torture/int24-mul.c: Same.
* gcc.target/avr/torture/pr109907-2.c: Same.
* gcc.target/avr/torture/pr61443.c: Same.
* gcc.target/avr/torture/pr63633-ice-mult.c: Same.
* gcc.target/avr/torture/shift-l-u24.c: Same.
* gcc.target/avr/torture/shift-r-i24.c: Same.
* gcc.target/avr/torture/shift-r-u24.c: Same.
* gcc.target/avr/torture/add-extend.c: Same.
* gcc.target/avr/torture/sub-extend.c: Same.
* gcc.target/avr/torture/sub-zerox.c: Same.
* gcc.target/avr/torture/test-gprs.h: Same.

Diff:
---
 gcc/config/avr/avr-modes.def|  1 +
 gcc/config/avr/avr.cc   | 12 +++-
 gcc/testsuite/gcc.target/avr/pr115830-add.c |  4 ++--
 gcc/testsuite/gcc.target/avr/pr115830-sub-ext.c |  4 ++--
 gcc/testsuite/gcc.target/avr/pr115830-sub.c |  4 ++--
 gcc/testsuite/gcc.target/avr/torture/add-extend.c   |  4 ++--
 gcc/testsuite/gcc.target/avr/torture/get-mem.c  |  2 +-
 gcc/testsuite/gcc.target/avr/torture/ifelse-c.h |  4 ++--
 gcc/testsuite/gcc.target/avr/torture/ifelse-d.h |  4 ++--
 gcc/testsuite/gcc.target/avr/torture/ifelse-q.h |  4 ++--
 gcc/testsuite/gcc.target/avr/torture/ifelse-r.h |  4 ++--
 gcc/testsuite/gcc.target/avr/torture/int24-mul.c|  9 ++---
 gcc/testsuite/gcc.target/avr/torture/pr109907-2.c   |  2 +-
 gcc/testsuite/gcc.target/avr/torture/pr61443.c  | 14 --
 gcc/testsuite/gcc.target/avr/torture/pr63633-ice-mult.c | 12 +++-
 gcc/testsuite/gcc.target/avr/torture/set-mem.c  |  2 +-
 gcc/testsuite/gcc.target/avr/torture/shift-l-u24.c  |  2 +-
 gcc/testsuite/gcc.target/avr/torture/shift-r-i24.c  |  2 +-
 gcc/testsuite/gcc.target/avr/torture/shift-r-u24.c  |  2 +-
 gcc/testsuite/gcc.target/avr/torture/sub-extend.c   |  4 ++--
 gcc/testsuite/gcc.target/avr/torture/sub-zerox.c|  2 +-
 gcc/testsuite/gcc.target/avr/torture/test-gprs.h|  2 +-
 22 files changed, 55 insertions(+), 45 deletions(-)

diff --git a/gcc/config/avr/avr-modes.def b/gcc/config/avr/avr-modes.def
index c71138c8d326..95d3814a8129 100644
--- a/gcc/config/avr/avr-modes.def
+++ b/gcc/config/avr/avr-modes.def
@@ -18,6 +18,7 @@
.  */
 
 FRACTIONAL_INT_MODE (PSI, 24, 3);
+INT_N (PSI, 24);
 
 /* Used when the N (and Z) flag(s) of SREG are set.
The N flag indicates  whether the value is negative.
diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc
index 41899289c3f1..c44ed7424538 100644
--- a/gcc/config/avr/avr.cc
+++ b/gcc/config/avr/avr.cc
@@ -15336,11 +15336,13 @@ avr_builtin_decl (unsigned id, bool /*initialize_p*/)
 static void
 avr_init_builtin_int24 (void)
 {
-  tree int24_type  = make_signed_type (GET_MODE_BITSIZE (PSImode));
-  tree uint24_type = make_unsigned_type (GET_MODE_BITSIZE (PSImode));
-
-  lang_hooks.types.register_builtin_type (int24_type, "__int24");
-  lang_hooks.types.register_builtin_type (uint24_type, "__uint24");
+  for (int i = 0; i < NUM_INT_N_ENTS; ++i)
+if (int_n_data[i].bitsize == 24)
+  {
+   tree uint24_type = int_n_trees[i].unsigned_type;
+   lang_hooks.types.register_builtin_type (uint24_type, "__uint24");
+   break;
+  }
 }
 
 
diff --git a/gcc/testsuite/gcc.target/avr/pr115830-add.c 
b/gcc/testsuite/gcc.target/avr/pr115830-add.c
index 99ac89cd0a60..89ce4847141c 100644
--- a/gcc/testsuite/gcc.target/avr/pr115830-add.c
+++ b/gcc/testsuite/gcc.target/avr/pr115830-add.c
@@ -5,8 +5,8 @@ typedef __UINT8_TYPE__ u8;
 typedef __I

[gcc r15-7006] d: Add testcase for fixed PR117115

2025-01-17 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:975c4f1a5de4ede89ee9499cd1a73d613a4aeae4

commit r15-7006-g975c4f1a5de4ede89ee9499cd1a73d613a4aeae4
Author: Iain Buclaw 
Date:   Fri Jan 17 20:10:39 2025 +0100

d: Add testcase for fixed PR117115

This was fixed in upstream dmd, and merged in r15-6824.

PR d/117115

gcc/testsuite/ChangeLog:

* gdc.dg/pr117115.d: New test.

Diff:
---
 gcc/testsuite/gdc.dg/pr117115.d | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/testsuite/gdc.dg/pr117115.d b/gcc/testsuite/gdc.dg/pr117115.d
new file mode 100644
index ..b012268b509e
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr117115.d
@@ -0,0 +1,3 @@
+// { dg-do compile }
+
+enum E117115 {} // { dg-error "must have at least one member" }