From patchwork Wed Mar 29 08:34: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: 76443 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp256419vqo; Wed, 29 Mar 2023 01:35:31 -0700 (PDT) X-Google-Smtp-Source: AKy350YgJb2PGFYBLhMHI3sGFkdCbet5WeJqN8FC7vNzfNrm+S3vPUAw3Av0+5LxM8GC0i+YBwmo X-Received: by 2002:a17:906:5a66:b0:932:83fa:d2fe with SMTP id my38-20020a1709065a6600b0093283fad2femr17933596ejc.12.1680078931056; Wed, 29 Mar 2023 01:35:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680078931; cv=none; d=google.com; s=arc-20160816; b=AniQxNiYL65JK12ZaGKbdJM4/CH2Kn+QMjpnPbr0oc33FakdjGmKuJRq7DNh3NCOft 51dK7RkdKpge8+bsQBaBVeL8PHU45n9B1MuH3j3rzJYL/e459nTE6Mz1cSkxI1Otn2H8 Ckhr6ovM27e/H5nUWMGmp7MFehg+5+PHISz1IzkADzu/YNTSCTJQ9oo5hmMwb/v5mEAo CiTIIZ+3Zpcy6EUmcOonB+rZQmx+LII9kAif/ZY16AbEyoQkocb/DQiEjyJSz3arUAok bizRGhSWAaj+r82bpqj7XJQgANho3L32iQ0V1zUWayL+stw7lmH50G7MIizNSzrlfuj/ F0Og== 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=JZEBAW84zzFyBFV84YdQseGOOBWjL68sO0XLvNTRGkE=; b=ojB3j8PPOSevSrx02LjUQNRYbcDAaTFqvAluWk6LcSvH4/LLy8YCMEd0tq6Tn0181h zupHkgFjBV4cZpcP8ulppdieNe+YkUI6dA6wvSXZ6xwyXQWxi19oQwrGTuMdGX0CHHP1 x787XQu1Q0K9o3pf8iwFQmxV8DXslmmgxQoVTdMaRkqUB9toRqfqxHHX5OPVpfO3JxOu eEjStm3yE615+tMdLN8MOAW67k0TEDIVsl4lcvYeWVH7DWNjcI2bWi/CBBRYEgwtfbyE AYROJD167g4YrBp9+Eu/oLhevOm+7/biWA48Ju36SsN4OlCMNKP3wbleQE6xwLK1XK5y ygEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DMyUaz6C; 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 f10-20020a170906048a00b0092fd7bea542si29036404eja.862.2023.03.29.01.35.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 01:35:31 -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=DMyUaz6C; 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 02DF1385703F for ; Wed, 29 Mar 2023 08:35:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 02DF1385703F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680078927; bh=JZEBAW84zzFyBFV84YdQseGOOBWjL68sO0XLvNTRGkE=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=DMyUaz6CNpx2dC1zzpWNaJ0yEvpNV3PD1I6RTFEi7UbV0BQYqNsllD1SUIKRTbKhK vpxkJ/NhcNIDsxsFrT7Rvk+pIPdZdvUWHvSGHY+w/9tg+glWgf4XnS9+PsrWGCvynA xb4fpoUtmrJEQhPkA/dphTZQbF9bvLm4IcYrzRnI= 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 7C5283858298 for ; Wed, 29 Mar 2023 08:34:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7C5283858298 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 9309D219E1 for ; Wed, 29 Mar 2023 08:34: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 8B2F22C141 for ; Wed, 29 Mar 2023 08:34:38 +0000 (UTC) Date: Wed, 29 Mar 2023 08:34:38 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/109327 - forwprop stmt removal issue 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: <20230329083527.02DF1385703F@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761690445437119701?= X-GMAIL-MSGID: =?utf-8?q?1761690445437119701?= There's interfering between the to_removed queue and other mechanisms removing stmts, in this case remove_prop_source_from_use. The following makes the to_remove queue draining more permissive. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/109327 * tree-ssa-forwprop.cc (pass_forwprop::execute): Deal with already removed stmts when draining to_remove. * gcc.dg/pr109327.c: New testcase. --- gcc/testsuite/gcc.dg/pr109327.c | 15 +++++++++++++++ gcc/tree-ssa-forwprop.cc | 4 ++++ 2 files changed, 19 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr109327.c diff --git a/gcc/testsuite/gcc.dg/pr109327.c b/gcc/testsuite/gcc.dg/pr109327.c new file mode 100644 index 00000000000..827b26f148e --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr109327.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fno-tree-ccp" } */ + +int a; +void b(int c) {} +int main() +{ + int d = 0, *e = &a; + if (d) { + int *f = e; + while (a) + b(e != f); + } + return 0; +} diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc index 5eccc7a89b5..bb0fa306312 100644 --- a/gcc/tree-ssa-forwprop.cc +++ b/gcc/tree-ssa-forwprop.cc @@ -4061,6 +4061,10 @@ pass_forwprop::execute (function *fun) while (!to_remove.is_empty()) { gimple *stmt = to_remove.pop (); + /* For example remove_prop_source_from_use can remove stmts queued + for removal. Deal with this gracefully. */ + if (!gimple_bb (stmt)) + continue; if (dump_file && (dump_flags & TDF_DETAILS)) { fprintf (dump_file, "Removing dead stmt ");