From deef6754b763fa1f3cbd4f685d35b1aafcd96f6c Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Thu, 29 May 2025 19:27:27 +0100 Subject: [PATCH] 11.5.0-7 Fix folding of BIT_NOT_EXPR for POLY_INT_CST (PR 118976, RHEL-90239) Resolves: RHEL-90239 --- gcc.spec | 7 ++++- gcc11-pr118976.patch | 64 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 gcc11-pr118976.patch diff --git a/gcc.spec b/gcc.spec index a34a685..1980243 100644 --- a/gcc.spec +++ b/gcc.spec @@ -4,7 +4,7 @@ %global gcc_major 11 # Note, gcc_release must be integer, if you want to add suffixes to # %%{release}, append them after %%{gcc_release} on Release: line. -%global gcc_release 6 +%global gcc_release 7 %global nvptx_tools_gitrev 5f6f343a302d620b0868edab376c00b15741e39e %global newlib_cygwin_gitrev 50e2a63b04bdd018484605fbb954fd1bd5147fa0 %global _unpackaged_files_terminate_build 0 @@ -300,6 +300,7 @@ Patch37: gcc11-pr113960.patch Patch38: gcc11-pr105157.patch Patch39: gcc11-testsuite-fixes-4.patch Patch40: gcc11-pr99888.patch +Patch41: gcc11-pr118976.patch Patch100: gcc11-fortran-fdec-duplicates.patch Patch101: gcc11-fortran-flogical-as-integer.patch @@ -905,6 +906,7 @@ mark them as cross compiled. %patch38 -p1 -b .pr105157~ %patch39 -p1 -b .testsuite4~ %patch40 -p1 -b .pr99888~ +%patch41 -p1 -b .pr118976~ %if 0%{?rhel} >= 9 %patch100 -p1 -b .fortran-fdec-duplicates~ @@ -3601,6 +3603,9 @@ end %endif %changelog +* Thu May 29 2025 Joseph Myers - 11.5.0-7 +- Fix folding of BIT_NOT_EXPR for POLY_INT_CST (PR 118976, RHEL-90239) + * Wed May 21 2025 David Malcolm - 11.5.0-6 - rs6000: Rework ELFv2 support for -fpatchable-function-entry (PR target/99888, RHEL-75806) diff --git a/gcc11-pr118976.patch b/gcc11-pr118976.patch new file mode 100644 index 0000000..f3485ff --- /dev/null +++ b/gcc11-pr118976.patch @@ -0,0 +1,64 @@ +Original patch (taken from GCC 12 branch version) edited for GCC 11 to +use .c rather than .cc filenames. + +commit 587b370c8492aadaab14c57e242c66778cc78891 +Author: Richard Sandiford +Date: Tue Mar 11 15:51:55 2025 +0000 + + Fix folding of BIT_NOT_EXPR for POLY_INT_CST [PR118976] + + There was an embarrassing typo in the folding of BIT_NOT_EXPR for + POLY_INT_CSTs: it used - rather than ~ on the poly_int. Not sure + how that happened, but it might have been due to the way that + ~x is implemented as -1 - x internally. + + gcc/ + PR tree-optimization/118976 + * fold-const.cc (const_unop): Use ~ rather than - for BIT_NOT_EXPR. + * config/aarch64/aarch64.cc (aarch64_test_sve_folding): New function. + (aarch64_run_selftests): Run it. + + (cherry picked from commit 78380fd7f743e23dfdf013d68a2f0347e1511550) + +diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c +index be0d958dcf6b..72d737d62228 100644 +--- a/gcc/config/aarch64/aarch64.c ++++ b/gcc/config/aarch64/aarch64.c +@@ -27541,6 +27541,16 @@ aarch64_test_fractional_cost () + ASSERT_EQ (cf (1, 2).as_double (), 0.5); + } + ++/* Test SVE arithmetic folding. */ ++ ++static void ++aarch64_test_sve_folding () ++{ ++ tree res = fold_unary (BIT_NOT_EXPR, ssizetype, ++ ssize_int (poly_int64 (1, 1))); ++ ASSERT_TRUE (operand_equal_p (res, ssize_int (poly_int64 (-2, -1)))); ++} ++ + /* Run all target-specific selftests. */ + + static void +@@ -27548,6 +27558,7 @@ aarch64_run_selftests (void) + { + aarch64_test_loading_full_dump (); + aarch64_test_fractional_cost (); ++ aarch64_test_sve_folding (); + } + + } // namespace selftest +diff --git a/gcc/fold-const.c b/gcc/fold-const.c +index d81a71c41a17..391f11095408 100644 +--- a/gcc/fold-const.c ++++ b/gcc/fold-const.c +@@ -1802,7 +1802,7 @@ const_unop (enum tree_code code, tree type, tree arg0) + if (TREE_CODE (arg0) == INTEGER_CST) + return fold_not_const (arg0, type); + else if (POLY_INT_CST_P (arg0)) +- return wide_int_to_tree (type, -poly_int_cst_value (arg0)); ++ return wide_int_to_tree (type, ~poly_int_cst_value (arg0)); + /* Perform BIT_NOT_EXPR on each element individually. */ + else if (TREE_CODE (arg0) == VECTOR_CST) + {