From 09188fce36c4544f7cf7fdb581886dcbbcc445e8 Mon Sep 17 00:00:00 2001 From: metrechen Date: Tue, 30 Jun 2026 11:41:51 +0800 Subject: [PATCH] [middle-end] backport fix for PR 124250: extend narrower shift amount before broadcasting - Bump gcc_release to 5 (12.3.1.8-5) - Add Patch3016: gcc12-middle-end-extend-the-narrower-shift-amount-before-b.patch - Extend shift amount to element size before broadcasting in vector shift operations to fix ICE/miscompile on narrower shift amounts. --- gcc.spec | 10 +- ...rrower-shift-amount-before-broadcast.patch | 107 ++++++++++++++++++ 2 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 loongarch-middle-end-extend-the-narrower-shift-amount-before-broadcast.patch diff --git a/gcc.spec b/gcc.spec index 6c29dfc..48df478 100644 --- a/gcc.spec +++ b/gcc.spec @@ -1,6 +1,6 @@ %global gcc_version 12.3.1.8 %global gcc_major 12 -%global gcc_release 4 +%global gcc_release 5 %global isl_version 0.18 %global tgcc_summary Tencent Compiler %global _unpackaged_files_terminate_build 0 @@ -155,6 +155,7 @@ Patch3012: 0001-Disparage-slightly-for-the-alternative-which-move-DF.patch Patch3013: HYGON-0001-i386-Support-HYGON-c86-4g-series-processors.patch Patch3014: HYGON-0002-i386-Adjust-some-c86-4g-.md-modeling-to-reduce-build.patch Patch3015: HYGON-0003-i386-Refine-c86-4g-fdiv-scheduling-model.patch +Patch3016: loongarch-middle-end-extend-the-narrower-shift-amount-before-broadcast.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 @@ -888,6 +889,7 @@ for cross toolchains %patch 3013 -p1 %patch 3014 -p1 %patch 3015 -p1 +%patch 3016 -p1 rm -f libphobos/testsuite/libphobos.gc/forkgc2.d @@ -2443,6 +2445,12 @@ end %changelog +* Tue Jun 30 2026 metrechen - 12.3.1.8-5 +- [Type] bugfix +- [DESC] [LoongArch] extend the narrower shift amount before broadcasting +- Backport fix for PR 124250: extend shift amount to element size before + broadcasting in vector shift operations. + * Fri Jun 12 2026 Kewen Lin - 12.3.1.8-4 - [Type] sync - [DESC] [X86] Support HYGON C86-4G series processors diff --git a/loongarch-middle-end-extend-the-narrower-shift-amount-before-broadcast.patch b/loongarch-middle-end-extend-the-narrower-shift-amount-before-broadcast.patch new file mode 100644 index 0000000..8ad5991 --- /dev/null +++ b/loongarch-middle-end-extend-the-narrower-shift-amount-before-broadcast.patch @@ -0,0 +1,107 @@ +From 062500172a2824ff1872c7d90dfe9bc443af0d4c Mon Sep 17 00:00:00 2001 +From: Xi Ruoyao +Date: Thu, 26 Feb 2026 11:55:22 +0800 +Subject: [PATCH] middle-end: extend the narrower shift amount before + broadcasting it [PR 124250] + +The comment above expand_vector_broadcast() states a precondition that +the mode of op must be the element mode of vmode. But when +expand_binop() called expand_vector_broadcast() to broadcast the shift +amount, it only truncated the shift amount if it's too wide, but no +action is performed if the shift amount is too narrow. + + PR middle-end/124250 + PR target/123807 + +gcc/ + * optabs.cc (expand_vector_broadcast): Add a checking assert to + verify the precondition about the input modes. + (expand_binop): Extend the shift amount if it's narrower than + the element of the shifted vector. + +gcc/testsuite/ + + * gcc.c-torture/compile/pr124250.c: New test. +--- + gcc/optabs.cc | 34 +++++++++++++------ + .../gcc.c-torture/compile/pr124250.c | 8 +++++ + 2 files changed, 31 insertions(+), 11 deletions(-) + create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr124250.c + +diff --git a/gcc/optabs.cc b/gcc/optabs.cc +index 3d8fa3abdfea..a96eee276bc7 100644 +--- a/gcc/optabs.cc ++++ b/gcc/optabs.cc +@@ -421,9 +421,9 @@ force_expand_binop (machine_mode mode, optab binoptab, + return true; + } + +-/* Create a new vector value in VMODE with all elements set to OP. The +- mode of OP must be the element mode of VMODE. If OP is a constant, +- then the return value will be a constant. */ ++/* Create a new vector value in VMODE with all elements set to OP. If OP ++ is not a constant, the mode of it must be the element mode of VMODE. ++ If OP is a constant, then the return value will be a constant. */ + + rtx + expand_vector_broadcast (machine_mode vmode, rtx op) +@@ -432,6 +432,8 @@ expand_vector_broadcast (machine_mode vmode, rtx op) + rtvec vec; + + gcc_checking_assert (VECTOR_MODE_P (vmode)); ++ gcc_checking_assert (CONST_INT_P (op) ++ || GET_MODE_INNER (vmode) == GET_MODE (op)); + + if (valid_for_const_vector_p (vmode, op)) + return gen_const_vec_duplicate (vmode, op); +@@ -1608,15 +1610,25 @@ expand_binop (machine_mode mode, optab binoptab, rtx op0, rtx op1, + if (otheroptab + && (icode = optab_handler (otheroptab, mode)) != CODE_FOR_nothing) + { +- /* The scalar may have been extended to be too wide. Truncate +- it back to the proper size to fit in the broadcast vector. */ ++ /* The scalar may be wider or narrower than the vector element. ++ Truncate or extend it to the proper size to fit in the ++ broadcast vector. */ + scalar_mode inner_mode = GET_MODE_INNER (mode); +- if (!CONST_INT_P (op1) +- && (GET_MODE_BITSIZE (as_a (GET_MODE (op1))) +- > GET_MODE_BITSIZE (inner_mode))) +- op1 = force_reg (inner_mode, +- simplify_gen_unary (TRUNCATE, inner_mode, op1, +- GET_MODE (op1))); ++ if (!CONST_INT_P (op1)) ++ { ++ auto mode1 = as_a (GET_MODE (op1)); ++ int size1 = GET_MODE_BITSIZE (mode1); ++ int inner_size = GET_MODE_BITSIZE (inner_mode); ++ ++ if (size1 != inner_size) ++ { ++ auto unary = size1 > inner_size ? TRUNCATE : ZERO_EXTEND; ++ op1 = force_reg (inner_mode, ++ simplify_gen_unary (unary, inner_mode, ++ op1, mode1)); ++ } ++ } ++ + rtx vop1 = expand_vector_broadcast (mode, op1); + if (vop1) + { +diff --git a/gcc/testsuite/gcc.c-torture/compile/pr124250.c b/gcc/testsuite/gcc.c-torture/compile/pr124250.c +new file mode 100644 +index 000000000000..1435091dc0b8 +--- /dev/null ++++ b/gcc/testsuite/gcc.c-torture/compile/pr124250.c +@@ -0,0 +1,8 @@ ++typedef long long v2i64 __attribute__ ((vector_size (16), aligned (16))); ++v2i64 a, b; ++ ++void ++test (int l) ++{ ++ a = b >> (-l); ++} +-- +2.27.0 + -- Gitee