[gcc r15-167] Update libbid according to the latest Intel Decimal Floating-Point Math Library.

2024-05-05 Thread hongtao Liu via Gcc-cvs
https://gcc.gnu.org/g:affd77d3fe7bfb525b3fb23316d164e847ed02d1

commit r15-167-gaffd77d3fe7bfb525b3fb23316d164e847ed02d1
Author: liuhongt 
Date:   Wed Mar 27 08:20:13 2024 +0800

Update libbid according to the latest Intel Decimal Floating-Point Math 
Library.

The Intel Decimal Floating-Point Math Library is available as open-source 
on Netlib[1].

[1] https://www.netlib.org/misc/intel/.

libgcc/config/libbid/ChangeLog:

* bid128_fma.c (add_and_round): Fix bug: the result
of (+5E+368)*(+10E-34)+(-10E+369) was returning
-99E+336 instead of expected
result -10E+337.
(bid128_ext_fma): Ditto.
(bid64qqq_fma): Ditto.
* bid128_noncomp.c: Change return type of bid128_class from
int to class_t.
* bid128_round_integral.c: Add default case to avoid compiler
warning.
* bid128_string.c (bid128_to_string): Replace 0x30 with '0'
for zero digit.
(bid128_from_string): Ditto.
* bid32_to_bid128.c (bid128_to_bid32): Fix Bug. In addition
to the INEXACT flag, the UNDERFLOW flag needs to be set (and
was not) when converting an input such as
+6931674235302037148946035460357709E+1857 to +100E-101
* bid32_to_bid64.c (bid64_to_bid32): fix Bug, In addition to
the INEXACT flag, the UNDERFLOW flag needs to be set (and was
not) when converting an input such as +9991E-111
to +100E-101. Furthermore, significant bits of NaNs are
set correctly now. For example,  0x7c3b9aca was
returning 0x7c02 instead of 0x 7c000100.
* bid64_noncomp.c: Change return type of bid64_class from int
to class_t.
* bid64_round_integral.c (bid64_round_integral_exact): Add
default case to avoid compiler warning.
* bid64_string.c (bid64_from_string): Fix bug for rounding
up. The input string "1" was returning
+1001E+1 instead of +1000E+1.
* bid64_to_bid128.c (bid128_to_bid64): Fix bug, in addition to
the INEXACT flag, the UNDERFLOW flag needs to be set (and was
not) when converting an input such as
+99E-417 to
+1000E-398.
* bid_binarydecimal.c (bid32_to_binary64): Fix bug for
conversion between binary and bid types. For example,
0x7c0F4240 was returning 0x7FFFA120 instead of
expected double precision 0x7FF8.
(binary64_to_bid32): Ditto.
(binary80_to_bid32): Ditto.
(binary128_to_bid32): Ditto.
(binary80_to_bid64): Ditto.
(binary128_to_bid64): Ditto.
* bid_conf.h (BID_HIGH_128W): New macro.
(BID_LOW_128W): Ditto.
* bid_functions.h (__ENABLE_BINARY80__): Ditto.
(ALIGN): Ditto.
* bid_inline_add.h (get_add128): Add default case to avoid compiler
warning.
* bid_internal.h (get_BID64): Ditto.
(fast_get_BID64_check_OF): Ditto.
(ALIGN): New macro.

Co-authored-by: Anderson, Cristina S 
Co-authored-by: Akkas, Ahmet 
Co-authored-by: Cornea, Marius 

Diff:
---
 libgcc/config/libbid/bid128_fma.c| 188 ++-
 libgcc/config/libbid/bid128_noncomp.c|   2 +-
 libgcc/config/libbid/bid128_round_integral.c |   2 +
 libgcc/config/libbid/bid128_string.c |   7 +-
 libgcc/config/libbid/bid32_to_bid128.c   |   3 -
 libgcc/config/libbid/bid32_to_bid64.c|  11 +-
 libgcc/config/libbid/bid64_noncomp.c |   2 +-
 libgcc/config/libbid/bid64_round_integral.c  |   2 +
 libgcc/config/libbid/bid64_string.c  |  21 ++-
 libgcc/config/libbid/bid64_to_bid128.c   |   3 -
 libgcc/config/libbid/bid_binarydecimal.c | 167 
 libgcc/config/libbid/bid_conf.h  |   8 ++
 libgcc/config/libbid/bid_functions.h |  23 +++-
 libgcc/config/libbid/bid_inline_add.h|   2 +
 libgcc/config/libbid/bid_internal.h  |  17 +--
 15 files changed, 220 insertions(+), 238 deletions(-)

