From patchwork Mon Nov 28 09:04:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 61143 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 35BB93858035 for ; Mon, 28 Nov 2022 09:05:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 35BB93858035 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669626310; bh=tsad10WdlP4rhY6SDC8ndP80XCg2YP7tHQiDUuKoGhk=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=USNU+gB4uzIMEgrSAYE1ArqiCOORlrPD9WG4p1Fs4O0dm2EvmCgilj1V7kCJZ/GcA 2VuZr6aGnOsW/8zQ84XacRpPC9n8G933pgrfcTd64DO7s3LyaP1mTXPK/htBzG7rEe wPuYodLVKNmafNRYLXYXb2MxMvDEsK269iT1IeW8= 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 830D23858D3C for ; Mon, 28 Nov 2022 09:04:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 830D23858D3C 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-out1.suse.de (Postfix) with ESMTPS id 58B1321BAE for ; Mon, 28 Nov 2022 09:04:34 +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 44F5E13273 for ; Mon, 28 Nov 2022 09:04:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id LGnWDqJ5hGMscAAAMHmgww (envelope-from ) for ; Mon, 28 Nov 2022 09:04:34 +0000 Date: Mon, 28 Nov 2022 10:04:33 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/107876 - unswitching of switch MIME-Version: 1.0 Message-Id: <20221128090434.44F5E13273@imap2.suse-dmz.suse.de> 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.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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The following shows a missed update of dominators when unswitching removes unreachable edges from switch stmts it unswitches. Fixed by wiping dominator info in that case. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/107876 * tree-ssa-loop-unswitch.cc (clean_up_after_unswitching): Wipe dominator info if we removed an edge. * g++.dg/tree-ssa/pr107876.C: New testcase. --- gcc/testsuite/g++.dg/tree-ssa/pr107876.C | 38 ++++++++++++++++++++++++ gcc/tree-ssa-loop-unswitch.cc | 10 ++++++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/tree-ssa/pr107876.C diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr107876.C b/gcc/testsuite/g++.dg/tree-ssa/pr107876.C new file mode 100644 index 00000000000..6cff2f1b166 --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/pr107876.C @@ -0,0 +1,38 @@ +// { dg-do compile } +// { dg-require-effective-target c++11 } +// { dg-options "-O2 -funswitch-loops --param max-unswitch-insns=5 -fdump-tree-unswitch-details" } + +class X { +public: + X(); + X(const X&); + X(const volatile X &); + ~X(); +}; + +X test17(int i) { + if (false) { + impossible: + if (i == 3) + return X(); + } + + while (true) { + X x; + if (i == 0) + return x; + if (i == 1) + break; + if (i == 2) + continue; + if (i == 3) + goto impossible; + if (i == 4) + __builtin_exit(1); + if (i == 5) + return x; + } + return X(); +} + +// { dg-final { scan-tree-dump "unswitching loop 1 on .switch. with condition: i_\[0-9\]+\\(D\\) == 2" "unswitch" } } diff --git a/gcc/tree-ssa-loop-unswitch.cc b/gcc/tree-ssa-loop-unswitch.cc index 186ae953f04..e8c9bd6812a 100644 --- a/gcc/tree-ssa-loop-unswitch.cc +++ b/gcc/tree-ssa-loop-unswitch.cc @@ -1631,6 +1631,7 @@ clean_up_after_unswitching (int ignored_edge_flag) basic_block bb; edge e; edge_iterator ei; + bool removed_edge = false; FOR_EACH_BB_FN (bb, cfun) { @@ -1655,7 +1656,10 @@ clean_up_after_unswitching (int ignored_edge_flag) to preserve its edge. But we can remove the non-default CASE sharing the edge. */ if (e != default_e) - remove_edge (e); + { + remove_edge (e); + removed_edge = true; + } } else { @@ -1672,6 +1676,10 @@ clean_up_after_unswitching (int ignored_edge_flag) FOR_EACH_EDGE (e, ei, bb->succs) e->flags &= ~ignored_edge_flag; } + + /* If we removed an edge we possibly have to recompute dominators. */ + if (removed_edge) + free_dominance_info (CDI_DOMINATORS); } /* Loop unswitching pass. */