commit: ac992a4b6aff941acb795efc308b9669402aa0b7 Author: Sam James <sam <AT> gentoo <DOT> org> AuthorDate: Mon Nov 3 08:58:51 2025 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Mon Nov 3 08:58:51 2025 +0000 URL: https://gitweb.gentoo.org/proj/gcc-patches.git/commit/?id=ac992a4b
16.0.0: switch workaround for PR122502 Signed-off-by: Sam James <sam <AT> gentoo.org> 16.0.0/gentoo/88_all_PR122502.patch | 452 +++++++++++++----------------------- 16.0.0/gentoo/README.history | 4 + 2 files changed, 164 insertions(+), 292 deletions(-) diff --git a/16.0.0/gentoo/88_all_PR122502.patch b/16.0.0/gentoo/88_all_PR122502.patch index 8e8aca4..d581a26 100644 --- a/16.0.0/gentoo/88_all_PR122502.patch +++ b/16.0.0/gentoo/88_all_PR122502.patch @@ -1,314 +1,182 @@ -From accd9639a67f0774f29514e67e0f79ea88359235 Mon Sep 17 00:00:00 2001 -Message-ID: <accd9639a67f0774f29514e67e0f79ea88359235.1762072263.git....@gentoo.org> -From: Sam James <[email protected]> -Date: Sun, 2 Nov 2025 08:30:21 +0000 -Subject: [PATCH] Revert "niter: Use ranger to query ctz range." +From 507cd2fe8006e630de1034640a6b675a44610c54 Mon Sep 17 00:00:00 2001 +Message-ID: <507cd2fe8006e630de1034640a6b675a44610c54.1762160303.git....@gentoo.org> +From: Richard Biener <[email protected]> +Date: Fri, 31 Oct 2025 13:08:05 +0100 +Subject: [PATCH] Make FOR_EACH_IMM_USE_STMT work w/o fake imm use node -This reverts commit 0919526efcb156a17947a2fc68d7aaa487e273ae. +This is an attempt to fix PR122502 by making a FOR_EACH_IMM_USE_FAST +with in an FOR_EACH_IMM_USE_STMT on _the same_ VAR work without +the former running into the FOR_EACH_IMM_USE_STMT inserted marker +use operand. It does this by getting rid of the marker. -Bug: https://gcc.gnu.org/PR122497 -Bug: https://gcc.gnu.org/PR122502 +The downside is that this in principle restricts the set of operations +that can be done on the immediate use list of VAR. Where previously +almost anything was OK (but technically not well-defined what happens +to the iteration) after this patch you may only remove immediate +uses of VAR on the current stmt from the FOR_EACH_IMM_USE_STMT +iteration. In particular things will break if you happen to remove +the one immediate use of VAR on the stmt immediately following +the set of immediate uses on the currrent stmt. + +FOR_EACH_IMM_USE_FAST seems to support altering the current use +(as in, removing it, but only it) and is also resitant to adding +additional uses (without defining whether those are going to be +visited, but they are not). Doing this from within an outer +FOR_EACH_IMM_USE_STMT iteration is still not OK (only strictly +read-only uses of FOR_EACH_IMM_USE_FAST are). + +Checking is weak in this area, as is documentation. + +Bootstrapped and tested on x86_64-unknown-linux-gnu. + +Any comments? I've had another patch trying to ignore the +FOR_EACH_IMM_USE_STMT marker from within a nested FOR_EACH_IMM_USE_FAST +iteration, but that seemed more ugly (but of course simpler). + +Thanks, +Richard. + +PR tree-optimization/122502 + * ssa-iterators.h (imm_use_iterator::iter_node): Remove. + (imm_use_iterator::next_stmt_use): New. + (next_readonly_imm_use): Adjust checking code. + (end_imm_use_stmt_traverse): Simplify. + (link_use_stmts_after): Likewise. Return the last use + with the same stmt. + (first_imm_use_stmt): Simplify. Set next_stmt_use. + (next_imm_use_stmt): Likewise. + (end_imm_use_on_stmt_p): Adjust. --- - gcc/testsuite/gcc.dg/pr41488.c | 2 +- - gcc/testsuite/gcc.dg/tree-ssa/ctz-ch.c | 23 ----- - gcc/testsuite/gcc.dg/tree-ssa/ctz-char.c | 2 +- - .../gcc.dg/tree-ssa/ctz-complement-char.c | 2 +- - .../gcc.dg/tree-ssa/ctz-complement-int.c | 2 +- - .../tree-ssa/ctz-complement-long-long.c | 2 +- - .../gcc.dg/tree-ssa/ctz-complement-long.c | 2 +- - gcc/testsuite/gcc.dg/tree-ssa/ctz-int.c | 2 +- - gcc/testsuite/gcc.dg/tree-ssa/ctz-long-long.c | 2 +- - gcc/testsuite/gcc.dg/tree-ssa/ctz-long.c | 2 +- - gcc/tree-ssa-loop-niter.cc | 93 +------------------ - gcc/tree-ssa-loop.cc | 5 - - 12 files changed, 12 insertions(+), 127 deletions(-) - delete mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ctz-ch.c + gcc/ssa-iterators.h | 50 ++++++++++++++++++--------------------------- + 1 file changed, 20 insertions(+), 30 deletions(-) -diff --git a/gcc/testsuite/gcc.dg/pr41488.c b/gcc/testsuite/gcc.dg/pr41488.c -index a7ba3672efef..1e4bf19c7da9 100644 ---- a/gcc/testsuite/gcc.dg/pr41488.c -+++ b/gcc/testsuite/gcc.dg/pr41488.c -@@ -1,5 +1,5 @@ - /* { dg-do compile } */ --/* { dg-options "-O2 -fno-tree-scev-cprop -fdump-tree-ivcanon-scev" } */ -+/* { dg-options "-O2 -fdump-tree-ivcanon-scev" } */ - - struct struct_t +diff --git a/gcc/ssa-iterators.h b/gcc/ssa-iterators.h +index 0822a98323d8..77ecfac19932 100644 +--- a/gcc/ssa-iterators.h ++++ b/gcc/ssa-iterators.h +@@ -53,8 +53,9 @@ struct imm_use_iterator + ssa_use_operand_t *imm_use; + /* This marks the last use in the list (use node from SSA_NAME) */ + ssa_use_operand_t *end_p; +- /* This node is inserted and used to mark the end of the uses for a stmt. */ +- ssa_use_operand_t iter_node; ++ /* This is the next ssa_name to visit in an outer FOR_EACH_IMM_USE_STMT. ++ Also used for fast imm use iterator checking. */ ++ ssa_use_operand_t *next_stmt_use; + /* This is the next ssa_name to visit. IMM_USE may get removed before + the next one is traversed to, so it must be cached early. */ + ssa_use_operand_t *next_imm_name; +@@ -345,7 +346,7 @@ first_readonly_imm_use (imm_use_iterator *imm, tree var) { -diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ctz-ch.c b/gcc/testsuite/gcc.dg/tree-ssa/ctz-ch.c -deleted file mode 100644 -index 5d725979971b..000000000000 ---- a/gcc/testsuite/gcc.dg/tree-ssa/ctz-ch.c -+++ /dev/null -@@ -1,23 +0,0 @@ --/* { dg-do compile } */ --/* { dg-options "-O2 -fdump-tree-optimized" } */ -- --typedef unsigned long BITMAP_WORD; -- --bool --bmp_iter_set (BITMAP_WORD bits, unsigned *bit_no) --{ -- /* If our current word is nonzero, it contains the bit we want. */ -- if (bits) -- { -- while (!(bits & 1)) -- { -- bits >>= 1; -- *bit_no += 1; -- } -- return true; -- } -- -- return false; --} -- --/* { dg-final { scan-tree-dump-times "__builtin_ctz|\\.CTZ" 1 "optimized" } } */ -diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ctz-char.c b/gcc/testsuite/gcc.dg/tree-ssa/ctz-char.c -index fa8b7f39de4b..3cd166acbd46 100644 ---- a/gcc/testsuite/gcc.dg/tree-ssa/ctz-char.c -+++ b/gcc/testsuite/gcc.dg/tree-ssa/ctz-char.c -@@ -1,6 +1,6 @@ - /* { dg-do run } */ - /* { dg-require-effective-target ctz } */ --/* { dg-options "-O2 -fdump-tree-optimized" } */ -+/* { dg-options "-O2 -fno-tree-ch -fdump-tree-optimized" } */ - - #define PREC (__CHAR_BIT__) - -diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-char.c b/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-char.c -index 5ebc32131692..b9afe8852d8f 100644 ---- a/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-char.c -+++ b/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-char.c -@@ -1,6 +1,6 @@ - /* { dg-do run } */ - /* { dg-require-effective-target ctz } */ --/* { dg-options "-O2 -fno-tree-ch -fdump-tree-optimized" } */ -+/* { dg-options "-O2 -fdump-tree-optimized" } */ - - #define PREC (__CHAR_BIT__) - -diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-int.c b/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-int.c -index 0ce4b6beaa7d..d2702a65daf3 100644 ---- a/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-int.c -+++ b/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-int.c -@@ -1,6 +1,6 @@ - /* { dg-do run } */ - /* { dg-require-effective-target ctz } */ --/* { dg-options "-O2 -fno-tree-ch -fdump-tree-optimized" } */ -+/* { dg-options "-O2 -fdump-tree-optimized" } */ - - #define PREC (__CHAR_BIT__ * __SIZEOF_INT__) - -diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-long-long.c b/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-long-long.c -index f98bec039b35..1ea0d5d7d9f8 100644 ---- a/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-long-long.c -+++ b/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-long-long.c -@@ -1,6 +1,6 @@ - /* { dg-do run } */ - /* { dg-require-effective-target ctzll } */ --/* { dg-options "-O2 -fno-tree-ch -fdump-tree-optimized" } */ -+/* { dg-options "-O2 -fdump-tree-optimized" } */ - - #define PREC (__CHAR_BIT__ * __SIZEOF_LONG_LONG__) - -diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-long.c b/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-long.c -index 8edb3728131c..80fb02dcfa68 100644 ---- a/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-long.c -+++ b/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-long.c -@@ -1,6 +1,6 @@ - /* { dg-do run } */ - /* { dg-require-effective-target ctzl } */ --/* { dg-options "-O2 -fno-tree-ch -fdump-tree-optimized" } */ -+/* { dg-options "-O2 -fdump-tree-optimized" } */ - - #define PREC (__CHAR_BIT__ * __SIZEOF_LONG__) - -diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ctz-int.c b/gcc/testsuite/gcc.dg/tree-ssa/ctz-int.c -index 2bf3ae69b938..7f63493eb738 100644 ---- a/gcc/testsuite/gcc.dg/tree-ssa/ctz-int.c -+++ b/gcc/testsuite/gcc.dg/tree-ssa/ctz-int.c -@@ -1,6 +1,6 @@ - /* { dg-do run } */ - /* { dg-require-effective-target ctz } */ --/* { dg-options "-O2 -fdump-tree-optimized" } */ -+/* { dg-options "-O2 -fno-tree-ch -fdump-tree-optimized" } */ - - #define PREC (__CHAR_BIT__ * __SIZEOF_INT__) - -diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ctz-long-long.c b/gcc/testsuite/gcc.dg/tree-ssa/ctz-long-long.c -index 2e159485cb98..924f61b76f01 100644 ---- a/gcc/testsuite/gcc.dg/tree-ssa/ctz-long-long.c -+++ b/gcc/testsuite/gcc.dg/tree-ssa/ctz-long-long.c -@@ -1,6 +1,6 @@ - /* { dg-do run } */ - /* { dg-require-effective-target ctzll } */ --/* { dg-options "-O2 -fdump-tree-optimized" } */ -+/* { dg-options "-O2 -fno-tree-ch -fdump-tree-optimized" } */ - - #define PREC (__CHAR_BIT__ * __SIZEOF_LONG_LONG__) - -diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ctz-long.c b/gcc/testsuite/gcc.dg/tree-ssa/ctz-long.c -index 2e3be652a0bc..178945daa8a2 100644 ---- a/gcc/testsuite/gcc.dg/tree-ssa/ctz-long.c -+++ b/gcc/testsuite/gcc.dg/tree-ssa/ctz-long.c -@@ -1,6 +1,6 @@ - /* { dg-do run } */ - /* { dg-require-effective-target ctzl } */ --/* { dg-options "-O2 -fdump-tree-optimized" } */ -+/* { dg-options "-O2 -fno-tree-ch -fdump-tree-optimized" } */ - - #define PREC (__CHAR_BIT__ * __SIZEOF_LONG__) - -diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc -index cc763839edcd..6e1308625491 100644 ---- a/gcc/tree-ssa-loop-niter.cc -+++ b/gcc/tree-ssa-loop-niter.cc -@@ -2321,48 +2321,6 @@ is_rshift_by_1 (gassign *stmt) - return false; + imm->end_p = &(SSA_NAME_IMM_USE_NODE (var)); + imm->imm_use = imm->end_p->next; +- imm->iter_node.next = imm->imm_use->next; ++ imm->next_stmt_use = imm->imm_use->next; + if (end_readonly_imm_use_p (imm)) + return NULL_USE_OPERAND_P; + return imm->imm_use; +@@ -363,8 +364,8 @@ next_readonly_imm_use (imm_use_iterator *imm) + using the SAFE version of the iterator. */ + if (flag_checking) + { +- gcc_assert (imm->iter_node.next == old->next); +- imm->iter_node.next = old->next->next; ++ gcc_assert (imm->next_stmt_use == old->next); ++ imm->next_stmt_use = old->next->next; + } + + imm->imm_use = old->next; +@@ -840,9 +841,8 @@ end_imm_use_stmt_p (const imm_use_iterator *imm) + placeholder node from the list. */ + + inline void +-end_imm_use_stmt_traverse (imm_use_iterator *imm) ++end_imm_use_stmt_traverse (imm_use_iterator *) + { +- delink_imm_use (&(imm->iter_node)); } --/* Helper for number_of_iterations_cltz that uses ranger to determine -- if SRC's range, shifted left (when LEFT_SHIFT is true) or right -- by NUM_IGNORED_BITS, is guaranteed to be != 0 on LOOP's preheader -- edge. -- Return true if so or false otherwise. */ -- --static bool --shifted_range_nonzero_p (loop_p loop, tree src, -- bool left_shift, int num_ignored_bits) --{ -- int_range_max r (TREE_TYPE (src)); -- gcc_assert (num_ignored_bits >= 0); -- -- if (get_range_query (cfun)->range_on_edge -- (r, loop_preheader_edge (loop), src) -- && !r.varying_p () -- && !r.undefined_p ()) -- { -- if (num_ignored_bits) -- { -- range_op_handler op (left_shift ? LSHIFT_EXPR : RSHIFT_EXPR); -- int_range_max shifted_range (TREE_TYPE (src)); -- wide_int shift_count = wi::shwi (num_ignored_bits, -- TYPE_PRECISION (TREE_TYPE -- (src))); -- int_range_max shift_amount -- (TREE_TYPE (src), shift_count, shift_count); -- -- if (op.fold_range (shifted_range, TREE_TYPE (src), r, -- shift_amount)) -- r = shifted_range; -- } -- -- /* If the range does not contain zero we are good. */ -- if (!range_includes_zero_p (r)) -- return true; -- } -- -- return false; --} -- -- - /* See comment below for number_of_iterations_bitcount. - For c[lt]z, we have: + /* Immediate use traversal of uses within a stmt require that all the +@@ -875,10 +875,11 @@ move_use_after_head (use_operand_p use_p, use_operand_p head, -@@ -2480,9 +2438,6 @@ number_of_iterations_cltz (loop_p loop, edge exit, - tree src = gimple_phi_arg_def (phi, loop_preheader_edge (loop)->dest_idx); - int src_precision = TYPE_PRECISION (TREE_TYPE (src)); -- /* Save the original SSA name before preprocessing for ranger queries. */ -- tree unshifted_src = src; -- - /* Apply any needed preprocessing to src. */ - int num_ignored_bits; - if (left_shift) -@@ -2508,52 +2463,10 @@ number_of_iterations_cltz (loop_p loop, edge exit, + /* This routine will relink all uses with the same stmt as HEAD into the list +- immediately following HEAD for iterator IMM. */ ++ immediately following HEAD for iterator IMM and returns the last use on ++ that stmt. */ - expr = fold_convert (unsigned_type_node, expr); +-inline void +-link_use_stmts_after (use_operand_p head, imm_use_iterator *imm) ++inline use_operand_p ++link_use_stmts_after (use_operand_p head, imm_use_iterator *) + { + use_operand_p use_p; + use_operand_p last_p = head; +@@ -910,10 +911,7 @@ link_use_stmts_after (use_operand_p head, imm_use_iterator *imm) + last_p = move_use_after_head (use_p, head, last_p); + } + } +- /* Link iter node in after last_p. */ +- if (imm->iter_node.prev != NULL) +- delink_imm_use (&imm->iter_node); +- link_imm_use_to_list (&(imm->iter_node), last_p); ++ return last_p; + } -- /* If the copy-header (ch) pass peeled one iteration we're shifting -- SRC by preprocessing it above. -- -- A loop like -- if (bits) -- { -- while (!(bits & 1)) -- { -- bits >>= 1; -- cnt += 1; -- } -- return cnt; -- } -- ch (roughly) transforms into: -- if (bits) -- { -- if (!(bits & 1) -- { -- do -- { -- bits >>= 1; -- cnt += 1; -- } while (!(bits & 1)); -- } -- else -- cnt = 1; -- return cnt; -- } -- -- Then, our preprocessed SRC (that is used for c[tl]z computation) -- will be bits >> 1, and the assumption is bits >> 1 != 0. */ -- -- tree assumptions; -- if (shifted_range_nonzero_p (loop, unshifted_src, -- left_shift, num_ignored_bits)) -- assumptions = boolean_true_node; -- else + /* Initialize IMM to traverse over uses of VAR. Return the first statement. */ +@@ -924,18 +922,14 @@ first_imm_use_stmt (imm_use_iterator *imm, tree var) + imm->imm_use = imm->end_p->next; + imm->next_imm_name = NULL_USE_OPERAND_P; + +- /* iter_node is used as a marker within the immediate use list to indicate +- where the end of the current stmt's uses are. Initialize it to NULL +- stmt and use, which indicates a marker node. */ +- imm->iter_node.prev = NULL_USE_OPERAND_P; +- imm->iter_node.next = NULL_USE_OPERAND_P; +- imm->iter_node.loc.stmt = NULL; +- imm->iter_node.use = NULL; ++ /* next_stmt_use is used to point to the immediate use node after ++ the set of uses for the current stmt. */ ++ imm->next_stmt_use = NULL_USE_OPERAND_P; + + if (end_imm_use_stmt_p (imm)) + return NULL; + +- link_use_stmts_after (imm->imm_use, imm); ++ imm->next_stmt_use = link_use_stmts_after (imm->imm_use, imm)->next; + + return USE_STMT (imm->imm_use); + } +@@ -945,15 +939,11 @@ first_imm_use_stmt (imm_use_iterator *imm, tree var) + inline gimple * + next_imm_use_stmt (imm_use_iterator *imm) + { +- imm->imm_use = imm->iter_node.next; ++ imm->imm_use = imm->next_stmt_use; + if (end_imm_use_stmt_p (imm)) - { -- /* If ranger couldn't prove the assumption, try -- simplify_using_initial_conditions. */ -- assumptions = fold_build2 (NE_EXPR, boolean_type_node, src, -- build_zero_cst (TREE_TYPE (src))); -- assumptions = simplify_using_initial_conditions (loop, assumptions); +- if (imm->iter_node.prev != NULL) +- delink_imm_use (&imm->iter_node); +- return NULL; - } -+ tree assumptions = fold_build2 (NE_EXPR, boolean_type_node, src, -+ build_zero_cst (TREE_TYPE (src))); ++ return NULL; -- niter->assumptions = assumptions; -+ niter->assumptions = simplify_using_initial_conditions (loop, assumptions); - niter->may_be_zero = boolean_false_node; - niter->niter = simplify_using_initial_conditions (loop, expr); +- link_use_stmts_after (imm->imm_use, imm); ++ imm->next_stmt_use = link_use_stmts_after (imm->imm_use, imm)->next; + return USE_STMT (imm->imm_use); + } -diff --git a/gcc/tree-ssa-loop.cc b/gcc/tree-ssa-loop.cc -index dc4b560e9245..5629524afb2f 100644 ---- a/gcc/tree-ssa-loop.cc -+++ b/gcc/tree-ssa-loop.cc -@@ -28,7 +28,6 @@ along with GCC; see the file COPYING3. If not see - #include "tm_p.h" - #include "fold-const.h" - #include "gimple-iterator.h" --#include "gimple-range.h" - #include "tree-ssa-loop-ivopts.h" - #include "tree-ssa-loop-manip.h" - #include "tree-ssa-loop-niter.h" -@@ -405,15 +404,11 @@ pass_scev_cprop::execute (function *) +@@ -972,7 +962,7 @@ first_imm_use_on_stmt (imm_use_iterator *imm) + inline bool + end_imm_use_on_stmt_p (const imm_use_iterator *imm) { - bool any = false; - -- enable_ranger (cfun); -- - /* Perform final value replacement in loops, in case the replacement - expressions are cheap. */ - for (auto loop : loops_list (cfun, LI_FROM_INNERMOST)) - any |= final_value_replacement_loop (loop); - -- disable_ranger (cfun); -- - return any ? TODO_cleanup_cfg | TODO_update_ssa_only_virtuals : 0; +- return (imm->imm_use == &(imm->iter_node)); ++ return (imm->imm_use == imm->next_stmt_use); } + /* Bump to the next use on the stmt IMM refers to, return NULL if done. */ -base-commit: 6b6696fa3dfc13d26fbb01856757b73df80fe161 +base-commit: 870fed53f5e7f18b1134737f007193ebff5ef2b7 -- 2.51.2 diff --git a/16.0.0/gentoo/README.history b/16.0.0/gentoo/README.history index 38d6725..4d82d29 100644 --- a/16.0.0/gentoo/README.history +++ b/16.0.0/gentoo/README.history @@ -1,3 +1,7 @@ +21 ???? + + U 88_all_PR122502.patch + 20 3 November 2025 + 88_all_PR122502.patch
