From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id BA53B3846062 for ; Fri, 5 Apr 2024 13:34:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BA53B3846062 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BA53B3846062 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712324060; cv=none; b=UsBczEfxpV51XIc3gqJaIA2m2Tzek42J10j49IRm4WnWJik8nt88aBn9HHFFT244ZY1rnXqC8+bnXmRsp+g48LrZQo0L+IYVWD16zXzf5ZqnIsOxyD348E4HS2+TAiVz78JUH/fqEzUCceED78xB0renr6ZbiXMw2NY0ksnJijo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712324060; c=relaxed/simple; bh=UkjXBL+jfz+klEyxVeL/l8a+uoJQYYFOnAbqVdgomYM=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=tjYmU1b4trRz2vp9OeTprK3FrqVibw8Wsrvvq4nuwzhty5t8i8sdQMC0QPUt7qV5ysxhahhCYTr2eQ1ccayLKl/fKM3zCL1udWUPYUVJbF5itbYXRlxTQtlkWmrk+iW/6dVsWZpQ3wmWC2tvKTGup0L8S2eQvRKboCLMarhkYZU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1e0d8403257so19189385ad.1 for ; Fri, 05 Apr 2024 06:34:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1712324055; x=1712928855; darn=gcc.gnu.org; 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=zpZOsJg9fqj573QlnTAXd4xMJSMKxDXNrqKW16DENLk=; b=OmOXG1Lp3A1liKbcjyYnKU6nG50zlkM+f3Lwpv9yFT/g6y4bpi2+V89anVyoH2cRzt z13ObqOKizq8QZf3b6cHXMSBMflCOcxCmVlNinHIL6M32E5/g43JG+Y+FjGNodIpLB/+ BL7YOQdeBo+Pa3DaaQN7eeqhGfNZA7J65M25PckEtMu10kz6Q5mkWLo5xVoSn9Z5FKJl Vbv0/nLEaa0cS+kM8vUc95MUSqYboyv3CyMYx+eTFYXz1bPXIyT0jW02ALnpteEH2BYC ZoamXl9gwoMIOQnx6xoRDATy7wdlG9fsVHqC0Fts+NuGLMPeEciRc3kcL7EgtD5WwBcK U6jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712324055; x=1712928855; 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=zpZOsJg9fqj573QlnTAXd4xMJSMKxDXNrqKW16DENLk=; b=gBVTGZI9FY5YQvQ0KOYOcGROG4D61JPwQrwbDg1rhUbIvN/gl72Q1nF9jLR+mx9T44 aG5B3ijz2NMX3Pc2JqUjD/m6FTOV0u57McCh2znO7Gxu4JFfjcTsguXUH5Owcll/6R2s exw5ZzljOEdt0VCJdsUXmjmAomGwEAhJjQaztHFLdLy5S1YbwB4KyOEhGfiQHMPrQNBs imzBsEHaGpm49aU0vAytfyDf7Xq0eYvYan7NBV/p+r4tA0RzmRGq03MSfp8c8SHH2AAS rNJttn5Hyypyz1VD5+HFi44srvFxfIwh93y6RMxCzsVi79LT1/VITlNnnFqCx7WTJ4EX LOfw== X-Gm-Message-State: AOJu0YylzpVRZkFn1B/6OnzasKJX39/TQO1cyZHKa6k5IYCGcreiQHGy OPtNVGwSBCO4qXk1NhlnbAi6tCLMoRyTmAGOrv0qoDlERuaeoF5dNs2blawIxquT5x5tBYz5Zkz DWU7942Ra+fudME6GHykvD+784CPsbLo0HUvZTA== X-Google-Smtp-Source: AGHT+IEVZfFwVAyC9ZyZYSbkzfPJmyEhSsIvbFpcqn6dvzd8UEXkRmxNW5PTdbYXZJ7ypyfbYEoQpWbMs1BPBzvM+mQ= X-Received: by 2002:a17:903:2385:b0:1db:3a22:1fd6 with SMTP id v5-20020a170903238500b001db3a221fd6mr1626717plh.66.1712324054565; Fri, 05 Apr 2024 06:34:14 -0700 (PDT) MIME-Version: 1.0 References: <20240405122625.847311-1-manolis.tsamis@vrull.eu> In-Reply-To: From: Manolis Tsamis Date: Fri, 5 Apr 2024 16:33:38 +0300 Message-ID: Subject: Re: [PATCH] Add extra copy of the ifcombine pass after pre [PR102793] To: Richard Biener Cc: gcc-patches@gcc.gnu.org, Andrew Pinski , Philipp Tomsich , Tamar Christina , Jiangning Liu Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,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 List-Id: On Fri, Apr 5, 2024 at 3:43=E2=80=AFPM Richard Biener wrote: > > On Fri, Apr 5, 2024 at 2:28=E2=80=AFPM Manolis Tsamis wrote: > > > > If we consider code like: > > > > if (bar1 =3D=3D x) > > return foo(); > > if (bar2 !=3D y) > > return foo(); > > return 0; > > > > We would like the ifcombine pass to convert this to: > > > > if (bar1 =3D=3D x || bar2 !=3D y) > > return foo(); > > return 0; > > > > The ifcombine pass can handle this transformation but it is ran very ea= rly and > > it misses the opportunity because there are two seperate blocks for foo= (). > > The pre pass is good at removing duplicate code and blocks and due to t= hat > > running ifcombine again after it can increase the number of successful > > conversions. > > > > PR 102793 > > > > gcc/ChangeLog: > > > > * common.opt: -ftree-ifcombine option, enabled by default. > > * doc/invoke.texi: Document. > > * passes.def: Re-run ssa-ifcombine after pre. > > * tree-ssa-ifcombine.cc: Make ifcombine cloneable. Add gate fun= ction. > > > > gcc/testsuite/ChangeLog: > > > > * gcc.dg/tree-ssa/20030922-2.c: Change flag to -fno-tree-ifcomb= ine. > > * gcc.dg/uninit-pred-6_c.c: Remove inconsistent check. > > * gcc.target/aarch64/pr102793.c: New test. > > > > Signed-off-by: Manolis Tsamis > > --- > > > > gcc/common.opt | 4 +++ > > gcc/doc/invoke.texi | 5 ++++ > > gcc/passes.def | 1 + > > gcc/testsuite/gcc.dg/tree-ssa/20030922-2.c | 2 +- > > gcc/testsuite/gcc.dg/uninit-pred-6_c.c | 4 --- > > gcc/testsuite/gcc.target/aarch64/pr102793.c | 30 +++++++++++++++++++++ > > gcc/tree-ssa-ifcombine.cc | 5 ++++ > > 7 files changed, 46 insertions(+), 5 deletions(-) > > create mode 100644 gcc/testsuite/gcc.target/aarch64/pr102793.c > > > > diff --git a/gcc/common.opt b/gcc/common.opt > > index ad348844775..e943202bcf1 100644 > > --- a/gcc/common.opt > > +++ b/gcc/common.opt > > @@ -3163,6 +3163,10 @@ ftree-phiprop > > Common Var(flag_tree_phiprop) Init(1) Optimization > > Enable hoisting loads from conditional pointers. > > > > +ftree-ifcombine > > Please don't add further -ftree-X flags, 'tree' means nothing > to users. -fif-combine would be better. > Ok, thanks for pointing out, will do. > > +Common Var(flag_tree_ifcombine) Init(1) Optimization > > +Merge some conditional branches to simplify control flow. > > + > > ftree-pre > > Common Var(flag_tree_pre) Optimization > > Enable SSA-PRE optimization on trees. > > diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi > > index e2edf7a6c13..8d2ff6b4512 100644 > > --- a/gcc/doc/invoke.texi > > +++ b/gcc/doc/invoke.texi > > @@ -13454,6 +13454,11 @@ This flag is enabled by default at @option{-O1= } and higher. > > Perform hoisting of loads from conditional pointers on trees. This > > pass is enabled by default at @option{-O1} and higher. > > > > +@opindex ftree-ifcombine > > +@item -ftree-ifcombine > > +Merge some conditional branches to simplify control flow. This pass > > +is enabled by default at @option{-O1} and higher. > > + > > @opindex fhoist-adjacent-loads > > @item -fhoist-adjacent-loads > > Speculatively hoist loads from both branches of an if-then-else if the > > diff --git a/gcc/passes.def b/gcc/passes.def > > index 1cbbd413097..1765b476131 100644 > > --- a/gcc/passes.def > > +++ b/gcc/passes.def > > @@ -270,6 +270,7 @@ along with GCC; see the file COPYING3. If not see > > NEXT_PASS (pass_lim); > > NEXT_PASS (pass_walloca, false); > > NEXT_PASS (pass_pre); > > + NEXT_PASS (pass_tree_ifcombine); > > NEXT_PASS (pass_sink_code, false /* unsplit edges */); > > Please move it here, after sinking. > My initial placement was there, but I saw that in some cases (including the testcase), sinking would introduce some blocks that prohibited the ifcombining. > > NEXT_PASS (pass_sancov); > > NEXT_PASS (pass_asan); > > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/20030922-2.c b/gcc/testsuite= /gcc.dg/tree-ssa/20030922-2.c > > index 16c79da9521..66c9f481a2f 100644 > > --- a/gcc/testsuite/gcc.dg/tree-ssa/20030922-2.c > > +++ b/gcc/testsuite/gcc.dg/tree-ssa/20030922-2.c > > @@ -1,5 +1,5 @@ > > /* { dg-do compile } */ > > -/* { dg-options "-O1 -fdump-tree-dom2 -fdisable-tree-ifcombine" } */ > > +/* { dg-options "-O1 -fdump-tree-dom2 -fno-tree-ifcombine" } */ > > > > struct rtx_def; > > typedef struct rtx_def *rtx; > > diff --git a/gcc/testsuite/gcc.dg/uninit-pred-6_c.c b/gcc/testsuite/gcc= .dg/uninit-pred-6_c.c > > index f60868dad23..2d8e6501a45 100644 > > --- a/gcc/testsuite/gcc.dg/uninit-pred-6_c.c > > +++ b/gcc/testsuite/gcc.dg/uninit-pred-6_c.c > > @@ -20,10 +20,6 @@ int foo (int n, int l, int m, int r) > > if ( (n > 10) && l) > > blah(v); /* { dg-bogus "uninitialized" "bogus warning" } */ > > > > - if (l) > > - if (n > 12) > > - blah(v); /* { dg-bogus "uninitialized" "bogus warning" } */ > > - > > What's "inconsistent" about this check? I suppose we now diagnose this? > The appropriate way would be to XFAIL this but I'd like you to explain > why we now diagnose this (I don't see obvious if-combining opportunities)= . > Maybe inconsistent wasn't the correct word, but what I meant was: If the condition in the test is merged into if (l && (n > 12)) then the "bogus warning" appears on master too and the test fails. By inconsistent I meant that the analysis relies on a particular arrangement of conditionals that is fragile. After this change the branch is optimized by ifcombine and the "bogus warning" appears. We also get better codegen, at least for AArch64. It felt wrong to just remove this, it didn't occur to me that this can be made XFAIL instead. I can change it to that if you think it's justified. > On a general note you rely on the tail-merging pass which is part of PRE > and which hasn't seen any love and which isn't very powerful either. I'm= not > sure it's worth doing if-combining on the whole IL again because of it. > It might be possible to locally try if-combining from the immediate domin= ator > of a merged tail from inside tail-merging itself? > I had a feeling that the ifcombine pass is not very expensive and that's why I opted to just duplicate it (instead of e.g. moving it). I'm not really familiar with PRE so I made the placement just by observing the block deduplication. I don't know the answer to the last part, but if you believe it's worthwhile I can try it out. Thanks, Manolis > Richard. > > > return 0; > > } > > > > diff --git a/gcc/testsuite/gcc.target/aarch64/pr102793.c b/gcc/testsuit= e/gcc.target/aarch64/pr102793.c > > new file mode 100644 > > index 00000000000..78d48e01637 > > --- /dev/null > > +++ b/gcc/testsuite/gcc.target/aarch64/pr102793.c > > @@ -0,0 +1,30 @@ > > +/* { dg-do compile } */ > > +/* { dg-options "-O2" } */ > > + > > +typedef unsigned long uint64_t; > > + > > +int ccmp1(uint64_t* s1, uint64_t* s2, int(*foo)(void)) > > +{ > > + uint64_t d1, d2, bar; > > + d1 =3D *s1++; > > + d2 =3D *s2++; > > + bar =3D (d1 + d2) & 0xabcd; > > + if (bar =3D=3D 0 || d1 !=3D d2) > > + return foo(); > > + return 0; > > +} > > + > > +int ccmp2(uint64_t* s1, uint64_t* s2, int(*foo)(void)) > > +{ > > + uint64_t d1, d2, bar; > > + d1 =3D *s1++; > > + d2 =3D *s2++; > > + bar =3D (d1 + d2) & 0xabcd; > > + if (bar =3D=3D 0) > > + return foo(); > > + if (d1 !=3D d2) > > + return foo(); > > + return 0; > > +} > > + > > +/* { dg-final { scan-assembler-times "ccmp\t" 2 } } */ > > \ No newline at end of file > > diff --git a/gcc/tree-ssa-ifcombine.cc b/gcc/tree-ssa-ifcombine.cc > > index 6a3bc99190d..0bf9fe8b692 100644 > > --- a/gcc/tree-ssa-ifcombine.cc > > +++ b/gcc/tree-ssa-ifcombine.cc > > @@ -838,6 +838,11 @@ public: > > {} > > > > /* opt_pass methods: */ > > + opt_pass * clone () final override > > + { > > + return new pass_tree_ifcombine (m_ctxt); > > + } > > + bool gate (function *) final override { return flag_tree_ifcombine; = } > > unsigned int execute (function *) final override; > > > > }; // class pass_tree_ifcombine > > -- > > 2.44.0 > >