diff --git a/libgcc/config/libbid/bid128_fma.c 
b/libgcc/config/libbid/bid128_fma.c
index 67233193a42..cbcf225546f 100644
--- a/libgcc/config/libbid/bid128_fma.c
+++ b/libgcc/config/libbid/bid128_fma.c
@@ -417,13 +417,12 @@ add_and_round (int q3,
   R128.w[1] = R256.w[1];
   R128.w[0] = R256.w[0];
 }
+if (e4 + x0 < expmin) { // for all rounding modes
+  is_tiny = 1;
+}
 // the rounded result has p34 = 34 digits
 e4 = e4 + x0 + incr_exp;
-if (rnd_mode == ROUNDING_TO_NEAREST) {
-  if (e

[gcc r15-168] Fortran: fix issues with class(*) assignment [PR114827]

2024-05-05 Thread Harald Anlauf via Gcc-cvs
https://gcc.gnu.org/g:21e7aa5f3ea44ca2fef8deb8788edffc04901b5c

commit r15-168-g21e7aa5f3ea44ca2fef8deb8788edffc04901b5c
Author: Harald Anlauf 
Date:   Mon Apr 29 19:52:52 2024 +0200

Fortran: fix issues with class(*) assignment [PR114827]

gcc/fortran/ChangeLog:

PR fortran/114827
* trans-array.cc (gfc_alloc_allocatable_for_assignment): Take into
account _len of unlimited polymorphic entities when calculating
the effective element size for allocation size and array span.
Set _len of lhs to _len of rhs.
* trans-expr.cc (trans_class_assignment): Take into account _len
of unlimited polymorphic entities for allocation size.

gcc/testsuite/ChangeLog:

PR fortran/114827
* gfortran.dg/asan/unlimited_polymorphic_34.f90: New test.

Diff:
---
 gcc/fortran/trans-array.cc |  16 +++
 gcc/fortran/trans-expr.cc  |  13 ++
 .../gfortran.dg/asan/unlimited_polymorphic_34.f90  | 135 +
 3 files changed, 164 insertions(+)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 30b84762346..7ec33fb1598 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -11278,6 +11278,19 @@ gfc_alloc_allocatable_for_assignment (gfc_loopinfo 
*loop,
gfc_add_modify (&fblock, linfo->delta[dim], tmp);
 }
 
+  /* Take into account _len of unlimited polymorphic entities, so that span
+ for array descriptors and allocation sizes are computed correctly.  */
+  if (UNLIMITED_POLY (expr2))
+{
+  tree len = gfc_class_len_get (TREE_OPERAND (desc2, 0));
+  len = fold_build2_loc (input_location, MAX_EXPR, size_type_node,
+fold_convert (size_type_node, len),
+size_one_node);
+  elemsize2 = fold_build2_loc (input_location, MULT_EXPR,
+  gfc_array_index_type, elemsize2,
+  fold_convert (gfc_array_index_type, len));
+}
+
   if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (desc)))
 gfc_conv_descriptor_span_set (&fblock, desc, elemsize2);
 
