From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 35629385842B; Fri, 11 Nov 2022 14:05:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 35629385842B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668175531; bh=DMvnwp3VQ6zrRZDPldrER/Z0dIbH56gQxEWjp3sjAC0=; h=From:To:Subject:Date:From; b=DhDKvra8wWlcKjSn1c7MhDYMs6m7opUvNoqpFIniYiSjSMfITj+4NrSYtcvZdxlsg CSk1l/F+sIs592zEbYG8I1ksTiCG1zDzEtKDgeInvg2/0l7Y8FMjHeTRnFUbcK7EOV E3jFg7eI49hnh/AIH2sryBn395I7dU9IAun4GvsY= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3904] tree-optimization/105142 - improve maybe_fold_comparisons_from_match_pd fix X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: e0cfde7e8b36a8176b661af16dff91ebf4f99a8e X-Git-Newrev: 4b3874d803e7961f38b22fa798517a63171bb985 Message-Id: <20221111140531.35629385842B@sourceware.org> Date: Fri, 11 Nov 2022 14:05:31 +0000 (GMT) List-Id: https://gcc.gnu.org/g:4b3874d803e7961f38b22fa798517a63171bb985 commit r13-3904-g4b3874d803e7961f38b22fa798517a63171bb985 Author: Richard Biener Date: Tue Jul 26 11:52:49 2022 +0200 tree-optimization/105142 - improve maybe_fold_comparisons_from_match_pd fix The following improves on the fix for PR105142 which restricted the expression lookup used for maybe_fold_comparisons_from_match_pd to avoid picking up flow-sensitive info for use in places where guarding conditions do not hold. Instead of not allowing to expand SSA definitions there the following temporarily clears flow-sensitive info on the SSA names and restores it when finished matching. PR tree-optimization/105142 * gimple-fold.cc (fosa_unwind): New global. (follow_outer_ssa_edges): When the SSA definition to follow is does not dominate fosa_bb, temporarily clear flow-sensitive info. Make sure to not expand stmts with not defined overflow. (maybe_fold_comparisons_from_match_pd): Set up unwind stack for follow_outer_ssa_edges and unwind flow-sensitive info clearing after matching. Diff: --- gcc/gimple-fold.cc | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc index 8d4079870be..0a212e6d0d4 100644 --- a/gcc/gimple-fold.cc +++ b/gcc/gimple-fold.cc @@ -6916,6 +6916,7 @@ and_comparisons_1 (tree type, enum tree_code code1, tree op1a, tree op1b, } static basic_block fosa_bb; +static vec > *fosa_unwind; static tree follow_outer_ssa_edges (tree val) { @@ -6929,7 +6930,21 @@ follow_outer_ssa_edges (tree val) && (def_bb == fosa_bb || dominated_by_p (CDI_DOMINATORS, fosa_bb, def_bb)))) return val; - return NULL_TREE; + /* We cannot temporarily rewrite stmts with undefined overflow + behavior, so avoid expanding them. */ + if ((ANY_INTEGRAL_TYPE_P (TREE_TYPE (val)) + || POINTER_TYPE_P (TREE_TYPE (val))) + && !TYPE_OVERFLOW_WRAPS (TREE_TYPE (val))) + return NULL_TREE; + /* If the definition does not dominate fosa_bb temporarily reset + flow-sensitive info. */ + if (val->ssa_name.info.range_info) + { + fosa_unwind->safe_push (std::make_pair + (val, val->ssa_name.info.range_info)); + val->ssa_name.info.range_info = NULL; + } + return val; } return val; } @@ -6988,9 +7003,14 @@ maybe_fold_comparisons_from_match_pd (tree type, enum tree_code code, type, gimple_assign_lhs (stmt1), gimple_assign_lhs (stmt2)); fosa_bb = outer_cond_bb; + auto_vec, 8> unwind_stack; + fosa_unwind = &unwind_stack; if (op.resimplify (NULL, (!outer_cond_bb ? follow_all_ssa_edges : follow_outer_ssa_edges))) { + fosa_unwind = NULL; + for (auto p : unwind_stack) + p.first->ssa_name.info.range_info = p.second; if (gimple_simplified_result_is_gimple_val (&op)) { tree res = op.ops[0]; @@ -7012,6 +7032,9 @@ maybe_fold_comparisons_from_match_pd (tree type, enum tree_code code, return build2 ((enum tree_code)op.code, op.type, op0, op1); } } + fosa_unwind = NULL; + for (auto p : unwind_stack) + p.first->ssa_name.info.range_info = p.second; return NULL_TREE; }