[gcc r15-5420] aarch64: Improve early_ra dump information

2024-11-18 Thread Richard Sandiford via Gcc-cvs
https://gcc.gnu.org/g:102e42a0dffafdd389604f877dbf6430c7394f73

commit r15-5420-g102e42a0dffafdd389604f877dbf6430c7394f73
Author: Richard Sandiford 
Date:   Mon Nov 18 19:32:49 2024 +

aarch64: Improve early_ra dump information

The early-ra pass often didn't print a dump message when aborting the
allocation.  This patch uses a similar helper to the previous patch.

gcc/
* config/aarch64/aarch64-early-ra.cc
(early_ra::record_allocation_failure): New member function.
(early_ra::get_allocno_subgroup): Use it instead of setting
m_allocation_successful directly.
(early_ra::record_constraints): Likewise.
(early_ra::allocate_colors): Likewise.

Diff:
---
 gcc/config/aarch64/aarch64-early-ra.cc | 43 ++
 1 file changed, 38 insertions(+), 5 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-early-ra.cc 
b/gcc/config/aarch64/aarch64-early-ra.cc
index bf8827f33427..68e96bd4da85 100644
--- a/gcc/config/aarch64/aarch64-early-ra.cc
+++ b/gcc/config/aarch64/aarch64-early-ra.cc
@@ -441,6 +441,8 @@ private:
 
   template
   void record_live_range_failure (T);
+  template
+  void record_allocation_failure (T);
 
   allocno_group_info *create_allocno_group (unsigned int, unsigned int);
   allocno_subgroup get_allocno_subgroup (rtx);
@@ -1345,6 +1347,24 @@ early_ra::record_live_range_failure (T dump)
 }
 }
 
+// Record that the allocation of the current region has filed.  Call DUMP to
+// dump the reason to a dump file.
+template
+void
+early_ra::record_allocation_failure (T dump)
+{
+  if (!m_allocation_successful)
+return;
+
+  m_allocation_successful = false;
+  if (dump_file && (dump_flags & TDF_DETAILS))
+{
+  fprintf (dump_file, "Not allocating region: ");
+  dump ();
+  fprintf (dump_file, "\n");
+}
+}
+
 // Create and return an allocno group of size SIZE for register REGNO.
 // REGNO can be INVALID_REGNUM if the group just exists to allow
 // other groups to be chained together, and does not have any new