@@ -11324,6 +11337,9 @@ gfc_alloc_allocatable_for_assignment (gfc_loopinfo 
*loop,
gfc_add_modify (&fblock, tmp,
fold_convert (TREE_TYPE (tmp),
  TYPE_SIZE_UNIT (type)));
+ else if (UNLIMITED_POLY (expr2))
+   gfc_add_modify (&fblock, tmp,
+   gfc_class_len_get (TREE_OPERAND (desc2, 0)));
  else
gfc_add_modify (&fblock, tmp,
build_int_cst (TREE_TYPE (tmp), 0));
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 0280c441ced..bc8eb419cff 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -11991,6 +11991,19 @@ trans_class_assignment (stmtblock_t *block, gfc_expr 
*lhs, gfc_expr *rhs,
old_vptr = build_int_cst (TREE_TYPE (vptr), 0);
 
   size = gfc_vptr_size_get (rhs_vptr);
+
+  /* Take into account _len of unlimited polymorphic entities.
+TODO: handle class(*) allocatable function results on rhs.  */
+  if (UNLIMITED_POLY (rhs) && rhs->expr_type == EXPR_VARIABLE)
+   {
+ tree len = trans_get_upoly_len (block, rhs);
+ len = fold_build2_loc (input_location, MAX_EXPR, size_type_node,
+fold_convert (size_type_node, len),
+size_one_node);
+ size = fold_build2_loc (input_location, MULT_EXPR, TREE_TYPE (size),
+ size, fold_convert (TREE_TYPE (size), len));
+   }
+
   tmp = lse->expr;
   class_han = GFC_CLASS_TYPE_P (TREE_TYPE (tmp))
  ? gfc_class_data_get (tmp) : tmp;
diff --git a/gcc/testsuite/gfortran.dg/asan/unlimited_polymorphic_34.f90 
b/gcc/testsuite/gfortran.dg/asan/unlimited_polymorphic_34.f90
new file mode 100644
index 000..c69158a1b55
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/asan/unlimited_polymorphic_34.f90
@@ -0,0 +1,135 @@
+! { dg-do run }
+! PR fortran/114827 - issues with class(*) assignment found by valgrind
+!
+! Contributed by Neil Carlson 
+
+program main
+  implicit none
+  call run
+  call run1
+  call run2
+contains
+  ! Scalar tests
+  subroutine run ()
+character(*),parameter :: c = 'fubarfubarfubarfubarfubarfu'
+character(*,kind=4), parameter :: d = 4_"abcdef"
+complex, parameter :: z = (1.,2.)
+class(*),  allocatable :: y
+
+call foo (c, y)
+select type (y)
+type is (character(*))
+!  print *, y(5:6)  ! ICE (-> pr114874)
+   if (y /= c) stop 1
+class default
+   stop 2
+end select
+
+call foo (z, y)
+select type (y)
+type is (complex)
+   if (y /= z) stop 3
+class default
+   stop 4
+end select
+
+call foo (d, 

[gcc(refs/users/omachota/heads/rtl-ssa-dce)] rlt-ssa: dce init and done functions

2024-05-05 Thread Ondrej Machota via Gcc-cvs
https://gcc.gnu.org/g:8f4b6a6dadd92a06849b78af5630a2ca5dd70212

commit 8f4b6a6dadd92a06849b78af5630a2ca5dd70212
Author: Ondřej Machota 
Date:   Sun May 5 21:19:18 2024 +0200

rlt-ssa: dce init and done functions

Diff:
---
 gcc/dce.cc | 42 +++---
 1 file changed, 35 insertions(+), 7 deletions(-)

diff --git a/gcc/dce.cc b/gcc/dce.cc
index 9ded9256c3b..591a750e456 100644
--- a/gcc/dce.cc
+++ b/gcc/dce.cc
@@ -17,6 +17,8 @@ You should have received a copy of the GNU General Public 
License
 along with GCC; see the file COPYING3.  If not see
 .  */
 
+#define INCLUDE_ALGORITHM
+#define INCLUDE_FUNCTIONAL
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
@@ -25,6 +27,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree.h"
 #include "predict.h"
 #include "df.h"
+#include "rtl-ssa.h"
 #include "memmodel.h"
 #include "tm_p.h"
 #include "emit-rtl.h"  /* FIXME: Can go away once crtl is moved to rtl.h.  */
@@ -1292,7 +1295,37 @@ public:
 
 }; // class pass_fast_rtl_dce
 
-} // anon namespace
+} // namespace
+
+static void
+rtl_ssa_dce_init ()
+{
+calculate_dominance_info (CDI_DOMINATORS);
+crtl->ssa = new rtl_ssa::function_info (cfun);
+}
+
+static void
+rtl_ssa_dce_done ()
+{
+free_dominance_info (CDI_DOMINATORS);
+if (crtl->ssa->perform_pending_updates ())
+  cleanup_cfg (0);
+
+delete crtl->ssa;
+crtl->ssa = nullptr;
+
+if (dump_file)
+  fprintf (dump_file, "\nFinished running rtl_ssa_dce\n\n");
+}
+
+static unsigned int
+rtl_ssa_dce ()
+{
+rtl_ssa_dce_init ();
+
+rtl_ssa_dce_done ();
+return 0;
+}
 
 rtl_opt_pass *
 make_pass_fast_rtl_dce (gcc::context *ctxt)
@@ -1324,12 +1357,7 @@ public:
   /* opt_pass methods: */
   bool gate (function *) final override { return flag_dce; }
 
-  unsigned int execute (function *) final override
-  {
-if (dump_file)
-  fprintf (dump_file, "pass_rtl_ssa_dce called\n");
-return 0;
-  }
+  unsigned int execute (function *) final override { return rtl_ssa_dce (); }
 
 }; // class pass_fast_rtl_dce


