diff --git a/0001-LoongArch-Optimize-the-loading-of-immediate-numbers-.patch b/0001-LoongArch-Optimize-the-loading-of-immediate-numbers-.patch new file mode 100644 index 0000000000000000000000000000000000000000..0addd090fa3a6490a8ad02f065602132af5a4b0a --- /dev/null +++ b/0001-LoongArch-Optimize-the-loading-of-immediate-numbers-.patch @@ -0,0 +1,112 @@ +From 8c4083b2726b01119414c04bfc1c7f3f6c90001c Mon Sep 17 00:00:00 2001 +From: Guo Jie +Date: Thu, 23 Nov 2023 11:04:17 +0800 +Subject: [PATCH 1/2] LoongArch: Optimize the loading of immediate numbers with + the same high and low 32-bit values + +For the following immediate load operation in gcc/testsuite/gcc.target/loongarch/imm-load1.c: + + long long r = 0x0101010101010101; + +Before this patch: + + lu12i.w $r15,16842752>>12 + ori $r15,$r15,257 + lu32i.d $r15,0x1010100000000>>32 + lu52i.d $r15,$r15,0x100000000000000>>52 + +After this patch: + + lu12i.w $r15,16842752>>12 + ori $r15,$r15,257 + bstrins.d $r15,$r15,63,32 + +gcc/ChangeLog: + + * config/loongarch/loongarch.cc + (enum loongarch_load_imm_method): Add new method. + (loongarch_build_integer): Add relevant implementations for + new method. + (loongarch_move_integer): Ditto. + +gcc/testsuite/ChangeLog: + + * gcc.target/loongarch/imm-load1.c: Change old check. +--- + gcc/config/loongarch/loongarch.cc | 22 ++++++++++++++++++- + .../gcc.target/loongarch/imm-load1.c | 3 ++- + 2 files changed, 23 insertions(+), 2 deletions(-) + +diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc +index f2e796a6b0f..7a8d5665c78 100644 +--- a/gcc/config/loongarch/loongarch.cc ++++ b/gcc/config/loongarch/loongarch.cc +@@ -140,12 +140,16 @@ struct loongarch_address_info + + METHOD_LU52I: + Load 52-63 bit of the immediate number. ++ ++ METHOD_MIRROR: ++ Copy 0-31 bit of the immediate number to 32-63bit. + */ + enum loongarch_load_imm_method + { + METHOD_NORMAL, + METHOD_LU32I, +- METHOD_LU52I ++ METHOD_LU52I, ++ METHOD_MIRROR + }; + + struct loongarch_integer_op +@@ -1551,11 +1555,23 @@ loongarch_build_integer (struct loongarch_integer_op *codes, + + int sign31 = (value & (HOST_WIDE_INT_1U << 31)) >> 31; + int sign51 = (value & (HOST_WIDE_INT_1U << 51)) >> 51; ++ ++ uint32_t hival = (uint32_t) (value >> 32); ++ uint32_t loval = (uint32_t) value; ++ + /* Determine whether the upper 32 bits are sign-extended from the lower + 32 bits. If it is, the instructions to load the high order can be + ommitted. */ + if (lu32i[sign31] && lu52i[sign31]) + return cost; ++ /* If the lower 32 bits are the same as the upper 32 bits, just copy ++ the lower 32 bits to the upper 32 bits. */ ++ else if (loval == hival) ++ { ++ codes[cost].method = METHOD_MIRROR; ++ codes[cost].curr_value = value; ++ return cost + 1; ++ } + /* Determine whether bits 32-51 are sign-extended from the lower 32 + bits. If so, directly load 52-63 bits. */ + else if (lu32i[sign31]) +@@ -3193,6 +3209,10 @@ loongarch_move_integer (rtx temp, rtx dest, unsigned HOST_WIDE_INT value) + gen_rtx_AND (DImode, x, GEN_INT (0xfffffffffffff)), + GEN_INT (codes[i].value)); + break; ++ case METHOD_MIRROR: ++ gcc_assert (mode == DImode); ++ emit_insn (gen_insvdi (x, GEN_INT (32), GEN_INT (32), x)); ++ break; + default: + gcc_unreachable (); + } +diff --git a/gcc/testsuite/gcc.target/loongarch/imm-load1.c b/gcc/testsuite/gcc.target/loongarch/imm-load1.c +index 2ff02971239..f64cc2956a3 100644 +--- a/gcc/testsuite/gcc.target/loongarch/imm-load1.c ++++ b/gcc/testsuite/gcc.target/loongarch/imm-load1.c +@@ -1,6 +1,7 @@ + /* { dg-do compile } */ + /* { dg-options "-mabi=lp64d -O2" } */ +-/* { dg-final { scan-assembler "test:.*lu52i\.d.*\n\taddi\.w.*\n\.L2:" } } */ ++/* { dg-final { scan-assembler-not "test:.*lu52i\.d.*\n\taddi\.w.*\n\.L2:" } } */ ++/* { dg-final { scan-assembler "test:.*lu12i\.w.*\n\tbstrins\.d.*\n\.L2:" } } */ + + + extern long long b[10]; +-- +2.33.0 + diff --git a/0002-LoongArch-Fixed-bug-in-bstrins_-mode-_for_ior_mask-t.patch b/0002-LoongArch-Fixed-bug-in-bstrins_-mode-_for_ior_mask-t.patch new file mode 100644 index 0000000000000000000000000000000000000000..c901811b498a09b4c2178f222204819b4ae34b43 --- /dev/null +++ b/0002-LoongArch-Fixed-bug-in-bstrins_-mode-_for_ior_mask-t.patch @@ -0,0 +1,37 @@ +From 6a487dd4e37a1738df5103bd06a2c69dd154d553 Mon Sep 17 00:00:00 2001 +From: Li Wei +Date: Mon, 25 Dec 2023 11:20:23 +0800 +Subject: [PATCH 2/2] LoongArch: Fixed bug in *bstrins__for_ior_mask + template. + +We found that using the latest compiled gcc will cause a miscompare error +when running spec2006 400.perlbench test with -flto turned on. After testing, +it was found that only the LoongArch architecture will report errors. +The first error commit was located through the git bisect command as +r14-3773-g5b857e87201335. Through debugging, it was found that the problem +was that the split condition of the *bstrins__for_ior_mask template was +empty, which should actually be consistent with the insn condition. + +gcc/ChangeLog: + + * config/loongarch/loongarch.md: Adjust. +--- + gcc/config/loongarch/loongarch.md | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md +index 63ff32e7569..3b2c57ef99a 100644 +--- a/gcc/config/loongarch/loongarch.md ++++ b/gcc/config/loongarch/loongarch.md +@@ -1377,7 +1377,7 @@ + "loongarch_pre_reload_split () && \ + loongarch_use_bstrins_for_ior_with_mask (mode, operands)" + "#" +- "" ++ "&& true" + [(set (match_dup 0) (match_dup 1)) + (set (zero_extract:GPR (match_dup 0) (match_dup 2) (match_dup 4)) + (match_dup 3))] +-- +2.33.0 + diff --git a/gcc.spec b/gcc.spec index 7a4681349a93f6f0c56d4564b2cef36f646ca6cb..debe78fb9d7f1d780ab7b86dde1559b8ed89504f 100644 --- a/gcc.spec +++ b/gcc.spec @@ -1,6 +1,6 @@ %global gcc_version 12.3.1.2 %global gcc_major 12 -%global gcc_release 2 +%global gcc_release 3 %global isl_version 0.18 %global tgcc_summary Tencent Compiler %global _unpackaged_files_terminate_build 0 @@ -126,6 +126,9 @@ Patch3005: gcc12-no-add-needed.patch Patch3006: gcc12-Wno-format-security.patch Patch3007: gcc12-rh1574936.patch Patch3008: gcc12-d-shared-libphobos.patch +# Fix GNOME desktop startup failure on loongarch architecture +Patch3009: 0001-LoongArch-Optimize-the-loading-of-immediate-numbers-.patch +Patch3010: 0002-LoongArch-Fixed-bug-in-bstrins_-mode-_for_ior_mask-t.patch BuildRequires: binutils >= 2.31, elfutils-devel >= 0.147, elfutils-libelf-devel >= 0.147, sharutils, gcc, gcc-c++, make BuildRequires: glibc-static, glibc-devel >= 2.4.90-13, gdb @@ -848,6 +851,8 @@ for cross toolchains %patch 3006 -p0 %patch 3007 -p0 %patch 3008 -p0 +%patch 3009 -p1 +%patch 3010 -p1 rm -f libphobos/testsuite/libphobos.gc/forkgc2.d @@ -951,10 +956,7 @@ CONFIGURE_OPTS="\ --with-abi=lp64d \ --enable-tls \ --with-long-double-128 \ - --enable-initfini-array \ - --enable-gnu-indirect-function \ --disable-emultls \ - --with-linker-hash-style=gnu \ %endif --build=%{gcc_target_platform} \ --with-build-config=bootstrap-lto --enable-link-serialization=1 \ @@ -2398,6 +2400,11 @@ end %changelog +* Thu Jul 25 2024 Huang Yang - 12.3.1.2-3 +- [Type] bugfix +- [DESC] Fix GNOME desktop startup failure on loongarch architecture +- Remove some duplicate configure options + * Mon Jun 24 2024 Zhao Zhen - 12.3.1.2-2 - provides a new subpackage included patched source for cross toolchains @@ -2459,4 +2466,4 @@ end - disabled generating documents of libstdc++ * Wed Jul 20 2022 Zhao Zhen 12.1.0-1 -- Initial building. \ No newline at end of file +- Initial building.