@@ -1473,7 +1493,9 @@ early_ra::get_allocno_subgroup (rtx reg)
  || ((flags & ALLOWS_NONFPR)
  && !FLOAT_MODE_P (GET_MODE (reg))
  && !VECTOR_MODE_P (GET_MODE (reg
-   m_allocation_successful = false;
+   record_allocation_failure ([&](){
+ fprintf (dump_file, "r%d has FPR and non-FPR references", regno);
+   });
 
   if (flags & ALLOWS_FPR8)
group->fpr_candidates &= 0xff;
@@ -1865,7 +1887,10 @@ early_ra::record_constraints (rtx_insn *insn)
  rtx op = recog_data.operand[opno];
  if (GET_CODE (op) == SCRATCH
  && reg_classes_intersect_p (op_alt[opno].cl, FP_REGS))
-   m_allocation_successful = false;
+   record_allocation_failure ([&](){
+ fprintf (dump_file, "insn %d has FPR match_scratch",
+  INSN_UID (insn));
+   });
 
  // Record filter information, which applies to the first register
  // in the operand.
@@ -1892,7 +1917,10 @@ early_ra::record_constraints (rtx_insn *insn)
 {
   if (dump_file && (dump_flags & TDF_DETAILS))
fprintf (dump_file, "   -- no match\n");
-  m_allocation_successful = false;
+  record_allocation_failure ([&](){
+   fprintf (dump_file, "no matching constraints for insn %d",
+INSN_UID (insn));
+  });
 }
 
   // Record if there is an output operand that is never earlyclobber and never
@@ -1920,7 +1948,10 @@ early_ra::record_constraints (rtx_insn *insn)
   // register, since we don't have IRA's ability to find an alternative.
   // It's better if earlier passes don't create this kind of situation.
   if (REG_P (op) && FP_REGNUM_P (REGNO (op)))
-   m_allocation_successful = false;
+   record_allocation_failure ([&](){
+ fprintf (dump_file, "operand %d of insn %d refers directly to %s",
+  opno, INSN_UID (insn), reg_names[REGNO (op)]);
+   });
 
   // Treat input operands as being earlyclobbered if an output is
   // sometimes earlyclobber and if the input never matches an output.
@@ -2903,7 +2934,9 @@ early_ra::allocate_colors ()
 
   if (best == INVALID_REGNUM)
{
- m_allocation_successful = false;
+ record_allocation_failure ([&](){
+   fprintf (dump_file, "no free register for color %d", color->id);
+ });
  return;
}


[gcc r15-5419] aarch64: Add early_ra::record_live_range_failure

2024-11-18 Thread Richard Sandiford via Gcc-cvs
https://gcc.gnu.org/g:716aa5a668388a09b27525dce847d8d36c4c2fab

commit r15-5419-g716aa5a668388a09b27525dce847d8d36c4c2fab
Author: Richard Sandiford 
Date:   Mon Nov 18 19:32:49 2024 +

aarch64: Add early_ra::record_live_range_failure

So far, early_ra has used a single m_allocation_successful bool
to record whether the current region is still being allocated.
But there are (at least) two reasons why we might pull out of
attempting an allocation:

(1) We can't track the liveness of individual FP allocnos,
due to some awkward subregs.

(2) We're afraid of doing a worse job than the proper allocator.

A later patch needs to distinguish (1) from other reasons, since
(1) means that the liveness information is not trustworthy.
(Currently we assume it is not trustworthy whenever
m_allocation_successful is false, but that's too conservative.)

gcc/
* config/aarch64/aarch64-early-ra.cc
(early_ra::record_live_range_failure): New member function.
(early_ra::m_accurate_live_ranges): New member variable.
(early_ra::start_new_region): Set m_accurate_live_ranges to true.
(early_ra::get_allocno_subgroup): Use record_live_range_failure
to abort the allocation on invalid subregs.

Diff:
---
 gcc/config/aarch64/aarch64-early-ra.cc | 39 --
 1 file changed, 37 insertions(+), 2 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-early-ra.cc 
b/gcc/config/aarch64/aarch64-early-ra.cc
index d6ed7fee48b6..bf8827f33427 100644
--- a/gcc/config/aarch64/aarch64-early-ra.cc
+++ b/gcc/config/aarch64/aarch64-early-ra.cc
@@ -439,6 +439,9 @@ private:
 
   void start_new_region ();
 
+  template
+  void record_live_range_failure (T);
+
   allocno_group_info *create_allocno_group (unsigned int, unsigned int);
   allocno_subgroup get_allocno_subgroup (rtx);
   void record_fpr_use (unsigned int);
@@ -551,6 +554,10 @@ private:
   // current function.
   unsigned int m_call_preserved_fprs;
 
+  // True if we have so far been able to track the live ranges of individual
+  // allocnos.
+  bool m_accurate_live_ranges;
+
   // True if we haven't yet failed to allocate the current region.
   bool m_allocation_successful;
 
@@ -1314,10 +1321,30 @@ early_ra::start_new_region ()
   m_dead_insns.truncate (0);
   m_allocated_fprs = 0;
   m_call_preserved_fprs = 0;
+  m_accurate_live_ranges = true;
   m_allocation_successful = true;
   m_current_region += 1;
 }
 
+// Record that we can no longer track the liveness of individual allocnos.
+// Call DUMP to dump the reason to a dump file.
+template
+void
+early_ra::record_live_range_failure (T dump)
+{
+  if (!m_accurate_live_ranges)
+return;
+
+  m_accurate_live_ranges = false;
+  m_allocation_successful = false;
+  if (dump_file && (dump_flags & TDF_DETAILS))
+{
+  fprintf (dump_file, "Unable to track live ranges further: ");
+  dump ();
+  fprintf (dump_file, "\n");
+}
+}
+
 // Create and return an allocno group of size SIZE for register REGNO.
 // REGNO can be INVALID_REGNUM if the group just exists to allow
 // other groups to be chained together, and does not have any new
@@ -1390,7 +1417,12 @@ early_ra::get_allocno_subgroup (rtx reg)
   if (!targetm.modes_tieable_p (GET_MODE (SUBREG_REG (reg)),
GET_MODE (reg)))
{
- m_allocation_successful = false;
+ record_live_range_failure ([&](){
+   fprintf (dump_file, "cannot refer to r%d:%s in mode %s",
+REGNO (SUBREG_REG (reg)),
+GET_MODE_NAME (GET_MODE (SUBREG_REG (reg))),
+GET_MODE_NAME (GET_MODE (reg)));
+ });
  return {};
}
 
@@ -1399,7 +1431,10 @@ early_ra::get_allocno_subgroup (rtx reg)
   SUBREG_BYTE (reg), GET_MODE (reg), &info);
   if (!info.representable_p)
{
- m_allocation_successful = false;
+ record_live_range_failure ([&](){
+   fprintf (dump_file, "subreg of r%d is invalid for V0",
+REGNO (SUBREG_REG (reg)));
+ });
  return {};
}


[gcc r15-5425] Fix test failures for enum-alias-{1, 2, 3} on arm-eabi [PR117419]

2024-11-18 Thread Martin Uecker via Gcc-cvs
https://gcc.gnu.org/g:a3098b9a7281adef2028c2be3674094697557c2c

commit r15-5425-ga3098b9a7281adef2028c2be3674094697557c2c
Author: Martin Uecker 
Date:   Tue Nov 12 18:08:17 2024 +0100

Fix test failures for enum-alias-{1,2,3} on arm-eabi [PR117419]

The tests added for PR115157 fail on arm-eabi.  Add __INT_MAX__
to enum to make sure they have size int.

PR testsuite/117419

gcc/testsuite/ChangeLog:
* gcc.dg/enum-alias-1.c: Add __INT_MAX__.
* gcc.dg/enum-alias-2.c: Likewise.
* gcc.dg/enum-alias-3.c: Likewise.

Tested-by: Thiago Jung Bauermann 

Diff:
---
 gcc/testsuite/gcc.dg/enum-alias-1.c | 2 +-
 gcc/testsuite/gcc.dg/enum-alias-2.c | 2 +-
 gcc/testsuite/gcc.dg/enum-alias-3.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/enum-alias-1.c 
b/gcc/testsuite/gcc.dg/enum-alias-1.c
index 8fa30eb78970..a91eb666ac26 100644
--- a/gcc/testsuite/gcc.dg/enum-alias-1.c
+++ b/gcc/testsuite/gcc.dg/enum-alias-1.c
@@ -1,7 +1,7 @@
 /* { dg-do run } */
 /* { dg-options "-O2" } */
 
-enum E { E1 = -1, E2 = 0, E3 = 1 };
+enum E { E1 = -1, E2 = 0, E3 = 1, MAX = __INT_MAX__ };
 
 typedef int A;
 typedef enum E B;
diff --git a/gcc/testsuite/gcc.dg/enum-alias-2.c 
b/gcc/testsuite/gcc.dg/enum-alias-2.c
index 7ca3f3b2db8c..f107968435cf 100644
--- a/gcc/testsuite/gcc.dg/enum-alias-2.c
+++ b/gcc/testsuite/gcc.dg/enum-alias-2.c
@@ -9,7 +9,7 @@ void* foo(void* a, void *b, void *c, void *d)
 
{
typedef enum E B;
-   enum E { E1 = -1, E2 = 0, E3 = 1 };
+   enum E { E1 = -1, E2 = 0, E3 = 1, MAX = __INT_MAX__ };
*(B**)b = d;
}
 
diff --git a/gcc/testsuite/gcc.dg/enum-alias-3.c 
b/gcc/testsuite/gcc.dg/enum-alias-3.c
index 322c8d82952c..fd226a41408d 100644
--- a/gcc/testsuite/gcc.dg/enum-alias-3.c
+++ b/gcc/testsuite/gcc.dg/enum-alias-3.c
@@ -9,7 +9,7 @@ void* foo(void* a, void *b, void *c, void *d)
*(A**)a = c;
 
typedef enum E *B;
-   enum E { E1 = -1, E2 = 0, E3 = 1 };
+   enum E { E1 = -1, E2 = 0, E3 = 1, MAX = __INT_MAX__ };
{
*(B**)b = d;
}


[gcc r15-5423] aarch64: Improve early-ra handling of reductions

2024-11-18 Thread Richard Sandiford via Gcc-cvs
https://gcc.gnu.org/g:8633bdb346be748bb4dcd774ab63a01378e6af48

commit r15-5423-g8633bdb346be748bb4dcd774ab63a01378e6af48
Author: Richard Sandiford 
Date:   Mon Nov 18 19:32:51 2024 +

aarch64: Improve early-ra handling of reductions

At the moment, early-ra ducks out of allocating any region
that contains a register with both a strong FPR affinity and
a strong GPR affinity.  The proper allocators are much better
at handling that situation.

But this means that early-ra tends not to allocate a region
of vector code that ends in a reduction to a scalar integer
if any later arithmetic is done on the scalar integer result.

Currently, if a block acts as an isolated allocation region, the pass
will try to split the block into subregions *between* instructions if
there are no live FPRs or FPR allocnos.  In the reduction case described
above, it's convenient to try the same thing *within* instructions.
If a block of vector code ends in a reduction, all FPRs and FPR
allocnos will be dead between the "use phase" and the "def phase"
of the reduction: the vector input will then have died, but the
scalar result will not yet have been born.

If we split the block that way, the problematic reduction result
will be part of the second region, which we can skip allocating,
but the vector work will be part of a separate region, which we
might be able to allocate.

This avoids a MOV in the testcase and also helps a small amount
with x264.

gcc/
* config/aarch64/aarch64-early-ra.cc
(early_ra::IGNORE_REG): New flag.
(early_ra::fpr_preference): Handle it.
(early_ra::record_constraints): Fail the allocation if an
IGNORE_REG output operand is not independent of the inputs.
(defines_multi_def_pseudo): New function.
(early_ra::could_split_region_here): New member function, split
out from...
(early_ra::process_block): ...here.  Try splitting a block into
multiple regions between the definition and use phases of an
instruction.  Set IGNORE_REG on the output registers if we do so.

gcc/testsuite/
* gcc.target/aarch64/early_ra_1.c: New test.

Diff:
---
 gcc/config/aarch64/aarch64-early-ra.cc| 108 +++---
 gcc/testsuite/gcc.target/aarch64/early_ra_1.c |  14 
 2 files changed, 113 insertions(+), 9 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-early-ra.cc 
b/gcc/config/aarch64/aarch64-early-ra.cc
index 33d82ea64c2a..3d5355b040e4 100644
--- a/gcc/config/aarch64/aarch64-early-ra.cc
+++ b/gcc/config/aarch64/aarch64-early-ra.cc
@@ -160,6 +160,9 @@ private:
   // as a multi-register vector operand in some other non-move instruction.
   static constexpr unsigned int HAS_FLEXIBLE_STRIDE = 1U << 10;
   static constexpr unsigned int HAS_FIXED_STRIDE = 1U << 11;
+  //
+  // Whether we have decided not to allocate the pseudo register.
+  static constexpr unsigned int IGNORE_REG = 1U << 12;
 
   // Flags that should be propagated across moves between pseudo registers.
   static constexpr unsigned int PSEUDO_COPY_FLAGS = ~(HAS_FLEXIBLE_STRIDE
@@ -500,6 +503,7 @@ private:
 
   void process_region ();
   bool is_dead_insn (rtx_insn *);
+  bool could_split_region_here ();
   void process_block (basic_block, bool);
   void process_blocks ();
 
@@ -1227,7 +1231,9 @@ early_ra::fpr_preference (unsigned int regno)
 {
   auto mode = m_pseudo_regs[regno].mode;
   auto flags = m_pseudo_regs[regno].flags;
-  if (mode == VOIDmode || !targetm.hard_regno_mode_ok (V0_REGNUM, mode))
+  if (flags & IGNORE_REG)
+return -4;
+  else if (mode == VOIDmode || !targetm.hard_regno_mode_ok (V0_REGNUM, mode))
 return -3;
   else if (flags & HAS_FLEXIBLE_STRIDE)
 return 3;
@@ -1932,19 +1938,34 @@ early_ra::record_constraints (rtx_insn *insn)
   });
 }
 
-  // Record if there is an output operand that is never earlyclobber and never
-  // matched to an input.  See the comment below for how this is used.
   rtx dest_op = NULL_RTX;
   for (int opno = 0; opno < recog_data.n_operands; ++opno)
 {
+  rtx op = recog_data.operand[opno];
   auto op_mask = operand_mask (1) << opno;
+  // Record if there is an output operand that is "independent" of the
+  // inputs, in the sense that it is never earlyclobber and is never
+  // matched to an input.  See the comment below for how this is used.
   if (recog_data.operand_type[opno] == OP_OUT
  && (earlyclobber_operands & op_mask) == 0
  && (matched_operands & op_mask) == 0)
{
- dest_op = recog_data.operand[opno];
+ dest_op = op;
  break;
}
+  // We sometimes decide not to allocate pseudos even if they meet
+  // the normal FPR preference criteria; see the setters of IGNORE_REG
+  // for details.  However, the premise is that

[gcc r15-5392] libgomp/plugin/plugin-gcn.c: async-queue init - fix function-return type and fail fatally

2024-11-18 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:884637b6362391921100efa2c7db4f4452e2a13f

commit r15-5392-g884637b6362391921100efa2c7db4f4452e2a13f
Author: Tobias Burnus 
Date:   Mon Nov 18 14:58:21 2024 +0100

libgomp/plugin/plugin-gcn.c: async-queue init - fix function-return type 
and fail fatally

libgomp/ChangeLog:

* plugin/plugin-gcn.c (GOMP_OFFLOAD_openacc_async_construct): In
case of an error, call GOMP_PLUGIN_fatal not ..._error; use NULL
not false in return.

Diff:
---
 libgomp/plugin/plugin-gcn.c | 16 +---
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/libgomp/plugin/plugin-gcn.c b/libgomp/plugin/plugin-gcn.c
index f2f2940de9db..d26b93657bf6 100644
--- a/libgomp/plugin/plugin-gcn.c
+++ b/libgomp/plugin/plugin-gcn.c
@@ -4388,7 +4388,9 @@ GOMP_OFFLOAD_openacc_async_exec (void (*fn_ptr) (void *),
   gcn_exec (kernel, devaddrs, dims, targ_mem_desc, true, aq);
 }
 
-/* Create a new asynchronous thread and queue for running future kernels.  */
+/* Create a new asynchronous thread and queue for running future kernels;
+   issues a fatal error if the queue cannot be created as all callers expect
+   that the queue exists.  */
 
 struct goacc_asyncqueue *
 GOMP_OFFLOAD_openacc_async_construct (int device)
@@ -4416,18 +4418,18 @@ GOMP_OFFLOAD_openacc_async_construct (int device)
 
   if (pthread_mutex_init (&aq->mutex, NULL))
 {
-  GOMP_PLUGIN_error ("Failed to initialize a GCN agent queue mutex");
-  return false;
+  GOMP_PLUGIN_fatal ("Failed to initialize a GCN agent queue mutex");
+  return NULL;
 }
   if (pthread_cond_init (&aq->queue_cond_in, NULL))
 {
-  GOMP_PLUGIN_error ("Failed to initialize a GCN agent queue cond");
-  return false;
+  GOMP_PLUGIN_fatal ("Failed to initialize a GCN agent queue cond");
+  return NULL;
 }
   if (pthread_cond_init (&aq->queue_cond_out, NULL))
 {
-  GOMP_PLUGIN_error ("Failed to initialize a GCN agent queue cond");
-  return false;
+  GOMP_PLUGIN_fatal ("Failed to initialize a GCN agent queue cond");
+  return NULL;
 }
 
   hsa_status_t status = hsa_fns.hsa_queue_create_fn (agent->id,


[gcc(refs/users/meissner/heads/work186-bugs)] Revert changes

2024-11-18 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:72607d8e90fa1a90fff2a5a3f28ff16130ad6974

commit 72607d8e90fa1a90fff2a5a3f28ff16130ad6974
Author: Michael Meissner 
Date:   Sun Nov 17 23:26:02 2024 -0500

Revert changes

Diff:
---
 gcc/config/rs6000/rs6000.md   | 46 -
 gcc/testsuite/gcc.target/powerpc/pr108958-2.c | 97 ---
 gcc/testsuite/gcc.target/powerpc/pr108958.c   | 73 
 3 files changed, 216 deletions(-)

diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index bfb02b07ef4e..d266f93ff2e4 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -1026,52 +1026,6 @@
(set_attr "dot" "yes")
(set_attr "length" "4,8")])
 
-(define_insn_and_split "zero_extendditi2"
-  [(set (match_operand:TI 0 "gpc_reg_operand" "=r,wa,&wa")
-   (zero_extend:TI
-(match_operand:DI 1 "gpc_reg_operand" "rwa,r,wa")))]
-  "TARGET_P9_VECTOR && TARGET_POWERPC64"
-  "@
-  #
-  mtvsrdd %x0,0,%1
-  #"
-  "&& reload_completed
-   && (int_reg_operand (operands[0], TImode)
-   || vsx_register_operand (operands[1], DImode))"
-  [(set (match_dup 2)
-   (match_dup 3))
-   (set (match_dup 4)
-   (match_dup 5))]
-{
-  rtx op0 = operands[0];
-  rtx op1 = operands[1];
-  int r = reg_or_subregno (op0);
-
-  if (int_reg_operand (op0, TImode))
-{
-  int lo = BYTES_BIG_ENDIAN ? 1 : 0;
-  int hi = 1 - lo;
-
-  operands[2] = gen_rtx_REG (DImode, r + lo);
-  operands[3] = op1;
-  operands[4] = gen_rtx_REG (DImode, r + hi);
-  operands[5] = const0_rtx;
-}
-  else
-{
-  rtx op0_di = gen_rtx_REG (DImode, r);
-  rtx op0_v2di = gen_rtx_REG (V2DImode, r);
-  rtx lo = WORDS_BIG_ENDIAN ? op1 : op0_di;
-  rtx hi = WORDS_BIG_ENDIAN ? op0_di : op1;
-
-  operands[2] = op0_v2di;
-  operands[3] = CONST0_RTX (V2DImode);
-  operands[4] = op0_v2di;
-  operands[5] = gen_rtx_VEC_CONCAT (V2DImode, hi, lo);
-}
-}
-  [(set_attr "type" "*,mtvsr,vecperm")
-   (set_attr "length" "8,*,8")])
 
 (define_insn "extendqi2"
   [(set (match_operand:EXTQI 0 "gpc_reg_operand" "=r,?*v")
diff --git a/gcc/testsuite/gcc.target/powerpc/pr108958-2.c 
b/gcc/testsuite/gcc.target/powerpc/pr108958-2.c
deleted file mode 100644
index d75f0ca602bc..
--- a/gcc/testsuite/gcc.target/powerpc/pr108958-2.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/* { dg-do run P target { lp64 && p9vector_hw && int128 } } */
-/* { dg-options "-mdejagnu-cpu=power9 -O2" } */
-
-/* PR target/108958, use mtvsrdd to zero extend gpr to vsx register.  */
-
-#include 
-
-union u {
-  double d;
-  unsigned long long u64;
-};
-
-void
-gpr_to_vsx (unsigned long long x, __uint128_t *p)
-{
-  /* mtvsrdd vsx,0,gpr.  */
-  __uint128_t y = x;
-  __asm__ (" # %x0" : "+wa" (y));
-  *p = y;
-}
-
-void
-vsx_to_vsx (double d, __uint128_t *p)
-{
-  unsigned long long x;
-  __uint128_t y;
-  union u u2;
-
-  u2.d = d;
-  x = u2.u64;
-
-  __asm__ (" # %x0" : "+wa" (x));
-
-  /* xxspltib and xxpermdi.  */
-  y = x;
-  __asm__ (" # %x0" : "+wa" (y));
-
-  *p = y;
-}
-
-void
-gpr_to_gpr (unsigned long long x, __uint128_t *p)
-{
-  /* mr and li.  */
-  __uint128_t y = x;
-  __asm__ (" # %0" : "+r" (y));
-  *p = y;
-}
-
-void
-vsx_to_gpr (double d, __uint128_t *p)
-{
-  unsigned long long x;
-  __uint128_t y;
-  union u u2;
-
-  u2.d = d;
-  x = u2.u64;
-
-  __asm__ (" # %x0" : "+wa" (x));
-
-  /* mfvsrd and li.  */
-  y = x;
-  __asm__ (" # %0" : "+r" (y));
-
-  *p = y;
-}
-
-__uint128_t result[4];
-
-int
-main (void)
-{
-  union u u2, u3;
-
-  gpr_to_vsx (3, &result[0]);
-  vsx_to_vsx (4.0, &result[1]);
-  gpr_to_gpr (5, &result[2]);
-  vsx_to_gpr (6.0, &result[3]);
-
-  u2.d = 4.0;
-  u3.d = 6.0;
-
-  if (result[0] != 3)
-abort ();
-
-  if (result[1] != u2.u64)
-abort ();
-
-  if (result[2] != 5)
-abort ();
-
-  if (result[3] != u3.u64)
-abort ();
-
-  return 0;
-}
diff --git a/gcc/testsuite/gcc.target/powerpc/pr108958.c 
b/gcc/testsuite/gcc.target/powerpc/pr108958.c
deleted file mode 100644
index 52a969507cb1..
--- a/gcc/testsuite/gcc.target/powerpc/pr108958.c
+++ /dev/null
@@ -1,73 +0,0 @@
-/* { dg-do compile } */
-/* { dg-require-effective-target int128 } */
-/* { dg-require-effective-target lp64 } */
-/* { dg-options "-mdejagnu-cpu=power9 -O2" } */
-
-/* PR target/108958, use mtvsrdd to zero extend gpr to vsx register.  */
-
-union u {
-  double d;
-  unsigned long long u64;
-};
-
-void
-gpr_to_vsx (unsigned long long x, __uint128_t *p)
-{
-  /* mtvsrdd vsx,0,gpr.  */
-  __uint128_t y = x;
-  __asm__ (" # %x0" : "+wa" (y));
-  *p = y;
-}
-
-void
-vsx_to_vsx (double d, __uint128_t *p)
-{
-  unsigned long long x;
-  __uint128_t y;
-  union u u2;
-
-  u2.d = d;
-  x = u2.u64;
-
-  __asm__ (" # %x0" : "+wa" (x));
-
-  /* xxspltib and xxpermdi.  */
-  y = x;
-  __asm__ (" # %x0" : "+wa" (y));
-
-  *p = y;
-}
-
-void
-gpr_to_gpr (unsigned long long x, __uint128_t *p)
-{
-  /* mr and li.  */
-  __uint128_t y = x;
-  __asm__ (" # %

[gcc(refs/users/meissner/heads/work186-bugs)] PR target/108958 -- use mtvsrdd to zero extend GPR DImode to VSX TImode

2024-11-18 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:a5a5aa1275e77101110276ada3b1da4344e71aef

commit a5a5aa1275e77101110276ada3b1da4344e71aef
Author: Michael Meissner 
Date:   Sun Nov 17 23:16:46 2024 -0500

PR target/108958 -- use mtvsrdd to zero extend GPR DImode to VSX TImode

Previously GCC would zero externd a DImode GPR value to TImode by first zero
extending the DImode value into a GPR TImode value, and then do a MTVSRDD to
move this value to a VSX register.

This patch does the move directly, since if the middle argument to MTVSRDD 
is 0,
it does the zero extend.

This patch also generates LXVRDX if the DImode value is in memory.

Finally, it the DImode is already in a vector register, it does a XXSPLTIB 
and
XXPERMDI to get the value into the bottom 64-bits of the register.

I have built GCC with the patches in this patch set applied on both little 
and
big endian PowerPC systems and there were no regressions.  Can I apply this
patch to GCC 15?

2024-11-17  Michael Meissner  

gcc/

PR target/108598
* gcc/config/rs6000/rs6000.md (zero_extendditi2): New insn.

gcc/testsuite/

PR target/108598
* gcc.target/powerpc/pr108958.c: New test.
* gcc.target/powerpc/pr108958-2.c: Likewise.

Diff:
---
 gcc/config/rs6000/rs6000.md   | 46 +
 gcc/testsuite/gcc.target/powerpc/pr108958-2.c | 97 +++
 gcc/testsuite/gcc.target/powerpc/pr108958.c   | 73 
 3 files changed, 216 insertions(+)

diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index d266f93ff2e4..bfb02b07ef4e 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -1026,6 +1026,52 @@
(set_attr "dot" "yes")
(set_attr "length" "4,8")])
 
+(define_insn_and_split "zero_extendditi2"
+  [(set (match_operand:TI 0 "gpc_reg_operand" "=r,wa,&wa")
+   (zero_extend:TI
+(match_operand:DI 1 "gpc_reg_operand" "rwa,r,wa")))]
+  "TARGET_P9_VECTOR && TARGET_POWERPC64"
+  "@
+  #
+  mtvsrdd %x0,0,%1
+  #"
+  "&& reload_completed
+   && (int_reg_operand (operands[0], TImode)
+   || vsx_register_operand (operands[1], DImode))"
+  [(set (match_dup 2)
+   (match_dup 3))
+   (set (match_dup 4)
+   (match_dup 5))]
+{
+  rtx op0 = operands[0];
+  rtx op1 = operands[1];
+  int r = reg_or_subregno (op0);
+
+  if (int_reg_operand (op0, TImode))
+{
+  int lo = BYTES_BIG_ENDIAN ? 1 : 0;
+  int hi = 1 - lo;
+
+  operands[2] = gen_rtx_REG (DImode, r + lo);
+  operands[3] = op1;
+  operands[4] = gen_rtx_REG (DImode, r + hi);
+  operands[5] = const0_rtx;
+}
+  else
+{
+  rtx op0_di = gen_rtx_REG (DImode, r);
+  rtx op0_v2di = gen_rtx_REG (V2DImode, r);
+  rtx lo = WORDS_BIG_ENDIAN ? op1 : op0_di;
+  rtx hi = WORDS_BIG_ENDIAN ? op0_di : op1;
+
+  operands[2] = op0_v2di;
+  operands[3] = CONST0_RTX (V2DImode);
+  operands[4] = op0_v2di;
+  operands[5] = gen_rtx_VEC_CONCAT (V2DImode, hi, lo);
+}
+}
+  [(set_attr "type" "*,mtvsr,vecperm")
+   (set_attr "length" "8,*,8")])
 
 (define_insn "extendqi2"
   [(set (match_operand:EXTQI 0 "gpc_reg_operand" "=r,?*v")
diff --git a/gcc/testsuite/gcc.target/powerpc/pr108958-2.c 
b/gcc/testsuite/gcc.target/powerpc/pr108958-2.c
new file mode 100644
index ..d75f0ca602bc
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr108958-2.c
@@ -0,0 +1,97 @@
+/* { dg-do run P target { lp64 && p9vector_hw && int128 } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2" } */
+
+/* PR target/108958, use mtvsrdd to zero extend gpr to vsx register.  */
+
+#include 
+
+union u {
+  double d;
+  unsigned long long u64;
+};
+
+void
+gpr_to_vsx (unsigned long long x, __uint128_t *p)
+{
+  /* mtvsrdd vsx,0,gpr.  */
+  __uint128_t y = x;
+  __asm__ (" # %x0" : "+wa" (y));
+  *p = y;
+}
+
+void
+vsx_to_vsx (double d, __uint128_t *p)
+{
+  unsigned long long x;
+  __uint128_t y;
+  union u u2;
+
+  u2.d = d;
+  x = u2.u64;
+
+  __asm__ (" # %x0" : "+wa" (x));
+
+  /* xxspltib and xxpermdi.  */
+  y = x;
+  __asm__ (" # %x0" : "+wa" (y));
+
+  *p = y;
+}
+
+void
+gpr_to_gpr (unsigned long long x, __uint128_t *p)
+{
+  /* mr and li.  */
+  __uint128_t y = x;
+  __asm__ (" # %0" : "+r" (y));
+  *p = y;
+}
+
+void
+vsx_to_gpr (double d, __uint128_t *p)
+{
+  unsigned long long x;
+  __uint128_t y;
+  union u u2;
+
+  u2.d = d;
+  x = u2.u64;
+
+  __asm__ (" # %x0" : "+wa" (x));
+
+  /* mfvsrd and li.  */
+  y = x;
+  __asm__ (" # %0" : "+r" (y));
+
+  *p = y;
+}
+
+__uint128_t result[4];
+
+int
+main (void)
+{
+  union u u2, u3;
+
+  gpr_to_vsx (3, &result[0]);
+  vsx_to_vsx (4.0, &result[1]);
+  gpr_to_gpr (5, &result[2]);
+  vsx_to_gpr (6.0, &result[3]);
+
+  u2.d = 4.0;
+  u3.d = 6.0;
+
+  if (result[0] != 3)
+abort ();
+
+  if (result[1] != u2.u64)
+abort ();
+
+  if (result[2] != 5)
+abort ();
+
+  if (result[3] != 

[gcc r15-5396] ada: Small cleanup in expansion of array aggregates in allocators

2024-11-18 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:856467a7e6d2d24d8816b2036ae5fd52c3e91145

commit r15-5396-g856467a7e6d2d24d8816b2036ae5fd52c3e91145
Author: Eric Botcazou 
Date:   Tue Nov 5 11:24:06 2024 +0100

ada: Small cleanup in expansion of array aggregates in allocators

Convert_Array_Aggr_In_Allocator does nothing that Late_Expansion cannot do,
so this deletes the former and moves its support code for Storage_Model to
the latter.  No functional changes.

gcc/ada/ChangeLog:

* exp_aggr.adb (Convert_Array_Aggr_In_Allocator): Delete.
(Convert_Aggr_In_Allocator): Do not call above procedure.
(Late_Expansion): Deal with a target that is the dereference of a
prefix with a Storage_Model.  Remove an useless actual parameter
in the call to Build_Array_Aggr_Code.

Diff:
---
 gcc/ada/exp_aggr.adb | 103 +--
 1 file changed, 25 insertions(+), 78 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 7f2a47069412..eabbc6a0df50 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -296,13 +296,6 @@ package body Exp_Aggr is
--Indexes is the current list of expressions used to index the object we
--are writing into.
 
-   procedure Convert_Array_Aggr_In_Allocator (N : Node_Id; Target : Node_Id);
-   --  If the aggregate appears within an allocator and can be expanded in
-   --  place, this routine generates the individual assignments to components
-   --  of the designated object. This is an optimization over the general
-   --  case, where a temporary is first created on the stack and then used to
-   --  construct the allocated object on the heap.
-
procedure Convert_To_Positional
  (N : Node_Id;
   Handle_Bit_Packed : Boolean := False);
@@ -3519,10 +3512,7 @@ package body Exp_Aggr is
   Make_Explicit_Dereference (Loc, New_Occurrence_Of (Temp, Loc)));
 
begin
-  if Is_Array_Type (Typ) then
- Convert_Array_Aggr_In_Allocator (N, Occ);
-
-  elsif Has_Default_Init_Comps (Aggr) then
+  if Has_Default_Init_Comps (Aggr) then
  declare
 Init_Stmts : constant List_Id := Late_Expansion (Aggr, Typ, Occ);
 
@@ -3742,66 +3732,6 @@ package body Exp_Aggr is
   Initialize_Discriminants (N, Typ);
end Convert_Aggr_In_Object_Decl;
 
-   -
-   -- Convert_Array_Aggr_In_Allocator --
-   -
-
-   procedure Convert_Array_Aggr_In_Allocator (N : Node_Id; Target : Node_Id) is
-  Aggr : constant Node_Id   := Unqualify (Expression (N));
-  Typ  : constant Entity_Id := Etype (Aggr);
-  Ctyp : constant Entity_Id := Component_Type (Typ);
-
-  Aggr_Code : List_Id;
-  New_Aggr  : Node_Id;
-
-   begin
-  --  The target is an explicit dereference of the allocated object
-
-  --  If the assignment can be done directly by the back end, then
-  --  reset Set_Expansion_Delayed and do not expand further.
-
-  if not CodePeer_Mode
-and then Aggr_Assignment_OK_For_Backend (Aggr)
-  then
- New_Aggr := New_Copy_Tree (Aggr);
- Set_Expansion_Delayed (New_Aggr, False);
-
- --  In the case of Target's type using the Designated_Storage_Model
- --  aspect with a Copy_To procedure, insert a temporary and have the
- --  back end handle the assignment to it. Copy the result to the
- --  original target.
-
- if Has_Designated_Storage_Model_Aspect
-  (Etype (Prefix (Expression (Target
-   and then Present (Storage_Model_Copy_To
-   (Storage_Model_Object
-  (Etype (Prefix (Expression (Target))
- then
-Aggr_Code :=
-  Build_Assignment_With_Temporary (Target, Typ, New_Aggr);
-
- else
-Aggr_Code :=
-  New_List (
-Make_OK_Assignment_Statement (Sloc (New_Aggr),
-  Name   => Target,
-  Expression => New_Aggr));
- end if;
-
-  --  Or else, generate component assignments to it, as for an aggregate
-  --  that appears on the right-hand side of an assignment statement.
-  else
- Aggr_Code :=
-   Build_Array_Aggr_Code (Aggr,
- Ctype   => Ctyp,
- Index   => First_Index (Typ),
- Into=> Target,
- Scalar_Comp => Is_Scalar_Type (Ctyp));
-  end if;
-
-  Insert_Actions (N, Aggr_Code);
-   end Convert_Array_Aggr_In_Allocator;
-

-- In_Place_Assign_OK --

@@ -9028,11 +8958,29 @@ package body Exp_Aggr is
 New_Aggr := New_Copy_Tree (N);
 Set_Expansion_Delayed (New_Aggr, False);
 
-Aggr_Code :=
-  New_List (
-Make_OK_Assignment_Statement (Sloc (New_

[gcc r15-5395] ada: Constraint error not raised in ACATS test c413007

2024-11-18 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:7eafe8e9e9ec08f1d8b2f4ea0da2f47a7dedbeaa

commit r15-5395-g7eafe8e9e9ec08f1d8b2f4ea0da2f47a7dedbeaa
Author: Javier Miranda 
Date:   Sun Oct 20 12:13:03 2024 +

ada: Constraint error not raised in ACATS test c413007

Reverse the meaning of switch -gnatd_P; that is, enable by default
the generating of a runtime check when the prefix of the call is
an access-to-subprogram type with a null value.

gcc/ada/ChangeLog:

* sem_res.adb (Resolve_Actuals): Add by default a null-exclusion
check on the prefix of the call when it is an access-type; it can
be disabled using -gnatd_P.
* debug.adb (gnatd_P): Update documentation.

Diff:
---
 gcc/ada/debug.adb   | 17 +
 gcc/ada/sem_res.adb |  2 +-
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/gcc/ada/debug.adb b/gcc/ada/debug.adb
index 9daa0110233b..2d0c32b0f094 100644
--- a/gcc/ada/debug.adb
+++ b/gcc/ada/debug.adb
@@ -180,7 +180,7 @@ package body Debug is
--  d_M  Ignore Source_File_Name and Source_File_Name_Project pragmas
--  d_N
--  d_O
-   --  d_P  Enable runtime check for null prefix of prefixed subprogram call
+   --  d_P  Disable runtime check for null prefix of prefixed subprogram call
--  d_Q
--  d_R  For LLVM, dump the representation of records
--  d_S
@@ -1040,13 +1040,14 @@ package body Debug is
--   it is checked, and the progress of the recursive trace through
--   elaboration calls at compile time.
 
-   --  d_P  For prefixed subprogram calls with an access-type prefix, generate
-   --   a null-excluding runtime check on the prefix, even when the called
-   --   subprogram has a first access parameter that does not exclude null
-   --   (that is the case only for class-wide parameter, as controlling
-   --   parameters are automatically null-excluding). In such a case,
-   --   P.Proc is equivalent to Proc(P.all'Access); see RM 6.4(9.1/5).
-   --   This includes a dereference, and thus a null check.
+   --  d_P  For prefixed subprogram calls with an access-type prefix, disable
+   --   the generation of a null-excluding runtime check on the prefix,
+   --   even when the called subprogram has a first access parameter that
+   --   does not exclude null (that is the case only for class-wide
+   --   parameter, as controlling parameters are automatically null-
+   --   excluding). In such a case, P.Proc is equivalent to the call
+   --   Proc(P.all'Access); see RM 6.4(9.1/5). This includes a dereference,
+   --   and thus a null check.
 
--  d_R  In the LLVM backend, output the internal representation of
--   each record
diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
index d2b019aef173..2d0e2be18497 100644
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -4942,7 +4942,7 @@ package body Sem_Res is
A, Nam);
   end if;
 
-  if Debug_Flag_Underscore_PP
+  if not Debug_Flag_Underscore_PP
 and then
   (Is_Controlling_Formal (F)
  or else Is_Class_Wide_Type (Designated_Type (F_Typ)))


[gcc r15-5397] ada: Further cleanup in expansion of array aggregates in allocators

2024-11-18 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:7617b83242b19efa2216eb817befb53b75a6794c

commit r15-5397-g7617b83242b19efa2216eb817befb53b75a6794c
Author: Eric Botcazou 
Date:   Tue Nov 5 15:46:45 2024 +0100

ada: Further cleanup in expansion of array aggregates in allocators

This mainly decouples the handling of the allocator case from that of the
assignment case in Expand_Array_Aggregate and also makes Must_Slide a bit
more forgiving.

gcc/ada/ChangeLog:

* exp_aggr.adb (In_Place_Assign_OK): Remove handling of allocators
and call Must_Slide instead of implementing the check manually.
(Convert_To_Assignments): Adjust outdated comment.
(Expand_Array_Aggregate): Move handling of allocator case to STEP 3
and call Must_Slide directly for it.
(Must_Slide): Replace tests based on Is_OK_Static_Expression with
tests based on Compile_Time_Known_Value.

Diff:
---
 gcc/ada/exp_aggr.adb | 182 ---
 1 file changed, 58 insertions(+), 124 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index eabbc6a0df50..65ef081109b3 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -3997,10 +3997,6 @@ package body Exp_Aggr is
 
   --  Local variables
 
-  Aggr_In : Node_Id;
-  Aggr_Bounds : Range_Nodes;
-  Obj_In  : Node_Id;
-  Obj_Bounds  : Range_Nodes;
   Parent_Kind : Node_Kind;
   Parent_Node : Node_Id;
 
@@ -4025,86 +4021,15 @@ package body Exp_Aggr is
   --  assignment in place unless the bounds of the aggregate are
   --  statically equal to those of the target.
 
-  --  If the aggregate is given by an others choice, the bounds are
-  --  derived from the left-hand side, and the assignment is safe if
-  --  the expression is.
-
   if Is_Array
-and then Present (Component_Associations (N))
-and then not Is_Others_Aggregate (N)
+and then Must_Slide (N, Etype (Name (Parent_Node)), Etype (N))
   then
- Aggr_In := First_Index (Etype (N));
-
- --  Context is an assignment
-
- if Parent_Kind = N_Assignment_Statement then
-Obj_In := First_Index (Etype (Name (Parent_Node)));
-
- --  Context is an allocator. Check the bounds of the aggregate against
- --  those of the designated type, except in the case where the type is
- --  unconstrained (and then we can directly return true, see below).
-
- else pragma Assert (Parent_Kind = N_Allocator);
-declare
-   Desig_Typ : constant Entity_Id :=
- Designated_Type (Etype (Parent_Node));
-begin
-   if not Is_Constrained (Desig_Typ) then
-  return True;
-   end if;
-
-   Obj_In := First_Index (Desig_Typ);
-end;
- end if;
-
- while Present (Aggr_In) loop
-Aggr_Bounds := Get_Index_Bounds (Aggr_In);
-Obj_Bounds := Get_Index_Bounds (Obj_In);
-
---  We require static bounds for the target and a static matching
---  of low bound for the aggregate.
-
-if not Compile_Time_Known_Value (Obj_Bounds.First)
-  or else not Compile_Time_Known_Value (Obj_Bounds.Last)
-  or else not Compile_Time_Known_Value (Aggr_Bounds.First)
-  or else Expr_Value (Aggr_Bounds.First) /=
-  Expr_Value (Obj_Bounds.First)
-then
-   return False;
-
---  For an assignment statement we require static matching of
---  bounds. Ditto for an allocator whose qualified expression
---  is a constrained type. If the expression in the allocator
---  is an unconstrained array, we accept an upper bound that
---  is not static, to allow for nonstatic expressions of the
---  base type. Clearly there are further possibilities (with
---  diminishing returns) for safely building arrays in place
---  here.
-
-elsif Parent_Kind = N_Assignment_Statement
-  or else Is_Constrained (Etype (Parent_Node))
-then
-   if not Compile_Time_Known_Value (Aggr_Bounds.Last)
- or else Expr_Value (Aggr_Bounds.Last) /=
- Expr_Value (Obj_Bounds.Last)
-   then
-  return False;
-   end if;
-end if;
-
-Next_Index (Aggr_In);
-Next_Index (Obj_In);
- end loop;
+ return False;
   end if;
 
-  --  Now check the component values themselves, except for an allocator
-  --  for which the target is newly allocated memory.
+  --  Now check the component values themselves
 
-  if Parent_Kind = N_Allocator then
- return True;
-  else
- return Safe_Aggregate (N);

[gcc r15-5394] ada: Crash on 'Access for Stream_Element_Array object

2024-11-18 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:1850d0dbd32cf0b2cfa3225f0f8fbe1754b37393

commit r15-5394-g1850d0dbd32cf0b2cfa3225f0f8fbe1754b37393
Author: squirek 
Date:   Thu Oct 24 17:02:53 2024 +

ada: Crash on 'Access for Stream_Element_Array object

This patch fixes a crash in the compiler when the actual for an anonymous
access type formal is an 'Access of a Sream_Element_Array object during
the calculation of said actual's accessibility level.

gcc/ada/ChangeLog:

* accessibility.adb (Accessibility_Level): Handle the Input 
attribute
case

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

diff --git a/gcc/ada/accessibility.adb b/gcc/ada/accessibility.adb
index a4129819109d..376eb9d0bb94 100644
--- a/gcc/ada/accessibility.adb
+++ b/gcc/ada/accessibility.adb
@@ -464,6 +464,23 @@ package body Accessibility is
 if Attribute_Name (E) = Name_Access then
return Accessibility_Level (Prefix (E));
 
+--  If we have reached a 'Input attribute then this is the
+--  the result of the expansion of an object declaration with
+--  an initial value featuring it. Is this the only case ???
+
+--  For example:
+
+--Opaque : aliased Stream_Element_Array :=
+--  Stream_Element_Array'Input (S);
+
+elsif Attribute_Name (E) = Name_Input then
+
+   --  Return the level of the enclosing declaration
+
+   return Make_Level_Literal
+(Innermost_Master_Scope_Depth
+  (Enclosing_Declaration (Expr)));
+
 --  Unchecked or unrestricted attributes have unlimited depth
 
 elsif Attribute_Name (E) in Name_Address


[gcc r15-5393] ada: Tweak test for predefined main unit

2024-11-18 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:28a69cb3db4525cb40c224a6beb0f5c4f9a94c57

commit r15-5393-g28a69cb3db4525cb40c224a6beb0f5c4f9a94c57
Author: Ronan Desplanques 
Date:   Mon Nov 4 17:57:15 2024 +0100

ada: Tweak test for predefined main unit

This change is part of an effort to reduce usage of
Is_Predefined_Filename.

gcc/ada/ChangeLog:

* frontend.adb (Frontend): tweak test for predefined main unit.

Diff:
---
 gcc/ada/frontend.adb | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/gcc/ada/frontend.adb b/gcc/ada/frontend.adb
index ea0c7b12b4a0..bb7a332986c8 100644
--- a/gcc/ada/frontend.adb
+++ b/gcc/ada/frontend.adb
@@ -380,9 +380,7 @@ begin
   --  Disable Initialize_Scalars for runtime files to avoid circular
   --  dependencies.
 
-  if Initialize_Scalars
-and then Fname.Is_Predefined_File_Name (File_Name (Main_Source_File))
-  then
+  if Initialize_Scalars and then Is_Predefined_Unit (Main_Unit) then
  Initialize_Scalars   := False;
  Init_Or_Norm_Scalars := Normalize_Scalars;
   end if;


[gcc r15-5398] ada: Cleanup in expansion of array aggregates in object declarations

2024-11-18 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:b2320a12dfe4a16514a3ad8ae1fbe27ab704ff15

commit r15-5398-gb2320a12dfe4a16514a3ad8ae1fbe27ab704ff15
Author: Eric Botcazou 
Date:   Wed Nov 6 16:09:28 2024 +0100

ada: Cleanup in expansion of array aggregates in object declarations

This mainly decouples the handling of the declaration case from that of the
assignment case in Expand_Array_Aggregate, as well as moves the expansion
in the case of an aggregate that can be processed by the back end to the
Build_Array_Aggr_Code routine.

gcc/ada/ChangeLog:

* exp_aggr.adb (Build_Array_Aggr_Code): Build the simple assignment
for the case of an aggregate that can be handled by the back end.
(Expand_Array_Aggregate): Adjust description of the processing.
Move handling of declaration case to STEP 4 and remove handling of
the case of an aggregate that can be processed by the back end.
(Late_Expansion): Likewise for the second part.
* exp_ch3.adb (Expand_N_Object_Declaration): Deal with a delayed
aggregate synthesized for the default initialization, if any.
* sem_eval.adb (Eval_Indexed_Component): Bail out for the name of
an assignment statement.

Diff:
---
 gcc/ada/exp_aggr.adb | 358 +--
 gcc/ada/exp_ch3.adb  |  21 ++-
 gcc/ada/sem_eval.adb |   8 ++
 3 files changed, 143 insertions(+), 244 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 65ef081109b3..c63d22b58fa4 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -1924,6 +1924,48 @@ package body Exp_Aggr is
--  Start of processing for Build_Array_Aggr_Code
 
begin
+  --  If the assignment can be done directly by the back end, then reset
+  --  the Set_Expansion_Delayed flag and do not expand further.
+
+  if Present (Etype (N))
+and then Aggr_Assignment_OK_For_Backend (N)
+and then not Possible_Bit_Aligned_Component (Into)
+and then not Is_Possibly_Unaligned_Slice (Into)
+and then not CodePeer_Mode
+  then
+ declare
+New_Aggr : constant Node_Id := Relocate_Node (N);
+Target   : constant Node_Id :=
+ (if Nkind (Into) = N_Unchecked_Type_Conversion
+  then Expression (Into)
+  else Into);
+ begin
+Set_Expansion_Delayed (New_Aggr, False);
+
+--  In the case where the target is the dereference of a prefix
+--  with Designated_Storage_Model aspect specifying the Copy_To
+--  procedure, first insert a temporary and have the back end
+--  handle the assignment to it, then assign the result to the
+--  original target.
+
+if Nkind (Target) = N_Explicit_Dereference
+  and then
+Has_Designated_Storage_Model_Aspect (Etype (Prefix (Target)))
+  and then Present (Storage_Model_Copy_To
+ (Storage_Model_Object
+   (Etype (Prefix (Target)
+then
+   return Build_Assignment_With_Temporary (Into, Typ, New_Aggr);
+
+else
+   return New_List (
+ Make_OK_Assignment_Statement (Loc,
+   Name   => Into,
+   Expression => New_Aggr));
+end if;
+ end;
+  end if;
+
   --  First before we start, a special case. If we have a bit packed
   --  array represented as a modular type, then clear the value to
   --  zero first, to ensure that unused bits are properly cleared.
@@ -4873,17 +4915,17 @@ package body Exp_Aggr is
--  2. Check for packed array aggregate which can be converted to a
-- constant so that the aggregate disappears completely.
 
-   --  3. Check case of nested aggregate. Generally nested aggregates are
-   -- handled during the processing of the parent aggregate.
-
-   --  4. Check if the aggregate can be statically processed. If this is the
+   --  3. Check if the aggregate can be statically processed. If this is the
-- case pass it as is to Gigi. Note that a necessary condition for
-- static processing is that the aggregate be fully positional.
 
-   --  5. If in-place aggregate expansion is possible (i.e. no need to create
-   -- a temporary) then mark the aggregate as such and return. Otherwise
-   -- create a new temporary and generate the appropriate initialization
-   -- code.
+   --  4. Check if delayed expansion is needed, for example in the cases of
+   -- nested aggregates or aggregates in allocators or declarations.
+
+   --  5. If in-place aggregate expansion is not possible, create a temporary
+   -- and generate the appropriate initialization code.
+
+   --  6. Build and insert the aggregate code
 
procedure Expand_A

[gcc r15-5370] hppa: Remove typedef for bool type

2024-11-18 Thread John David Anglin via Gcc-cvs
https://gcc.gnu.org/g:8f50a0794076d6e1d4d1ed693b94d6ee2e4cd849

commit r15-5370-g8f50a0794076d6e1d4d1ed693b94d6ee2e4cd849
Author: John David Anglin 
Date:   Sun Nov 17 14:42:39 2024 -0500

hppa: Remove typedef for bool type

In C23, bool is now a keyword.  So, doing a typedef for it is invalid.

2024-11-17  John David Anglin  

libgcc/ChangeLog:

PR target/117627
* config/pa/linux-atomic.c: Remove typedef for bool type.

Diff:
---
 libgcc/config/pa/linux-atomic.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libgcc/config/pa/linux-atomic.c b/libgcc/config/pa/linux-atomic.c
index 03ebccfc0707..6191f83ed1c7 100644
--- a/libgcc/config/pa/linux-atomic.c
+++ b/libgcc/config/pa/linux-atomic.c
@@ -264,8 +264,6 @@ OP_AND_FETCH_WORD (and,   , &)
 OP_AND_FETCH_WORD (xor,   , ^)
 OP_AND_FETCH_WORD (nand, ~, &)
 
-typedef unsigned char bool;
-
 #define COMPARE_AND_SWAP_2(TYPE, WIDTH, INDEX) \
   TYPE HIDDEN  \
   __sync_val_compare_and_swap_##WIDTH (volatile void *ptr, TYPE oldval,
\


[gcc r15-5389] RISC-V: Add else operand to masked loads [PR115336].

2024-11-18 Thread Robin Dapp via Gcc-cvs
https://gcc.gnu.org/g:b89273a049a76ffc29dd43a536ad329f0d994c05

commit r15-5389-gb89273a049a76ffc29dd43a536ad329f0d994c05
Author: Robin Dapp 
Date:   Thu Aug 8 10:31:22 2024 +0200

RISC-V: Add else operand to masked loads [PR115336].

This patch adds else operands to masked loads.  Currently the default
else operand predicate just accepts "undefined" (i.e. SCRATCH) values.

PR middle-end/115336
PR middle-end/116059

gcc/ChangeLog:

* config/riscv/autovec.md: Add else operand.
* config/riscv/predicates.md (maskload_else_operand): New
predicate.
* config/riscv/riscv-v.cc (get_else_operand): Remove static.
(expand_load_store): Use get_else_operand and adjust index.
(expand_gather_scatter): Ditto.
(expand_lanes_load_store): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/pr115336.c: New test.
* gcc.target/riscv/rvv/autovec/pr116059.c: New test.

Diff:
---
 gcc/config/riscv/autovec.md| 50 +-
 gcc/config/riscv/predicates.md |  3 ++
 gcc/config/riscv/riscv-v.cc| 30 -
 .../gcc.target/riscv/rvv/autovec/pr115336.c| 20 +
 .../gcc.target/riscv/rvv/autovec/pr116059.c| 15 +++
 5 files changed, 88 insertions(+), 30 deletions(-)

diff --git a/gcc/config/riscv/autovec.md b/gcc/config/riscv/autovec.md
index b5fbe98b5fc5..c64ef5a12b43 100644
--- a/gcc/config/riscv/autovec.md
+++ b/gcc/config/riscv/autovec.md
@@ -26,8 +26,9 @@
   [(match_operand:V 0 "register_operand")
(match_operand:V 1 "memory_operand")
(match_operand: 2 "vector_mask_operand")
-   (match_operand 3 "autovec_length_operand")
-   (match_operand 4 "const_0_operand")]
+   (match_operand:V 3 "maskload_else_operand")
+   (match_operand 4 "autovec_length_operand")
+   (match_operand 5 "const_0_operand")]
   "TARGET_VECTOR"
 {
   riscv_vector::expand_load_store (operands, true);
@@ -57,8 +58,9 @@
(match_operand 3 "")
(match_operand 4 "")
(match_operand: 5 "vector_mask_operand")
-   (match_operand 6 "autovec_length_operand")
-   (match_operand 7 "const_0_operand")]
+   (match_operand 6 "maskload_else_operand")
+   (match_operand 7 "autovec_length_operand")
+   (match_operand 8 "const_0_operand")]
   "TARGET_VECTOR && riscv_vector::gather_scatter_valid_offset_p 
(mode)"
 {
   riscv_vector::expand_gather_scatter (operands, true);
@@ -72,8 +74,9 @@
(match_operand 3 "")
(match_operand 4 "")
(match_operand: 5 "vector_mask_operand")
-   (match_operand 6 "autovec_length_operand")
-   (match_operand 7 "const_0_operand")]
+   (match_operand 6 "maskload_else_operand")
+   (match_operand 7 "autovec_length_operand")
+   (match_operand 8 "const_0_operand")]
   "TARGET_VECTOR && riscv_vector::gather_scatter_valid_offset_p 
(mode)"
 {
   riscv_vector::expand_gather_scatter (operands, true);
@@ -87,8 +90,9 @@
(match_operand 3 "")
(match_operand 4 "")
(match_operand: 5 "vector_mask_operand")
-   (match_operand 6 "autovec_length_operand")
-   (match_operand 7 "const_0_operand")]
+   (match_operand 6 "maskload_else_operand")
+   (match_operand 7 "autovec_length_operand")
+   (match_operand 8 "const_0_operand")]
   "TARGET_VECTOR && riscv_vector::gather_scatter_valid_offset_p 
(mode)"
 {
   riscv_vector::expand_gather_scatter (operands, true);
@@ -102,8 +106,9 @@
(match_operand 3 "")
(match_operand 4 "")
(match_operand: 5 "vector_mask_operand")
-   (match_operand 6 "autovec_length_operand")
-   (match_operand 7 "const_0_operand")]
+   (match_operand 6 "maskload_else_operand")
+   (match_operand 7 "autovec_length_operand")
+   (match_operand 8 "const_0_operand")]
   "TARGET_VECTOR && riscv_vector::gather_scatter_valid_offset_p 
(mode)"
 {
   riscv_vector::expand_gather_scatter (operands, true);
@@ -117,8 +122,9 @@
(match_operand 3 "")
(match_operand 4 "")
(match_operand: 5 "vector_mask_operand")
-   (match_operand 6 "autovec_length_operand")
-   (match_operand 7 "const_0_operand")]
+   (match_operand 6 "maskload_else_operand")
+   (match_operand 7 "autovec_length_operand")
+   (match_operand 8 "const_0_operand")]
   "TARGET_VECTOR && riscv_vector::gather_scatter_valid_offset_p 
(mode)"
 {
   riscv_vector::expand_gather_scatter (operands, true);
@@ -132,8 +138,9 @@
(match_operand 3 "")
(match_operand 4 "")
(match_operand: 5 "vector_mask_operand")
-   (match_operand 6 "autovec_length_operand")
-   (match_operand 7 "const_0_operand")]
+   (match_operand 6 "maskload_else_operand")
+   (match_operand 7 "autovec_length_operand")
+   (match_operand 8 "const_0_operand")]
   "TARGET_VECTOR && riscv_vector::gather_scatter_valid_offset_p 
(mode)"
 {
   riscv_vector::expand_gather_scatter (operands, true);
@@ -151,8 +158,9 @@
(match_operand 3 "")
(match_operand 4 "")
(match_operand: 5 "vector_m

[gcc r15-5426] i386: Enable *rsqrtsf2_sse without TARGET_SSE_MATH [PR117357]

2024-11-18 Thread Uros Bizjak via Gcc-cvs
https://gcc.gnu.org/g:344356f781ddb7bf0abb11edf9bdd13f6802dea8

commit r15-5426-g344356f781ddb7bf0abb11edf9bdd13f6802dea8
Author: Uros Bizjak 
Date:   Mon Nov 18 22:38:46 2024 +0100

i386: Enable *rsqrtsf2_sse without TARGET_SSE_MATH [PR117357]

__builtin_ia32_rsqrtsf2 expander generates UNSPEC_RSQRT insn pattern
also when TARGET_SSE_MATH is not set.  Enable *rsqrtsf2_sse without
TARGET_SSE_MATH to avoid ICE with unrecognizable insn.

PR target/117357

gcc/ChangeLog:

* config/i386/i386.md (*rsqrtsf2_sse):
Also enable for !TARGET_SSE_MATH.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr117357.c: New test.

Diff:
---
 gcc/config/i386/i386.md  | 2 +-
 gcc/testsuite/gcc.target/i386/pr117357.c | 7 +++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index 03b0f548467e..b2209492fa0e 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -23364,7 +23364,7 @@
   [(set (match_operand:SF 0 "register_operand" "=x,x,x,x")
(unspec:SF [(match_operand:SF 1 "nonimmediate_operand" "0,x,m,ja")]
   UNSPEC_RSQRT))]
-  "TARGET_SSE && TARGET_SSE_MATH"
+  "TARGET_SSE"
   "@
%vrsqrtss\t{%d1, %0|%0, %d1}
%vrsqrtss\t{%d1, %0|%0, %d1}
diff --git a/gcc/testsuite/gcc.target/i386/pr117357.c 
b/gcc/testsuite/gcc.target/i386/pr117357.c
new file mode 100644
index ..7a27691a9776
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr117357.c
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-msse -mfpmath=387" } */
+
+float foo (float f)
+{
+  return __builtin_ia32_rsqrtf (f);
+}


[gcc r15-5427] testsuite: move dg-test cleanup code from gcc-dg.exp to its own file

2024-11-18 Thread David Malcolm via Libstdc++-cvs
https://gcc.gnu.org/g:c9d21e19df2836b70365efbf759027b0f86a9b93

commit r15-5427-gc9d21e19df2836b70365efbf759027b0f86a9b93
Author: David Malcolm 
Date:   Mon Nov 18 16:49:04 2024 -0500

testsuite: move dg-test cleanup code from gcc-dg.exp to its own file

I need to use this cleanup logic for the testsuite for libdiagnostics
where it's too awkward to directly use gcc-dg.exp itself.

No functional change intended.

gcc/testsuite/ChangeLog:
* lib/dg-test-cleanup.exp: New file, from material moved from
lib/gcc-dg.exp.
* lib/gcc-dg.exp: Add load_lib of dg-test-cleanup.exp.
(cleanup-after-saved-dg-test): Move to lib/dg-test-cleanup.exp.
(dg-test): Likewise for override.
(initialize_prune_notes): Likewise.

libatomic/ChangeLog:
* testsuite/lib/libatomic.exp: Add
"load_gcc_lib dg-test-cleanup.exp".

libgomp/ChangeLog:
* testsuite/lib/libgomp.exp: Add
"load_gcc_lib dg-test-cleanup.exp".
libitm/ChangeLog:
* testsuite/lib/libitm.exp: Add
"load_gcc_lib dg-test-cleanup.exp".

libphobos/ChangeLog:
* testsuite/lib/libphobos-dg.exp: Add
"load_gcc_lib dg-test-cleanup.exp".

libstdc++-v3/ChangeLog:
* testsuite/lib/libstdc++.exp: Add
"load_gcc_lib dg-test-cleanup.exp".

libvtv/ChangeLog:
* testsuite/lib/libvtv.exp: Add
"load_gcc_lib dg-test-cleanup.exp".

Signed-off-by: David Malcolm 

Diff:
---
 gcc/testsuite/lib/dg-test-cleanup.exp| 116 +++
 gcc/testsuite/lib/gcc-dg.exp | 102 +--
 libatomic/testsuite/lib/libatomic.exp|   1 +
 libgomp/testsuite/lib/libgomp.exp|   1 +
 libitm/testsuite/lib/libitm.exp  |   1 +
 libphobos/testsuite/lib/libphobos-dg.exp |   1 +
 libstdc++-v3/testsuite/lib/libstdc++.exp |   1 +
 libvtv/testsuite/lib/libvtv.exp  |   1 +
 8 files changed, 123 insertions(+), 101 deletions(-)

diff --git a/gcc/testsuite/lib/dg-test-cleanup.exp 
b/gcc/testsuite/lib/dg-test-cleanup.exp
new file mode 100644
index ..b2b8507a0320
--- /dev/null
+++ b/gcc/testsuite/lib/dg-test-cleanup.exp
@@ -0,0 +1,116 @@
+#   Copyright (C) 1997-2024 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# .
+
+# We need to make sure that additional_* are cleared out after every
+# test.  It is not enough to clear them out *before* the next test run
+# because gcc-target-compile gets run directly from some .exp files
+# (outside of any test).  (Those uses should eventually be eliminated.)
+
+# Because the DG framework doesn't provide a hook that is run at the
+# end of a test, we must replace dg-test with a wrapper.
+
+if { [info procs saved-dg-test] == [list] } {
+rename dg-test saved-dg-test
+
+# Helper function for cleanups that should happen after the call
+# to the real dg-test, whether or not it returns normally, or
+# fails with an error.
+proc cleanup-after-saved-dg-test { } {
+   global additional_files
+   global additional_sources
+   global additional_sources_used
+   global additional_prunes
+   global compiler_conditional_xfail_data
+   global shouldfail
+   global expect_ice
+   global testname_with_flags
+   global set_target_env_var
+   global set_compiler_env_var
+   global saved_compiler_env_var
+   global keep_saved_temps_suffixes
+   global nn_line_numbers_enabled
+   global multiline_expected_outputs
+   global freeform_regexps
+   global save_linenr_varnames
+
+   set additional_files ""
+   set additional_sources ""
+   set additional_sources_used ""
+   set additional_prunes ""
+   set shouldfail 0
+   set expect_ice 0
+   if [info exists set_target_env_var] {
+   unset set_target_env_var
+   }
+   if [info exists set_compiler_env_var] {
+   restore-compiler-env-var
+   unset set_compiler_env_var
+   unset saved_compiler_env_var
+   }
+   if [info exists keep_saved_temps_suffixes] {
+   unset keep_saved_temps_suffixes
+   }
+   unset_timeout_vars
+   if [info exists compiler_conditional_xfail_data] {
+   un

[gcc(refs/users/meissner/heads/work186-bugs)] Revert changes

2024-11-18 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:1c6b11ccc285c06a0bb74e31a79a9880d56355cd

commit 1c6b11ccc285c06a0bb74e31a79a9880d56355cd
Author: Michael Meissner 
Date:   Sun Nov 17 20:26:48 2024 -0500

Revert changes

Diff:
---
 gcc/config/rs6000/rs6000.md | 26 
 gcc/testsuite/gcc.target/powerpc/pr108958.c | 47 -
 2 files changed, 73 deletions(-)

diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index e4c52f937d33..d266f93ff2e4 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -1026,32 +1026,6 @@
(set_attr "dot" "yes")
(set_attr "length" "4,8")])
 
-(define_insn_and_split "zero_extendditi2"
-  [(set (match_operand:TI 0 "gpc_reg_operand" "=r,r,wa,wa")
-   (zero_extend:TI
-(match_operand:DI 1 "reg_or_mem_operand" "r,m,r,Z")))]
-  "TARGET_DIRECT_MOVE_64BIT"
-  "@
-  #
-  #
-  mtvsrdd %x0,0,%1
-  lxvrdx %x0,%y1"
-  "&& reload_completed && int_reg_operand (operands[0], TImode)"
-  [(set (match_dup 2)
-   (match_dup 1))
-   (set (match_dup 3)
-   (const_int 0))]
-{
-  int lo = BYTES_BIG_ENDIAN ? 1 : 0;
-  int hi = 1 - lo;
-  int r = reg_or_subregno (operands[0]);
-
-  operands[2] = gen_rtx_REG (DImode, r + lo);
-  operands[3] = gen_rtx_REG (DImode, r + hi);
-}
-  [(set_attr "type" "*,load,mtvsr,vecload")
-   (set_attr "length" "8,8,*,*")
-   (set_attr "isa" "*,*,*,p10")])
 
 (define_insn "extendqi2"
   [(set (match_operand:EXTQI 0 "gpc_reg_operand" "=r,?*v")
diff --git a/gcc/testsuite/gcc.target/powerpc/pr108958.c 
b/gcc/testsuite/gcc.target/powerpc/pr108958.c
deleted file mode 100644
index aa79dc880c8e..
--- a/gcc/testsuite/gcc.target/powerpc/pr108958.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/* { dg-do compile } */
-/* { dg-require-effective-target int128 } */
-/* { dg-require-effective-target lp64 } */
-/* { dg-require-effective-target power10_ok } */
-/* { dg-options "-mdejagnu-cpu=power10 -O2" } */
-
-/* PR target/108958, use mtvsrdd to zero extend gpr to vsx register.  */
-
-void
-arg_to_vsx (unsigned long long x, __uint128_t *p)
-{
-  /* mtvsrdd vsx,0,gpr.  */
-  __uint128_t y = x;
-  __asm__ (" # %x0" : "+wa" (y));
-  *p = y;
-}
-
-void
-mem_to_vsx (unsigned long long *p, __uint128_t *q)
-{
-  /* lxrdx vsx,0,ptr.  */
-  __uint128_t y = *p;
-  __asm__ (" # %x0" : "+wa" (y));
-  *q = y;
-}
-
-
-void
-arg_to_gpr (unsigned long long x, __uint128_t *p)
-{
-  /* mr gpr1_lo,gpr2; li gpr1_hi,0.  */
-  __uint128_t y = x;
-  __asm__ (" # %0" : "+r" (y));
-  *p = y;
-}
-
-void
-mem_to_gpr (unsigned long long *p, __uint128_t *q)
-{
-  /* ld gpr1_lo,addr; li gpr1_hi,0.  */
-  __uint128_t y = *p;
-  __asm__ (" # %0" : "+r" (y));
-  *q = y;
-}
-
-/* { dg-final { scan-assembler-times {\mmtvsrdd .*,0,.*\M} 1 } } */
-/* { dg-final { scan-assembler-times {\mlxvrdx\M}  1 } } */


[gcc r15-5385] vect: Add maskload else value support.

2024-11-18 Thread Robin Dapp via Gcc-cvs
https://gcc.gnu.org/g:634ae740f5a839df6567c58cfdcd32a3833c4626

commit r15-5385-g634ae740f5a839df6567c58cfdcd32a3833c4626
Author: Robin Dapp 
Date:   Thu Aug 8 14:29:05 2024 +0200

vect: Add maskload else value support.

This patch adds an else operand to vectorized masked load calls.
The current implementation adds else-value arguments to the respective
target-querying functions that is used to supply the vectorizer with the
proper else value.

We query the target for its supported else operand and uses that for the
maskload call.  If necessary, i.e. if the mode has padding bits and if
the else operand is nonzero, a VEC_COND enforcing a zero else value is
emitted.

gcc/ChangeLog:

* optabs-query.cc (supports_vec_convert_optab_p): Return icode.
(get_supported_else_val): Return supported else value for
optab's operand at index.
(supports_vec_gather_load_p): Add else argument.
(supports_vec_scatter_store_p): Ditto.
* optabs-query.h (supports_vec_gather_load_p): Ditto.
(get_supported_else_val): Ditto.
* optabs-tree.cc (target_supports_mask_load_store_p): Ditto.
(can_vec_mask_load_store_p): Ditto.
(target_supports_len_load_store_p): Ditto.
(get_len_load_store_mode): Ditto.
* optabs-tree.h (target_supports_mask_load_store_p): Ditto.
(can_vec_mask_load_store_p): Ditto.
* tree-vect-data-refs.cc (vect_lanes_optab_supported_p): Ditto.
(vect_gather_scatter_fn_p): Ditto.
(vect_check_gather_scatter): Ditto.
(vect_load_lanes_supported): Ditto.
* tree-vect-patterns.cc (vect_recog_gather_scatter_pattern):
Ditto.
* tree-vect-slp.cc (vect_get_operand_map): Adjust indices for
else operand.
(vect_slp_analyze_node_operations): Skip undefined else operand.
* tree-vect-stmts.cc (exist_non_indexing_operands_for_use_p):
Add else operand handling.
(vect_get_vec_defs_for_operand): Handle undefined else operand.
(check_load_store_for_partial_vectors): Add else argument.
(vect_truncate_gather_scatter_offset): Ditto.
(vect_use_strided_gather_scatters_p): Ditto.
(get_group_load_store_type): Ditto.
(get_load_store_type): Ditto.
(vect_get_mask_load_else): Ditto.
(vect_get_else_val_from_tree): Ditto.
(vect_build_one_gather_load_call): Add zero else operand.
(vectorizable_load): Use else operand.
* tree-vectorizer.h (vect_gather_scatter_fn_p): Add else
argument.
(vect_load_lanes_supported): Ditto.
(vect_get_mask_load_else): Ditto.
(vect_get_else_val_from_tree): Ditto.

Diff:
---
 gcc/optabs-query.cc|  70 +++---
 gcc/optabs-query.h |   3 +-
 gcc/optabs-tree.cc |  66 ++---
 gcc/optabs-tree.h  |   8 +-
 gcc/tree-vect-data-refs.cc |  74 +++---
 gcc/tree-vect-patterns.cc  |  12 +-
 gcc/tree-vect-slp.cc   |  22 ++-
 gcc/tree-vect-stmts.cc | 326 +
 gcc/tree-vectorizer.h  |  10 +-
 9 files changed, 466 insertions(+), 125 deletions(-)

diff --git a/gcc/optabs-query.cc b/gcc/optabs-query.cc
index cc52bc0f5ea7..c1f3558af920 100644
--- a/gcc/optabs-query.cc
+++ b/gcc/optabs-query.cc
@@ -29,6 +29,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "rtl.h"
 #include "recog.h"
 #include "vec-perm-indices.h"
+#include "internal-fn.h"
+#include "memmodel.h"
+#include "optabs.h"
 
 struct target_optabs default_target_optabs;
 struct target_optabs *this_fn_optabs = &default_target_optabs;
@@ -672,34 +675,57 @@ lshift_cheap_p (bool speed_p)
that mode, given that the second mode is always an integer vector.
If MODE is VOIDmode, return true if OP supports any vector mode.  */
 
-static bool
-supports_vec_convert_optab_p (optab op, machine_mode mode)
+static enum insn_code
+supported_vec_convert_optab (optab op, machine_mode mode)
 {
   int start = mode == VOIDmode ? 0 : mode;
   int end = mode == VOIDmode ? MAX_MACHINE_MODE - 1 : mode;
+  enum insn_code icode = CODE_FOR_nothing;
   for (int i = start; i <= end; ++i)
 if (VECTOR_MODE_P ((machine_mode) i))
   for (int j = MIN_MODE_VECTOR_INT; j < MAX_MODE_VECTOR_INT; ++j)
-   if (convert_optab_handler (op, (machine_mode) i,
-  (machine_mode) j) != CODE_FOR_nothing)
- return true;
+   {
+ if ((icode
+  = convert_optab_handler (op, (machine_mode) i,
+   (machine_mode) j)) != CODE_FOR_nothing)
+   return icode;
+   }
 
-  return false;
+  return icode;
 }
 
 /* If MODE is not VOIDmode, return true if vec_gather_load is available for
that mode.  If MODE is V

[gcc r15-5406] ada: Fix interaction of aspect Predicate and static case expressions

2024-11-18 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:70999668a1305571d3b5fc57168fcb060a976418

commit r15-5406-g70999668a1305571d3b5fc57168fcb060a976418
Author: Eric Botcazou 
Date:   Sun Nov 10 19:20:13 2024 +0100

ada: Fix interaction of aspect Predicate and static case expressions

The semantics of the GNAT-specific Predicate aspect should be equivalent
to those of the Static_Predicate aspect when the predicate expression is
static, but that is not correctly implemented for static case expressions.

gcc/ada/ChangeLog:

* exp_ch4.adb (Expand_N_Case_Expression): Remove the test on
enclosing predicate function for the return optimization.
Rewrite it in the general case to catch all nondynamic predicates.
(Expand_N_If_Expression): Remove the test on enclosing predicate
function for the return optimization.

Diff:
---
 gcc/ada/exp_ch4.adb | 43 ++-
 1 file changed, 18 insertions(+), 25 deletions(-)

diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index 9e82b78e3b6b..5ae2d11b04c1 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -4989,17 +4989,13 @@ package body Exp_Ch4 is
--
 
procedure Expand_N_Case_Expression (N : Node_Id) is
-  Loc : constant Source_Ptr := Sloc (N);
-  Par : constant Node_Id:= Parent (N);
-  Typ : constant Entity_Id  := Etype (N);
-
-  In_Predicate : constant Boolean :=
-Ekind (Current_Scope) in E_Function | E_Procedure
-  and then Is_Predicate_Function (Current_Scope);
-  --  Flag set when the case expression appears within a predicate
+  Loc  : constant Source_Ptr := Sloc (N);
+  Par  : constant Node_Id:= Parent (N);
+  Scop : constant Entity_Id  := Current_Scope;
+  Typ  : constant Entity_Id  := Etype (N);
 
   Optimize_Return_Stmt : constant Boolean :=
-Nkind (Par) = N_Simple_Return_Statement and then not In_Predicate;
+Nkind (Par) = N_Simple_Return_Statement;
   --  Small optimization: when the case expression appears in the context
   --  of a simple return statement, expand into
 
@@ -5012,8 +5008,7 @@ package body Exp_Ch4 is
   --end case;
 
   --  This makes the expansion much easier when expressions are calls to
-  --  a BIP function. But do not perform it when the return statement is
-  --  within a predicate function, as this causes spurious errors.
+  --  build-in-place functions.
 
   function Is_Copy_Type (Typ : Entity_Id) return Boolean;
   --  Return True if we can copy objects of this type when expanding a case
@@ -5081,13 +5076,17 @@ package body Exp_Ch4 is
  return;
   end if;
 
-  --  If the case expression is a predicate specification, and the type
-  --  to which it applies has a static predicate aspect, do not expand,
-  --  because it will be converted to the proper predicate form later.
+  --  If the case expression is a predicate specification, do not expand
+  --  because it will need to be recognized and converted to the canonical
+  --  predicate form later if it it happens to be static.
 
-  if In_Predicate
-and then
-  Has_Static_Predicate_Aspect (Etype (First_Entity (Current_Scope)))
+  if Ekind (Scop) in E_Function | E_Procedure
+and then Is_Predicate_Function (Scop)
+and then Is_Entity_Name (Expression (N))
+and then Entity (Expression (N)) = First_Entity (Scop)
+and then (Is_Scalar_Type (Etype (Expression (N)))
+   or else Is_String_Type (Etype (Expression (N
+and then not Has_Dynamic_Predicate_Aspect (Etype (Expression (N)))
   then
  return;
   end if;
@@ -5471,13 +5470,8 @@ package body Exp_Ch4 is
   Par   : constant Node_Id:= Parent (N);
   Typ   : constant Entity_Id  := Etype (N);
 
-  In_Predicate : constant Boolean :=
-Ekind (Current_Scope) in E_Function | E_Procedure
-  and then Is_Predicate_Function (Current_Scope);
-  --  Flag set when the if expression appears within a predicate
-
   Optimize_Return_Stmt : constant Boolean :=
-Nkind (Par) = N_Simple_Return_Statement and then not In_Predicate;
+Nkind (Par) = N_Simple_Return_Statement;
   --  Small optimization: when the if expression appears in the context of
   --  a simple return statement, expand into
 
@@ -5488,8 +5482,7 @@ package body Exp_Ch4 is
   --end if;
 
   --  This makes the expansion much easier when expressions are calls to
-  --  a BIP function. But do not perform it when the return statement is
-  --  within a predicate function, as this causes spurious errors.
+  --  build-in-place functions.
 
   Force_Expand : constant Boolean := Is_Anonymous_Access_Actual (N);
   --  Determine if we are dealing with a special case of a conditional


[gcc r15-5376] libstdc++: Update reference to Angelika Langer's article

2024-11-18 Thread Gerald Pfeifer via Libstdc++-cvs
https://gcc.gnu.org/g:83e86397b0c1d97c24075793cc5311b48baa2907

commit r15-5376-g83e86397b0c1d97c24075793cc5311b48baa2907
Author: Gerald Pfeifer 
Date:   Mon Nov 18 08:33:49 2024 +0100

libstdc++: Update reference to Angelika Langer's article

libstdc++-v3:
* doc/xml/manual/allocator.xml: Update reference to Angelika
Langer's article.
* doc/html/manual/memory.html: Regenerate.

Diff:
---
 libstdc++-v3/doc/html/manual/memory.html  | 2 +-
 libstdc++-v3/doc/xml/manual/allocator.xml | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/doc/html/manual/memory.html 
b/libstdc++-v3/doc/html/manual/memory.html
index 8b583591d7d7..e24af81e83b3 100644
--- a/libstdc++-v3/doc/html/manual/memory.html
+++ b/libstdc++-v3/doc/html/manual/memory.html
@@ -296,7 +296,7 @@
   Reconsidering Custom Memory Allocation

   . Emery 
Berger. Ben Zorn. Kathryn McKinley. Copyright © 
2002 OOPSLA. 
-   http://www.angelikalanger.com/Articles/C++Report/Allocators/Allocators.html";
 target="_top">
+   https://angelikalanger.com/Articles/C++Report/Allocators/Allocators.html"; 
target="_top">
   Allocator Types

   . Klaus 
Kreft. Angelika Langer. 

diff --git a/libstdc++-v3/doc/xml/manual/allocator.xml 
b/libstdc++-v3/doc/xml/manual/allocator.xml
index 7e74dca404ae..f9fab499abcf 100644
--- a/libstdc++-v3/doc/xml/manual/allocator.xml
+++ b/libstdc++-v3/doc/xml/manual/allocator.xml
@@ -505,7 +505,7 @@
   
   
http://www.w3.org/1999/xlink";
- 
xlink:href="http://www.angelikalanger.com/Articles/C++Report/Allocators/Allocators.html";>
+ 
xlink:href="https://angelikalanger.com/Articles/C++Report/Allocators/Allocators.html";>
   Allocator Types

   


[gcc r15-5402] ada: Fix another minor fallout of previous changes to aggregate expansion

2024-11-18 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:1b24e30cabbe2d796dc12afbcccfe849b0b9eb92

commit r15-5402-g1b24e30cabbe2d796dc12afbcccfe849b0b9eb92
Author: Eric Botcazou 
Date:   Thu Nov 7 19:23:39 2024 +0100

ada: Fix another minor fallout of previous changes to aggregate expansion

The processing of static array aggregates in Exp_Aggr requires that their
bounds be representable as Int(eger) values for practical purposes, and
the previous changes have exposed another path where this is not checked.

This introduces a UI_Are_In_Int_Range local predicate for convenience.

gcc/ada/ChangeLog:

* exp_aggr.adb (UI_Are_In_Int_Range): New predicate.
(Aggr_Size_OK): Use it.
(Flatten): Likewise.
(Packed_Array_Aggregate_Handled): Likewise.
(Static_Array_Aggregate): Likewise.

Diff:
---
 gcc/ada/exp_aggr.adb | 37 +
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 1cfc97b5bc6f..c34df8404012 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -161,6 +161,10 @@ package body Exp_Aggr is
--  statement of variant part will usually be small and probably in near
--  sorted order.
 
+   function UI_Are_In_Int_Range (Left, Right : Uint) return Boolean is
+ (UI_Is_In_Int_Range (Left) and then UI_Is_In_Int_Range (Right));
+   --  Return True if both Left and Right are in Int range
+
--
-- Local subprograms for Record Aggregate Expansion --
--
@@ -777,10 +781,7 @@ package body Exp_Aggr is
 
  --  Bounds must be in integer range, for later array construction
 
- if not UI_Is_In_Int_Range (Lov)
- or else
-not UI_Is_In_Int_Range (Hiv)
- then
+ if not UI_Are_In_Int_Range (Lov, Hiv) then
 return False;
  end if;
 
@@ -4504,13 +4505,13 @@ package body Exp_Aggr is
  --  present we can proceed since the bounds can be obtained from the
  --  aggregate.
 
- if not Compile_Time_Known_Value (Blo) and then Others_Present
- then
+ if not Compile_Time_Known_Value (Blo) and then Others_Present then
 return False;
  end if;
 
- if not (UI_Is_In_Int_Range (Lov) and UI_Is_In_Int_Range (Hiv)) then
---  guard against raising C_E in UI_To_Int
+ --  Guard against raising C_E in UI_To_Int
+
+ if not UI_Are_In_Int_Range (Lov, Hiv) then
 return False;
  end if;
 
@@ -9100,17 +9101,15 @@ package body Exp_Aggr is
  end if;
 
  declare
-Bounds_Vals : Range_Values;
+Bounds_Vals : constant Range_Values :=
+  (First => Expr_Value (Bounds.First),
+   Last  => Expr_Value (Bounds.Last));
 --  Compile-time known values of bounds
- begin
---  Or are silly out of range of int bounds
 
-Bounds_Vals.First := Expr_Value (Bounds.First);
-Bounds_Vals.Last := Expr_Value (Bounds.Last);
+ begin
+--  Guard against raising C_E in UI_To_Int
 
-if not UI_Is_In_Int_Range (Bounds_Vals.First)
- or else
-   not UI_Is_In_Int_Range (Bounds_Vals.Last)
+if not UI_Are_In_Int_Range (Bounds_Vals.First, Bounds_Vals.Last)
 then
return False;
 end if;
@@ -9497,6 +9496,12 @@ package body Exp_Aggr is
   return False;
end if;
 
+   --  Guard against raising C_E in UI_To_Int
+
+   if not UI_Are_In_Int_Range (Intval (Lo), Intval (Hi)) then
+  return False;
+   end if;
+
--  Create a positional aggregate with the right number of
--  copies of the expression.


[gcc r15-5417] diagnostics: add support for nested diagnostics [PR116253]

2024-11-18 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:a5af2ec16fa75941a39a5a339d13590cd13c54e9

commit r15-5417-ga5af2ec16fa75941a39a5a339d13590cd13c54e9
Author: David Malcolm 
Date:   Mon Nov 18 14:20:17 2024 -0500

diagnostics: add support for nested diagnostics [PR116253]

Previously the diagnostic subsystem supported a one-deep
hierarchy via auto_diagnostic_group, for associating
notes with the warning/error they annotate; this only
affects SARIF output, not text output.

This patch adds support to the diagnostics subsystem for
capturing arbitrarily deep nesting structure within
diagnostic messages.

This patch:
* adds the ability to express nesting internally when
  building diagnostics
* captures the nesting in SARIF output in the form documented
  in SG15's P3358R0 ("SARIF for Structured Diagnostics") via
  a "nestingLevel" property
* adds a new experimental mode to text output to see the
  hierarchy, via:
  -fdiagnostics-set-output=text:experimental-nesting=yes
* adds test coverage via a plugin, which with the above
  option emits:
  • note: child 0
• note: grandchild 0 0
• note: grandchild 0 1
• note: grandchild 0 2
  • note: child 1
• note: grandchild 1 0
• note: grandchild 1 1
• note: grandchild 1 2
  • note: child 2
• note: grandchild 2 0
• note: grandchild 2 1
• note: grandchild 2 2
  using '*' rather than '•' if the text_art::theme is ascii-only.

My hope is to eventually:
(a) use this to improve C++'s template diagnostics
(b) remove the "experimental" caveat from the the text output mode

but this patch doesn't touch the C++ frontend, leaving both of these
to followup work.

gcc/c-family/ChangeLog:
PR other/116253
* c-opts.cc (c_diagnostic_text_finalizer): Use
text_output.build_indent_prefix for prefix to
diagnostic_show_locus.

gcc/ChangeLog:
PR other/116253
* diagnostic-core.h (class auto_diagnostic_nesting_level): New.
* diagnostic-format-sarif.cc (class sarif_builder): Update leading
comment re nesting of diagnostics.
(sarif_result::on_nested_diagnostic): Add nestingLevel property.
* diagnostic-format-text.cc (on_report_diagnostic): If we're
showing nested diagnostics, then print changes of location on a
new line, indented, and update m_last_location.
(diagnostic_text_output_format::build_prefix): If m_show_nesting,
then potentially add indentation and a bullet point.
(get_bullet_point_unichar): New.
(use_unicode_p): New.
(diagnostic_text_output_format::build_indent_prefix): New.
* diagnostic-format-text.h
(diagnostic_text_output_format::diagnostic_text_output_format):
Initialize m_show_nesting and m_show_nesting_levels.
(diagnostic_text_output_format::build_indent_prefix): New decl.
(diagnostic_text_output_format::show_nesting_p): New accessor
(diagnostic_text_output_format::show_locations_in_nesting_p):
Likewise.
(diagnostic_text_output_format::set_show_nesting): New.
(diagnostic_text_output_format::set_show_locations_in_nesting):
New.
(diagnostic_text_output_format::set_show_nesting_levels): New.
(diagnostic_text_output_format::m_show_nesting): New field.
(diagnostic_text_output_format::m_show_locations_in_nesting): New
field.
(diagnostic_text_output_format::m_show_nesting_levels): New field.
* diagnostic-global-context.cc
(auto_diagnostic_nesting_level::auto_diagnostic_nesting_level):
New.
(auto_diagnostic_nesting_level::~auto_diagnostic_nesting_level):
New.
* diagnostic-show-locus.cc (layout_printer::print): Temporarily
set DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE.
* diagnostic.cc (diagnostic_context::initialize): Update for
renaming of m_nesting_depth to m_group_nesting_depth and
initialize m_diagnostic_nesting_level.
(diagnostic_context::finish): Update for renaming of
m_nesting_depth to m_group_nesting_depth.
(diagnostic_context::report_diagnostic): Likewise.
(diagnostic_context::begin_group): Likewise.
(diagnostic_context::end_group): Likewise.
(diagnostic_context::push_nesting_level): New.
(diagnostic_context::pop_nesting_level): New.
(diagnostic_context::set_diagnostic_buffer): Update for renaming
of m_nesting_depth to m_group_nesting_depth.  Assert that we don't
have nested diagnostics.
* diagnostic.h (diagnostic_context::push_nesting_level): New decl.
(diagnost

[gcc r15-5418] aarch64: Split early_ra::record_insn_refs

2024-11-18 Thread Richard Sandiford via Gcc-cvs
https://gcc.gnu.org/g:4712ecde4869cf29c40a7df44e4655939d90d4d8

commit r15-5418-g4712ecde4869cf29c40a7df44e4655939d90d4d8
Author: Richard Sandiford 
Date:   Mon Nov 18 19:32:48 2024 +

aarch64: Split early_ra::record_insn_refs

record_insn_refs has three distinct phases: model the definitions,
model any call, and model the uses.  This patch splits each phase
out into its own function.

This isn't beneficial on its own, but it helps with later patches.

gcc/
* config/aarch64/aarch64-early-ra.cc
(early_ra::record_insn_refs): Split into...
(early_ra::record_insn_defs, early_ra::record_insn_call)
(early_ra::record_insn_uses): ...this new functions.
(early_ra::process_block): Update accordingly.

Diff:
---
 gcc/config/aarch64/aarch64-early-ra.cc | 46 ++
 1 file changed, 30 insertions(+), 16 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-early-ra.cc 
b/gcc/config/aarch64/aarch64-early-ra.cc
index 0db8ea24389e..d6ed7fee48b6 100644
--- a/gcc/config/aarch64/aarch64-early-ra.cc
+++ b/gcc/config/aarch64/aarch64-early-ra.cc
@@ -450,7 +450,9 @@ private:
   void record_copy (rtx, rtx, bool = false);
   void record_constraints (rtx_insn *);
   void record_artificial_refs (unsigned int);
-  void record_insn_refs (rtx_insn *);
+  void record_insn_defs (rtx_insn *);
+  void record_insn_call (rtx_call_insn *);
+  void record_insn_uses (rtx_insn *);
 
   bool consider_strong_copy_src_chain (allocno_info *);
   int strided_polarity_pref (allocno_info *, allocno_info *);
@@ -1936,13 +1938,13 @@ early_ra::record_artificial_refs (unsigned int flags)
   m_current_point += 1;
 }
 
-// Model the register references in INSN as part of a backwards walk.
+// Called as part of a backwards walk over a block.  Model the definitions
+// in INSN, excluding partial call clobbers.
 void
-early_ra::record_insn_refs (rtx_insn *insn)
+early_ra::record_insn_defs (rtx_insn *insn)
 {
   df_ref ref;
 
-  // Record all definitions, excluding partial call clobbers.
   FOR_EACH_INSN_DEF (ref, insn)
 if (IN_RANGE (DF_REF_REGNO (ref), V0_REGNUM, V31_REGNUM))
   record_fpr_def (DF_REF_REGNO (ref));
@@ -1959,19 +1961,28 @@ early_ra::record_insn_refs (rtx_insn *insn)
  }
   }
   m_current_point += 1;
+}
 
-  // Model the call made by a call insn as a separate phase in the
-  // evaluation of the insn.  Any partial call clobbers happen at that
-  // point, rather than in the definition or use phase of the insn.
-  if (auto *call_insn = dyn_cast (insn))
-{
-  function_abi abi = insn_callee_abi (call_insn);
-  m_call_points[abi.id ()].safe_push (m_current_point);
-  m_current_point += 1;
-}
+// Called as part of a backwards walk over a block.  Model the call made
+// by INSN as a separate phase in the evaluation of the insn.  Any partial
+// call clobbers happen at that point, rather than in the definition or use
+// phase of the insn.
+void
+early_ra::record_insn_call (rtx_call_insn *insn)
+{
+  function_abi abi = insn_callee_abi (insn);
+  m_call_points[abi.id ()].safe_push (m_current_point);
+  m_current_point += 1;
+}
+
+// Called as part of a backwards walk over a block.  Model the uses in INSN.
+// We can ignore READ_MODIFY_WRITE uses of plain subregs, since we track the
+// FPR-sized parts of them individually.
+void
+early_ra::record_insn_uses (rtx_insn *insn)
+{
+  df_ref ref;
 
-  // Record all uses.  We can ignore READ_MODIFY_WRITE uses of plain subregs,
-  // since we track the FPR-sized parts of them individually.
   FOR_EACH_INSN_USE (ref, insn)
 if (IN_RANGE (DF_REF_REGNO (ref), V0_REGNUM, V31_REGNUM))
   record_fpr_use (DF_REF_REGNO (ref));
@@ -3470,7 +3481,10 @@ early_ra::process_block (basic_block bb, bool 
is_isolated)
}
   else
{
- record_insn_refs (insn);
+ record_insn_defs (insn);
+ if (auto *call_insn = dyn_cast (insn))
+   record_insn_call (call_insn);
+ record_insn_uses (insn);
  rtx pat = PATTERN (insn);
  if (is_move_set (pat))
record_copy (SET_DEST (pat), SET_SRC (pat), true);


[gcc r15-5421] aarch64: Relax early_ra treatment of modes_tieable_p

2024-11-18 Thread Richard Sandiford via Gcc-cvs
https://gcc.gnu.org/g:428f3cacdd6aa631040379cb3c39eb8832957ef1

commit r15-5421-g428f3cacdd6aa631040379cb3c39eb8832957ef1
Author: Richard Sandiford 
Date:   Mon Nov 18 19:32:50 2024 +

aarch64: Relax early_ra treatment of modes_tieable_p

At least on aarch64, modes_tieable_p is a stricter condition than
can_change_mode_class.  can_change_mode_class tells us whether the
subreg rules produce a sensible result for a particular mode change.
modes_tieable_p in addition tells us whether a mode change is
reasonable for optimisation purposes.

A false return from either hook should (and does) prevent early_ra
from attempting an allocation.  But only a false return from
can_change_mode_class should invalidate the liveness tracking;
we can still analyse subregs for which can_change_mode_class is
true and modes_tieable_p is false.

This doesn't make a difference on its own, but it helps later
patches.

gcc/
* config/aarch64/aarch64-early-ra.cc
(early_ra::get_allocno_subgroup): Split can_change_mode_class test
out from modes_tieable_p test and only invalidate the live range
information for the former.

Diff:
---
 gcc/config/aarch64/aarch64-early-ra.cc | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-early-ra.cc 
b/gcc/config/aarch64/aarch64-early-ra.cc
index 68e96bd4da85..79ac7b099ebb 100644
--- a/gcc/config/aarch64/aarch64-early-ra.cc
+++ b/gcc/config/aarch64/aarch64-early-ra.cc
@@ -1434,8 +1434,8 @@ early_ra::get_allocno_subgroup (rtx reg)
   if (!inner)
return {};
 
-  if (!targetm.modes_tieable_p (GET_MODE (SUBREG_REG (reg)),
-   GET_MODE (reg)))
+  if (!targetm.can_change_mode_class (GET_MODE (SUBREG_REG (reg)),
+ GET_MODE (reg), FP_REGS))
{
  record_live_range_failure ([&](){
fprintf (dump_file, "cannot refer to r%d:%s in mode %s",
@@ -1446,6 +1446,15 @@ early_ra::get_allocno_subgroup (rtx reg)
  return {};
}
 
+  if (!targetm.modes_tieable_p (GET_MODE (SUBREG_REG (reg)),
+   GET_MODE (reg)))
+   record_allocation_failure ([&](){
+   fprintf (dump_file, "r%d's mode %s is not tieable to mode %s",
+REGNO (SUBREG_REG (reg)),
+GET_MODE_NAME (GET_MODE (SUBREG_REG (reg))),
+GET_MODE_NAME (GET_MODE (reg)));
+   });
+
   subreg_info info;
   subreg_get_info (V0_REGNUM, GET_MODE (SUBREG_REG (reg)),
   SUBREG_BYTE (reg), GET_MODE (reg), &info);


[gcc r15-5399] ada: Array aggregate with large static bounds causes compiler crash

2024-11-18 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:0019e8dc7696f62667816ce321f9b3a1ab3c1837

commit r15-5399-g0019e8dc7696f62667816ce321f9b3a1ab3c1837
Author: Steve Baird 
Date:   Wed Oct 30 15:34:50 2024 -0700

ada: Array aggregate with large static bounds causes compiler crash

In some cases an array aggregate with statically known bounds and at least
one bound outside of the range of a 32-bit signed integer causes
a bugbox.

gcc/ada/ChangeLog:

* exp_aggr.adb (Convert_To_Positional.Flatten): Avoid raising
Constraint_Error in UI_To_Int by testing UI_Is_In_Int_Range first.

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

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index c63d22b58fa4..1cfc97b5bc6f 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -4509,6 +4509,11 @@ package body Exp_Aggr is
 return False;
  end if;
 
+ if not (UI_Is_In_Int_Range (Lov) and UI_Is_In_Int_Range (Hiv)) then
+--  guard against raising C_E in UI_To_Int
+return False;
+ end if;
+
  --  Determine if set of alternatives is suitable for conversion and
  --  build an array containing the values in sequence.


[gcc r15-5405] ada: Atomic_Synchronization is not a user-visible check

2024-11-18 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:4e23ce507067b04865342bb1a22a3651caaf28bc

commit r15-5405-g4e23ce507067b04865342bb1a22a3651caaf28bc
Author: Bob Duff 
Date:   Sun Nov 10 06:39:57 2024 -0500

ada: Atomic_Synchronization is not a user-visible check

Remove all user-level documentation of the check name
"Atomic_Synchronization". The documentation was confusing because
this check should never be used in source code, and because it
raises the question of whether All_Checks applies to it (it does
not).

Change the name Atomic_Synchronization to be _Atomic_Synchronization
(with a leading underscore) so that it cannot be used in source code.

This "check" is not really a check at all; it is used only internally in
the implementation of Disable/Enable_Atomic_Synchronization, because the
placement and scope of these pragmas match pragma Suppress.

gcc/ada/ChangeLog:

* doc/gnat_rm/implementation_defined_characteristics.rst:
Remove Atomic_Synchronization.
* doc/gnat_ugn/building_executable_programs_with_gnat.rst:
Likewise.
* doc/gnat_rm/implementation_defined_pragmas.rst: DRY.
Consolidate documentation of Disable/Enable_Atomic_Synchronization.
* checks.adb: Comment fix.
* exp_util.ads: Likewise.
* targparm.ads: Likewise.
* types.ads: Likewise.
* gnat1drv.adb: Likewise. DRY.
* sem_prag.adb (Process_Disable_Enable_Atomic_Sync):
Change name of Atomic_Synchronization to start with
underscore.
(Process_Suppress_Unsuppress): No need to check Comes_From_Source 
for
Atomic_Synchronization anymore; _Atomic_Synchronization can never
come from source. (Anyway, it shouldn't be ignored; it should be
an error.)
* snames.ads-tmpl (Atomic_Synchronization):
Change name to start with underscore.
* switch-c.adb (Scan_Front_End_Switches):
Minor cleanup: Use 'in'.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

Diff:
---
 gcc/ada/checks.adb |  6 ++-
 .../implementation_defined_characteristics.rst | 12 +++---
 .../doc/gnat_rm/implementation_defined_pragmas.rst | 35 ++--
 .../building_executable_programs_with_gnat.rst |  6 +--
 gcc/ada/exp_util.ads   |  6 +--
 gcc/ada/gnat1drv.adb   |  5 +--
 gcc/ada/gnat_rm.texi   | 49 +-
 gcc/ada/gnat_ugn.texi  | 10 ++---
 gcc/ada/sem_prag.adb   | 19 +++--
 gcc/ada/snames.ads-tmpl|  6 +--
 gcc/ada/switch-c.adb   |  4 +-
 gcc/ada/targparm.ads   |  6 +--
 gcc/ada/types.ads  |  3 +-
 13 files changed, 66 insertions(+), 101 deletions(-)

diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb
index 06e7997cb3f8..8a3c4e8b4bfb 100644
--- a/gcc/ada/checks.adb
+++ b/gcc/ada/checks.adb
@@ -3976,8 +3976,10 @@ package body Checks is
-
 
--  Note: internally Disable/Enable_Atomic_Synchronization is implemented
-   --  using a bogus check called Atomic_Synchronization. This is to make it
-   --  more convenient to get exactly the same semantics as [Un]Suppress.
+   --  using a pseudo-check called _Atomic_Synchronization. This is to make it
+   --  more convenient to get the same placement and scope rules as
+   --  [Un]Suppress. The check name has a leading underscore to make
+   --  it reserved by the implementation.
 
function Atomic_Synchronization_Disabled (E : Entity_Id) return Boolean is
begin
diff --git a/gcc/ada/doc/gnat_rm/implementation_defined_characteristics.rst 
b/gcc/ada/doc/gnat_rm/implementation_defined_characteristics.rst
index 5399bda55e8d..3e41899f95ef 100644
--- a/gcc/ada/doc/gnat_rm/implementation_defined_characteristics.rst
+++ b/gcc/ada/doc/gnat_rm/implementation_defined_characteristics.rst
@@ -478,12 +478,12 @@ via compiler switches such as "-gnata".
 *
   "Implementation-defined check names.  See 11.5(27)."
 
-The implementation defined check names include Alignment_Check,
-Atomic_Synchronization, Container_Checks, Duplicated_Tag_Check,
-Predicate_Check, Raise_Check, Tampering_Check, and Validity_Check.
-In addition, a user program can add implementation-defined check
-names by means of the pragma Check_Name. See the description of
-pragma ``Suppress`` for full details.
+The implementation-defined check names include Alignment_Check,
+Container_Checks, Duplicated_Tag_Check, Predicate_Check,
+Raise_Check, Tampering_Check, and Validity_Check. In addition, a
+user program can add implementation-defined check names by means
+of the pragma Check_Name. See the description of p

[gcc r15-5400] ada: Small cleanup and refactoring in expansion of asynchronous select

2024-11-18 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:6a7849592d442563a799cff35f3b43fd4b828681

commit r15-5400-g6a7849592d442563a799cff35f3b43fd4b828681
Author: Eric Botcazou 
Date:   Thu Oct 31 11:21:56 2024 +0100

ada: Small cleanup and refactoring in expansion of asynchronous select

The exception handler that catches Abort_Signal does nothing nowadays.
This refactors the code to use Build_Abort_Block more consistently and
also makes it simpler by dropping the identifier on the abort block.

No functional changes.

gcc/ada/ChangeLog:

* exp_sel.ads (Build_Abort_Block): Remove second parameter and
rename the third.
(Build_Abort_Block_Handler): Fix description.
* exp_sel.adb (Build_Abort_Block): Remove second parameter, rename
the third and adjust accordingly.
* exp_ch9.adb (Expand_N_Asynchronous_Select): Fix the description
of the exception handler throughout.  Remove Abort_Block_Ent and
Hdle local variables.  Call Build_Abort_Block consistently to build
the abort block and adjust existing calls.

Diff:
---
 gcc/ada/exp_ch9.adb | 117 
 gcc/ada/exp_sel.adb |  13 ++
 gcc/ada/exp_sel.ads |  13 +++---
 3 files changed, 53 insertions(+), 90 deletions(-)

diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb
index 9b82a9fcfdda..cf4d4d822562 100644
--- a/gcc/ada/exp_ch9.adb
+++ b/gcc/ada/exp_ch9.adb
@@ -6482,7 +6482,7 @@ package body Exp_Ch9 is
-- _clean;  --  Added by Exp_Ch7.Expand_Cleanup_Actions
--  end;
--   exception
-   --  when Abort_Signal => Abort_Undefer;
+   --  when Abort_Signal => null;
--   end;
 
--   parm := P.param;
@@ -6545,7 +6545,7 @@ package body Exp_Ch9 is
--   _clean;  --  Added by Exp_Ch7.Expand_Cleanup_Actions
--end;
-- exception
-   --when Abort_Signal => Abort_Undefer;
+   --when Abort_Signal => null;
-- end;
 
-- if not Cancelled (Bnn) then
@@ -6626,7 +6626,7 @@ package body Exp_Ch9 is
--   _clean;  --  Added by Exp_Ch7.Expand_Cleanup_Actions
--end;
-- exception
-   --when Abort_Signal => Abort_Undefer;
+   --when Abort_Signal => null;
-- end;
 
-- if not Cancelled (Bnn) then
@@ -6659,7 +6659,7 @@ package body Exp_Ch9 is
--  _clean;  --  Added by Exp_Ch7.Expand_Cleanup_Actions
--   end;
--exception
-   --   when Abort_Signal => Abort_Undefer;
+   --   when Abort_Signal => null;
--end;
 
--if not U then
@@ -6693,7 +6693,6 @@ package body Exp_Ch9 is
   Abrt : constant Node_Id:= Abortable_Part (N);
   Trig : constant Node_Id:= Triggering_Alternative (N);
 
-  Abort_Block_Ent   : Entity_Id;
   Abortable_Block   : Node_Id;
   Actuals   : List_Id;
   Astats: List_Id;
@@ -6714,7 +6713,6 @@ package body Exp_Ch9 is
   Ename : Node_Id;
   Enqueue_Call  : Node_Id;
   Formals   : List_Id;
-  Hdle  : List_Id;
   Index : Node_Id;
   Lim_Typ_Stmts : List_Id;
   N_Orig: Node_Id;
@@ -6968,17 +6966,11 @@ package body Exp_Ch9 is
 --begin
 --   Cleanup_Block
 --exception
---   when Abort_Signal => Abort_Undefer;
+--   when Abort_Signal => null;
 --end;
 
-Abort_Block_Ent := Make_Temporary (Loc, 'A');
-ProtE_Stmts :=
-  New_List (
-Make_Implicit_Label_Declaration (Loc,
-  Defining_Identifier => Abort_Block_Ent),
-
-Build_Abort_Block
-  (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
+ProtE_Stmts := New_List (
+  Build_Abort_Block (Loc, Cleanup_Block_Ent, Cleanup_Block));
 
 --  Generate:
 --if not Cancelled (Bnn) then
@@ -7081,18 +7073,11 @@ package body Exp_Ch9 is
 --begin
 --   Cleanup_Block
 --exception
---   when Abort_Signal => Abort_Undefer;
+--   when Abort_Signal => null;
 --end;
 
-Abort_Block_Ent := Make_Temporary (Loc, 'A');
-
-Append_To (TaskE_Stmts,
-  Make_Implicit_Label_Declaration (Loc,
-Defining_Identifier => Abort_Block_Ent));
-
 Append_To (TaskE_Stmts,
-  Build_Abort_Block
-(Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
+  Build_Abort_Block (Loc, Cleanup_Block_Ent, Cleanup_Block));
 
 --  Generate:
 --i

[gcc r15-5403] ada: Fix another minor fallout of previous changes to aggregate expansion

2024-11-18 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:b4fd15d8bea6224a431e062d846459cc57724e41

commit r15-5403-gb4fd15d8bea6224a431e062d846459cc57724e41
Author: Eric Botcazou 
Date:   Fri Nov 8 11:01:11 2024 +0100

ada: Fix another minor fallout of previous changes to aggregate expansion

This is another glitch associated with Initialization_Statements.

gcc/ada/ChangeLog:

* exp_util.adb (Remove_Init_Call): Rewrite a compound statement in
the Initialization_Statements of the variable as a null statement
instead of removing it.
* freeze.adb (Explode_Initialization_Compound_Statement): Small
comment tweaks.

Diff:
---
 gcc/ada/exp_util.adb | 16 
 gcc/ada/freeze.adb   |  4 ++--
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index 767191060d82..e4397fe868d7 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -12124,6 +12124,22 @@ package body Exp_Util is
  Init_Call := Initialization_Statements (Var);
  Set_Initialization_Statements (Var, Empty);
 
+ --  Note that we rewrite Init_Call into a null statement, rather than
+ --  just removing it, because Freeze_All may rely on this particular
+ --  node still being present in the enclosing list to know where to
+ --  stop freezing (see Explode_Initialization_Compound_Statement).
+
+ if Nkind (Init_Call) = N_Compound_Statement then
+declare
+   Init_Actions : constant List_Id:= Actions (Init_Call);
+   Loc  : constant Source_Ptr := Sloc (Init_Call);
+
+begin
+   Rewrite (Init_Call, Make_Null_Statement (Loc));
+   return Make_Compound_Statement (Loc, Init_Actions);
+end;
+ end if;
+
   elsif not Has_Non_Null_Base_Init_Proc (Typ) then
 
  --  No init proc for the type, so obviously no call to be found
diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
index 3b781f7d21c1..67a51899f951 100644
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -2471,9 +2471,9 @@ package body Freeze is
 Insert_List_Before (Init_Stmts, Actions (Init_Stmts));
  end if;
 
- --  Note that we rewrite Init_Stmts into a NULL statement, rather than
+ --  Note that we rewrite Init_Stmts into a null statement, rather than
  --  just removing it, because Freeze_All may rely on this particular
- --  Node_Id still being present in the enclosing list to know where to
+ --  node still being present in the enclosing list to know where to
  --  stop freezing.
 
  Rewrite (Init_Stmts, Make_Null_Statement (Sloc (Init_Stmts)));


[gcc r15-5401] ada: Fix minor fallout of previous changes to aggregate expansion

2024-11-18 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:3716d9887c9e4d8533b1a2346ac2025508f76ea4

commit r15-5401-g3716d9887c9e4d8533b1a2346ac2025508f76ea4
Author: Eric Botcazou 
Date:   Thu Nov 7 18:50:49 2024 +0100

ada: Fix minor fallout of previous changes to aggregate expansion

The problem occurs for an anonymous array object declared with an aspect and
when pragma {Initialize,Normalize}_Scalars is in effect: in this case, the
synthesized aggregate is attached to the Initialization_Statements field by
Convert_Aggr_In_Object_Decl, but Explode_Initialization_Compound_Statement
puts it back at the point of declaration instead of the freeze point, thus
voiding the effects of the mechanism.

This was previously hidden because of a bypass in Freeze_Entity which drops
the freeze node on the floor in this case, so the change fixes the issue and
removes the bypass in the process.

gcc/ada/ChangeLog:

* freeze.ads (Explode_Initialization_Compound_Statement): Adjust the
description.
* freeze.adb (Explode_Initialization_Compound_Statement): If the
entity has its freezing delayed, append the initialization actions
to its freeze actions.
(Freeze_Object_Declaration): Remove commented out code.
(Freeze_Entity): Remove bypass for object of anonymous array type.

Diff:
---
 gcc/ada/freeze.adb | 28 +---
 gcc/ada/freeze.ads |  2 +-
 2 files changed, 10 insertions(+), 20 deletions(-)

diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
index 7502a04d5175..3b781f7d21c1 100644
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -2461,7 +2461,15 @@ package body Freeze is
   if Present (Init_Stmts)
 and then Nkind (Init_Stmts) = N_Compound_Statement
   then
- Insert_List_Before (Init_Stmts, Actions (Init_Stmts));
+ --  If the entity has its freezing delayed, append the initialization
+ --  actions to its freeze actions. Otherwise insert them back at the
+ --  point where they have been generated.
+
+ if Has_Delayed_Freeze (E) then
+Append_Freeze_Actions (E, Actions (Init_Stmts));
+ else
+Insert_List_Before (Init_Stmts, Actions (Init_Stmts));
+ end if;
 
  --  Note that we rewrite Init_Stmts into a NULL statement, rather than
  --  just removing it, because Freeze_All may rely on this particular
@@ -4519,7 +4527,6 @@ package body Freeze is
Expression => Expression (Decl)));
 
Set_No_Initialization (Decl);
-   --  Set_Is_Frozen (E, False);
 end;
  end if;
 
@@ -6799,23 +6806,6 @@ package body Freeze is
   and then Within_Scope (Etype (E), Current_Scope)
 then
Freeze_And_Append (Etype (E), N, Result);
-
-   --  For an object of an anonymous array type, aspects on the
-   --  object declaration apply to the type itself. This is the
-   --  case for Atomic_Components, Volatile_Components, and
-   --  Independent_Components. In these cases analysis of the
-   --  generated pragma will mark the anonymous types accordingly,
-   --  and the object itself does not require a freeze node.
-
-   if Ekind (E) = E_Variable
- and then Is_Itype (Etype (E))
- and then Is_Array_Type (Etype (E))
- and then Has_Delayed_Aspects (E)
-   then
-  Set_Has_Delayed_Aspects (E, False);
-  Set_Has_Delayed_Freeze  (E, False);
-  Set_Freeze_Node (E, Empty);
-   end if;
 end if;
 
 --  Special processing for objects created by object declaration;
diff --git a/gcc/ada/freeze.ads b/gcc/ada/freeze.ads
index 4bc03c4ef596..67f0a55fbdd1 100644
--- a/gcc/ada/freeze.ads
+++ b/gcc/ada/freeze.ads
@@ -181,7 +181,7 @@ package Freeze is
 
procedure Explode_Initialization_Compound_Statement (E : Entity_Id);
--  If Initialization_Statements (E) is an N_Compound_Statement, insert its
-   --  actions in the enclosing list and reset the attribute.
+   --  actions at the appropriate point and clear the attribute.
 
function Freeze_Entity
  (E : Entity_Id;


[gcc r14-10938] fold-const: Fix BIT_INSERT_EXPR folding for BYTES_BIG_ENDIAN [PR116997]

2024-11-18 Thread Andre Simoes Dias Vieira via Gcc-cvs
https://gcc.gnu.org/g:b51b45eaf7131ec97b7fa180ffa6e8dedc24e74f

commit r14-10938-gb51b45eaf7131ec97b7fa180ffa6e8dedc24e74f
Author: Andre Vieira 
Date:   Mon Oct 14 16:24:07 2024 +0100

fold-const: Fix BIT_INSERT_EXPR folding for BYTES_BIG_ENDIAN [PR116997]

Fix constant folding of BIT_INSER_EXPR for BYTES_BIG_ENDIAN targets.

gcc/ChangeLog:

PR middle-end/116997
* fold-const.cc (fold_ternary_loc): Fix BIT_INSERT_EXPR constant 
folding
for BYTES_BIG_ENDIAN targets.

gcc/testsuite/ChangeLog:

* gcc.dg/vect/pr116997.c: New test.

Co-authored-by: Andrew Pinski 
(cherry picked from commit 2e30e90a0c2bf8147a6d24854aa653c332c8f84f)

Diff:
---
 gcc/fold-const.cc|  2 ++
 gcc/testsuite/gcc.dg/vect/pr116997.c | 18 ++
 2 files changed, 20 insertions(+)

diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 1e6b573ca01a..89df178c6968 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -13652,6 +13652,8 @@ fold_ternary_loc (location_t loc, enum tree_code code, 
tree type,
{
  unsigned HOST_WIDE_INT bitpos = tree_to_uhwi (op2);
  unsigned bitsize = TYPE_PRECISION (TREE_TYPE (arg1));
+ if (BYTES_BIG_ENDIAN)
+   bitpos = TYPE_PRECISION (type) - bitpos - bitsize;
  wide_int tem = (wi::to_wide (arg0)
  & wi::shifted_mask (bitpos, bitsize, true,
  TYPE_PRECISION (type)));
diff --git a/gcc/testsuite/gcc.dg/vect/pr116997.c 
b/gcc/testsuite/gcc.dg/vect/pr116997.c
new file mode 100644
index ..4563fc2bfb6f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr116997.c
@@ -0,0 +1,18 @@
+/* PR 116997.  */
+struct S0
+{
+  unsigned f0;
+  signed f2 : 11;
+  signed : 6;
+} GlobS, *Ptr = &GlobS;
+
+const struct S0 Initializer = {7, 3};
+
+int main (void)
+{
+  for (unsigned i = 0; i <= 2; i++)
+*Ptr = Initializer;
+  if (GlobS.f2 != 3)
+__builtin_abort ();
+  return 0;
+}


[gcc r15-5407] PR modula2/117371: Add check for zero step in for loop

2024-11-18 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:e37641458e9e1be1a81ff7fab4f4ab8398147d80

commit r15-5407-ge37641458e9e1be1a81ff7fab4f4ab8398147d80
Author: Gaius Mulley 
Date:   Mon Nov 18 16:34:42 2024 +

PR modula2/117371: Add check for zero step in for loop

This patch is a follow on from PR modula2/117371 which could include
a check to enforce the ISO restriction on a zero for loop step.

gcc/m2/ChangeLog:

PR modula2/117371
* gm2-compiler/M2GenGCC.mod (PerformLastForIterator):
Add check for zero step value and issue an error message.

gcc/testsuite/ChangeLog:

PR modula2/117371
* gm2/iso/fail/forloopbyzero.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2GenGCC.mod | 24 
 gcc/testsuite/gm2/iso/fail/forloopbyzero.mod | 18 ++
 2 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2GenGCC.mod b/gcc/m2/gm2-compiler/M2GenGCC.mod
index 1cb60a87a84f..b6e34e019b04 100644
--- a/gcc/m2/gm2-compiler/M2GenGCC.mod
+++ b/gcc/m2/gm2-compiler/M2GenGCC.mod
@@ -529,7 +529,15 @@ BEGIN
   e2 := GetNth (tuple, 2) ;
   e1tree := Mod2Gcc (e1) ;
   e2tree := Mod2Gcc (e2) ;
-  IF CompareTrees (incrtree, GetIntegerZero (location)) > 0
+  IF CompareTrees (incrtree, GetIntegerZero (location)) = 0
+  THEN
+ MetaErrorT0 (lastpos,
+  'the {%kFOR} loop step value must not be zero') ;
+ MetaErrorDecl (incr, TRUE) ;
+ NoChange := FALSE ;
+ SubQuad (quad) ;
+ success := FALSE
+  ELSIF CompareTrees (incrtree, GetIntegerZero (location)) > 0
   THEN
  (* If incr > 0 then LastIterator := ((e2-e1) DIV incr) * incr + e1.  
*)
  expr := BuildSub (location, e2tree, e1tree, FALSE) ;
@@ -3537,9 +3545,9 @@ BEGIN
IF StrictTypeChecking AND
   (NOT AssignmentTypeCompatible (virtpos, "", des, expr))
THEN
-  MetaErrorT2 (virtpos,
-   'assignment check caught mismatch between {%1Ead} and 
{%2ad}',
-   des, expr)
+  ErrorMessageDecl (virtpos,
+'assignment check caught mismatch between {%1Ead} and 
{%2ad}',
+des, expr, TRUE)
END ;
IF IsConstString (expr) AND (NOT IsConstStringKnown (expr))
THEN
@@ -3554,9 +3562,9 @@ BEGIN
   checkDeclare (des) ;
   IF NOT PrepareCopyString (becomespos, length, exprt, expr, SkipType 
(GetType (des)))
   THEN
- MetaErrorT2 (virtpos,
-  'string constant {%1Ea} is too large to be assigned to 
the array {%2ad}',
-  expr, des)
+ ErrorMessageDecl (virtpos,
+   'string constant {%1Ea} is too large to be assigned 
to the array {%2ad}',
+   expr, des, TRUE)
   END ;
   AddStatement (location,
 MaybeDebugBuiltinMemcpy (location,
@@ -3590,7 +3598,7 @@ BEGIN
  FoldConstBecomes (virtpos, des, expr))
 END
  ELSE
-SubQuad (quad)  (* we don't want multiple errors for the quad.  *)
+SubQuad (quad)  (* We don't want multiple errors for the quad.  *)
  END
   END
END
diff --git a/gcc/testsuite/gm2/iso/fail/forloopbyzero.mod 
b/gcc/testsuite/gm2/iso/fail/forloopbyzero.mod
new file mode 100644
index ..912eccfddfff
--- /dev/null
+++ b/gcc/testsuite/gm2/iso/fail/forloopbyzero.mod
@@ -0,0 +1,18 @@
+MODULE forloopbyzero ;
+
+CONST
+   ConstExp = 10 - 10 ;
+
+PROCEDURE test ;
+VAR
+   i: CARDINAL ;
+BEGIN
+   FOR i := 1 TO 10 BY ConstExp DO
+
+   END
+END test ;
+
+
+BEGIN
+   test
+END forloopbyzero.


[gcc r15-5408] [RFA] Fix csky and c6x build failures

2024-11-18 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:39a39d1f38ccb9ba292b22003dc3c7febb0b6512

commit r15-5408-g39a39d1f38ccb9ba292b22003dc3c7febb0b6512
Author: Jeff Law 
Date:   Mon Nov 18 09:59:54 2024 -0700

[RFA] Fix csky and c6x build failures

csky fails to build libgcc after the c23 changes because it has a typedef 
for
bool.  AFAICT it's internal to the file, so removing the typedef isn't an 
ABI
change.

Similiarly for c6x which includes unwind-arm-common.inc.  I suspect most, if
not all of the arm-v7 and older targets are failing to build right now.

I've built and regression tested both csky-linux-gnu and c6x-elf with this
change.  OK for the trunk?

PR target/117628
libgcc/
* config/csky/linux-atomic.c (bool): Remove unnecessary typedef.
* unwind-arm-common.inc (bool): Similarly.

Diff:
---
 libgcc/config/csky/linux-atomic.c | 2 --
 libgcc/unwind-arm-common.inc  | 2 --
 2 files changed, 4 deletions(-)

diff --git a/libgcc/config/csky/linux-atomic.c 
b/libgcc/config/csky/linux-atomic.c
index 15c38156c778..274485547308 100644
--- a/libgcc/config/csky/linux-atomic.c
+++ b/libgcc/config/csky/linux-atomic.c
@@ -215,8 +215,6 @@ __sync_val_compare_and_swap_4 (int *ptr, int oldval, int 
newval)
 SUBWORD_VAL_CAS (unsigned short, 2)
 SUBWORD_VAL_CAS (unsigned char,1)
 
-typedef unsigned char bool;
-
 bool HIDDEN
 __sync_bool_compare_and_swap_4 (int *ptr, int oldval, int newval)
 {
diff --git a/libgcc/unwind-arm-common.inc b/libgcc/unwind-arm-common.inc
index 576f7e93e8a8..1e9a58dbab2a 100644
--- a/libgcc/unwind-arm-common.inc
+++ b/libgcc/unwind-arm-common.inc
@@ -52,8 +52,6 @@
 
 /* Definitions for C++ runtime support routines.  We make these weak
declarations to avoid pulling in libsupc++ unnecessarily.  */
-typedef unsigned char bool;
-
 typedef struct _ZSt9type_info type_info; /* This names C++ type_info type */
 enum __cxa_type_match_result
   {


[gcc r15-5412] [committed][RISC-V][PR target/117595] Fix bogus use of simplify_gen_subreg

2024-11-18 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:f5ceca96278b2ffaff838216aa6644fedb603573

commit r15-5412-gf5ceca96278b2ffaff838216aa6644fedb603573
Author: Jeff Law 
Date:   Mon Nov 18 10:55:09 2024 -0700

[committed][RISC-V][PR target/117595] Fix bogus use of simplify_gen_subreg

And stage3 begins...

Zdenek's fuzzer caught this one.  Essentially using simplify_gen_subreg
directly with an offset of 0 when we just needed a lowpart.

The offset of 0 works for little endian, but for big endian it's simply 
wrong.
simplify_gen_subreg will return NULL_RTX because the case isn't 
representable.
We then embed that NULL_RTX into an insn that's later scanned during
mark_jump_label.

Scanning the port I see a couple more instances of this incorrect idiom.   
One
is pretty obvious to fix.  The others look a bit goofy and I'll probably 
need
to sync with Patrick on them.

Anyway tested on riscv64-elf and riscv32-elf with no regressions.  Pushing 
to
the trunk.

PR target/117595
gcc/
* config/riscv/sync.md (atomic_compare_and_swap): Use 
gen_lowpart
rather than simplify_gen_subreg.
* config/riscv/riscv.cc (riscv_legitimize_move): Similarly.

gcc/testsuite/
* gcc.target/riscv/pr117595.c: New test.

Diff:
---
 gcc/config/riscv/riscv.cc | 2 +-
 gcc/config/riscv/sync.md  | 2 +-
 gcc/testsuite/gcc.target/riscv/pr117595.c | 5 +
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 7694954c4c5c..03271d893b60 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -3646,7 +3646,7 @@ riscv_legitimize_move (machine_mode mode, rtx dest, rtx 
src)
   rtx mask = force_reg (word_mode, gen_int_mode (-65536, word_mode));
   rtx temp = gen_reg_rtx (word_mode);
   emit_insn (gen_extend_insn (temp,
- simplify_gen_subreg (HImode, src, mode, 0),
+ gen_lowpart (HImode, src),
  word_mode, HImode, 1));
   if (word_mode == SImode)
emit_insn (gen_iorsi3 (temp, mask, temp));
diff --git a/gcc/config/riscv/sync.md b/gcc/config/riscv/sync.md
index aa0c20446f42..23c0859e0856 100644
--- a/gcc/config/riscv/sync.md
+++ b/gcc/config/riscv/sync.md
@@ -580,7 +580,7 @@
 value is sign-extended.  */
   rtx tmp0 = gen_reg_rtx (word_mode);
   emit_insn (gen_extend_insn (tmp0, operands[3], word_mode, mode, 
0));
-  operands[3] = simplify_gen_subreg (mode, tmp0, word_mode, 0);
+  operands[3] = gen_lowpart (mode, tmp0);
 }
 
   if (TARGET_ZACAS)
diff --git a/gcc/testsuite/gcc.target/riscv/pr117595.c 
b/gcc/testsuite/gcc.target/riscv/pr117595.c
new file mode 100644
index ..a870df08ee4b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/pr117595.c
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-options "-mbig-endian" } */
+
+_Atomic enum { E0 } e;
+void foo() { e++; }


[gcc r15-5413] tree-optimization/117594 - fix live op vectorization for length masked case

2024-11-18 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:c108785c425b2042f63fa975c58c274d19a8d160

commit r15-5413-gc108785c425b2042f63fa975c58c274d19a8d160
Author: Richard Biener 
Date:   Mon Nov 18 13:46:52 2024 +0100

tree-optimization/117594 - fix live op vectorization for length masked case

The code was passing factor == 0 to vect_get_loop_len which always
returns an unmodified length, even if the number of scalar elements
doesn't agree.  It also failed to insert the eventually generated
code.

PR tree-optimization/117594
* tree-vect-loop.cc (vectorizable_live_operation_1): Pass
factor == 1 to vect_get_loop_len, insert generated stmts.

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

Diff:
---
 gcc/testsuite/gcc.dg/vect/pr117594.c | 20 
 gcc/tree-vect-loop.cc|  3 ++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/vect/pr117594.c 
b/gcc/testsuite/gcc.dg/vect/pr117594.c
new file mode 100644
index ..ab213908bbc9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr117594.c
@@ -0,0 +1,20 @@
+/* { dg-require-effective-target int32plus } */
+
+#include "tree-vect.h"
+
+unsigned a;
+short b, d, e;
+int main()
+{
+  check_vect ();
+  short h = d;
+  short *z = &h;
+  for (_Bool i = 0; i < 1; i = 1)
+for (unsigned j = 0; j < (z[i] ?: 10); j += 3)
+  {
+   a -= 9;
+   b -= ~e;
+  }
+  if (a != 4294967260)
+__builtin_abort ();
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 18c4fa1d000a..ce728143469d 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -11221,7 +11221,8 @@ vectorizable_live_operation_1 (loop_vec_info loop_vinfo,
   gimple_stmt_iterator gsi = gsi_last (tem);
   tree len = vect_get_loop_len (loop_vinfo, &gsi,
&LOOP_VINFO_LENS (loop_vinfo),
-   1, vectype, 0, 0);
+   1, vectype, 0, 1);
+  gimple_seq_add_seq (&stmts, tem);
 
   /* BIAS - 1.  */
   signed char biasval = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);


[gcc r15-5414] Fortran: add bounds-checking for ALLOCATE of CHARACTER with type-spec [PR53357]

2024-11-18 Thread Harald Anlauf via Gcc-cvs
https://gcc.gnu.org/g:386f6d98ba0d438d65da1ad5b203f7b2743fc6da

commit r15-5414-g386f6d98ba0d438d65da1ad5b203f7b2743fc6da
Author: Harald Anlauf 
Date:   Sun Nov 17 23:04:58 2024 +0100

Fortran: add bounds-checking for ALLOCATE of CHARACTER with type-spec 
[PR53357]

Fix a rejects-(potentially)-valid code for ALLOCATE of CHARACTER with
type-spec, and implement a string-length check for -fcheck=bounds.
Implement more detailed errors or warnings when character function
declarations and references do not match.

PR fortran/53357

gcc/fortran/ChangeLog:

* dependency.cc (gfc_dep_compare_expr): Return correct result if
relationship of expressions could not be determined.
* interface.cc (gfc_check_result_characteristics): Implement error
messages if character function declations and references do not
agree, else emit warning in cases where a mismatch is suspected.
* trans-stmt.cc (gfc_trans_allocate): Implement a string length
check for -fcheck=bounds.

gcc/testsuite/ChangeLog:

* gfortran.dg/auto_char_len_4.f90: Adjust patterns.
* gfortran.dg/typebound_override_1.f90: Likewise.
* gfortran.dg/bounds_check_strlen_10.f90: New test.

Diff:
---
 gcc/fortran/dependency.cc  |  2 +-
 gcc/fortran/interface.cc   | 27 +++---
 gcc/fortran/trans-stmt.cc  | 11 +
 gcc/testsuite/gfortran.dg/auto_char_len_4.f90  | 25 ++--
 .../gfortran.dg/bounds_check_strlen_10.f90 | 21 +
 gcc/testsuite/gfortran.dg/typebound_override_1.f90 |  4 ++--
 6 files changed, 77 insertions(+), 13 deletions(-)

diff --git a/gcc/fortran/dependency.cc b/gcc/fortran/dependency.cc
index 2d3db9541bba..1fd65bbadca6 100644
--- a/gcc/fortran/dependency.cc
+++ b/gcc/fortran/dependency.cc
@@ -474,7 +474,7 @@ gfc_dep_compare_expr (gfc_expr *e1, gfc_expr *e2)
   }
 
   if (e1->expr_type != e2->expr_type)
-return -3;
+return -2;
 
   switch (e1->expr_type)
 {
diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc
index 61c506bfdb5d..176c7d4a8ed4 100644
--- a/gcc/fortran/interface.cc
+++ b/gcc/fortran/interface.cc
@@ -1692,9 +1692,30 @@ gfc_check_result_characteristics (gfc_symbol *s1, 
gfc_symbol *s2,
  return false;
 
case -2:
- /* FIXME: Implement a warning for this case.
- snprintf (errmsg, err_len, "Possible character length mismatch "
-   "in function result");*/
+ if (r1->ts.u.cl->length->expr_type == EXPR_CONSTANT)
+   {
+ snprintf (errmsg, err_len,
+   "Function declared with a non-constant character "
+   "length referenced with a constant length");
+ return false;
+   }
+ else if (r2->ts.u.cl->length->expr_type == EXPR_CONSTANT)
+   {
+ snprintf (errmsg, err_len,
+   "Function declared with a constant character "
+   "length referenced with a non-constant length");
+ return false;
+   }
+ /* Warn if length expression types are different, except for
+ possibly false positives where complex expressions might have
+ been used.  */
+ else if ((r1->ts.u.cl->length->expr_type
+   != r2->ts.u.cl->length->expr_type)
+  && (r1->ts.u.cl->length->expr_type != EXPR_OP
+  || r2->ts.u.cl->length->expr_type != EXPR_OP))
+   gfc_warning (0, "Possible character length mismatch in "
+"function result between %L and %L",
+&r1->declared_at, &r2->declared_at);
  break;
 
case 0:
diff --git a/gcc/fortran/trans-stmt.cc b/gcc/fortran/trans-stmt.cc
index 520ab505659f..a409c25b8991 100644
--- a/gcc/fortran/trans-stmt.cc
+++ b/gcc/fortran/trans-stmt.cc
@@ -6393,6 +6393,7 @@ gfc_trans_allocate (gfc_code * code, gfc_omp_namelist 
*omp_allocate)
   gfc_symtree *newsym = NULL;
   symbol_attribute caf_attr;
   gfc_actual_arglist *param_list;
+  tree ts_string_length = NULL_TREE;
 
   if (!code->ext.alloc.list)
 return NULL_TREE;
@@ -6741,6 +6742,7 @@ gfc_trans_allocate (gfc_code * code, gfc_omp_namelist 
*omp_allocate)
  gfc_init_se (&se_sz, NULL);
  gfc_conv_expr (&se_sz, sz);
  gfc_free_expr (sz);
+ ts_string_length = fold_convert (gfc_charlen_type_node, se_sz.expr);
  tmp = gfc_get_char_type (code->ext.alloc.ts.kind);
  tmp = TYPE_SIZE_UNIT (tmp);
  tmp = fold_convert (TREE_TYPE (se_sz.expr), tmp);
@@ -6951,6 +6953,15 @@ gfc_trans_allocate (gfc_code * code, gfc_omp_namelist 
*omp_alloca

[gcc r13-9198] AVR: target/117659 - Fix wrong code for u24 << 16.

2024-11-18 Thread Georg-Johann Lay via Gcc-cvs
https://gcc.gnu.org/g:3c15b26d5f072cd083d469df976cf6adf3e68fb3

commit r13-9198-g3c15b26d5f072cd083d469df976cf6adf3e68fb3
Author: Georg-Johann Lay 
Date:   Mon Nov 18 18:12:38 2024 +0100

AVR: target/117659 - Fix wrong code for u24 << 16.

gcc/
PR target/117659
* config/avr/avr.cc (avr_out_ashlpsi3) [case 16]: Use %A1 as
input (instead of bogus %A0).

(cherry picked from commit bba27015f2815a8fa6fae46a29a70644e868341c)

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

diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc
index d729936b7daa..b2d98cc46a18 100644
--- a/gcc/config/avr/avr.cc
+++ b/gcc/config/avr/avr.cc
@@ -7097,7 +7097,7 @@ avr_out_ashlpsi3 (rtx_insn *insn, rtx *op, int *plen)
 int reg1 = REGNO (op[1]);
 
 if (reg0 + 2 != reg1)
-  avr_asm_len ("mov %C0,%A0", op, plen, 1);
+  avr_asm_len ("mov %C0,%A1", op, plen, 1);
 
 return avr_asm_len ("clr %B0"  CR_TAB
 "clr %A0", op, plen, 2);


[gcc r15-5404] ada: Fix small oversight in removal of N_Unchecked_Expression node

2024-11-18 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:70faad19613748c7894afafac2703d7aa856a7c6

commit r15-5404-g70faad19613748c7894afafac2703d7aa856a7c6
Author: Eric Botcazou 
Date:   Fri Nov 8 15:35:27 2024 +0100

ada: Fix small oversight in removal of N_Unchecked_Expression node

In addition to Resolve_Indexed_Component, Eval_Indexed_Component can also
set the Do_Range_Check flag on the expressions of an N_Indexed_Component
node through the call on Check_Non_Static_Context, so this also needs to
be blocked by the Kill_Range_Check flag.

gcc/ada/ChangeLog:

* sem_eval.adb (Eval_Indexed_Component): Clear Do_Range_Check on
the expressions if Kill_Range_Check is set on the node.

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

diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb
index a880acabad87..9ea042ba0d33 100644
--- a/gcc/ada/sem_eval.adb
+++ b/gcc/ada/sem_eval.adb
@@ -2629,6 +2629,9 @@ package body Sem_Eval is
   Expr := First (Expressions (N));
   while Present (Expr) loop
  Check_Non_Static_Context (Expr);
+ if Kill_Range_Check (N) then
+Set_Do_Range_Check (Expr, False);
+ end if;
  Next (Expr);
   end loop;


[gcc r15-5416] PR modula2/117555: libgm2 build failure after r15-5081-g95960cd473297c

2024-11-18 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:6d90f5d0ae928320e6e4ce9fce8e658404d8cb72

commit r15-5416-g6d90f5d0ae928320e6e4ce9fce8e658404d8cb72
Author: Gaius Mulley 
Date:   Mon Nov 18 18:35:28 2024 +

PR modula2/117555: libgm2 build failure after r15-5081-g95960cd473297c

This patch adds missing return statements to library procedure
functions.  These missing statements occur after a call to RAISE.

gcc/m2/ChangeLog:

PR modula2/117555
* gm2-libs-iso/M2EXCEPTION.mod (M2Exception): Add missing
return statement.
* gm2-libs-iso/RealConv.mod (ValueReal): Ditto.
* gm2-libs-iso/RndFile.mod (StartPos): Ditto.
(EndPos): Ditto.
(NewPos): Ditto.
* gm2-libs-iso/ShortConv.mod (ValueReal): Ditto.
* gm2-libs-iso/WholeConv.mod (ValueInt): Ditto.
(ValueCard): Ditto.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-libs-iso/M2EXCEPTION.mod |  3 ++-
 gcc/m2/gm2-libs-iso/RealConv.mod|  3 ++-
 gcc/m2/gm2-libs-iso/RndFile.mod | 15 +--
 gcc/m2/gm2-libs-iso/ShortConv.mod   |  3 ++-
 gcc/m2/gm2-libs-iso/WholeConv.mod   |  6 --
 5 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/gcc/m2/gm2-libs-iso/M2EXCEPTION.mod 
b/gcc/m2/gm2-libs-iso/M2EXCEPTION.mod
index 637e086c2998..2ff7c7296647 100644
--- a/gcc/m2/gm2-libs-iso/M2EXCEPTION.mod
+++ b/gcc/m2/gm2-libs-iso/M2EXCEPTION.mod
@@ -42,7 +42,8 @@ BEGIN
ELSE
   RTExceptions.Raise(ORD(exException),
  ADR(__FILE__), __LINE__, __COLUMN__, 
ADR(__FUNCTION__),
- ADR('current coroutine is not in the exceptional 
execution state'))
+ ADR('current coroutine is not in the exceptional 
execution state')) ;
+  RETURN exException
END
 END M2Exception ;
 
diff --git a/gcc/m2/gm2-libs-iso/RealConv.mod b/gcc/m2/gm2-libs-iso/RealConv.mod
index 4223f3029ae8..6f9fe6fcc7b2 100644
--- a/gcc/m2/gm2-libs-iso/RealConv.mod
+++ b/gcc/m2/gm2-libs-iso/RealConv.mod
@@ -256,7 +256,8 @@ BEGIN
   RETURN( doValueReal(str) )
ELSE
   EXCEPTIONS.RAISE(realConv, ORD(invalid),
-   'RealConv.' + __FUNCTION__ + ': real number is invalid')
+   'RealConv.' + __FUNCTION__ + ': real number is 
invalid') ;
+  RETURN 0.0
END
 END ValueReal ;
 
diff --git a/gcc/m2/gm2-libs-iso/RndFile.mod b/gcc/m2/gm2-libs-iso/RndFile.mod
index 46a2efdaac4a..42451888bafe 100644
--- a/gcc/m2/gm2-libs-iso/RndFile.mod
+++ b/gcc/m2/gm2-libs-iso/RndFile.mod
@@ -359,13 +359,13 @@ VAR
 BEGIN
IF IsRndFile(cid)
THEN
-  d := DeviceTablePtrValue(cid, did) ;
-  RETURN( 0 )
+  d := DeviceTablePtrValue(cid, did)
ELSE
   RAISEdevException(cid, did, IOChan.wrongDevice,
 'RndFile.' + __FUNCTION__ +
 ': channel is not a random file')
-   END
+   END ;
+   RETURN( 0 )
 END StartPos ;
 
 
@@ -386,7 +386,8 @@ BEGIN
ELSE
   RAISEdevException(cid, did, IOChan.wrongDevice,
 'RndFile.' + __FUNCTION__ +
-': channel is not a random file')
+': channel is not a random file') ;
+  RETURN 0
END
 END CurrentPos ;
 
@@ -416,7 +417,8 @@ BEGIN
ELSE
   RAISEdevException(cid, did, IOChan.wrongDevice,
 'RndFile.' + __FUNCTION__ +
-': channel is not a random file')
+': channel is not a random file') ;
+  RETURN 0
END
 END EndPos ;
 
@@ -442,7 +444,8 @@ BEGIN
ELSE
   RAISEdevException(cid, did, IOChan.wrongDevice,
 'RndFile.' + __FUNCTION__ +
-': channel is not a random file')
+': channel is not a random file') ;
+  RETURN 0
END
 END NewPos ;
 
diff --git a/gcc/m2/gm2-libs-iso/ShortConv.mod 
b/gcc/m2/gm2-libs-iso/ShortConv.mod
index cfceb25c8f4c..bb835c6102ec 100644
--- a/gcc/m2/gm2-libs-iso/ShortConv.mod
+++ b/gcc/m2/gm2-libs-iso/ShortConv.mod
@@ -257,7 +257,8 @@ BEGIN
   RETURN( doValueReal(str) )
ELSE
   EXCEPTIONS.RAISE(realConv, ORD(invalid),
-   'ShortConv.' + __FUNCTION__ + ': real number is 
invalid')
+   'ShortConv.' + __FUNCTION__ + ': real number is 
invalid') ;
+  RETURN 0.0
END
 END ValueReal ;
 
diff --git a/gcc/m2/gm2-libs-iso/WholeConv.mod 
b/gcc/m2/gm2-libs-iso/WholeConv.mod
index 34ca7aca1a11..769a568fe32f 100644
--- a/gcc/m2/gm2-libs-iso/WholeConv.mod
+++ b/gcc/m2/gm2-libs-iso/WholeConv.mod
@@ -196,7 +196,8 @@ BEGIN
   RETURN( v )
ELSE
   EXCEPTIONS.RAISE(wholeConv, ORD(invalidSigned),
-   'WholeConv.' + __FUNCTION__ + ': signed number is 
invalid')
+   'WholeConv.' + __FUNCTION__ + ': signed number is 
invalid') ;
+  RETURN 0
END
 END ValueInt ;
 
@@ -333,7 +334,8 @@ BEGIN
   RETURN( value 

[gcc r15-5424] Add a timevar for late combine

2024-11-18 Thread Richard Sandiford via Gcc-cvs
https://gcc.gnu.org/g:a019429f365e32d0ce01b0b60924f0dd37737769

commit r15-5424-ga019429f365e32d0ce01b0b60924f0dd37737769
Author: Richard Sandiford 
Date:   Mon Nov 18 19:33:58 2024 +

Add a timevar for late combine

When adding late-combine.cc, I forgot to add a timevar for it.

gcc/
* timevar.def (TV_LATE_COMBINE): New timevar.
* late-combine.cc (pass_data_late_combine): Use it.

Diff:
---
 gcc/late-combine.cc | 2 +-
 gcc/timevar.def | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/late-combine.cc b/gcc/late-combine.cc
index 1b6cd0bea2c1..ba65e4a93b47 100644
--- a/gcc/late-combine.cc
+++ b/gcc/late-combine.cc
@@ -53,7 +53,7 @@ const pass_data pass_data_late_combine =
   RTL_PASS, // type
   "late_combine", // name
   OPTGROUP_NONE, // optinfo_flags
-  TV_NONE, // tv_id
+  TV_LATE_COMBINE, // tv_id
   0, // properties_required
   0, // properties_provided
   0, // properties_destroyed
diff --git a/gcc/timevar.def b/gcc/timevar.def
index ae80a311a2d2..115b20392533 100644
--- a/gcc/timevar.def
+++ b/gcc/timevar.def
@@ -262,6 +262,7 @@ DEFTIMEVAR (TV_AUTO_INC_DEC  , "auto inc dec")
 DEFTIMEVAR (TV_CSE2  , "CSE 2")
 DEFTIMEVAR (TV_BRANCH_PROB   , "branch prediction")
 DEFTIMEVAR (TV_COMBINE   , "combiner")
+DEFTIMEVAR (TV_LATE_COMBINE  , "late combiner")
 DEFTIMEVAR (TV_IFCVT, "if-conversion")
 DEFTIMEVAR (TV_MODE_SWITCH   , "mode switching")
 DEFTIMEVAR (TV_SMS  , "sms modulo scheduling")


[gcc r15-5381] libgomp/plugin/plugin-nvptx.c: Change false to NULL to fix C23 wrong-return-type error [PR117626]

2024-11-18 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:e7e3d1838f7cfb4a9fca711d735d8f5ea47d16dc

commit r15-5381-ge7e3d1838f7cfb4a9fca711d735d8f5ea47d16dc
Author: Tobias Burnus 
Date:   Mon Nov 18 11:06:58 2024 +0100

libgomp/plugin/plugin-nvptx.c: Change false to NULL to fix C23 
wrong-return-type error [PR117626]

libgomp/ChangeLog:

PR libgomp/117626
* plugin/plugin-nvptx.c (nvptx_open_device): Use 'CUDA_CALL_ERET'
with 'NULL' as error return instead of 'CUDA_CALL' that returns 
false.

Diff:
---
 libgomp/plugin/plugin-nvptx.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libgomp/plugin/plugin-nvptx.c b/libgomp/plugin/plugin-nvptx.c
index e9a9d798fe6b..f6d7f0675714 100644
--- a/libgomp/plugin/plugin-nvptx.c
+++ b/libgomp/plugin/plugin-nvptx.c
@@ -595,8 +595,10 @@ nvptx_open_device (int n)
   GOMP_PLUGIN_debug (0, "Setting \"native\" GPU thread stack size"
 " ('CU_LIMIT_STACK_SIZE') to %u bytes\n",
 native_gpu_thread_stack_size);
-  CUDA_CALL (cuCtxSetLimit,
-CU_LIMIT_STACK_SIZE, (size_t) native_gpu_thread_stack_size);
+  CUDA_CALL_ERET (NULL,
+ cuCtxSetLimit,
+ CU_LIMIT_STACK_SIZE,
+ (size_t) native_gpu_thread_stack_size);
 }
 
   /* OpenMP "soft stacks".  */


[gcc r15-5429] json: add json parsing support

2024-11-18 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:66e6e4f131e517344e4f2c16f96de90d391d94e0

commit r15-5429-g66e6e4f131e517344e4f2c16f96de90d391d94e0
Author: David Malcolm 
Date:   Mon Nov 18 17:08:36 2024 -0500

json: add json parsing support

This patch implements JSON parsing support.

It's based on the parsing parts of the patch I posted here:
https://gcc.gnu.org/legacy-ml/gcc-patches/2017-08/msg00417.html
with the parsing moved to a separate source file and header, heavily
rewritten to capture source location information for JSON values, and
to capture errors via a result template.

I also added optional support for C and C++ style comments, which is
extremely useful in DejaGnu tests.

gcc/ChangeLog:
* Makefile.in (OBJS-libcommon): Add json-parsing.o.
* json-parsing.cc: New file.
* json-parsing.h: New file.
* json.cc (selftest::assert_print_eq): Remove "static".
* json.h (json::array::begin): New.
(json::array::end): New.
(json::array::length): New.
(json::array::get): New.
(is_a_helper ::test): New.
(is_a_helper ::test): New.
(is_a_helper ::test): New.
(is_a_helper ::test): New.
(is_a_helper ::test): New.
(is_a_helper ::test): New.
(is_a_helper ::test): New.
(is_a_helper ::test): New.
(is_a_helper ::test): New.
(is_a_helper ::test): New.
(is_a_helper ::test): New.
(is_a_helper ::test): New.
(selftest::assert_print_eq): New decl.
* selftest-run-tests.cc (selftest::run_tests): Call
selftest::json_parser_cc_tests.
* selftest.h (selftest::json_parser_cc_tests): New decl.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/Makefile.in   |2 +-
 gcc/json-parsing.cc   | 2394 +
 gcc/json-parsing.h|  113 +++
 gcc/json.cc   |2 +-
 gcc/json.h|  122 ++-
 gcc/selftest-run-tests.cc |1 +
 gcc/selftest.h|1 +
 7 files changed, 2631 insertions(+), 4 deletions(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 41b0c2d0248e..5c8832d65654 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1838,7 +1838,7 @@ OBJS-libcommon = diagnostic-spec.o diagnostic.o 
diagnostic-color.o \
diagnostic-show-locus.o \
edit-context.o \
pretty-print.o intl.o \
-   json.o \
+   json.o json-parsing.o \
sbitmap.o \
vec.o input.o hash-table.o ggc-none.o memory-block.o \
selftest.o selftest-diagnostic.o sort.o \
diff --git a/gcc/json-parsing.cc b/gcc/json-parsing.cc
new file mode 100644
index ..78188c4fef9c
--- /dev/null
+++ b/gcc/json-parsing.cc
@@ -0,0 +1,2394 @@
+/* JSON parsing
+   Copyright (C) 2017-2024 Free Software Foundation, Inc.
+   Contributed by David Malcolm .
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#include "config.h"
+#define INCLUDE_MEMORY
+#include "system.h"
+#include "coretypes.h"
+#include "json-parsing.h"
+#include "pretty-print.h"
+#include "math.h"
+#include "make-unique.h"
+#include "selftest.h"
+
+using namespace json;
+
+/* Declarations relating to parsing JSON, all within an
+   anonymous namespace.  */
+
+namespace {
+
+/* A typedef representing a single unicode character.  */
+
+typedef unsigned unichar;
+
+/* An enum for discriminating different kinds of JSON token.  */
+
+enum token_id
+{
+  TOK_ERROR,
+
+  TOK_EOF,
+
+  /* Punctuation.  */
+  TOK_OPEN_SQUARE,
+  TOK_OPEN_CURLY,
+  TOK_CLOSE_SQUARE,
+  TOK_CLOSE_CURLY,
+  TOK_COLON,
+  TOK_COMMA,
+
+  /* Literal names.  */
+  TOK_TRUE,
+  TOK_FALSE,
+  TOK_NULL,
+
+  TOK_STRING,
+  TOK_FLOAT_NUMBER,
+  TOK_INTEGER_NUMBER
+};
+
+/* Human-readable descriptions of enum token_id.  */
+
+static const char *token_id_name[] = {
+  "error",
+  "EOF",
+  "'['",
+  "'{'",
+  "']'",
+  "'}'",
+  "':'",
+  "','",
+  "'true'",
+  "'false'",
+  "'null'",
+  "string",
+  "number",
+  "number"
+};
+
+/* Tokens within the JSON lexer.  */
+
+struct token
+{
+  /* The kind of token.  */
+  enum token_id id;
+
+  /* The location of this token within the unicode
+ character stream.  */
+  location_map::range range;
+
+  union
+  {
+/* Value for TOK_ERROR and TOK_STRING.  */
+

[gcc r15-5431] c: Allow bool and enum null pointer constants [PR112556]

2024-11-18 Thread Joseph Myers via Gcc-cvs
https://gcc.gnu.org/g:3d525fce70fa0ffa0b22af6e213643e1ceca5ab5

commit r15-5431-g3d525fce70fa0ffa0b22af6e213643e1ceca5ab5
Author: Joseph Myers 
Date:   Mon Nov 18 22:24:48 2024 +

c: Allow bool and enum null pointer constants [PR112556]

As reported in bug 112556, GCC wrongly rejects conversion of null
pointer constants with bool or enum type to pointers in
convert_for_assignment (assignment, initialization, argument passing,
return).  Fix the code there to allow BOOLEAN_TYPE and ENUMERAL_TYPE;
it already allowed INTEGER_TYPE and BITINT_TYPE.

This bug (together with -std=gnu23 meaning false has type bool rather
than int) has in turn resulted in people thinking they need to fix
code using false as a null pointer constant for C23 compatibility.
While such a usage is certainly questionable, it has nothing to do
with C23 compatibility and the right place for warnings about such
usage is -Wzero-as-null-pointer-constant.  I think it would be
appropriate to extend -Wzero-as-null-pointer-constant to cover
BOOLEAN_TYPE, ENUMERAL_TYPE and BITINT_TYPE (in all the various
contexts in which that option generates warnings), though this patch
doesn't do anything about that option.

Bootstrapped with no regressions for x86-64-pc-linux-gnu.

PR c/112556

gcc/c/
* c-typeck.cc (convert_for_assignment): Allow conversion of
ENUMERAL_TYPE and BOOLEAN_TYPE null pointer constants to pointers.

gcc/testsuite/
* gcc.dg/c11-null-pointer-constant-1.c,
gcc.dg/c23-null-pointer-constant-1.c: New tests.

Diff:
---
 gcc/c/c-typeck.cc  |   2 +
 gcc/testsuite/gcc.dg/c11-null-pointer-constant-1.c |  55 ++
 gcc/testsuite/gcc.dg/c23-null-pointer-constant-1.c | 120 +
 3 files changed, 177 insertions(+)

diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 26ee0ebf91f0..a701dd090fb8 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -8457,6 +8457,8 @@ convert_for_assignment (location_t location, location_t 
expr_loc, tree type,
 }
   else if (codel == POINTER_TYPE
   && (coder == INTEGER_TYPE
+  || coder == ENUMERAL_TYPE
+  || coder == BOOLEAN_TYPE
   || coder == NULLPTR_TYPE
   || coder == BITINT_TYPE))
 {
diff --git a/gcc/testsuite/gcc.dg/c11-null-pointer-constant-1.c 
b/gcc/testsuite/gcc.dg/c11-null-pointer-constant-1.c
new file mode 100644
index ..f463a1a59da3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c11-null-pointer-constant-1.c
@@ -0,0 +1,55 @@
+/* Test zero with different types as null pointer constant: bug 112556.  */
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -pedantic-errors -Wno-pointer-compare" } */
+
+enum e { ZERO };
+
+void *p1 = 0;
+void *p2 = 0LL;
+void *p3 = (char) 0;
+void *p4 = 0UL;
+void *p5 = (_Bool) 0;
+void *p6 = (enum e) ZERO;
+
+void f (void *);
+
+void *
+g (void)
+{
+  p1 = 0;
+  p2 = 0LL;
+  p3 = (char) 0;
+  p4 = 0UL;
+  p5 = (_Bool) 0;
+  p6 = (enum e) ZERO;
+  f (0);
+  f (0ULL);
+  f (0L);
+  f ((char) 0);
+  f ((_Bool) 0);
+  f ((enum e) ZERO);
+  (1 ? p1 : 0);
+  (1 ? p1 : 0L);
+  (1 ? p1 : 0ULL);
+  (1 ? p1 : (char) 0);
+  (1 ? p1 : (_Bool) 0);
+  (1 ? p1 : (enum e) 0);
+  p1 == 0;
+  p1 == 0LL;
+  p1 == 0U;
+  p1 == (char) 0;
+  p1 == (_Bool) 0;
+  p1 == (enum e) 0;
+  p1 != 0;
+  p1 != 0LL;
+  p1 != 0U;
+  p1 != (char) 0;
+  p1 != (_Bool) 0;
+  p1 != (enum e) 0;
+  return 0;
+  return 0UL;
+  return 0LL;
+  return (char) 0;
+  return (_Bool) 0;
+  return (enum e) 0;
+}
diff --git a/gcc/testsuite/gcc.dg/c23-null-pointer-constant-1.c 
b/gcc/testsuite/gcc.dg/c23-null-pointer-constant-1.c
new file mode 100644
index ..71b66cc35d6b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c23-null-pointer-constant-1.c
@@ -0,0 +1,120 @@
+/* Test zero with different types as null pointer constant: bug 112556.  */
+/* { dg-do compile } */
+/* { dg-options "-std=c23 -pedantic-errors -Wno-pointer-compare" } */
+
+enum e { ZERO };
+enum e2 : bool { BZERO };
+enum e3 : long { LZERO };
+
+void *p1 = 0;
+void *p2 = 0LL;
+void *p3 = (char) 0;
+void *p4 = 0UL;
+void *p5 = (bool) 0;
+void *p6 = (enum e) ZERO;
+void *p7 = false;
+void *p8 = BZERO;
+void *p9 = (enum e2) 0;
+void *p10 = LZERO;
+void *p11 = (enum e3) 0;
+#ifdef __BITINT_MAXWIDTH__
+void *p12 = 0wb;
+void *p13 = 0uwb;
+#endif
+
+void f (void *);
+
+void *
+g (void)
+{
+  p1 = 0;
+  p2 = 0LL;
+  p3 = (char) 0;
+  p4 = 0UL;
+  p5 = (bool) 0;
+  p6 = (enum e) ZERO;
+  p7 = false;
+  p8 = BZERO;
+  p9 = (enum e2) 0;
+  p10 = LZERO;
+  p11 = (enum e3) 0;
+#ifdef __BITINT_MAXWIDTH__
+  p12 = 0wb;
+  p13 = 0uwb;
+#endif
+  f (0);
+  f (0ULL);
+  f (0L);
+  f ((char) 0);
+  f ((bool) 0);
+  f ((enum e) ZERO);
+  f (false);
+  f (BZERO);
+  f ((enum e2) 0);
+  f (LZERO);
+  f ((enum e3) 0);
+#ifdef __BITINT_MAXWIDTH__
+  f (0wb);
+  f (0uwb);
+#endif
+  (1 ? p1 :

[gcc r15-5434] Flatten anonymous structs in CodeView types

2024-11-18 Thread Mark Harmstone via Gcc-cvs
https://gcc.gnu.org/g:f1f8d4c5115975875b5b1a15adbac50bc28a3922

commit r15-5434-gf1f8d4c5115975875b5b1a15adbac50bc28a3922
Author: Mark Harmstone 
Date:   Sun Nov 10 00:23:49 2024 +

Flatten anonymous structs in CodeView types

If a CodeView struct, class, or union has as a member an anonymous
struct, class, or union, this gets flattened. The sub-struct's members
will appear as if they were part of their parent.

For this, we move part of get_type_num_struct into a new function
add_to_fieldlist, which also handles creating an LF_INDEX overflow item
if an LF_FIELDLIST grows too large. This is because add_struct_member
now calls itself recursively, and so needs to handle overflows itself.

gcc/
* dwarf2codeview.cc (add_to_fieldlist): New function.
(add_struct_member): Call recursively to flatten structs, and call
add_to_fieldlist.
(add_struct_static_member): Call add_to_fieldlist.
(add_struct_function): Call add_to_fieldlist.
(add_struct_inheritance): Call add_to_fieldlist.
(add_struct_nested_type): Call add_to_fieldlist.
(get_type_num_struct): Move code to add_to_fieldlist, and move
responsibility for this to subfunctions.

Diff:
---
 gcc/dwarf2codeview.cc | 280 ++
 1 file changed, 167 insertions(+), 113 deletions(-)

diff --git a/gcc/dwarf2codeview.cc b/gcc/dwarf2codeview.cc
index ccb1109611c9..650e83f5ac37 100644
--- a/gcc/dwarf2codeview.cc
+++ b/gcc/dwarf2codeview.cc
@@ -5404,6 +5404,52 @@ add_struct_forward_def (dw_die_ref type)
   return ct->num;
 }
 
+/* Add a new subtype to an LF_FIELDLIST type, and handle overflows if
+   necessary.  */
+
+static void
+add_to_fieldlist (codeview_custom_type **ct, uint16_t *num_members,
+ codeview_subtype *el, size_t el_len)
+{
+  /* Add an LF_INDEX subtype if everything's too big for one
+ LF_FIELDLIST.  */
+
+  if ((*ct)->lf_fieldlist.length + el_len > MAX_FIELDLIST_SIZE)
+{
+  codeview_subtype *idx;
+  codeview_custom_type *ct2;
+
+  idx = (codeview_subtype *) xmalloc (sizeof (*idx));
+  idx->next = NULL;
+  idx->kind = LF_INDEX;
+  idx->lf_index.type_num = 0;
+
+  (*ct)->lf_fieldlist.last_subtype->next = idx;
+  (*ct)->lf_fieldlist.last_subtype = idx;
+
+  ct2 = (codeview_custom_type *)
+   xmalloc (sizeof (codeview_custom_type));
+
+  ct2->next = *ct;
+  ct2->kind = LF_FIELDLIST;
+  ct2->lf_fieldlist.length = 0;
+  ct2->lf_fieldlist.subtypes = NULL;
+  ct2->lf_fieldlist.last_subtype = NULL;
+
+  *ct = ct2;
+}
+
+  (*ct)->lf_fieldlist.length += el_len;
+
+  if ((*ct)->lf_fieldlist.last_subtype)
+(*ct)->lf_fieldlist.last_subtype->next = el;
+  else
+(*ct)->lf_fieldlist.subtypes = el;
+
+  (*ct)->lf_fieldlist.last_subtype = el;
+  (*num_members)++;
+}
+
 /* Add an LF_BITFIELD type, returning its number.  DWARF represents bitfields
as members in a struct with a DW_AT_data_bit_offset attribute, whereas in
CodeView they're a distinct type.  */
@@ -5436,36 +5482,69 @@ create_bitfield (dw_die_ref c)
 
 static void
 add_struct_member (dw_die_ref c, uint16_t accessibility,
-  codeview_subtype **el, size_t *el_len)
+  codeview_custom_type **ct, uint16_t *num_members,
+  unsigned int base_offset)
 {
-  *el = (codeview_subtype *) xmalloc (sizeof (**el));
-  (*el)->next = NULL;
-  (*el)->kind = LF_MEMBER;
-  (*el)->lf_member.attributes = accessibility;
+  codeview_subtype *el;
+  size_t el_len;
+  dw_die_ref type = get_AT_ref (c, DW_AT_type);
+  unsigned int offset;
+
+  offset = base_offset + get_AT_unsigned (c, DW_AT_data_member_location);
+
+  /* If the data member is actually an anonymous struct, class, or union,
+ follow MSVC by flattening this into its parent.  */
+  if (!get_AT_string (c, DW_AT_name) && type
+  && (dw_get_die_tag (type) == DW_TAG_structure_type
+ || dw_get_die_tag (type) == DW_TAG_class_type
+ || dw_get_die_tag (type) == DW_TAG_union_type))
+{
+  dw_die_ref c2, first_child;
+
+  first_child = dw_get_die_child (type);
+  c2 = first_child;
+
+  do
+   {
+ c2 = dw_get_die_sib (c2);
+
+ if (dw_get_die_tag (c2) == DW_TAG_member)
+ add_struct_member (c2, accessibility, ct, num_members, offset);
+   }
+  while (c2 != first_child);
+
+  return;
+}
+
+  el = (codeview_subtype *) xmalloc (sizeof (*el));
+  el->next = NULL;
+  el->kind = LF_MEMBER;
+  el->lf_member.attributes = accessibility;
 
   if (get_AT (c, DW_AT_data_bit_offset))
-(*el)->lf_member.type = create_bitfield (c);
+el->lf_member.type = create_bitfield (c);
   else
-(*el)->lf_member.type = get_type_num (get_AT_ref (c, DW_AT_type),
- true, false);
+el->lf_member.type = get_type_num (type, true, fa

[gcc r15-5437] Regenerate config/avr/avr.opt.urls

2024-11-18 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:fff5cfa4353e0c45400d8cb9cbff5c40c55fc97a

commit r15-5437-gfff5cfa4353e0c45400d8cb9cbff5c40c55fc97a
Author: David Malcolm 
Date:   Mon Nov 18 20:44:09 2024 -0500

Regenerate config/avr/avr.opt.urls

gcc/ChangeLog:
* config/avr/avr.opt.urls: Regenerate for
r15-5415-gc3db52bb47913a.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/config/avr/avr.opt.urls | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/gcc/config/avr/avr.opt.urls b/gcc/config/avr/avr.opt.urls
index 6acc418b407d..672821db79d5 100644
--- a/gcc/config/avr/avr.opt.urls
+++ b/gcc/config/avr/avr.opt.urls
@@ -71,6 +71,12 @@ UrlSuffix(gcc/AVR-Options.html#index-Wmisspelled-isr)
 mfract-convert-truncate
 UrlSuffix(gcc/AVR-Options.html#index-mfract-convert-truncate)
 
+mfuse-move
+UrlSuffix(gcc/AVR-Options.html#index-mfuse-move)
+
+mfuse-move=
+UrlSuffix(gcc/AVR-Options.html#index-mfuse-move)
+
 mabsdata
 UrlSuffix(gcc/AVR-Options.html#index-mabsdata)


[gcc r14-10940] i386: Enable *rsqrtsf2_sse without TARGET_SSE_MATH [PR117357]

2024-11-18 Thread Uros Bizjak via Gcc-cvs
https://gcc.gnu.org/g:fee461613856c98946e15ef55d813831a73d2485

commit r14-10940-gfee461613856c98946e15ef55d813831a73d2485
Author: Uros Bizjak 
Date:   Mon Nov 18 22:38:46 2024 +0100

i386: Enable *rsqrtsf2_sse without TARGET_SSE_MATH [PR117357]

__builtin_ia32_rsqrtsf2 expander generates UNSPEC_RSQRT insn pattern
also when TARGET_SSE_MATH is not set.  Enable *rsqrtsf2_sse without
TARGET_SSE_MATH to avoid ICE with unrecognizable insn.

PR target/117357

gcc/ChangeLog:

* config/i386/i386.md (*rsqrtsf2_sse):
Also enable for !TARGET_SSE_MATH.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr117357.c: New test.

(cherry picked from commit 344356f781ddb7bf0abb11edf9bdd13f6802dea8)

Diff:
---
 gcc/config/i386/i386.md  | 2 +-
 gcc/testsuite/gcc.target/i386/pr117357.c | 7 +++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index f9757433687e..a72f6687296e 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -21865,7 +21865,7 @@
   [(set (match_operand:SF 0 "register_operand" "=x,x,x,x")
(unspec:SF [(match_operand:SF 1 "nonimmediate_operand" "0,x,m,ja")]
   UNSPEC_RSQRT))]
-  "TARGET_SSE && TARGET_SSE_MATH"
+  "TARGET_SSE"
   "@
%vrsqrtss\t{%d1, %0|%0, %d1}
%vrsqrtss\t{%d1, %0|%0, %d1}
diff --git a/gcc/testsuite/gcc.target/i386/pr117357.c 
b/gcc/testsuite/gcc.target/i386/pr117357.c
new file mode 100644
index ..7a27691a9776
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr117357.c
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-msse -mfpmath=387" } */
+
+float foo (float f)
+{
+  return __builtin_ia32_rsqrtf (f);
+}


[gcc r15-5436] RISC-V: Remove unnecessary option for scalar SAT_TRUNC testcase

2024-11-18 Thread Pan Li via Gcc-cvs
https://gcc.gnu.org/g:75034a77dc831c76e2c616131d372bf4619eb0f6

commit r15-5436-g75034a77dc831c76e2c616131d372bf4619eb0f6
Author: Pan Li 
Date:   Sat Nov 16 10:43:37 2024 +0800

RISC-V: Remove unnecessary option for scalar SAT_TRUNC testcase

After we create a isolated folder to hold all SAT scalar test,
we have fully control of what optimization options passing to
the testcase.  Thus, it is better to remove the unnecessary
work around for flto option, as well as the -O3 option for
each cases.  The riscv.exp will pass sorts of different optimization
options for each case.

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

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

gcc/testsuite/ChangeLog:

* gcc.target/riscv/sat/sat_u_trunc-1-u16.c: Remove flto
dg-skip workaround and -O3 option.
* gcc.target/riscv/sat/sat_u_trunc-1-u32.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-1-u64.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-1-u8.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-2-u16.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-2-u32.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-2-u64.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-2-u8.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-3-u16.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-3-u32.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-3-u64.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-3-u8.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-4-u16.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-4-u32.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-4-u64.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-4-u8.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-5-u16.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-5-u32.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-5-u64.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-5-u8.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-6-u16.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-6-u32.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-6-u64.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-6-u8.c: Ditto.
* gcc.target/riscv/sat/scalar_sat_unary.h: New test.

Signed-off-by: Pan Li 

Diff:
---
 .../gcc.target/riscv/sat/sat_u_trunc-1-u16.c   |  3 +--
 .../gcc.target/riscv/sat/sat_u_trunc-1-u32.c   |  3 +--
 .../gcc.target/riscv/sat/sat_u_trunc-1-u64.c   |  3 +--
 .../gcc.target/riscv/sat/sat_u_trunc-1-u8.c|  3 +--
 .../gcc.target/riscv/sat/sat_u_trunc-2-u16.c   |  3 +--
 .../gcc.target/riscv/sat/sat_u_trunc-2-u32.c   |  3 +--
 .../gcc.target/riscv/sat/sat_u_trunc-2-u64.c   |  3 +--
 .../gcc.target/riscv/sat/sat_u_trunc-2-u8.c|  3 +--
 .../gcc.target/riscv/sat/sat_u_trunc-3-u16.c   |  3 +--
 .../gcc.target/riscv/sat/sat_u_trunc-3-u32.c   |  3 +--
 .../gcc.target/riscv/sat/sat_u_trunc-3-u64.c   |  3 +--
 .../gcc.target/riscv/sat/sat_u_trunc-3-u8.c|  3 +--
 .../gcc.target/riscv/sat/sat_u_trunc-4-u16.c   |  3 +--
 .../gcc.target/riscv/sat/sat_u_trunc-4-u32.c   |  3 +--
 .../gcc.target/riscv/sat/sat_u_trunc-4-u64.c   |  3 +--
 .../gcc.target/riscv/sat/sat_u_trunc-4-u8.c|  3 +--
 .../gcc.target/riscv/sat/sat_u_trunc-5-u16.c   |  3 +--
 .../gcc.target/riscv/sat/sat_u_trunc-5-u32.c   |  3 +--
 .../gcc.target/riscv/sat/sat_u_trunc-5-u64.c   |  3 +--
 .../gcc.target/riscv/sat/sat_u_trunc-5-u8.c|  3 +--
 .../gcc.target/riscv/sat/sat_u_trunc-6-u16.c   |  3 +--
 .../gcc.target/riscv/sat/sat_u_trunc-6-u32.c   |  3 +--
 .../gcc.target/riscv/sat/sat_u_trunc-6-u64.c   |  3 +--
 .../gcc.target/riscv/sat/sat_u_trunc-6-u8.c|  3 +--
 .../gcc.target/riscv/sat/scalar_sat_unary.h| 22 ++
 25 files changed, 46 insertions(+), 48 deletions(-)

diff --git a/gcc/testsuite/gcc.target/riscv/sat/sat_u_trunc-1-u16.c 
b/gcc/testsuite/gcc.target/riscv/sat/sat_u_trunc-1-u16.c
index 1c4b2c7abf27..995abc9a18ec 100644
--- a/gcc/testsuite/gcc.target/riscv/sat/sat_u_trunc-1-u16.c
+++ b/gcc/testsuite/gcc.target/riscv/sat/sat_u_trunc-1-u16.c
@@ -1,6 +1,5 @@
 /* { dg-do compile } */
-/* { dg-skip-if  "" { *-*-* } { "-flto" } } */
-/* { dg-options "-march=rv64gc -mabi=lp64d -O3 -fdump-rtl-expand-details 
-fno-schedule-insns -fno-schedule-insns2" } */
+/* { dg-options "-march=rv64gc -mabi=lp64d -fdump-rtl-expand-details 
-fno-schedule-insns -fno-schedule-insns2" } */
 /* { dg-final { check-function-bodies "**" "" } } */
 
 #include "sat_arith.h"
diff --git a/gcc/testsuite/gcc.target/riscv/sat/sat_u_trunc-1-u32.c 
b/gcc/testsuite/gcc.target/riscv/sat/sat_u_trunc-1-u32.c
index ee7140e6b2a6..048b4b1c7153 100644
--- a/gcc

[gcc r15-5433] Produce CodeView info about nested types

2024-11-18 Thread Mark Harmstone via Gcc-cvs
https://gcc.gnu.org/g:14d706ed0e90373c98a0ce223ffeea8846f6d9bc

commit r15-5433-g14d706ed0e90373c98a0ce223ffeea8846f6d9bc
Author: Mark Harmstone 
Date:   Tue Nov 19 00:46:45 2024 +

Produce CodeView info about nested types

If the DIE for a struct, class, or union contains a nested type, add a
LF_NESTTYPE entry to its field list recording this.

Plus if we use a nested type, make sure that its parent also gets
defined. This may entail adding a forward definition and creating a
deferred type, so we need to call flush_deferred_types in
codeview_debug_finish as well.

gcc/
* dwarf2codeview.cc (enum cv_leaf_type): Add LF_NESTTYPE.
(struct codeview_subtype): Add lf_nesttype to union.
(flush_deferred_types): Add declaration.
(write_lf_fieldlist): Handle LF_NESTTYPE.
(codeview_debug_finish): Call flush_deferred_types.
(add_struct_nested_type): New function.
(get_type_num_struct): Call add_struct_nested_type, and if nested 
make
that parent is added.

Diff:
---
 gcc/dwarf2codeview.cc | 89 ++-
 1 file changed, 88 insertions(+), 1 deletion(-)

diff --git a/gcc/dwarf2codeview.cc b/gcc/dwarf2codeview.cc
index 5e8a4ab39e7d..ccb1109611c9 100644
--- a/gcc/dwarf2codeview.cc
+++ b/gcc/dwarf2codeview.cc
@@ -111,6 +111,7 @@ enum cv_leaf_type {
   LF_MEMBER = 0x150d,
   LF_STMEMBER = 0x150e,
   LF_METHOD = 0x150f,
+  LF_NESTTYPE = 0x1510,
   LF_ONEMETHOD = 0x1511,
   LF_FUNC_ID = 0x1601,
   LF_MFUNC_ID = 0x1602,
@@ -1249,6 +1250,11 @@ struct codeview_subtype
   uint32_t base_class_type;
   codeview_integer offset;
 } lf_bclass;
+struct
+{
+  uint32_t type;
+  char *name;
+} lf_nesttype;
   };
 };
 
@@ -1432,6 +1438,7 @@ static uint32_t get_type_num_subroutine_type (dw_die_ref 
type, bool in_struct,
  uint32_t this_type,
  int32_t this_adjustment);
 static void write_cv_padding (size_t padding);
+static void flush_deferred_types (void);
 
 /* Record new line number against the current function.  */
 
@@ -3904,6 +3911,40 @@ write_lf_fieldlist (codeview_custom_type *t)
  write_cv_padding (4 - (leaf_len % 4));
  break;
 
+   case LF_NESTTYPE:
+ /* This is lf_nest_type in binutils and lfNestType in Microsoft's
+cvinfo.h:
+
+   struct lf_nest_type
+   {
+ uint16_t kind;
+ uint16_t padding;
+ uint32_t type;
+ char name[];
+   } ATTRIBUTE_PACKED;
+ */
+
+ fputs (integer_asm_op (2, false), asm_out_file);
+ fprint_whex (asm_out_file, LF_NESTTYPE);
+ putc ('\n', asm_out_file);
+
+ fputs (integer_asm_op (2, false), asm_out_file);
+ fprint_whex (asm_out_file, 0);
+ putc ('\n', asm_out_file);
+
+ fputs (integer_asm_op (4, false), asm_out_file);
+ fprint_whex (asm_out_file, v->lf_nesttype.type);
+ putc ('\n', asm_out_file);
+
+ name_len = strlen (v->lf_nesttype.name) + 1;
+ ASM_OUTPUT_ASCII (asm_out_file, v->lf_nesttype.name, name_len);
+
+ leaf_len = 8 + name_len;
+ write_cv_padding (4 - (leaf_len % 4));
+
+ free (v->lf_nesttype.name);
+ break;
+
default:
  break;
}
@@ -4673,6 +4714,12 @@ codeview_debug_finish (void)
   write_line_numbers ();
   write_codeview_symbols ();
 
+  /* If we reference a nested struct but not its parent, add_deferred_type
+ gets called if we create a forward reference for this, even though we've
+ already flushed this in codeview_debug_early_finish.  In this case we will
+ need to flush this list again.  */
+  flush_deferred_types ();
+
   if (custom_types)
 write_custom_types ();
 
@@ -5638,6 +5685,32 @@ is_templated_func (dw_die_ref die)
   return false;
 }
 
+/* Create a field list subtype that records that a struct has a nested type
+   contained within it.  */
+
+static void
+add_struct_nested_type (dw_die_ref c, codeview_subtype **el, size_t *el_len)
+{
+  const char *name = get_AT_string (c, DW_AT_name);
+  size_t name_len;
+
+  if (!name)
+return;
+
+  name_len = strlen (name);
+
+  *el = (codeview_subtype *) xmalloc (sizeof (**el));
+  (*el)->next = NULL;
+  (*el)->kind = LF_NESTTYPE;
+  (*el)->lf_nesttype.type = get_type_num (c, true, false);
+  (*el)->lf_nesttype.name = xstrdup (name);
+
+  *el_len = 9 + name_len;
+
+  if (*el_len % 4)
+*el_len += 4 - (*el_len % 4);
+}
+
 /* Process a DW_TAG_structure_type, DW_TAG_class_type, or DW_TAG_union_type
DIE, add an LF_FIELDLIST and an LF_STRUCTURE / LF_CLASS / LF_UNION type,
and return the number of the latter.  */
@@ -5645,11 +5718,18 @@ is_templated_func (dw_die_ref die)
 static uint32_t
 get_type_num_struct (dw_die_ref type, bool in_struct, bool *is_fwd_ref)
 

[gcc r15-5387] gcn: Add else operand to masked loads.

2024-11-18 Thread Robin Dapp via Gcc-cvs
https://gcc.gnu.org/g:4a39addb4921ca1f7aa013835cd1351226e5e6b6

commit r15-5387-g4a39addb4921ca1f7aa013835cd1351226e5e6b6
Author: Robin Dapp 
Date:   Thu Aug 8 10:31:05 2024 +0200

gcn: Add else operand to masked loads.

This patch adds an undefined else operand to the masked loads.

gcc/ChangeLog:

* config/gcn/predicates.md (maskload_else_operand): New
predicate.
* config/gcn/gcn-valu.md: Use new predicate.

Diff:
---
 gcc/config/gcn/gcn-valu.md   | 23 +++
 gcc/config/gcn/predicates.md |  2 ++
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/gcc/config/gcn/gcn-valu.md b/gcc/config/gcn/gcn-valu.md
index cb2f4a780355..ce7a68f0e2d3 100644
--- a/gcc/config/gcn/gcn-valu.md
+++ b/gcc/config/gcn/gcn-valu.md
@@ -3989,7 +3989,8 @@
 (define_expand "maskloaddi"
   [(match_operand:V_MOV 0 "register_operand")
(match_operand:V_MOV 1 "memory_operand")
-   (match_operand 2 "")]
+   (match_operand 2 "")
+   (match_operand:V_MOV 3 "maskload_else_operand")]
   ""
   {
 rtx exec = force_reg (DImode, operands[2]);
@@ -3998,11 +3999,8 @@
 rtx as = gen_rtx_CONST_INT (VOIDmode, MEM_ADDR_SPACE (operands[1]));
 rtx v = gen_rtx_CONST_INT (VOIDmode, MEM_VOLATILE_P (operands[1]));
 
-/* Masked lanes are required to hold zero.  */
-emit_move_insn (operands[0], gcn_vec_constant (mode, 0));
-
 emit_insn (gen_gather_expr_exec (operands[0], addr, as, v,
-  operands[0], exec));
+  gcn_gen_undef (mode), exec));
 DONE;
   })
 
@@ -4027,7 +4025,8 @@
(match_operand: 2 "register_operand")
(match_operand 3 "immediate_operand")
(match_operand:SI 4 "gcn_alu_operand")
-   (match_operand:DI 5 "")]
+   (match_operand:DI 5 "")
+   (match_operand:V_MOV 6 "maskload_else_operand")]
   ""
   {
 rtx exec = force_reg (DImode, operands[5]);
@@ -4036,18 +4035,18 @@
  operands[2], operands[4],
  INTVAL (operands[3]), exec);
 
-/* Masked lanes are required to hold zero.  */
-emit_move_insn (operands[0], gcn_vec_constant (mode, 0));
-
 if (GET_MODE (addr) == mode)
   emit_insn (gen_gather_insn_1offset_exec (operands[0], addr,
 const0_rtx, const0_rtx,
-const0_rtx, operands[0],
-exec));
+gcn_gen_undef
+   (mode),
+operands[0], exec));
 else
   emit_insn (gen_gather_insn_2offsets_exec (operands[0], operands[1],
  addr, const0_rtx,
- const0_rtx, const0_rtx,
+ const0_rtx,
+ gcn_gen_undef
+   (mode),
  operands[0], exec));
 DONE;
   })
diff --git a/gcc/config/gcn/predicates.md b/gcc/config/gcn/predicates.md
index 3f59396a6498..21beeb586a44 100644
--- a/gcc/config/gcn/predicates.md
+++ b/gcc/config/gcn/predicates.md
@@ -228,3 +228,5 @@
   return gcn_stepped_zero_int_parallel_p (op, 1);
 })
 
+(define_predicate "maskload_else_operand"
+  (match_operand 0 "scratch_operand"))


[gcc r15-5386] aarch64: Add masked-load else operands.

2024-11-18 Thread Robin Dapp via Gcc-cvs
https://gcc.gnu.org/g:a166a6ccdc6c3d6532a24ba3a2057a177ce44752

commit r15-5386-ga166a6ccdc6c3d6532a24ba3a2057a177ce44752
Author: Robin Dapp 
Date:   Thu Aug 8 10:30:58 2024 +0200

aarch64: Add masked-load else operands.

This adds zero else operands to masked loads and their intrinsics.
I needed to adjust more than initially thought because we rely on
combine for several instructions and a change in a "base" pattern
needs to propagate to all those.

gcc/ChangeLog:

* config/aarch64/aarch64-sve-builtins-base.cc: Add else
handling.
* config/aarch64/aarch64-sve-builtins.cc 
(function_expander::use_contiguous_load_insn):
Ditto.
* config/aarch64/aarch64-sve-builtins.h: Add else operand to
contiguous load.
* config/aarch64/aarch64-sve.md 
(@aarch64_load
_):
Split and add else operand.

(@aarch64_load_):
Ditto.

(*aarch64_load__mov):
Ditto.
* config/aarch64/aarch64-sve2.md: Ditto.
* config/aarch64/iterators.md: Remove unused iterators.
* config/aarch64/predicates.md (aarch64_maskload_else_operand):
Add zero else operand.

Diff:
---
 gcc/config/aarch64/aarch64-sve-builtins-base.cc | 24 +++-
 gcc/config/aarch64/aarch64-sve-builtins.cc  | 12 +-
 gcc/config/aarch64/aarch64-sve-builtins.h   |  2 +-
 gcc/config/aarch64/aarch64-sve.md   | 52 +
 gcc/config/aarch64/aarch64-sve2.md  |  3 +-
 gcc/config/aarch64/iterators.md |  4 --
 gcc/config/aarch64/predicates.md|  4 ++
 7 files changed, 77 insertions(+), 24 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-sve-builtins-base.cc 
b/gcc/config/aarch64/aarch64-sve-builtins-base.cc
index 2117eceb6063..20820fb1985c 100644
--- a/gcc/config/aarch64/aarch64-sve-builtins-base.cc
+++ b/gcc/config/aarch64/aarch64-sve-builtins-base.cc
@@ -1524,11 +1524,12 @@ public:
 gimple_seq stmts = NULL;
 tree pred = f.convert_pred (stmts, vectype, 0);
 tree base = f.fold_contiguous_base (stmts, vectype);
+tree els = build_zero_cst (vectype);
 gsi_insert_seq_before (f.gsi, stmts, GSI_SAME_STMT);
 
 tree cookie = f.load_store_cookie (TREE_TYPE (vectype));
-gcall *new_call = gimple_build_call_internal (IFN_MASK_LOAD, 3,
- base, cookie, pred);
+gcall *new_call = gimple_build_call_internal (IFN_MASK_LOAD, 4,
+ base, cookie, pred, els);
 gimple_call_set_lhs (new_call, f.lhs);
 return new_call;
   }
@@ -1542,7 +1543,7 @@ public:
 e.vector_mode (0), e.gp_mode (0));
 else
   icode = code_for_aarch64 (UNSPEC_LD1_COUNT, e.tuple_mode (0));
-return e.use_contiguous_load_insn (icode);
+return e.use_contiguous_load_insn (icode, true);
   }
 };
 
@@ -1555,10 +1556,10 @@ public:
   rtx
   expand (function_expander &e) const override
   {
-insn_code icode = code_for_aarch64_load (UNSPEC_LD1_SVE, extend_rtx_code 
(),
+insn_code icode = code_for_aarch64_load (extend_rtx_code (),
 e.vector_mode (0),
 e.memory_vector_mode ());
-return e.use_contiguous_load_insn (icode);
+return e.use_contiguous_load_insn (icode, true);
   }
 };
 
@@ -1577,6 +1578,8 @@ public:
 e.prepare_gather_address_operands (1);
 /* Put the predicate last, as required by mask_gather_load_optab.  */
 e.rotate_inputs_left (0, 5);
+/* Add the else operand.  */
+e.args.quick_push (CONST0_RTX (e.vector_mode (0)));
 machine_mode mem_mode = e.memory_vector_mode ();
 machine_mode int_mode = aarch64_sve_int_mode (mem_mode);
 insn_code icode = convert_optab_handler (mask_gather_load_optab,
@@ -1600,6 +1603,8 @@ public:
 e.rotate_inputs_left (0, 5);
 /* Add a constant predicate for the extension rtx.  */
 e.args.quick_push (CONSTM1_RTX (VNx16BImode));
+/* Add the else operand.  */
+e.args.quick_push (CONST0_RTX (e.vector_mode (1)));
 insn_code icode = code_for_aarch64_gather_load (extend_rtx_code (),
e.vector_mode (0),
e.memory_vector_mode ());
@@ -1742,6 +1747,7 @@ public:
 /* Get the predicate and base pointer.  */
 gimple_seq stmts = NULL;
 tree pred = f.convert_pred (stmts, vectype, 0);
+tree els = build_zero_cst (vectype);
 tree base = f.fold_contiguous_base (stmts, vectype);
 gsi_insert_seq_before (f.gsi, stmts, GSI_SAME_STMT);
 
@@ -1760,8 +1766,8 @@ public:
 
 /* Emit the load itself.  */
 tree cookie = f.load_store_cookie (TREE_TYPE (vectype));
-gcall *new_call = gimple_build_call_internal (IFN_MASK_LOAD_LANES, 3,
- 

[gcc r15-5384] tree-ifcvt: Add zero maskload else value.

2024-11-18 Thread Robin Dapp via Gcc-cvs
https://gcc.gnu.org/g:6b6bd53619fd11bab3def8dee737711a7ee539ea

commit r15-5384-g6b6bd53619fd11bab3def8dee737711a7ee539ea
Author: Robin Dapp 
Date:   Thu Aug 8 12:54:36 2024 +0200

tree-ifcvt: Add zero maskload else value.

When predicating a load we implicitly assume that the else value is
zero.  This matters in case the loaded value is padded (like e.g.
a Bool) and we must ensure that the padding bytes are zero on targets
that don't implicitly zero inactive elements.

A former version of this patch still had this handling in ifcvt but
the latest version defers it to the vectorizer.

gcc/ChangeLog:

* tree-if-conv.cc (predicate_load_or_store): Add zero else
operand and comment.

Diff:
---
 gcc/tree-if-conv.cc | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc
index eb981642bae1..f1a1f8fd0d35 100644
--- a/gcc/tree-if-conv.cc
+++ b/gcc/tree-if-conv.cc
@@ -2555,9 +2555,17 @@ predicate_load_or_store (gimple_stmt_iterator *gsi, 
gassign *stmt, tree mask)
   ref);
   if (TREE_CODE (lhs) == SSA_NAME)
 {
+  /* Get a zero else value.  This might not be what a target actually uses
+but we cannot be sure about which vector mode the vectorizer will
+choose.  Therefore, leave the decision whether we need to force the
+inactive elements to zero to the vectorizer.  */
+  tree els = vect_get_mask_load_else (MASK_LOAD_ELSE_ZERO,
+ TREE_TYPE (lhs));
+
   new_stmt
-   = gimple_build_call_internal (IFN_MASK_LOAD, 3, addr,
- ptr, mask);
+   = gimple_build_call_internal (IFN_MASK_LOAD, 4, addr,
+ ptr, mask, els);
+
   gimple_call_set_lhs (new_stmt, lhs);
   gimple_set_vuse (new_stmt, gimple_vuse (stmt));
 }


[gcc r15-5382] docs: Document maskload else operand and behavior.

2024-11-18 Thread Robin Dapp via Gcc-cvs
https://gcc.gnu.org/g:5214ddb464aab6c98b6eb6a267dcc9952f030d2f

commit r15-5382-g5214ddb464aab6c98b6eb6a267dcc9952f030d2f
Author: Robin Dapp 
Date:   Thu Aug 8 10:32:25 2024 +0200

docs: Document maskload else operand and behavior.

This patch amends the documentation for masked loads (maskload,
vec_mask_load_lanes, and mask_gather_load as well as their len
counterparts) with an else operand.

gcc/ChangeLog:

* doc/md.texi: Document masked load else operand.

Diff:
---
 gcc/doc/md.texi | 63 +
 1 file changed, 41 insertions(+), 22 deletions(-)

diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi
index 25ded86f0d14..c8f1424a0424 100644
--- a/gcc/doc/md.texi
+++ b/gcc/doc/md.texi
@@ -5014,8 +5014,10 @@ This pattern is not allowed to @code{FAIL}.
 @item @samp{vec_mask_load_lanes@var{m}@var{n}}
 Like @samp{vec_load_lanes@var{m}@var{n}}, but takes an additional
 mask operand (operand 2) that specifies which elements of the destination
-vectors should be loaded.  Other elements of the destination
-vectors are set to zero.  The operation is equivalent to:
+vectors should be loaded.  Other elements of the destination vectors are
+taken from operand 3, which is an else operand similar to the one in
+@code{maskload}.
+The operation is equivalent to:
 
 @smallexample
 int c = GET_MODE_SIZE (@var{m}) / GET_MODE_SIZE (@var{n});
@@ -5025,7 +5027,7 @@ for (j = 0; j < GET_MODE_NUNITS (@var{n}); j++)
   operand0[i][j] = operand1[j * c + i];
   else
 for (i = 0; i < c; i++)
-  operand0[i][j] = 0;
+  operand0[i][j] = operand3[j];
 @end smallexample
 
 This pattern is not allowed to @code{FAIL}.
@@ -5033,16 +5035,20 @@ This pattern is not allowed to @code{FAIL}.
 @cindex @code{vec_mask_len_load_lanes@var{m}@var{n}} instruction pattern
 @item @samp{vec_mask_len_load_lanes@var{m}@var{n}}
 Like @samp{vec_load_lanes@var{m}@var{n}}, but takes an additional
-mask operand (operand 2), length operand (operand 3) as well as bias operand 
(operand 4)
-that specifies which elements of the destination vectors should be loaded.
-Other elements of the destination vectors are undefined.  The operation is 
equivalent to:
+mask operand (operand 2), length operand (operand 4) as well as bias operand
+(operand 5) that specifies which elements of the destination vectors should be
+loaded.  Other elements of the destination vectors are taken from operand 3,
+which is an else operand similar to the one in @code{maskload}.
+The operation is equivalent to:
 
 @smallexample
 int c = GET_MODE_SIZE (@var{m}) / GET_MODE_SIZE (@var{n});
-for (j = 0; j < operand3 + operand4; j++)
-  if (operand2[j])
-for (i = 0; i < c; i++)
+for (j = 0; j < operand4 + operand5; j++)
+  for (i = 0; i < c; i++)
+if (operand2[j])
   operand0[i][j] = operand1[j * c + i];
+else
+  operand0[i][j] = operand3[j];
 @end smallexample
 
 This pattern is not allowed to @code{FAIL}.
@@ -5122,18 +5128,25 @@ address width.
 @cindex @code{mask_gather_load@var{m}@var{n}} instruction pattern
 @item @samp{mask_gather_load@var{m}@var{n}}
 Like @samp{gather_load@var{m}@var{n}}, but takes an extra mask operand as
-operand 5.  Bit @var{i} of the mask is set if element @var{i}
+operand 5.
+Other elements of the destination vectors are taken from operand 6,
+which is an else operand similar to the one in @code{maskload}.
+Bit @var{i} of the mask is set if element @var{i}
 of the result should be loaded from memory and clear if element @var{i}
-of the result should be set to zero.
+of the result should be set to operand 6.
 
 @cindex @code{mask_len_gather_load@var{m}@var{n}} instruction pattern
 @item @samp{mask_len_gather_load@var{m}@var{n}}
-Like @samp{gather_load@var{m}@var{n}}, but takes an extra mask operand 
(operand 5),
-a len operand (operand 6) as well as a bias operand (operand 7).  Similar to 
mask_len_load,
-the instruction loads at most (operand 6 + operand 7) elements from memory.
+Like @samp{gather_load@var{m}@var{n}}, but takes an extra mask operand
+(operand 5) and an else operand (operand 6) as well as a len operand
+(operand 7) and a bias operand (operand 8).
+
+Similar to mask_len_load the instruction loads at
+most (operand 7 + operand 8) elements from memory.
 Bit @var{i} of the mask is set if element @var{i} of the result should
-be loaded from memory and clear if element @var{i} of the result should be 
undefined.
-Mask elements @var{i} with @var{i} > (operand 6 + operand 7) are ignored.
+be loaded from memory and clear if element @var{i} of the result should
+be set to element @var{i} of operand 6.
+Mask elements @var{i} with @var{i} > (operand 7 + operand 8) are ignored.
 
 @cindex @code{mask_len_strided_load@var{m}} instruction pattern
 @item @samp{mask_len_strided_load@var{m}}
@@ -5392,8 +5405,13 @@ Operands 4 and 5 have a target-dependent scalar integer 
mode.
 @cindex @code{maskload@var{m}@var{n}} instruction pattern
 @item @samp{maskload@v

[gcc r15-5390] RISC-V: Add VLS modes to strided loads.

2024-11-18 Thread Robin Dapp via Gcc-cvs
https://gcc.gnu.org/g:52a392b8b797d01a7b0b06c8f20b0bf8374d489e

commit r15-5390-g52a392b8b797d01a7b0b06c8f20b0bf8374d489e
Author: Robin Dapp 
Date:   Mon Nov 4 15:34:50 2024 +0100

RISC-V: Add VLS modes to strided loads.

This patch adds VLS modes to the strided load expanders.

gcc/ChangeLog:

* config/riscv/autovec.md: Add VLS modes.
* config/riscv/vector-iterators.md: Ditto.
* config/riscv/vector.md: Ditto.

Diff:
---
 gcc/config/riscv/autovec.md  |   4 +-
 gcc/config/riscv/vector-iterators.md | 243 +++
 gcc/config/riscv/vector.md   |  22 ++--
 3 files changed, 256 insertions(+), 13 deletions(-)

diff --git a/gcc/config/riscv/autovec.md b/gcc/config/riscv/autovec.md
index c64ef5a12b43..2529dc77f221 100644
--- a/gcc/config/riscv/autovec.md
+++ b/gcc/config/riscv/autovec.md
@@ -2903,7 +2903,7 @@
 ;; == Strided Load/Store
 ;; =
 (define_expand "mask_len_strided_load_"
-  [(match_operand:V 0 "register_operand")
+  [(match_operand:V_VLS 0 "register_operand")
(match_operand   1 "pmode_reg_or_0_operand")
(match_operand   2 "pmode_reg_or_0_operand")
(match_operand:  3 "vector_mask_operand")
@@ -2919,7 +2919,7 @@
 (define_expand "mask_len_strided_store_"
   [(match_operand   0 "pmode_reg_or_0_operand")
(match_operand   1 "pmode_reg_or_0_operand")
-   (match_operand:V 2 "register_operand")
+   (match_operand:V_VLS 2 "register_operand")
(match_operand:  3 "vector_mask_operand")
(match_operand   4 "autovec_length_operand")
(match_operand   5 "const_0_operand")]
diff --git a/gcc/config/riscv/vector-iterators.md 
b/gcc/config/riscv/vector-iterators.md
index 43325d1ba87a..6a621459cc4a 100644
--- a/gcc/config/riscv/vector-iterators.md
+++ b/gcc/config/riscv/vector-iterators.md
@@ -3524,6 +3524,87 @@
 
   (RVVM8DF "vector_eew64_stride_operand") (RVVM4DF 
"vector_eew64_stride_operand")
   (RVVM2DF "vector_eew64_stride_operand") (RVVM1DF 
"vector_eew64_stride_operand")
+
+  (V1QI "vector_eew8_stride_operand")
+  (V2QI "vector_eew8_stride_operand")
+  (V4QI "vector_eew8_stride_operand")
+  (V8QI "vector_eew8_stride_operand")
+  (V16QI "vector_eew8_stride_operand")
+  (V32QI "vector_eew8_stride_operand")
+  (V64QI "vector_eew8_stride_operand")
+  (V128QI "vector_eew8_stride_operand")
+  (V256QI "vector_eew8_stride_operand")
+  (V512QI "vector_eew8_stride_operand")
+  (V1024QI "vector_eew8_stride_operand")
+  (V2048QI "vector_eew8_stride_operand")
+  (V4096QI "vector_eew8_stride_operand")
+  (V1HI "vector_eew16_stride_operand")
+  (V2HI "vector_eew16_stride_operand")
+  (V4HI "vector_eew16_stride_operand")
+  (V8HI "vector_eew16_stride_operand")
+  (V16HI "vector_eew16_stride_operand")
+  (V32HI "vector_eew16_stride_operand")
+  (V64HI "vector_eew16_stride_operand")
+  (V128HI "vector_eew16_stride_operand")
+  (V256HI "vector_eew16_stride_operand")
+  (V512HI "vector_eew16_stride_operand")
+  (V1024HI "vector_eew16_stride_operand")
+  (V2048HI "vector_eew16_stride_operand")
+  (V1SI "vector_eew32_stride_operand")
+  (V2SI "vector_eew32_stride_operand")
+  (V4SI "vector_eew32_stride_operand")
+  (V8SI "vector_eew32_stride_operand")
+  (V16SI "vector_eew32_stride_operand")
+  (V32SI "vector_eew32_stride_operand")
+  (V64SI "vector_eew32_stride_operand")
+  (V128SI "vector_eew32_stride_operand")
+  (V256SI "vector_eew32_stride_operand")
+  (V512SI "vector_eew32_stride_operand")
+  (V1024SI "vector_eew32_stride_operand")
+  (V1DI "vector_eew64_stride_operand")
+  (V2DI "vector_eew64_stride_operand")
+  (V4DI "vector_eew64_stride_operand")
+  (V8DI "vector_eew64_stride_operand")
+  (V16DI "vector_eew64_stride_operand")
+  (V32DI "vector_eew64_stride_operand")
+  (V64DI "vector_eew64_stride_operand")
+  (V128DI "vector_eew64_stride_operand")
+  (V256DI "vector_eew64_stride_operand")
+  (V512DI "vector_eew64_stride_operand")
+
+  (V1HF "vector_eew16_stride_operand")
+  (V2HF "vector_eew16_stride_operand")
+  (V4HF "vector_eew16_stride_operand")
+  (V8HF "vector_eew16_stride_operand")
+  (V16HF "vector_eew16_stride_operand")
+  (V32HF "vector_eew16_stride_operand")
+  (V64HF "vector_eew16_stride_operand")
+  (V128HF "vector_eew16_stride_operand")
+  (V256HF "vector_eew16_stride_operand")
+  (V512HF "vector_eew16_stride_operand")
+  (V1024HF "vector_eew16_stride_operand")
+  (V2048HF "vector_eew16_stride_operand")
+  (V1SF "vector_eew32_stride_operand")
+  (V2SF "vector_eew32_stride_operand")
+  (V4SF "vector_eew32_stride_operand")
+  (V8SF "vector_eew32_stride_operand")
+  (V16SF "vector_eew32_stride_operand")
+  (V32SF "vector_eew32_stride_operand")
+  (V64SF "vector_eew32_stride_operand")
+  (V128SF "vector_eew32_stride_operand")
+  (V256SF "vector_eew32_stride_operand")
+  (V512SF "vector_eew32_stride_operand")
+  (V1024SF "vector_eew32_stride_operand")
+  (V1DF "vector_eew64_stride_ope

[gcc r15-5388] i386: Add zero maskload else operand.

2024-11-18 Thread Robin Dapp via Gcc-cvs
https://gcc.gnu.org/g:ebf30772415cfd3fa544fc7262b28b948591538f

commit r15-5388-gebf30772415cfd3fa544fc7262b28b948591538f
Author: Robin Dapp 
Date:   Tue Nov 5 14:47:07 2024 +0100

i386: Add zero maskload else operand.

gcc/ChangeLog:

* config/i386/sse.md (maskload):
Call maskload..._1.
(maskload_1): Rename.

Diff:
---
 gcc/config/i386/sse.md | 21 ++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index efe32e5149fc..72acd5bde5e4 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -28650,7 +28650,7 @@
(set_attr "btver2_decode" "vector") 
(set_attr "mode" "")])
 
-(define_expand "maskload"
+(define_expand "maskload_1"
   [(set (match_operand:V48_128_256 0 "register_operand")
(unspec:V48_128_256
  [(match_operand: 2 "register_operand")
@@ -28658,13 +28658,28 @@
  UNSPEC_MASKMOV))]
   "TARGET_AVX")
 
+(define_expand "maskload"
+  [(set (match_operand:V48_128_256 0 "register_operand")
+   (unspec:V48_128_256
+ [(match_operand: 2 "register_operand")
+  (match_operand:V48_128_256 1 "memory_operand")
+  (match_operand:V48_128_256 3 "const0_operand")]
+ UNSPEC_MASKMOV))]
+  "TARGET_AVX"
+{
+  emit_insn (gen_maskload_1 (operands[0],
+  operands[1],
+  operands[2]));
+  DONE;
+})
+
 (define_expand "maskload"
   [(set (match_operand:V48_AVX512VL 0 "register_operand")
(vec_merge:V48_AVX512VL
  (unspec:V48_AVX512VL
[(match_operand:V48_AVX512VL 1 "memory_operand")]
UNSPEC_MASKLOAD)
- (match_dup 0)
+  (match_operand:V48_AVX512VL 3 "const0_operand")
  (match_operand: 2 "register_operand")))]
   "TARGET_AVX512F")
 
@@ -28674,7 +28689,7 @@
  (unspec:VI12HFBF_AVX512VL
[(match_operand:VI12HFBF_AVX512VL 1 "memory_operand")]
UNSPEC_MASKLOAD)
- (match_dup 0)
+  (match_operand:VI12HFBF_AVX512VL 3 "const0_operand")
  (match_operand: 2 "register_operand")))]
   "TARGET_AVX512BW")


[gcc r15-5383] ifn: Add else-operand handling.

2024-11-18 Thread Robin Dapp via Gcc-cvs
https://gcc.gnu.org/g:8f68d9cb7897df188f7dcd733d8c385f77fd8011

commit r15-5383-g8f68d9cb7897df188f7dcd733d8c385f77fd8011
Author: Robin Dapp 
Date:   Thu Aug 8 10:54:35 2024 +0200

ifn: Add else-operand handling.

This patch adds else-operand handling to the internal functions.

gcc/ChangeLog:

* internal-fn.cc (add_mask_and_len_args): Rename...
(add_mask_else_and_len_args): ...to this and add else handling.
(expand_partial_load_optab_fn): Use adjusted function.
(expand_partial_store_optab_fn): Ditto.
(expand_scatter_store_optab_fn): Ditto.
(expand_gather_load_optab_fn): Ditto.
(internal_fn_len_index): Add else handling.
(internal_fn_else_index): Ditto.
(internal_fn_mask_index): Ditto.
(get_supported_else_vals): New function.
(supported_else_val_p): New function.
(internal_gather_scatter_fn_supported_p): Add else operand.
* internal-fn.h (internal_gather_scatter_fn_supported_p): Define
else constants.
(MASK_LOAD_ELSE_ZERO): Ditto.
(MASK_LOAD_ELSE_M1): Ditto.
(MASK_LOAD_ELSE_UNDEFINED): Ditto.
(get_supported_else_vals): Declare.
(supported_else_val_p): Ditto.

Diff:
---
 gcc/internal-fn.cc | 148 +
 gcc/internal-fn.h  |  13 -
 2 files changed, 139 insertions(+), 22 deletions(-)

diff --git a/gcc/internal-fn.cc b/gcc/internal-fn.cc
index 0ee5f5bc7c55..c522a53a4334 100644
--- a/gcc/internal-fn.cc
+++ b/gcc/internal-fn.cc
@@ -333,17 +333,18 @@ get_multi_vector_move (tree array_type, convert_optab 
optab)
   return convert_optab_handler (optab, imode, vmode);
 }
 
-/* Add mask and len arguments according to the STMT.  */
+/* Add mask, else, and len arguments according to the STMT.  */
 
 static unsigned int
-add_mask_and_len_args (expand_operand *ops, unsigned int opno, gcall *stmt)
+add_mask_else_and_len_args (expand_operand *ops, unsigned int opno, gcall 
*stmt)
 {
   internal_fn ifn = gimple_call_internal_fn (stmt);
   int len_index = internal_fn_len_index (ifn);
   /* BIAS is always consecutive next of LEN.  */
   int bias_index = len_index + 1;
   int mask_index = internal_fn_mask_index (ifn);
-  /* The order of arguments are always {len,bias,mask}.  */
+
+  /* The order of arguments is always {mask, else, len, bias}.  */
   if (mask_index >= 0)
 {
   tree mask = gimple_call_arg (stmt, mask_index);
@@ -365,6 +366,22 @@ add_mask_and_len_args (expand_operand *ops, unsigned int 
opno, gcall *stmt)
   create_input_operand (&ops[opno++], mask_rtx,
TYPE_MODE (TREE_TYPE (mask)));
 }
+
+  int els_index = internal_fn_else_index (ifn);
+  if (els_index >= 0)
+{
+  tree els = gimple_call_arg (stmt, els_index);
+  tree els_type = TREE_TYPE (els);
+  if (TREE_CODE (els) == SSA_NAME
+ && SSA_NAME_IS_DEFAULT_DEF (els)
+ && VAR_P (SSA_NAME_VAR (els)))
+   create_undefined_input_operand (&ops[opno++], TYPE_MODE (els_type));
+  else
+   {
+ rtx els_rtx = expand_normal (els);
+ create_input_operand (&ops[opno++], els_rtx, TYPE_MODE (els_type));
+   }
+}
   if (len_index >= 0)
 {
   tree len = gimple_call_arg (stmt, len_index);
@@ -3024,7 +3041,7 @@ static void
 expand_partial_load_optab_fn (internal_fn ifn, gcall *stmt, convert_optab 
optab)
 {
   int i = 0;
-  class expand_operand ops[5];
+  class expand_operand ops[6];
   tree type, lhs, rhs, maskt;
   rtx mem, target;
   insn_code icode;
@@ -3054,7 +3071,7 @@ expand_partial_load_optab_fn (internal_fn ifn, gcall 
*stmt, convert_optab optab)
   target = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE);
   create_call_lhs_operand (&ops[i++], target, TYPE_MODE (type));
   create_fixed_operand (&ops[i++], mem);
-  i = add_mask_and_len_args (ops, i, stmt);
+  i = add_mask_else_and_len_args (ops, i, stmt);
   expand_insn (icode, i, ops);
 
   assign_call_lhs (lhs, target, &ops[0]);
@@ -3100,7 +3117,7 @@ expand_partial_store_optab_fn (internal_fn ifn, gcall 
*stmt, convert_optab optab
   reg = expand_normal (rhs);
   create_fixed_operand (&ops[i++], mem);
   create_input_operand (&ops[i++], reg, TYPE_MODE (type));
-  i = add_mask_and_len_args (ops, i, stmt);
+  i = add_mask_else_and_len_args (ops, i, stmt);
   expand_insn (icode, i, ops);
 }
 
@@ -3686,7 +3703,7 @@ expand_scatter_store_optab_fn (internal_fn, gcall *stmt, 
direct_optab optab)
   create_integer_operand (&ops[i++], TYPE_UNSIGNED (TREE_TYPE (offset)));
   create_integer_operand (&ops[i++], scale_int);
   create_input_operand (&ops[i++], rhs_rtx, TYPE_MODE (TREE_TYPE (rhs)));
-  i = add_mask_and_len_args (ops, i, stmt);
+  i = add_mask_else_and_len_args (ops, i, stmt);
 
   insn_code icode = convert_optab_handler (optab, TYPE_MODE (TREE_TYPE (rhs)),
   TYPE

[gcc r15-5410] AVR: target/117659 - Fix wrong code for u24 << 16.

2024-11-18 Thread Georg-Johann Lay via Gcc-cvs
https://gcc.gnu.org/g:bba27015f2815a8fa6fae46a29a70644e868341c

commit r15-5410-gbba27015f2815a8fa6fae46a29a70644e868341c
Author: Georg-Johann Lay 
Date:   Mon Nov 18 18:12:38 2024 +0100

AVR: target/117659 - Fix wrong code for u24 << 16.

gcc/
PR target/117659
* config/avr/avr.cc (avr_out_ashlpsi3) [case 16]: Use %A1 as
input (instead of bogus %A0).

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

diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc
index dc68675b2bc2..d0e39cd15dff 100644
--- a/gcc/config/avr/avr.cc
+++ b/gcc/config/avr/avr.cc
@@ -6966,7 +6966,7 @@ avr_out_ashlpsi3 (rtx_insn *insn, rtx *op, int *plen)
int reg1 = REGNO (op[1]);
 
if (reg0 + 2 != reg1)
- avr_asm_len ("mov %C0,%A0", op, plen, 1);
+ avr_asm_len ("mov %C0,%A1", op, plen, 1);
 
return avr_asm_len ("clr %B0"  CR_TAB
"clr %A0", op, plen, 2);


[gcc r15-5409] Fix more c23 bool fallout

2024-11-18 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:1100c0576b0c6f78ede0d3fecfc6c6e8148f954f

commit r15-5409-g1100c0576b0c6f78ede0d3fecfc6c6e8148f954f
Author: Jeff Law 
Date:   Mon Nov 18 10:11:01 2024 -0700

Fix more c23 bool fallout

While these haven't shown up in my tester (not configs I test) and I think
we're likely going to be deprecating the nds32 target. we might as well go
ahead and fix them.

I'm going to include this under the pr117628 umbrella.

PR target/117628

libgcc/
* config/arm/freebsd-atomic.c (bool): Remove unnecessary typedef.
* config/arm/linux-atomic-64bit.c: Likewise.
* config/arm/linux-atomic.c: Likewise.
* config/nds32/linux-atomic.c: Likewise.
* config/nios2/linux-atomic.c: Likewise.

Diff:
---
 libgcc/config/arm/freebsd-atomic.c | 2 --
 libgcc/config/arm/linux-atomic-64bit.c | 2 --
 libgcc/config/arm/linux-atomic.c   | 2 --
 libgcc/config/nds32/linux-atomic.c | 2 --
 libgcc/config/nios2/linux-atomic.c | 2 --
 5 files changed, 10 deletions(-)

diff --git a/libgcc/config/arm/freebsd-atomic.c 
b/libgcc/config/arm/freebsd-atomic.c
index 7cf00b1e75d4..b39706daa259 100644
--- a/libgcc/config/arm/freebsd-atomic.c
+++ b/libgcc/config/arm/freebsd-atomic.c
@@ -127,8 +127,6 @@ __sync_val_compare_and_swap_##N (TYPE *mem, TYPE expected,  
\
 return (old);  \
 }
 
-typedef unsigned char bool;
-
 #define SYNC_BOOL_CAS_N(N, TYPE)\
 bool HIDDEN\
 __sync_bool_compare_and_swap_##N (TYPE *ptr, TYPE oldval,  \
diff --git a/libgcc/config/arm/linux-atomic-64bit.c 
b/libgcc/config/arm/linux-atomic-64bit.c
index b35dcec0fb7b..45286a50cfb5 100644
--- a/libgcc/config/arm/linux-atomic-64bit.c
+++ b/libgcc/config/arm/linux-atomic-64bit.c
@@ -141,8 +141,6 @@ __sync_val_compare_and_swap_8 (long long *ptr, long long 
oldval,
 }
 }
 
-typedef unsigned char bool;
-
 bool HIDDEN
 __sync_bool_compare_and_swap_8 (long long *ptr, long long oldval,
 long long newval)
diff --git a/libgcc/config/arm/linux-atomic.c b/libgcc/config/arm/linux-atomic.c
index 2ad68ead502d..e1f6d27519fa 100644
--- a/libgcc/config/arm/linux-atomic.c
+++ b/libgcc/config/arm/linux-atomic.c
@@ -249,8 +249,6 @@ __sync_val_compare_and_swap_4 (int *ptr, int oldval, int 
newval)
 SUBWORD_VAL_CAS (short,   2)
 SUBWORD_VAL_CAS (signed char, 1)
 
-typedef unsigned char bool;
-
 bool HIDDEN
 __sync_bool_compare_and_swap_4 (int *ptr, int oldval, int newval)
 {
diff --git a/libgcc/config/nds32/linux-atomic.c 
b/libgcc/config/nds32/linux-atomic.c
index ef869e05f03b..5a5e7c0184aa 100644
--- a/libgcc/config/nds32/linux-atomic.c
+++ b/libgcc/config/nds32/linux-atomic.c
@@ -208,8 +208,6 @@ __sync_val_compare_and_swap_4 (int *ptr, int oldval, int 
newval)
 SUBWORD_VAL_CAS (unsigned short, 2)
 SUBWORD_VAL_CAS (unsigned char,  1)
 
-typedef unsigned char bool;
-
 bool HIDDEN
 __sync_bool_compare_and_swap_4 (int *ptr, int oldval, int newval)
 {
diff --git a/libgcc/config/nios2/linux-atomic.c 
b/libgcc/config/nios2/linux-atomic.c
index 9bb25575fbc6..1cad60b8e4fa 100644
--- a/libgcc/config/nios2/linux-atomic.c
+++ b/libgcc/config/nios2/linux-atomic.c
@@ -207,8 +207,6 @@ __sync_val_compare_and_swap_4 (int *ptr, int oldval, int 
newval)
 SUBWORD_VAL_CAS (unsigned short, 2)
 SUBWORD_VAL_CAS (unsigned char,  1)
 
-typedef unsigned char bool;
-
 bool HIDDEN
 __sync_bool_compare_and_swap_4 (int *ptr, int oldval, int newval)
 {


[gcc r14-10939] AVR: target/117659 - Fix wrong code for u24 << 16.

2024-11-18 Thread Georg-Johann Lay via Gcc-cvs
https://gcc.gnu.org/g:3cb7ac6f02d35eda5d9e52834d06f50d0c929ecc

commit r14-10939-g3cb7ac6f02d35eda5d9e52834d06f50d0c929ecc
Author: Georg-Johann Lay 
Date:   Mon Nov 18 18:12:38 2024 +0100

AVR: target/117659 - Fix wrong code for u24 << 16.

gcc/
PR target/117659
* config/avr/avr.cc (avr_out_ashlpsi3) [case 16]: Use %A1 as
input (instead of bogus %A0).

(cherry picked from commit bba27015f2815a8fa6fae46a29a70644e868341c)

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

diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc
index 269a22b71a20..f17438d97087 100644
--- a/gcc/config/avr/avr.cc
+++ b/gcc/config/avr/avr.cc
@@ -7851,7 +7851,7 @@ avr_out_ashlpsi3 (rtx_insn *insn, rtx *op, int *plen)
int reg1 = REGNO (op[1]);
 
if (reg0 + 2 != reg1)
- avr_asm_len ("mov %C0,%A0", op, plen, 1);
+ avr_asm_len ("mov %C0,%A1", op, plen, 1);
 
return avr_asm_len ("clr %B0"  CR_TAB
"clr %A0", op, plen, 2);


[gcc r15-5411] PR modula2/117660: Errors referring to variables of type array could display full declaration

2024-11-18 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:ab7abf1db09519a92f4a02af30ed6b834264c45e

commit r15-5411-gab7abf1db09519a92f4a02af30ed6b834264c45e
Author: Gaius Mulley 
Date:   Mon Nov 18 17:51:37 2024 +

PR modula2/117660: Errors referring to variables of type array could 
display full declaration

This patch ensures that the tokens defining the full declaration of an
ARRAY type is stored in the symbol table and used during production of
error messages.

gcc/m2/ChangeLog:

PR modula2/117660
* gm2-compiler/P2Build.bnf (ArrayType): Update tok with the
composite token produced during array type declaration.
* gm2-compiler/P2SymBuild.mod (EndBuildArray): Create the
combinedtok and store it into the symbol table.
Also ensure combinedtok is pushed to the quad stack.
(BuildFieldArray): Preserve typetok.
* gm2-compiler/SymbolTable.def (PutArray): Rename parameters.
* gm2-compiler/SymbolTable.mod (PutArray): Rename parameters.

gcc/testsuite/ChangeLog:

PR modula2/117660
* gm2/iso/fail/arraymismatch.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/P2Build.bnf  |  4 ++-
 gcc/m2/gm2-compiler/P2SymBuild.mod   | 41 
 gcc/m2/gm2-compiler/SymbolTable.def  |  4 +--
 gcc/m2/gm2-compiler/SymbolTable.mod  |  8 +++---
 gcc/testsuite/gm2/iso/fail/arraymismatch.mod |  8 ++
 5 files changed, 41 insertions(+), 24 deletions(-)

diff --git a/gcc/m2/gm2-compiler/P2Build.bnf b/gcc/m2/gm2-compiler/P2Build.bnf
index 9e1145e3f815..e3db5f077dc6 100644
--- a/gcc/m2/gm2-compiler/P2Build.bnf
+++ b/gcc/m2/gm2-compiler/P2Build.bnf
@@ -54,6 +54,7 @@ FROM M2Printf IMPORT printf0 ;
 FROM M2Debug IMPORT Assert ;
 
 FROM M2Quads IMPORT PushT, PopT, PushTF, PopTF, PopNothing, OperandT, PushTFA, 
Top, Annotate,
+OperandTok,
 PushTFtok, PopTFtok, PushTFAtok, PopTtok, PushTtok,
 StartBuildInit,
 EndBuildInit,
@@ -783,8 +784,9 @@ ArrayType := "ARRAY"
   % VAR
 SimpleType % 
BuildFieldArray ; %
   } "OF"   % 
BuildNulName ; %
  Type  % 
EndBuildArray ;
+ 
tok := OperandTok (1) ;
  
PopNothing ;
- 
PushTtok(arrayType, tok) %
+ 
PushTtok (arrayType, tok) %
=:
 
 RecordType := "RECORD" % 
BuildRecord %
diff --git a/gcc/m2/gm2-compiler/P2SymBuild.mod 
b/gcc/m2/gm2-compiler/P2SymBuild.mod
index 70492705129b..288d0cac03bd 100644
--- a/gcc/m2/gm2-compiler/P2SymBuild.mod
+++ b/gcc/m2/gm2-compiler/P2SymBuild.mod
@@ -1281,7 +1281,7 @@ BEGIN
 THEN
IF isunknown
THEN
-  MetaError2('attempting to declare a type {%1ad} to a type 
which is itself unknown {%2ad}',
+  MetaError2('attempting to declare a type {%1ad} to a type 
which is itself and also unknown {%2ad}',
  Sym, Type)
ELSE
   MetaError1('attempting to declare a type {%1ad} as itself', 
Sym)
@@ -2896,15 +2896,20 @@ END StartBuildArray ;
 
 PROCEDURE EndBuildArray ;
 VAR
+   typetok,
+   arraytok,
+   combinedtok: CARDINAL ;
TypeSym,
-   ArraySym: CARDINAL ;
-BEGIN
-   PopT(TypeSym) ;
-   PopT(ArraySym) ;
-   Assert(IsArray(ArraySym)) ;
-   PutArray(ArraySym, TypeSym) ;
-   PushT(ArraySym) ;
-   Annotate("%1s(%1d)||array type")
+   ArraySym   : CARDINAL ;
+BEGIN
+   PopTtok (TypeSym, typetok) ;
+   PopTtok (ArraySym, arraytok) ;
+   Assert (IsArray (ArraySym)) ;
+   combinedtok := MakeVirtual2Tok (arraytok, typetok) ;
+   PutArray (ArraySym, TypeSym) ;
+   PutDeclared (combinedtok, ArraySym) ;
+   PushTtok (ArraySym, combinedtok) ;
+   Annotate ("%1s(%1d)||array type")
 END EndBuildArray ;
 
 
@@ -2928,15 +2933,17 @@ END EndBuildArray ;
 
 PROCEDURE BuildFieldArray ;
 VAR
+   typetok,
+   arraytok  : CARDINAL ;
Subscript,
Type,
Array : CARDINAL ;
name  : Name ;
 BEGIN
-   PopTF(Type, name) ;
-   PopT(Array) ;
-   Assert(IsArray(Array)) ;
-   Subscript := MakeSubscript() ;
+   PopTFtok (Type, name, typetok) ;
+   PopTtok (Array, arraytok) ;
+   Assert (IsArray (Array)) ;
+   Subscript := MakeSubscript () ;
(*
   We cannot Assert(IsSubrange(Type)) as the subrange type might be
   declared later on in th

[gcc r12-10820] AVR: target/117659 - Fix wrong code for u24 << 16.

2024-11-18 Thread Georg-Johann Lay via Gcc-cvs
https://gcc.gnu.org/g:a2725b4ed6f248e1239aace322a78ee4d45db110

commit r12-10820-ga2725b4ed6f248e1239aace322a78ee4d45db110
Author: Georg-Johann Lay 
Date:   Mon Nov 18 18:12:38 2024 +0100

AVR: target/117659 - Fix wrong code for u24 << 16.

gcc/
PR target/117659
* config/avr/avr.cc (avr_out_ashlpsi3) [case 16]: Use %A1 as
input (instead of bogus %A0).

(cherry picked from commit bba27015f2815a8fa6fae46a29a70644e868341c)

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

diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc
index f355146f992b..c0f5242c0b2e 100644
--- a/gcc/config/avr/avr.cc
+++ b/gcc/config/avr/avr.cc
@@ -7048,7 +7048,7 @@ avr_out_ashlpsi3 (rtx_insn *insn, rtx *op, int *plen)
 int reg1 = REGNO (op[1]);
 
 if (reg0 + 2 != reg1)
-  avr_asm_len ("mov %C0,%A0", op, plen, 1);
+  avr_asm_len ("mov %C0,%A1", op, plen, 1);
 
 return avr_asm_len ("clr %B0"  CR_TAB
 "clr %A0", op, plen, 2);


[gcc r15-5422] aarch64: Extend early-ra splitting of single-block regions

2024-11-18 Thread Richard Sandiford via Gcc-cvs
https://gcc.gnu.org/g:279475fd7236a9e4ed1ecb634f82a2bc7c895cc8

commit r15-5422-g279475fd7236a9e4ed1ecb634f82a2bc7c895cc8
Author: Richard Sandiford 
Date:   Mon Nov 18 19:32:50 2024 +

aarch64: Extend early-ra splitting of single-block regions

When early-ra treats a block as an isolated allocation region,
it opportunistically splits the block into smaller regions
at points where no FPRs or FPR allocnos are live.  Previously
it only did this if m_allocation_successful, since the contrary
included cases in which the live range information wasn't trustworthy.

After earlier patches, we should now be able to trust the live range
information whenever m_accurate_live_ranges is true.  This means that
we can split the block into regions even if allocation failed for the
current (sub)region.

This is just something I noticed by inspection.  I don't have
a particular test case for it.

gcc/
* config/aarch64/aarch64-early-ra.cc
(early_ra::process_block): Check m_accurate_live_ranges
rather than m_allocation_successful when deciding whether
to split a block into multiple regions.  Skip over subregions
that we decide not to allocate.

Diff:
---
 gcc/config/aarch64/aarch64-early-ra.cc | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-early-ra.cc 
b/gcc/config/aarch64/aarch64-early-ra.cc
index 79ac7b099ebb..33d82ea64c2a 100644
--- a/gcc/config/aarch64/aarch64-early-ra.cc
+++ b/gcc/config/aarch64/aarch64-early-ra.cc
@@ -3575,14 +3575,17 @@ early_ra::process_block (basic_block bb, bool 
is_isolated)
   // See whether we have a complete region, with no remaining live
   // allocnos.
   if (is_isolated
+ && m_accurate_live_ranges
  && bitmap_empty_p (m_live_allocnos)
  && m_live_fprs == 0
- && m_allocation_successful
  && !m_allocnos.is_empty ())
{
  rtx_insn *prev_insn = PREV_INSN (insn);
- m_insn_ranges.safe_push ({ start_insn, prev_insn });
- process_region ();
+ if (m_allocation_successful)
+   {
+ m_insn_ranges.safe_push ({ start_insn, prev_insn });
+ process_region ();
+   }
  start_new_region ();
  is_first = true;
  start_insn = prev_insn;


[gcc r15-5378] libcpp: add .c++-header-unit target

2024-11-18 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:7b8b96a327f2201531c0a2b32db490532db4aa39

commit r15-5378-g7b8b96a327f2201531c0a2b32db490532db4aa39
Author: Jason Merrill 
Date:   Tue Jun 4 21:15:02 2024 -0400

libcpp: add .c++-header-unit target

The dependency output for header unit modules is based on the absolute
pathname of the header file, but that's not something that a makefile can
portably refer to.  This patch adds a .c++-header-unit target based on the
header name relative to an element of the include path.

libcpp/ChangeLog:

* internal.h (_cpp_get_file_dir): Declare.
* files.cc (_cpp_get_file_dir): New fn.
* mkdeps.cc (make_write): Use it.

gcc/testsuite/ChangeLog:

* g++.dg/modules/dep-4.H: New test.

Diff:
---
 libcpp/internal.h|  1 +
 libcpp/files.cc  |  7 +++
 libcpp/mkdeps.cc | 16 
 gcc/testsuite/g++.dg/modules/dep-4.H |  7 +++
 4 files changed, 31 insertions(+)

diff --git a/libcpp/internal.h b/libcpp/internal.h
index d91acd64ba39..ad4e5909cfae 100644
--- a/libcpp/internal.h
+++ b/libcpp/internal.h
@@ -786,6 +786,7 @@ extern bool _cpp_save_file_entries (cpp_reader *pfile, FILE 
*f);
 extern bool _cpp_read_file_entries (cpp_reader *, FILE *);
 extern const char *_cpp_get_file_name (_cpp_file *);
 extern struct stat *_cpp_get_file_stat (_cpp_file *);
+extern struct cpp_dir *_cpp_get_file_dir (_cpp_file *);
 extern bool _cpp_has_header (cpp_reader *, const char *, int,
 enum include_type);
 
diff --git a/libcpp/files.cc b/libcpp/files.cc
index 840dffccce42..1cbce4947ee1 100644
--- a/libcpp/files.cc
+++ b/libcpp/files.cc
@@ -2336,6 +2336,13 @@ _cpp_get_file_stat (_cpp_file *file)
   return &file->st;
 }
 
+/* Return the directory where FILE was found.  */
+struct cpp_dir *
+_cpp_get_file_dir (_cpp_file *file)
+{
+  return file->dir;
+}
+
 /* Set the include chain for "" to QUOTE, for <> to BRACKET.  If
QUOTE_IGNORES_SOURCE_DIR, then "" includes do not look in the
directory of the including file.
diff --git a/libcpp/mkdeps.cc b/libcpp/mkdeps.cc
index a31890a386a9..b37d33013bef 100644
--- a/libcpp/mkdeps.cc
+++ b/libcpp/mkdeps.cc
@@ -463,6 +463,19 @@ make_write (const cpp_reader *pfile, FILE *fp, unsigned 
int colmax)
  /* module-name : cmi-name */
  column = make_write_name (d->module_name, fp, 0, colmax,
true, ".c++-module");
+ const char *module_basename = nullptr;
+ if (d->is_header_unit)
+   {
+ /* Also emit a target for the include name, so for #include
+ you'd make iostream.c++-header-unit, regardless of
+what actual directory iostream lives in.  We reconstruct the
+include name by skipping the directory where we found it.  */
+ auto *dir = _cpp_get_file_dir (pfile->main_file);
+ gcc_assert (!strncmp (d->module_name, dir->name, dir->len));
+ module_basename = (d->module_name + dir->len + 1);
+ column = make_write_name (module_basename, fp, column, colmax,
+   true, ".c++-header-unit");
+   }
  fputs (":", fp);
  column++;
  column = make_write_name (d->cmi_name, fp, column, colmax);
@@ -471,6 +484,9 @@ make_write (const cpp_reader *pfile, FILE *fp, unsigned int 
colmax)
  column = fprintf (fp, ".PHONY:");
  column = make_write_name (d->module_name, fp, column, colmax,
true, ".c++-module");
+ if (module_basename)
+   column = make_write_name (module_basename, fp, column, colmax,
+ true, ".c++-header-unit");
  fputs ("\n", fp);
}
 
diff --git a/gcc/testsuite/g++.dg/modules/dep-4.H 
b/gcc/testsuite/g++.dg/modules/dep-4.H
new file mode 100644
index ..070fa5a70de6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/dep-4.H
@@ -0,0 +1,7 @@
+// { dg-do preprocess }
+// { dg-additional-options "-fmodules -M" }
+
+inline void f() { }
+
+// { dg-final { scan-file dep-4.i {dep-4\.H\.c\+\+-header-unit:} } }
+// { dg-final { scan-file-not dep-4.i {inline} } }


[gcc r15-5379] libstdc++: Fix invalid casts in unordered container merge functions

2024-11-18 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:dffc37deaddf08bd11208a459496b30021700203

commit r15-5379-gdffc37deaddf08bd11208a459496b30021700203
Author: Jonathan Wakely 
Date:   Thu Nov 14 14:25:52 2024 +

libstdc++: Fix invalid casts in unordered container merge functions

François pointed out that static_cast<__node_ptr>(&_M_before_begin) is
invalid, because _M_before_begin is only a node-base not a node.

Refactor the new merge overloads to only cast when we know we have a
valid node.

He also pointed out some optimizations to allow reusing hash codes that
might be cached in the node. The _M_src_hash_code function already has
the right logic to decide when a cached hash code can be reused by a
different _Hashtable object.

libstdc++-v3/ChangeLog:

* include/bits/hashtable.h (_Hashtable::_M_src_hash_code):
Improve comments.
(_Hashtable::_M_merge_unique(_Hashtable&)): Use pointer_traits
to get before-begin pointer. Only use static_cast on valid
nodes, not the before-begin pointer. Reuse a hash code cached in
the node when possible.
(_Hashtable::_M_merge_multi(_Hashtable&)): Likewise.

Reviewed-by: François Dumont 

Diff:
---
 libstdc++-v3/include/bits/hashtable.h | 43 ++-
 1 file changed, 27 insertions(+), 16 deletions(-)

diff --git a/libstdc++-v3/include/bits/hashtable.h 
b/libstdc++-v3/include/bits/hashtable.h
index 6a2da121ab98..a704816573ae 100644
--- a/libstdc++-v3/include/bits/hashtable.h
+++ b/libstdc++-v3/include/bits/hashtable.h
@@ -1204,8 +1204,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return { __n, this->_M_node_allocator() };
   }
 
-  // Only use the possibly cached node's hash code if its hash function
-  // _H2 matches _Hash and is stateless. Otherwise recompute it using 
_Hash.
+  // Hash code for node __src_n with key __k, using this->hash_function().
+  // Will use a hash code cached in the node if safe to do so. This is
+  // for use in _M_merge_multi where the node comes from another container
+  // with a hash function that might not match this->hash_function().
   template
__hash_code
_M_src_hash_code(const _H2&, const key_type& __k,
@@ -1213,6 +1215,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
  if constexpr (std::is_same_v<_H2, _Hash>)
if constexpr (std::is_empty_v<_Hash>)
+ // If the node has a cached hash code, it's OK to use it.
  return this->_M_hash_code(__src_n);
 
  return this->_M_hash_code(__k);
@@ -1246,28 +1249,31 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   {
__glibcxx_assert(get_allocator() == __src.get_allocator());
 
+   using _PTr = pointer_traits<__node_base_ptr>;
+
auto __n_elt = __src.size();
size_type __first = 1;
-   // For a container of identical type we can use its private members.
-   auto __p = static_cast<__node_ptr>(&__src._M_before_begin);
+   // For a container of identical type we can use its private members,
+   // __src._M_before_begin, __src._M_bucket_index etc.
+   auto __prev = _PTr::pointer_to(__src._M_before_begin);
while (__n_elt--)
  {
-   const auto __prev = __p;
-   __p = __p->_M_next();
-   const auto& __node = *__p;
+   const auto __next = __prev->_M_nxt;
+   const auto& __node = static_cast<__node_type&>(*__next);
const key_type& __k = _ExtractKey{}(__node._M_v());
-   auto __loc = _M_locate(__k);
+   const auto __loc = _M_locate(__k);
if (__loc)
- continue;
+ {
+   __prev = __next;
+   continue;
+ }
 
-   size_type __src_bkt
- = __src._M_bucket_index(__src.hash_function()(__k));
+   auto __src_bkt = __src._M_bucket_index(__node);
auto __nh = __src._M_extract_node(__src_bkt, __prev);
_M_insert_unique_node(__loc._M_bucket_index, __loc._M_hash_code,
  __nh._M_ptr, __first * __n_elt + 1);
__nh.release();
__first = 0;
-   __p = __prev;
  }
   }
 
@@ -1311,15 +1317,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
if (__src.size() == 0) [[__unlikely__]]
  return;
 
+   using _PTr = pointer_traits<__node_base_ptr>;
+
__node_ptr __hint = nullptr;
this->reserve(size() + __src.size());
-   // For a container of identical type we can use its private members.
-   auto __prev = static_cast<__node_ptr>(&__src._M_before_begin);
+   // For a container of identical type we can use its private members,
+   // __src._M_before_begin, __src._M_bucket_index etc.
+   auto __prev = _PTr::pointer_to(__src._M_before_begin);
do
  {
-   const auto& __node = *__prev->_M_next();
+   const auto& __n

[gcc r15-5380] match: Fix the `max==0` pattern for pointers [PR117646]

2024-11-18 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:45a3277149d95a51cf9109cab87ee39a7dce73e2

commit r15-5380-g45a3277149d95a51cf9109cab87ee39a7dce73e2
Author: Andrew Pinski 
Date:   Sun Nov 17 20:21:58 2024 -0800

match: Fix the `max==0` pattern for pointers [PR117646]

For pointers I forgot that BIT_IOR_EXPR is not valid so when
I added the pattern to convert `max != 0` (r15-5356), GCC
would start to ICEing saying pointer types were not valid for
BIT_IOR_EXPR.
This fixes the problem by casting to the unsigned type of the
inner type. There was another way of fixing this to handling it
as `a == 0 & b == 0` but both match and reassoication (for pointers)
will then convert it back into the form I am creating here so
let's just use that form instead.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/117646

gcc/ChangeLog:

* match.pd (`max==0`): Add casts to `unsigned type`.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/minmaxneeqptr-1.c: New test.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/match.pd   |  6 --
 gcc/testsuite/gcc.dg/torture/minmaxneeqptr-1.c | 21 +
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 4bec24a21b29..f5181325f3b9 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4799,9 +4799,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
MAX (A, B) != 0 -> (A|B) != 0 iff unsigned.  */
 (for cmp (eq ne)
  (simplify
-  (cmp (max @0 @1) integer_zerop@2)
+  (cmp (max @0 @1) integer_zerop)
   (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
-   (cmp (bit_ior @0 @1) @2
+   (with { tree utype = unsigned_type_for (TREE_TYPE (@0)); }
+(cmp (bit_ior (convert:utype @0) (convert:utype @1))
+ { build_zero_cst (utype); } )
 
 /* Undo fancy ways of writing max/min or other ?: expressions, like
a - ((a - b) & -(a < b))  and  a - (a - b) * (a < b) into (a < b) ? b : a.
diff --git a/gcc/testsuite/gcc.dg/torture/minmaxneeqptr-1.c 
b/gcc/testsuite/gcc.dg/torture/minmaxneeqptr-1.c
new file mode 100644
index ..aa45722330f4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/minmaxneeqptr-1.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+
+/* PR tree-optimization/117646 */
+
+int maxeq(char *a, char *b) {
+  char *p = a < b ? b : a;
+  return p == (void*)0;
+}
+int maxne(char *a, char *b) {
+  char *p = a < b ? b : a;
+  return p == (void*)0;
+}
+
+int mineq(char *a, char *b) {
+  char *p = a > b ? b : a;
+  return p == (void*)0;
+}
+int minne(char *a, char *b) {
+  char *p = a > b ? b : a;
+  return p == (void*)0;
+}


[gcc r15-5391] testsuite: Move test pr117093.c into gcc.target/aarch64.

2024-11-18 Thread Jennifer Schmitz via Gcc-cvs
https://gcc.gnu.org/g:944471eaee4042b816ec2d58968bbdff52e07933

commit r15-5391-g944471eaee4042b816ec2d58968bbdff52e07933
Author: Jennifer Schmitz 
Date:   Mon Nov 18 01:02:42 2024 -0800

testsuite: Move test pr117093.c into gcc.target/aarch64.

The test file pr117093.c failed on platforms other than aarch64, because
it uses arm_neon.h. We moved it into gcc.target/aarch64.

The patch was bootstrapped and tested on aarch64-linux-gnu and
x86_64-linux-gnu, no regression.
Committed as obvious.

Signed-off-by: Jennifer Schmitz 

gcc/testsuite/
PR tree-optimization/117093
* gcc.dg/tree-ssa/pr117093.c: Move to gcc.target/aarch64.
* gcc.target/aarch64/pr117093.c: New test.

Diff:
---
 gcc/testsuite/{gcc.dg/tree-ssa => gcc.target/aarch64}/pr117093.c | 0
 1 file changed, 0 insertions(+), 0 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr117093.c 
b/gcc/testsuite/gcc.target/aarch64/pr117093.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/tree-ssa/pr117093.c
rename to gcc/testsuite/gcc.target/aarch64/pr117093.c