From patchwork Mon Nov 29 09:11:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 48245 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6A530383582F for ; Mon, 29 Nov 2021 09:12:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6A530383582F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1638177170; bh=qnHbxOmyVJsx8s15zYSHPudvBYb1iFXZL8MhshdmvwE=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=gHE3iMv5pEGgbLv1DDYN7doKWfZoedSKGMFQ2qFy0PL445LDBLVfF/q9sc+MdX0ck WtKkghfTeAlBH6XAPHXSF4bwmmM9mGgLRw/XOv7zfdTp1eJ4dyoTq8V+c9mWsJHA2K kCXx7PBBDm0osmH0EmKfJOmnSm5oXKYhUUDLPh4E= 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 A0AEA3858417 for ; Mon, 29 Nov 2021 09:12:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A0AEA3858417 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 976C41FCA1 for ; Mon, 29 Nov 2021 09:11:59 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 83A6B133A7 for ; Mon, 29 Nov 2021 09:11:59 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id pBnzHl+ZpGF8TgAAMHmgww (envelope-from ) for ; Mon, 29 Nov 2021 09:11:59 +0000 Date: Mon, 29 Nov 2021 10:11:59 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/103458 - avoid creating new loops in CD-DCE Message-ID: <3sqo26s1-1510-6pnn-n948-spop8495r6s@fhfr.qr> MIME-Version: 1.0 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" When creating forwarders in CD-DCE we have to avoid creating loops where we formerly did not consider those because of abnormal predecessors. At this point simply excuse us when there are any abnormal predecessors. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. 2021-11-29 Richard Biener PR tree-optimization/103458 * tree-ssa-dce.c (make_forwarders_with_degenerate_phis): Do not create forwarders for blocks with abnormal predecessors. * gcc.dg/torture/pr103458.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr103458.c | 21 +++++++++++++++++++++ gcc/tree-ssa-dce.c | 8 ++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr103458.c diff --git a/gcc/testsuite/gcc.dg/torture/pr103458.c b/gcc/testsuite/gcc.dg/torture/pr103458.c new file mode 100644 index 00000000000..3fd3b5fd2ff --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr103458.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-Wno-div-by-zero" } */ + +__attribute__ ((returns_twice)) int +bar (void); + +void +foo (int *p, int x) +{ + *p = 0; + while (*p < 1) + { + x = 0; + while (x < 1) + bar (); + + x /= 0; + } + + foo (p, x); +} diff --git a/gcc/tree-ssa-dce.c b/gcc/tree-ssa-dce.c index e3e6f0955b7..1f817b95fab 100644 --- a/gcc/tree-ssa-dce.c +++ b/gcc/tree-ssa-dce.c @@ -1650,8 +1650,12 @@ make_forwarders_with_degenerate_phis (function *fn) /* Only PHIs with three or more arguments have opportunities. */ if (EDGE_COUNT (bb->preds) < 3) continue; - /* Do not touch loop headers. */ - if (bb->loop_father->header == bb) + /* Do not touch loop headers or blocks with abnormal predecessors. + ??? This is to avoid creating valid loops here, see PR103458. + We might want to improve things to either explicitely add those + loops or at least consider blocks with no backedges. */ + if (bb->loop_father->header == bb + || bb_has_abnormal_pred (bb)) continue; /* Take one PHI node as template to look for identical