commit: 3438a1297763a879778b4a4c31e78d3eb333ed13 Author: Sam James <sam <AT> gentoo <DOT> org> AuthorDate: Thu Apr 10 17:40:25 2025 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Thu Apr 10 17:41:49 2025 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=3438a129
sys-devel/gcc: backport two fixes to 15.0.1_pre20250406 * Backport a fix for riscv (bug #953420). (Note that while the bad patch was in this snapshot as a "backport", it was about to be merged upstream and indeed was on Monday, only got fixed up later. Such is the game.) * Backport a compare-debug fix which affects bootstrap in some cases, e.g. i486/i586. Partly throwing this in to make the rebuild worthwhile for non-riscv users. Closes: https://bugs.gentoo.org/953420 Signed-off-by: Sam James <sam <AT> gentoo.org> .../gcc-15.0.1_pre20250406-compare-debug.patch | 88 ++++++++++++++++++++++ .../gcc-15.0.1_pre20250406-simplify-oops.patch | 81 ++++++++++++++++++++ sys-devel/gcc/gcc-15.0.1_pre20250406-r1.ebuild | 57 ++++++++++++++ 3 files changed, 226 insertions(+) diff --git a/sys-devel/gcc/files/gcc-15.0.1_pre20250406-compare-debug.patch b/sys-devel/gcc/files/gcc-15.0.1_pre20250406-compare-debug.patch new file mode 100644 index 000000000000..5fd89cd8e5e9 --- /dev/null +++ b/sys-devel/gcc/files/gcc-15.0.1_pre20250406-compare-debug.patch @@ -0,0 +1,88 @@ +https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=088887de7717a22b1503760e9b79dfbe22a0f428 + +From 088887de7717a22b1503760e9b79dfbe22a0f428 Mon Sep 17 00:00:00 2001 +From: Richard Biener <[email protected]> +Date: Wed, 9 Apr 2025 14:36:19 +0200 +Subject: [PATCH] rtl-optimization/119689 - compare-debug failure with LRA + +The previous change to fix LRA rematerialization broke compare-debug +for i586 bootstrap. Fixed by using prev_nonnote_nondebug_insn +instead of prev_nonnote_insn. + + PR rtl-optimization/119689 + PR rtl-optimization/115568 + * lra-remat.cc (create_cands): Use prev_nonnote_nondebug_insn + to check whether insn2 is directly before insn. + + * g++.target/i386/pr119689.C: New testcase. +--- + gcc/lra-remat.cc | 2 +- + gcc/testsuite/g++.target/i386/pr119689.C | 44 ++++++++++++++++++++++++ + 2 files changed, 45 insertions(+), 1 deletion(-) + create mode 100644 gcc/testsuite/g++.target/i386/pr119689.C + +diff --git a/gcc/lra-remat.cc b/gcc/lra-remat.cc +index 2f3afffcf5be..5f823193aa73 100644 +--- a/gcc/lra-remat.cc ++++ b/gcc/lra-remat.cc +@@ -460,7 +460,7 @@ create_cands (void) + && dst_regno >= FIRST_PSEUDO_REGISTER + && reg_renumber[dst_regno] < 0 + && BLOCK_FOR_INSN (insn2) == BLOCK_FOR_INSN (insn) +- && insn2 == prev_nonnote_insn (insn)) ++ && insn2 == prev_nonnote_nondebug_insn (insn)) + { + create_cand (insn2, regno_potential_cand[src_regno].nop, + dst_regno, insn); +diff --git a/gcc/testsuite/g++.target/i386/pr119689.C b/gcc/testsuite/g++.target/i386/pr119689.C +new file mode 100644 +index 000000000000..cdc6d2dade53 +--- /dev/null ++++ b/gcc/testsuite/g++.target/i386/pr119689.C +@@ -0,0 +1,44 @@ ++// { dg-do compile } ++// { dg-options "-O2 -fcompare-debug" } ++// { dg-additional-options "-march=i586 -mtune=generic" { target ia32 } } ++// { dg-additional-options "-fPIC" { target { fpic } } } ++ ++enum gimple_code { GIMPLE_ASSIGN, GIMPLE_RETURN }; ++bool is_gimple_call(); ++int m_sig, m_exp, sreal_new_exp; ++struct sreal { ++ sreal(long long sig) { ++ long long __trans_tmp_6 = sig >= 0 ? sig : -(unsigned long long)sig; ++ sig = __trans_tmp_6 <<= sreal_new_exp -= m_exp = __trans_tmp_6; ++ m_sig = sig; ++ } ++ void operator/(sreal); ++}; ++struct ipa_predicate { ++ ipa_predicate(bool = true); ++ void operator&=(ipa_predicate); ++ void operator&(ipa_predicate); ++}; ++void add_condition(); ++gimple_code eliminated_by_inlining_prob_code; ++static int eliminated_by_inlining_prob() { ++ switch (eliminated_by_inlining_prob_code) { ++ case GIMPLE_RETURN: ++ return 2; ++ case GIMPLE_ASSIGN: ++ return 1; ++ } ++ return 0; ++} ++void fp_expression_p() { ++ ipa_predicate bb_predicate; ++ for (;;) { ++ int prob = eliminated_by_inlining_prob(); ++ ipa_predicate sra_predicate; ++ sra_predicate &= add_condition; ++ if (is_gimple_call()) ++ sreal(prob) / 2; ++ if (prob != 2) ++ bb_predicate & sra_predicate; ++ } ++} +-- +2.43.5 diff --git a/sys-devel/gcc/files/gcc-15.0.1_pre20250406-simplify-oops.patch b/sys-devel/gcc/files/gcc-15.0.1_pre20250406-simplify-oops.patch new file mode 100644 index 000000000000..abc7b6966cf7 --- /dev/null +++ b/sys-devel/gcc/files/gcc-15.0.1_pre20250406-simplify-oops.patch @@ -0,0 +1,81 @@ +https://gcc.gnu.org/PR119672 +https://gcc.gnu.org/PR119713 +https://bugs.gentoo.org/953420 +https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=04918a2d3f20b02ac3efad1096c33894d57789a0 + +From 04918a2d3f20b02ac3efad1096c33894d57789a0 Mon Sep 17 00:00:00 2001 +From: Jakub Jelinek <[email protected]> +Date: Tue, 8 Apr 2025 15:14:58 +0200 +Subject: [PATCH] simplify-rtx: Fix up POPCOUNT optimization [PR119672] + +The gcc.dg/vect/pr113281-1.c test and many others ICE on riscv since +presumably the r15-9238 change which allowed more cases of vector modes +in simplify_const_relational_operation. +In the testcase it is EQ of +(popcount:SI (unspec:RVVMF32BI [ + (and:RVVMF32BI (const_vector:RVVMF32BI repeat [ + (const_int 1 [0x1]) + ]) + (reg:RVVMF32BI 147 [ mask__6.8_35 ])) + (reg:SI 143 [ _41 ]) + (const_int 0 [0]) + (reg:SI 66 vl) + (reg:SI 67 vtype) + ] UNSPEC_VPREDICATE)) +and +(const_int 0 [0]) +which it tries to fold as EQ comparison of +(unspec:RVVMF32BI [ + (and:RVVMF32BI (const_vector:RVVMF32BI repeat [ + (const_int 1 [0x1]) + ]) + (reg:RVVMF32BI 147 [ mask__6.8_35 ])) + (reg:SI 143 [ _41 ]) + (const_int 0 [0]) + (reg:SI 66 vl) + (reg:SI 67 vtype) + ] UNSPEC_VPREDICATE) +with +(const_int 0 [0]) +which ICEs because const0_rtx isn't a vector. +Fixed by using CONST0_RTX, so that we pass +(const_vector:RVVMF32BI repeat [ + (const_int 0 [0]) + ]) +instead. + +2025-04-08 Jakub Jelinek <[email protected]> + + PR rtl-optimization/119672 + * simplify-rtx.cc (simplify_context::simplify_relational_operation_1): + For POPCOUNT == 0 or != 0 optimizations use + CONST0_RTX (GET_MODE (XEXP (op0, 0))) rather than const0_rtx. +--- + gcc/simplify-rtx.cc | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc +index 6f969effdf99..88d31a71c05a 100644 +--- a/gcc/simplify-rtx.cc ++++ b/gcc/simplify-rtx.cc +@@ -6465,14 +6465,16 @@ simplify_context::simplify_relational_operation_1 (rtx_code code, + case LEU: + /* (eq (popcount x) (const_int 0)) -> (eq x (const_int 0)). */ + return simplify_gen_relational (EQ, mode, GET_MODE (XEXP (op0, 0)), +- XEXP (op0, 0), const0_rtx); ++ XEXP (op0, 0), ++ CONST0_RTX (GET_MODE (XEXP (op0, 0)))); + + case NE: + case GT: + case GTU: + /* (ne (popcount x) (const_int 0)) -> (ne x (const_int 0)). */ + return simplify_gen_relational (NE, mode, GET_MODE (XEXP (op0, 0)), +- XEXP (op0, 0), const0_rtx); ++ XEXP (op0, 0), ++ CONST0_RTX (GET_MODE (XEXP (op0, 0)))); + + default: + break; +-- +2.43.5 diff --git a/sys-devel/gcc/gcc-15.0.1_pre20250406-r1.ebuild b/sys-devel/gcc/gcc-15.0.1_pre20250406-r1.ebuild new file mode 100644 index 000000000000..a27cfb06a0df --- /dev/null +++ b/sys-devel/gcc/gcc-15.0.1_pre20250406-r1.ebuild @@ -0,0 +1,57 @@ +# Copyright 1999-2025 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=8 + +# Maintenance notes and explanations of GCC handling are on the wiki: +# https://wiki.gentoo.org/wiki/Project:Toolchain/sys-devel/gcc + +TOOLCHAIN_PATCH_DEV="sam" +TOOLCHAIN_HAS_TESTS=1 +PATCH_GCC_VER="15.0.0" +PATCH_VER="53" +MUSL_VER="2" +MUSL_GCC_VER="15.0.0" +PYTHON_COMPAT=( python3_{10..13} ) + +if [[ -n ${TOOLCHAIN_GCC_RC} ]] ; then + # Cheesy hack for RCs + MY_PV=$(ver_cut 1).$((($(ver_cut 2) + 1))).$((($(ver_cut 3) - 1)))-RC-$(ver_cut 5) + MY_P=${PN}-${MY_PV} + GCC_TARBALL_SRC_URI="mirror://gcc/snapshots/${MY_PV}/${MY_P}.tar.xz" + TOOLCHAIN_SET_S=no + S="${WORKDIR}"/${MY_P} +fi + +inherit toolchain + +if tc_is_live ; then + # Needs to be after inherit (for now?), bug #830908 + EGIT_BRANCH=master +elif [[ -z ${TOOLCHAIN_USE_GIT_PATCHES} ]] ; then + # Don't keyword live ebuilds + #KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~loong ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86" + :; +fi + +if [[ ${CATEGORY} != cross-* ]] ; then + # Technically only if USE=hardened *too* right now, but no point in complicating it further. + # If GCC is enabling CET by default, we need glibc to be built with support for it. + # bug #830454 + RDEPEND="elibc_glibc? ( sys-libs/glibc[cet(-)?] )" + DEPEND="${RDEPEND}" +fi + +src_prepare() { + local p upstreamed_patches=( + # add them here + ) + for p in "${upstreamed_patches[@]}"; do + rm -v "${WORKDIR}/patch/${p}" || die + done + + toolchain_src_prepare + eapply "${FILESDIR}"/${P}-simplify-oops.patch + eapply "${FILESDIR}"/${P}-compare-debug.patch + eapply_user +}
