From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by sourceware.org (Postfix) with ESMTPS id 059753857006 for ; Thu, 4 May 2023 09:43:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 059753857006 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-4f139de8cefso8031197e87.0 for ; Thu, 04 May 2023 02:43:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683193423; x=1685785423; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=zpB9a5uLSAC5y/5wA0dPXvRSX94qc35BsxiH1Stp9go=; b=a/nYQPKGVPPiPkfzzlR+v7tDfLJ/uuLf5Y/X3oJwZfc//D7rSoN9EhXao/2qw4TaDL ovr7uf5FgiOSWJhm/xN8o8QO2l2b6i8ggJMX59f28Jqryn6Uvh0Vg6W/5ClwULZS92Ki k5UhEAtnEicxKL+xy/YwCmIlmffp0rjgnWjTBwZZyjM9uI8yCiH0mNYlnr1q+DmGroew IYNYL46S7Vm9uiJ6tKcPfIkLli/4d2sDoXyR5/Oo21gJR41q924HmPp+lOa4qdADGvQg 1mcy6GBkp+hXGAZzQGjSxMqjyFW49wy2J5P+5GWxCLTjs2Qse0nxPdMh5CbMAZfJb+m4 hcDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683193423; x=1685785423; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zpB9a5uLSAC5y/5wA0dPXvRSX94qc35BsxiH1Stp9go=; b=EN1Ok0zIDFBzSxsfg3WJjJHpXBSffcAz477vg7j4lxDExcpuEF2Gon+oOjg8W8aVKL ciW3mDruAcqgdaJbvdrZ7HVC50PHNurCZbKaV0M2WoCsDzDKvPEFY4d4OpUPVQBhta8n QH9rq/f1bsuGTctBk1NirXssoUJOEucTANywplRrjbiSHqUVpseN8a2fJEzT0CPI0731 bfFU0uPJ4FB3fGnlm0BcpnVi9y+JG673RWOAb7d8rH0eFLOQEZOTyQVkJW4t8c9HfdyK Eqn6r4Ct2PwafvYttdN7wFfL+ccySktijIst1JY4qwnshDh9OunG/FYjOljZx+xUEAC5 2vtA== X-Gm-Message-State: AC+VfDx6ALu9P4OEibG6t5UCk2PEDuaVGrFassSBqv1zegzkVv1WfHtY 3SPq25tRjhVCpd5tdPVhl9TfEVA6qR6dYcSvwz8= X-Google-Smtp-Source: ACHHUZ62yPAMmoZheJ6CJoG7HZKLrZgZoY3wyMmDbyAUUwEp5oFO5A5sq3GR+05SOZuTicGHWqfKRK3IZT7UH0pxw30= X-Received: by 2002:a2e:87c3:0:b0:2ac:7a78:dc97 with SMTP id v3-20020a2e87c3000000b002ac7a78dc97mr566789ljj.25.1683193423253; Thu, 04 May 2023 02:43:43 -0700 (PDT) MIME-Version: 1.0 References: <20230503231224.931656-1-apinski@marvell.com> <20230503231224.931656-2-apinski@marvell.com> In-Reply-To: <20230503231224.931656-2-apinski@marvell.com> From: Richard Biener Date: Thu, 4 May 2023 11:43:31 +0200 Message-ID: Subject: Re: [PATCHv2 2/2] PHIOPT: Improve replace_phi_edge_with_variable for diamond shapped bb To: Andrew Pinski Cc: gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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: On Thu, May 4, 2023 at 1:13=E2=80=AFAM Andrew Pinski via Gcc-patches wrote: > > While looking at differences between what minmax_replacement > and match_simplify_replacement does. I noticed that they sometimes > chose different edges to remove. I decided we should be able to do > better and be able to remove both empty basic blocks in the > case of match_simplify_replacement as that moves the statements. > > This also updates the testcases as now match_simplify_replacement > will remove the unused MIN/MAX_EXPR and they were checking for > those. > > OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. OK. > gcc/ChangeLog: > > * tree-ssa-phiopt.cc (replace_phi_edge_with_variable): Handle > diamond form bb with forwarder only empty blocks better. > > gcc/testsuite/ChangeLog: > > * gcc.dg/tree-ssa/minmax-15.c: Update test. > * gcc.dg/tree-ssa/minmax-16.c: Update test. > * gcc.dg/tree-ssa/minmax-3.c: Update test. > * gcc.dg/tree-ssa/minmax-4.c: Update test. > * gcc.dg/tree-ssa/minmax-5.c: Update test. > * gcc.dg/tree-ssa/minmax-8.c: Update test. > --- > gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c | 3 +- > gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c | 9 ++---- > gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c | 2 +- > gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c | 2 +- > gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c | 2 +- > gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c | 2 +- > gcc/tree-ssa-phiopt.cc | 35 ++++++++++++++++++++++- > 7 files changed, 43 insertions(+), 12 deletions(-) > > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c b/gcc/testsuite/gc= c.dg/tree-ssa/minmax-15.c > index 8a39871c938..6731f91e6c3 100644 > --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c > +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c > @@ -30,5 +30,6 @@ main (void) > return 0; > } > > -/* { dg-final { scan-tree-dump-times "MIN_EXPR" 3 "phiopt1" } } */ > +/* There should only be two MIN_EXPR left, the 3rd one was removed. */ > +/* { dg-final { scan-tree-dump-times "MIN_EXPR" 2 "phiopt1" } } */ > /* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "phiopt1" } } */ > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c b/gcc/testsuite/gc= c.dg/tree-ssa/minmax-16.c > index 623b12b3f74..094364e6424 100644 > --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c > +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c > @@ -25,11 +25,8 @@ main (void) > return 0; > } > > -/* After phiopt1, there really should be only 3 MIN_EXPR in the IR (incl= uding debug statements). > - But the way phiopt does not cleanup the CFG all the time, the PHI mig= ht still reference the > - alternative bb's moved statement. > - Note in the end, we do dce the statement and other debug statements t= o end up with only 2 MIN_EXPR. > - So check that too. */ > -/* { dg-final { scan-tree-dump-times "MIN_EXPR" 4 "phiopt1" } } */ > +/* After phiopt1, will be only 2 MIN_EXPR in the IR (including debug sta= tements). */ > +/* xk will only have the final result so the extra debug info does not c= hange anything. */ > +/* { dg-final { scan-tree-dump-times "MIN_EXPR" 2 "phiopt1" } } */ > /* { dg-final { scan-tree-dump-times "MIN_EXPR" 2 "optimized" } } */ > /* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "phiopt1" } } */ > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c b/gcc/testsuite/gcc= .dg/tree-ssa/minmax-3.c > index 2af10776346..521afe3e4d9 100644 > --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c > +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c > @@ -25,5 +25,5 @@ main (void) > return 0; > } > > -/* { dg-final { scan-tree-dump-times "MIN_EXPR" 3 "phiopt1" } } */ > +/* { dg-final { scan-tree-dump-times "MIN_EXPR" 2 "phiopt1" } } */ > /* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "phiopt1" } } */ > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c b/gcc/testsuite/gcc= .dg/tree-ssa/minmax-4.c > index 973f39bfed3..49e27185b5e 100644 > --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c > +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c > @@ -26,4 +26,4 @@ main (void) > } > > /* { dg-final { scan-tree-dump-times "MIN_EXPR" 0 "phiopt1" } } */ > -/* { dg-final { scan-tree-dump-times "MAX_EXPR" 3 "phiopt1" } } */ > +/* { dg-final { scan-tree-dump-times "MAX_EXPR" 2 "phiopt1" } } */ > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c b/gcc/testsuite/gcc= .dg/tree-ssa/minmax-5.c > index 34e4e720511..194c881cc98 100644 > --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c > +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c > @@ -25,5 +25,5 @@ main (void) > return 0; > } > > -/* { dg-final { scan-tree-dump-times "MIN_EXPR" 2 "phiopt1" } } */ > +/* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "phiopt1" } } */ > /* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "phiopt1" } } */ > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c b/gcc/testsuite/gcc= .dg/tree-ssa/minmax-8.c > index 0160e573fef..d5cb53145ea 100644 > --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c > +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c > @@ -26,4 +26,4 @@ main (void) > } > > /* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "phiopt1" } } */ > -/* { dg-final { scan-tree-dump-times "MAX_EXPR" 2 "phiopt1" } } */ > +/* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "phiopt1" } } */ > diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc > index fbc1fd66607..7ba24211025 100644 > --- a/gcc/tree-ssa-phiopt.cc > +++ b/gcc/tree-ssa-phiopt.cc > @@ -94,6 +94,7 @@ replace_phi_edge_with_variable (basic_block cond_block, > basic_block bb =3D gimple_bb (phi); > gimple_stmt_iterator gsi; > tree phi_result =3D PHI_RESULT (phi); > + bool deleteboth =3D false; > > /* Duplicate range info if they are the only things setting the target= PHI. > This is needed as later on, the new_tree will be replacing > @@ -137,7 +138,14 @@ replace_phi_edge_with_variable (basic_block cond_blo= ck, > keep_edge =3D EDGE_SUCC (cond_block, 1); > } > else if ((keep_edge =3D find_edge (cond_block, e->src))) > - ; > + { > + basic_block bb1 =3D EDGE_SUCC (cond_block, 0)->dest; > + basic_block bb2 =3D EDGE_SUCC (cond_block, 1)->dest; > + if (single_pred_p (bb1) && single_pred_p (bb2) > + && single_succ_p (bb1) && single_succ_p (bb2) > + && empty_block_p (bb1) && empty_block_p (bb2)) > + deleteboth =3D true; > + } > else > gcc_unreachable (); > > @@ -148,6 +156,31 @@ replace_phi_edge_with_variable (basic_block cond_blo= ck, > e->probability =3D profile_probability::always (); > delete_basic_block (edge_to_remove->dest); > > + /* Eliminate the COND_EXPR at the end of COND_BLOCK. */ > + gsi =3D gsi_last_bb (cond_block); > + gsi_remove (&gsi, true); > + } > + else if (deleteboth) > + { > + basic_block bb1 =3D EDGE_SUCC (cond_block, 0)->dest; > + basic_block bb2 =3D EDGE_SUCC (cond_block, 1)->dest; > + > + edge newedge =3D redirect_edge_and_branch (keep_edge, bb); > + > + /* The new edge should be the same. */ > + gcc_assert (newedge =3D=3D keep_edge); > + > + keep_edge->flags |=3D EDGE_FALLTHRU; > + keep_edge->flags &=3D ~(EDGE_TRUE_VALUE | EDGE_FALSE_VALUE); > + keep_edge->probability =3D profile_probability::always (); > + > + /* Copy the edge's phi entry from the old one. */ > + copy_phi_arg_into_existing_phi (e, keep_edge); > + > + /* Delete the old 2 empty basic blocks */ > + delete_basic_block (bb1); > + delete_basic_block (bb2); > + > /* Eliminate the COND_EXPR at the end of COND_BLOCK. */ > gsi =3D gsi_last_bb (cond_block); > gsi_remove (&gsi, true); > -- > 2.31.1 >