From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2140) id B2DEF3857B82; Thu, 26 May 2022 15:46:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B2DEF3857B82 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Alexandre Oliva To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/aoliva/heads/testme)] [PR105665] ivopts: check defs of names in base for undefs X-Act-Checkin: gcc X-Git-Author: Alexandre Oliva X-Git-Refname: refs/users/aoliva/heads/testme X-Git-Oldrev: e90f0f0296d12932b2ec3660b296328c11f73cb3 X-Git-Newrev: 8b85376e8c4279e620d7c9793776b42b9575b9ff Message-Id: <20220526154644.B2DEF3857B82@sourceware.org> Date: Thu, 26 May 2022 15:46:44 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 May 2022 15:46:44 -0000 https://gcc.gnu.org/g:8b85376e8c4279e620d7c9793776b42b9575b9ff commit 8b85376e8c4279e620d7c9793776b42b9575b9ff Author: Alexandre Oliva Date: Thu May 26 09:15:53 2022 -0300 [PR105665] ivopts: check defs of names in base for undefs Diff: --- gcc/testsuite/gcc.dg/torture/pr105665.c | 2 +- gcc/tree-ssa-loop-ivopts.cc | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/gcc/testsuite/gcc.dg/torture/pr105665.c b/gcc/testsuite/gcc.dg/torture/pr105665.c index 12f0b78a4b4..34cfc658434 100644 --- a/gcc/testsuite/gcc.dg/torture/pr105665.c +++ b/gcc/testsuite/gcc.dg/torture/pr105665.c @@ -6,7 +6,7 @@ int main() { for (; b < 2; b++) { int g; if (f) - b = 40; + g++, b = 40; a = d[b * b]; for (f = 0; f < 3; f++) { if (e) diff --git a/gcc/tree-ssa-loop-ivopts.cc b/gcc/tree-ssa-loop-ivopts.cc index 5b1c7340f77..654a0432ef4 100644 --- a/gcc/tree-ssa-loop-ivopts.cc +++ b/gcc/tree-ssa-loop-ivopts.cc @@ -3074,13 +3074,24 @@ get_loop_invariant_expr (struct ivopts_data *data, tree inv_expr) /* Find the first undefined SSA name in *TP. */ static tree -find_ssa_undef (tree *tp, int *walk_subtrees, void *) +find_ssa_undef (tree *tp, int *walk_subtrees, void *pset_) { + auto pset = static_cast *> (pset_); + if (TREE_CODE (*tp) == SSA_NAME) { + if (ssa_defined_default_def_p (*tp)) + return NULL; + if (ssa_undefined_value_p (*tp, false)) return *tp; + /* If we've already visited this SSA_NAME and got to it again, + we know we didn't find it to be undefined, otherwise we'd + have stopped the walk then. */ + if (pset && pset->add (*tp)) + return NULL; + gimple *def_stmt = SSA_NAME_DEF_STMT (*tp); /* ssa_undefined_value_p must have caught nop defs above. */ gcc_checking_assert (!gimple_nop_p (def_stmt)); @@ -3092,8 +3103,10 @@ find_ssa_undef (tree *tp, int *walk_subtrees, void *) { tree use = USE_FROM_PTR (use_p); - if (ssa_undefined_value_p (use, false)) - return use; + int wsub = 1; + tree result = find_ssa_undef (&use, &wsub, pset); + if (result) + return result; } } @@ -3132,7 +3145,8 @@ add_candidate_1 (struct ivopts_data *data, tree base, tree step, bool important, /* If BASE contains undefined SSA names make sure we only record the original IV. */ bool involves_undefs = false; - if (walk_tree (&base, find_ssa_undef, NULL, NULL)) + hash_set pset; + if (walk_tree (&base, find_ssa_undef, &pset, NULL)) { if (pos != IP_ORIGINAL) return NULL;