From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1681720898; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=8E3ghmTIfC+Ugl1Vtc4rX5FZELEafauKeE2YTRqXqJ4=; b=hvSUypoiXJnkT9+sHRz28ql9XshSwolcKFga5FiRivE2lJi0njzp5f8qjzfidjqt0Pr2fa TgbVqilwcjp8EJ3ZQStpUlZFRTx3Uw+ZUdljqGvz1EWbytnI9ktQp4xFqQDEIWwrVxWyqV Gr80613yrTzML5q+RSD/DkupJA3Anow= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1681720898; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=8E3ghmTIfC+Ugl1Vtc4rX5FZELEafauKeE2YTRqXqJ4=; b=mWTBSYLbBX3VZpl+nW4P+GPhcNeFjEgcCcWm/c9Nm/Gd/OrWjJkx7O0xSJFVyG7ekUxyOo t0AxrEMmZn2MaABg== 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) From: Richard Biener 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 Content-Type: text/plain; charset=US-ASCII 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 List-Id: Message-ID: <20230417084138.9y4gBof5GcolGjopnjz0-UIpRWcx8g8Ab_27JLteR9I@z> 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; -- 2.35.3