From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2140) id CBBBE3833787; Thu, 26 May 2022 12:49:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CBBBE3833787 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: e8e1a5d53833bab3774ca287381b84c5df1226ee X-Git-Newrev: ab0624ba523cb6118ef65962603bc150de66f6e3 Message-Id: <20220526124953.CBBBE3833787@sourceware.org> Date: Thu, 26 May 2022 12:49:53 +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 12:49:53 -0000 https://gcc.gnu.org/g:ab0624ba523cb6118ef65962603bc150de66f6e3 commit ab0624ba523cb6118ef65962603bc150de66f6e3 Author: Alexandre Oliva Date: Thu May 26 09:15:53 2022 -0300 [PR105665] ivopts: check defs of names in base for undefs Diff: --- gcc/tree-ssa-loop-ivopts.cc | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/gcc/tree-ssa-loop-ivopts.cc b/gcc/tree-ssa-loop-ivopts.cc index 2e8cd486cc0..e68968efc5f 100644 --- a/gcc/tree-ssa-loop-ivopts.cc +++ b/gcc/tree-ssa-loop-ivopts.cc @@ -3074,10 +3074,18 @@ 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 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; + if (ssa_undefined_value_p (*tp, false)) return *tp; @@ -3092,8 +3100,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 +3142,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;