[gcc r15-170] config-ml.in: Fix multi-os-dir search

2024-05-05 Thread YunQiang Su via Gcc-cvs
https://gcc.gnu.org/g:70d30dd656957f518b8169a125f6b17f53da8237

commit r15-170-g70d30dd656957f518b8169a125f6b17f53da8237
Author: YunQiang Su 
Date:   Sun May 5 23:12:37 2024 +0800

config-ml.in: Fix multi-os-dir search

When building multilib libraries, CC/CXX etc are set with an option
-B*/lib/, instead of -B/lib/.
This will make some trouble in some case, for example building
cross toolchain based on Debian's cross packages:

  If we have libc6-dev-i386-amd64-cross packages installed on
  a non-x86 machine. This package will have the files in
  /usr/x86_4-linux-gnu/lib32.  The fellow configure will fail
  when build libgcc for i386, with complains the libc is not
  i386 ones:
 ../configure --enable-multilib --enable-multilib \
--target=x86_64-linux-gnu

Let's insert a "-B*/lib/`CC ${flags} --print-multi-os-directory`"
before "-B*/lib/".

This patch is based on the patch used by Debian now.

ChangeLog

* config-ml.in: Insert an -B option with multi-os-dir into
compiler commands used to build libraries.

Diff:
---
 config-ml.in | 20 +++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/config-ml.in b/config-ml.in
index 68854a4f16c..645cac822fd 100644
--- a/config-ml.in
+++ b/config-ml.in
@@ -514,7 +514,12 @@ multi-do:
else \
  if [ -d ../$${dir}/$${lib} ]; then \
flags=`echo $$i | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`; \
-   if (cd ../$${dir}/$${lib}; $(MAKE) $(FLAGS_TO_PASS) \
+   libsuffix_=`$${compiler} $${flags} --print-multi-os-directory`; 
\
+   if (cd ../$${dir}/$${lib}; $(MAKE) $(subst \
+   -B$(build_tooldir)/lib/, \
+   -B$(build_tooldir)/lib/$${libsuffix_}/ \
+   -B$(build_tooldir)/lib/, \
+   $(FLAGS_TO_PASS)) \
CFLAGS="$(CFLAGS) $${flags}" \
CCASFLAGS="$(CCASFLAGS) $${flags}" \
FCFLAGS="$(FCFLAGS) $${flags}" \
@@ -768,6 +773,7 @@ if [ -n "${multidirs}" ] && [ -z "${ml_norecursion}" ]; then
# Create a regular expression that matches any string as long
# as ML_POPDIR.
popdir_rx=`echo "${ML_POPDIR}" | sed 's,.,.,g'`
+   multi_osdir=`${CC-gcc} ${flags} --print-multi-os-directory 2>/dev/null`
CC_=
for arg in ${CC}; do
  case $arg in
@@ -775,6 +781,8 @@ if [ -n "${multidirs}" ] && [ -z "${ml_norecursion}" ]; then
CC_="${CC_}"`echo "X${arg}" | sed -n 
"s/X\\(-[BIL]${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n 
"s/X-[BIL]${popdir_rx}\\(.*\\)/\1/p"`' ' ;;
  "${ML_POPDIR}"/*)
CC_="${CC_}"`echo "X${arg}" | sed -n 
"s/X\\(${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n 
"s/X${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
+ -B*/lib/)
+   CC_="${CC_}${arg}${multi_osdir} ${arg} " ;;
  *)
CC_="${CC_}${arg} " ;;
  esac
@@ -787,6 +795,8 @@ if [ -n "${multidirs}" ] && [ -z "${ml_norecursion}" ]; then
CXX_="${CXX_}"`echo "X${arg}" | sed -n 
"s/X\\(-[BIL]${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n 
"s/X-[BIL]${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
  "${ML_POPDIR}"/*)
CXX_="${CXX_}"`echo "X${arg}" | sed -n 
"s/X\\(${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n 
"s/X${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
+ -B*/lib/)
+   CXX_="${CXX_}${arg}${multi_osdir} ${arg} " ;;
  *)
CXX_="${CXX_}${arg} " ;;
  esac
@@ -799,6 +809,8 @@ if [ -n "${multidirs}" ] && [ -z "${ml_norecursion}" ]; then
F77_="${F77_}"`echo "X${arg}" | sed -n 
"s/X\\(-[BIL]${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n 
"s/X-[BIL]${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
  "${ML_POPDIR}"/*)
F77_="${F77_}"`echo "X${arg}" | sed -n 
"s/X\\(${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n 
"s/X${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
+ -B*/lib/)
+   F77_="${F77_}${arg}${multi_osdir} ${arg} " ;;
  *)
