From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id 9D3ED3858414 for ; Fri, 10 Feb 2023 21:16:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9D3ED3858414 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=ucw.cz Authentication-Results: sourceware.org; spf=none smtp.mailfrom=kam.mff.cuni.cz Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id DFF24284703; Fri, 10 Feb 2023 22:16:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ucw.cz; s=gen1; t=1676063796; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=B7irheA5LiDXeDiZVP7svkcjh+ffbotJ+fRX+7Y0DYI=; b=jX89uR0Nb6jwcQIkVNawM4A/LQaRWAVMqZcNlb4jhFW0CeEvWoV6yMKqq7ZiqcBGnNAyPh s2F458TjRGAkoo9oIbnqUcDHTm83duq0FCe94pQC+SuXTwEtS8+2ynArxVs8yHvzP4ce2m oMP8HaHUonSCuT/tL0PvbI9ONn9nKVQ= Date: Fri, 10 Feb 2023 22:16:36 +0100 From: Jan Hubicka To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] tree-optimization/106722 - fix CD-DCE edge marking Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 List-Id: > The following fixes a latent issue when we mark control edges but > end up with marking a block with no stmts necessary. In this case > we fail to mark dependent control edges of that block. > > Bootstrapped and tested on x86_64-unknown-linux-gnu. > > Does this look OK? > > Thanks, > Richard. > > PR tree-optimization/106722 > * tree-ssa-dce.cc (mark_last_stmt_necessary): Return > whether we marked a stmt. > (mark_control_dependent_edges_necessary): When > mark_last_stmt_necessary didn't mark any stmt make sure > to mark its control dependent edges. > (propagate_necessity): Likewise. > > * gcc.dg/torture/pr108737.c: New testcase. > diff --git a/gcc/tree-ssa-dce.cc b/gcc/tree-ssa-dce.cc > index b2fe9f4f55e..21b3294fc86 100644 > --- a/gcc/tree-ssa-dce.cc > +++ b/gcc/tree-ssa-dce.cc > @@ -327,17 +327,23 @@ mark_stmt_if_obviously_necessary (gimple *stmt, bool aggressive) > > /* Mark the last statement of BB as necessary. */ > > -static void > +static bool > mark_last_stmt_necessary (basic_block bb) > { > gimple *stmt = last_stmt (bb); > > - bitmap_set_bit (last_stmt_necessary, bb->index); > + if (!bitmap_set_bit (last_stmt_necessary, bb->index)) > + return true; > + > bitmap_set_bit (bb_contains_live_stmts, bb->index); > > /* We actually mark the statement only if it is a control statement. */ > if (stmt && is_ctrl_stmt (stmt)) > - mark_stmt_necessary (stmt, true); > + { > + mark_stmt_necessary (stmt, true); > + return true; > + } > + return false; > } > > > @@ -369,8 +375,8 @@ mark_control_dependent_edges_necessary (basic_block bb, bool ignore_self) > continue; > } > > - if (!bitmap_bit_p (last_stmt_necessary, cd_bb->index)) > - mark_last_stmt_necessary (cd_bb); > + if (!mark_last_stmt_necessary (cd_bb)) > + mark_control_dependent_edges_necessary (cd_bb, false); Makes sense to me, though I am bit surprised it took such a long time to show up. Honza