From patchwork Tue Jul 26 11:18:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 184 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:b5d6:b0:2b9:3548:2db5 with SMTP id v22csp2191903pxt; Tue, 26 Jul 2022 04:19:00 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uEiE2hkL7aVDQx1/oHKCQr24Z0UJELCffJxPPy1tOHQur2npIbZEMR1NbniaoogfxUeT0Z X-Received: by 2002:a05:6402:1807:b0:43c:87a3:8dc3 with SMTP id g7-20020a056402180700b0043c87a38dc3mr1141049edy.359.1658834340415; Tue, 26 Jul 2022 04:19:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658834340; cv=none; d=google.com; s=arc-20160816; b=t9tzY71EhViX1fsFQLJsnloZcZWQ+dObpR5VUE2skbakYnHkMR9DCoPc8Eg/sf4GsX q1CEv3DP5TuWdJegOxhYfTKortk5LiRX7LYEN07hWhkvHSN+eKIgPRwaI1ps8mJ2GfBH NF20J71evZPLhbz0C1TxVtwHcYv1Wp21JBlDBDccVj+xYCQVxV1hBDFT4FZAZUDc7Pbf 5+cV4Zd6TSkbl0HmIGOnN/uD+ivYIITCl6yNxTWg1SQ+pPMXUZdoQZNcWDWd4z1Gdit7 WY56uAZCnIRA0rcN/sfULZUhql/Yv4YCBX8j3uQxiuj0aS5Dhu2ycZAlonRcMrhLe6We rz0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=hLB9VzpGVc5IPpNKGJsLrikm51c6iBKhJxoXUvNCjSw=; b=iySFJPd2YSgmW/V9rYP0aavWCLgyfeHfmhL8a4osSGKmUs2F/7Al3qQtM6nJtQG/Z4 iWAVP8r1ao4MeZmpPZqpoSKq6tTnDzsBxYMfcavhu4W6arnNiZvdKU2mDmJUsTnav52Q v749M0fYQ0iw+9mm/koOTon/vWAbtMttgA4pBYczyvi4jQq63ELA7Ln6bVYaeZ2g8q1I OsQAZezT4/XpZw+qROQi7gdhtjYbRQLNzZKufS8inrJRMN8YLEZR73GISDO5JlqUdNi7 gk2DyUB5jdWJun1R0HktfNytDYaoLISLHvhi26E7KO1AOpL3LsQ1GOXhrlunIIvc52mr Pe2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jHZLRdXw; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u1-20020a1709061da100b00726d03899basi14215442ejh.344.2022.07.26.04.19.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 04:19:00 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jHZLRdXw; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 54099385781F for ; Tue, 26 Jul 2022 11:18:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 54099385781F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1658834339; bh=hLB9VzpGVc5IPpNKGJsLrikm51c6iBKhJxoXUvNCjSw=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=jHZLRdXw2mTKPnAnOyIFR876mrCMrW4Tju85P/OMXvBr8HLTaWZWo4dEz/SuWfHPs /61g8fVMvWKQeK+aHDRBP9XbfA+liXs9W3E8wfD9pFU7Bezekci26NRDp0tc/l/zTp rZL9ki25l4FDMccqim+Rt1gAan67eGTMkkyHA6Vc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id C8D963858C62 for ; Tue, 26 Jul 2022 11:18:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C8D963858C62 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id CE6671FBAE for ; Tue, 26 Jul 2022 11:18:14 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id C5A222C15D for ; Tue, 26 Jul 2022 11:18:14 +0000 (UTC) Date: Tue, 26 Jul 2022 11:18:14 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/105142 - improve maybe_fold_comparisons_from_match_pd fix User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20220726111859.54099385781F@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1739413877355496432?= X-GMAIL-MSGID: =?utf-8?q?1739413877355496432?= 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. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. 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. (maybe_fold_comparisons_from_match_pd): Set up unwind stack for follow_outer_ssa_edges and unwind flow-sensitive info clearing after matching. --- gcc/gimple-fold.cc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc index a1704784bc9..876ef45434e 100644 --- a/gcc/gimple-fold.cc +++ b/gcc/gimple-fold.cc @@ -6886,6 +6886,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) { @@ -6899,7 +6900,15 @@ follow_outer_ssa_edges (tree val) && (def_bb == fosa_bb || dominated_by_p (CDI_DOMINATORS, fosa_bb, def_bb)))) return 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; } @@ -6958,9 +6967,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]; @@ -6982,6 +6996,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; }