F77_="${F77_}${arg} " ;;
  esac
@@ -811,6 +823,8 @@ if [ -n "${multidirs}" ] && [ -z "${ml_norecursion}" ]; then
GFORTRAN_="${GFORTRAN_}"`echo "X${arg}" | sed -n 
"s/X\\(-[BIL]${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n 
"s/X-[BIL]${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
  "${ML_POPDIR}"/*)
GFORTRAN_="${GFORTRAN_}"`echo "X${arg}" | sed -n 
"s/X\\(${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n 
"s/X${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
+ -B*/lib/)
+   GFORTRAN_="${GFORTRAN_}${arg}${multi_osdir} ${arg} " ;;
  *)
GFORTRAN_="${GFORTRAN_}${arg} " ;;
  esac
@@ -823,6 +837,8 @@ if [ -n "${multidirs}" ] && [ -z "${ml_norecursion}

[gcc r15-171] expmed: TRUNCATE value1 if needed in store_bit_field_using_insv

2024-05-05 Thread YunQiang Su via Gcc-cvs
https://gcc.gnu.org/g:7d5d2b879ae7636ca118fb4f3a08b22705cdeacb

commit r15-171-g7d5d2b879ae7636ca118fb4f3a08b22705cdeacb
Author: YunQiang Su 
Date:   Mon Apr 29 00:33:44 2024 +0800

expmed: TRUNCATE value1 if needed in store_bit_field_using_insv

PR target/113179.

In `store_bit_field_using_insv`, we just use SUBREG if value_mode
>= op_mode, while in some ports, a sign_extend will be needed,
such as MIPS64:
  If either GPR rs or GPR rt does not contain sign-extended 32-bit
  values (bits 63..31 equal), then the result of the operation is
  UNPREDICTABLE.

The problem happens for the code like:
  struct xx {
int a:4;
int b:24;
int c:3;
int d:1;
  };

  void xx (struct xx *a, long long b) {
a->d = b;
  }

In the above code, the hard register contains `b`, may be note well
sign-extended.

gcc/
PR target/113179
* expmed.cc(store_bit_field_using_insv): TRUNCATE value1 if
needed.

gcc/testsuite
PR target/113179
* gcc.target/mips/pr113179.c: New tests.

Diff:
---
 gcc/expmed.cc| 12 +---
 gcc/testsuite/gcc.target/mips/pr113179.c | 18 ++
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/gcc/expmed.cc b/gcc/expmed.cc
index 4ec035e4843..20f3a36f38c 100644
--- a/gcc/expmed.cc
+++ b/gcc/expmed.cc
@@ -704,9 +704,15 @@ store_bit_field_using_insv (const extraction_insn *insv, 
rtx op0,
}
  else
{
- tmp = gen_lowpart_if_possible (op_mode, value1);
- if (! tmp)
-   tmp = gen_lowpart (op_mode, force_reg (value_mode, value1));
+ if (targetm.mode_rep_extended (op_mode, value_mode) != UNKNOWN)
+   tmp = simplify_gen_unary (TRUNCATE, op_mode,
+ value1, value_mode);
+ else
+   {
+ tmp = gen_lowpart_if_possible (op_mode, value1);
+ if (! tmp)
+   tmp = gen_lowpart (op_mode, force_reg (value_mode, value1));
+   }
}
  value1 = tmp;
}
diff --git a/gcc/testsuite/gcc.target/mips/pr113179.c 
b/gcc/testsuite/gcc.target/mips/pr113179.c
new file mode 100644
index 000..f32c5a16765
--- /dev/null
+++ b/gcc/testsuite/gcc.target/mips/pr113179.c
@@ -0,0 +1,18 @@
+/* Check if the operand of INS is sign-extended on MIPS64.  */
+/* { dg-options "-mips64r2 -mabi=64" } */
+/* { dg-skip-if "code quality test" { *-*-* } { "-O0" } { "" } } */
+
+struct xx {
+int a:1;
+int b:24;
+int c:6;
+int d:1;
+};
+
+long long xx (struct xx *a, long long b) {
+a->d = b;
+return b+1;
+}
+
+/* { dg-final { scan-assembler "\tsll\t\\\$3,\\\$5,0" } } */
+/* { dg-final { scan-assembler "\tdaddiu\t\\\$2,\\\$5,1" } } */