From patchwork Tue Jul 13 03:11:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 1504327 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GP5JB2mQCz9sWd for ; Tue, 13 Jul 2021 13:11:22 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2712B393D023 for ; Tue, 13 Jul 2021 03:11:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from rock.gnat.com (rock.gnat.com [IPv6:2620:20:4000:0:a9e:1ff:fe9b:1d1]) by sourceware.org (Postfix) with ESMTPS id 5BB52383302D for ; Tue, 13 Jul 2021 03:11:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5BB52383302D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 35213116335; Mon, 12 Jul 2021 23:11:07 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id NUzWyowgRKkx; Mon, 12 Jul 2021 23:11:07 -0400 (EDT) Received: from free.home (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPS id EC0C5116327; Mon, 12 Jul 2021 23:11:06 -0400 (EDT) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 16D3B0eF104176 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Jul 2021 00:11:00 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Subject: move unreachable user labels to entry point Organization: Free thinker, does not speak for AdaCore Date: Tue, 13 Jul 2021 00:11:00 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, 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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" pr42739.C, complicated by some extra wrappers and cleanups from a feature I'm working on, got me very confused because a user label ended up in a cleanup introduced by my pass, where it couldn't possibly have been initially. The current logic may move such an unreachable user label multiple times, if it ends up in blocks that get removed one after the other. Since it doesn't really matter where it lands (save for omp constraints), I propose we move it once and for all to a stable, final location, that we currently use only as a last resort: the entry point. Regstrapped on x86_64-linux-gnu. Ok to install? for gcc/ChangeLog * tree-cfg.c (remove_bb): When preserving an unreachable user label, use the entry block as the preferred choice for its surviving location, rather than as a last resort. --- gcc/tree-cfg.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index 1f0f4a2c6eb2c..f6f005f10a9f5 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -2300,13 +2300,11 @@ remove_bb (basic_block bb) FORCED_LABEL (gimple_label_label (label_stmt)) = 1; } - new_bb = bb->prev_bb; - /* Don't move any labels into ENTRY block. */ - if (new_bb == ENTRY_BLOCK_PTR_FOR_FN (cfun)) - { - new_bb = single_succ (new_bb); - gcc_assert (new_bb != bb); - } + /* We have to move the unreachable label somewhere. + Moving it to the entry block makes sure it's moved at + most once, and avoids messing with anonymous landing + pad labels. */ + new_bb = single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun)); if ((unsigned) bb->index < bb_to_omp_idx.length () && ((unsigned) new_bb->index >= bb_to_omp_idx.length () || (bb_to_omp_idx[bb->index] @@ -2316,7 +2314,6 @@ remove_bb (basic_block bb) into the right OMP region. */ unsigned int i; int idx; - new_bb = NULL; FOR_EACH_VEC_ELT (bb_to_omp_idx, i, idx) if (i >= NUM_FIXED_BLOCKS && idx == bb_to_omp_idx[bb->index] @@ -2325,11 +2322,6 @@ remove_bb (basic_block bb) new_bb = BASIC_BLOCK_FOR_FN (cfun, i); break; } - if (new_bb == NULL) - { - new_bb = single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun)); - gcc_assert (new_bb != bb); - } } new_gsi = gsi_after_labels (new_bb); gsi_remove (&i, false);