From patchwork Mon Apr 17 08:41:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 84060 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1968963vqo; Mon, 17 Apr 2023 01:42:24 -0700 (PDT) X-Google-Smtp-Source: AKy350Yt8DHL+iBVZ6vFbQy+wRyeQEFeHBs3zIJfKjGiy2rXyNSkSF9jGTwNKHemDnBijD6BQdwb X-Received: by 2002:a17:906:719b:b0:94f:2347:ce8e with SMTP id h27-20020a170906719b00b0094f2347ce8emr6022778ejk.70.1681720944056; Mon, 17 Apr 2023 01:42:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681720944; cv=none; d=google.com; s=arc-20160816; b=xxTAepsszhz+gUyEUsU6PB7T9caqil75kpokmehufDOIVlNNVGkYXi0VdsKzriUFoz g8skUdslkxjsT0J6fSJfaoRNqYKyswG3XTzZR8TtNJJxTL92gFgkikSuP9PSSYvBHmkJ 7THQVxYP0OWP7h/0iqj/D84TqFb3fB2vxFL9xc8ZpOz34cQNiSHPCGlfKgPVedzfbE4V TMBqt4bXPrgP3jJ6d+wvUCCDZfxU22+UWqWvw3ZPEE4ZGNqPMrOHjZRgYQlqcYnun9YK +CaW3ibpyAc7Ht3oyrhFuV8YGiv0P/mUCEbBHpPbAHSYxfyOVoJCnt2Q9wAKzieR3Utz AanA== 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:cc:to:date:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=8E3ghmTIfC+Ugl1Vtc4rX5FZELEafauKeE2YTRqXqJ4=; b=mKDM0+GUPnFKr+x39CyKxYDrI8YBYufPsdkxZVq45pjitgB5bhLBxQGOzUktifFV33 1IloYzM12qskwPHarAGQMkmOcOwNVyG3oVoYih+jEszHWew37wua8XpV9hkzKlJJ00Fa 5gor7zCtyF7OjXfMVdATptm9GLki8zmb5I69llccP80OuXDrNkLfpOQCE7hX7WjZEN1y Zgz6vBTc4mXQ+sTA9Up3QWspL9UmSjT/iV6/Zl3g+SpAsGUJkYsxRckzNevu7/Wb7llW O96rWLCvsCDyQC4lWgTjmNLOd0lnZ+wQUuSVz3b2mGpdRAL6Yxus89Oxrh3rRiphT8N8 jTjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="W/2j3GLu"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id d19-20020aa7ce13000000b00504ae1b658dsi4640596edv.490.2023.04.17.01.42.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 01:42:24 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="W/2j3GLu"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 B13A23858288 for ; Mon, 17 Apr 2023 08:42:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B13A23858288 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681720942; bh=8E3ghmTIfC+Ugl1Vtc4rX5FZELEafauKeE2YTRqXqJ4=; h=Date:To:cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=W/2j3GLu6ZwP34Uu6Cjx+Fnq0q6bPi1pKoSLeZGv+vAX/ngraoMF1ZXX5sx1IZ8yo 0RiWUIpjdb0OJf934J+aXwaPxVw6m2E0UXCDLlicxQKrXly+LBCbI/jzIJ4mOrPzpS 341EiRUfaMbv92kgXvLGcHfbaXRFPztkw/kaivaE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 827A83858C2C for ; Mon, 17 Apr 2023 08:41:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 827A83858C2C Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id ADC6F21A4A; Mon, 17 Apr 2023 08:41:38 +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 A0E112C141; Mon, 17 Apr 2023 08:41:38 +0000 (UTC) Date: Mon, 17 Apr 2023 08:41:38 +0000 (UTC) To: gcc-patches@gcc.gnu.org cc: Jakub Jelinek Subject: [PATCH] tree-optimization/109524 - ICE with VRP edge removal 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, T_SCC_BODY_TEXT_LINE 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: <20230417084222.B13A23858288@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763412220668463894?= X-GMAIL-MSGID: =?utf-8?q?1763412220668463894?= VRP queues edges to process late for updating global ranges for __builtin_unreachable. But this interferes with edge removal from substitute_and_fold. The following deals with this by looking up the edge with source/dest block indices which do not become stale. For GCC 14 we probably want to refactor substitute_and_fold but that doesn't seem appropriate at this stage. Bootstrapped and tested on x86_64-unknown-linux-gnu, OK? Thanks, Richard. PR tree-optimization/109524 * tree-vrp.cc (remove_unreachable::m_list): Change to a vector of pairs of block indices. (remove_unreachable::maybe_register_block): Adjust. (remove_unreachable::remove_and_update_globals): Likewise. Deal with removed blocks. * g++.dg/pr109524.C: New testcase. --- gcc/testsuite/g++.dg/pr109524.C | 41 +++++++++++++++++++++++++++++++++ gcc/tree-vrp.cc | 13 +++++++---- 2 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pr109524.C diff --git a/gcc/testsuite/g++.dg/pr109524.C b/gcc/testsuite/g++.dg/pr109524.C new file mode 100644 index 00000000000..a560839cd5b --- /dev/null +++ b/gcc/testsuite/g++.dg/pr109524.C @@ -0,0 +1,41 @@ +// { dg-do compile } +// { dg-require-effective-target c++11 } +// { dg-options "-O3 -fno-tree-forwprop -fnon-call-exceptions -fno-tree-ccp -fno-tree-fre" } + +struct nn; +void f(); +int *m; +struct _Guard { + ~_Guard() { + if (_M_guarded) + __builtin_unreachable(); + } + nn *_M_guarded; +}; +struct nn { + int * _M_dataplus; + nn(nn &) + { + f(); + _Guard __guard; + m = _M_dataplus; + } + nn(){} +}; + void hnn(nn *a) + { + f(); + _Guard __guard; + m = a->_M_dataplus; + } +bool gg(); +static inline nn +hh(nn str) { + if (gg()) + return str; + __builtin_unreachable(); +} +void h() { + + hh({}); +} diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc index be7d06f565c..f4d484526c7 100644 --- a/gcc/tree-vrp.cc +++ b/gcc/tree-vrp.cc @@ -75,7 +75,7 @@ public: ~remove_unreachable () { m_list.release (); } void maybe_register_block (basic_block bb); bool remove_and_update_globals (bool final_p); - vec m_list; + vec > m_list; gimple_ranger &m_ranger; }; @@ -103,9 +103,9 @@ remove_unreachable::maybe_register_block (basic_block bb) return; if (un0) - m_list.safe_push (e1); + m_list.safe_push (std::make_pair (e1->src->index, e1->dest->index)); else - m_list.safe_push (e0); + m_list.safe_push (std::make_pair (e0->src->index, e0->dest->index)); } // Process the edges in the list, change the conditions and removing any @@ -132,7 +132,12 @@ remove_unreachable::remove_and_update_globals (bool final_p) auto_bitmap all_exports; for (i = 0; i < m_list.length (); i++) { - edge e = m_list[i]; + auto eb = m_list[i]; + basic_block src = BASIC_BLOCK_FOR_FN (cfun, eb.first); + basic_block dest = BASIC_BLOCK_FOR_FN (cfun, eb.second); + if (!src || !dest) + continue; + edge e = find_edge (src, dest); gimple *s = gimple_outgoing_range_stmt_p (e->src); gcc_checking_assert (gimple_code (s) == GIMPLE_COND); bool lhs_p = TREE_CODE (gimple_cond_lhs (s)) == SSA_NAME;