From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by sourceware.org (Postfix) with ESMTPS id 6377B384AB5A for ; Thu, 16 May 2024 08:35:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6377B384AB5A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6377B384AB5A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::135 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715848537; cv=none; b=nGWJvLUq4EVM9hgzvm8hEfEMIW0EKgglf9olXptS8P8FiQ4ONjaqEPmOHcmVJYIWGCz3ANYP8UN9YCoU5Xs8appL26PPdmn43rJBiTu0OCYQqhvd8Fz6waqeqQxZa+XrzbReNcvid2/59KKmuNruuZumNH6j37J0Iqu45emHsi4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715848537; c=relaxed/simple; bh=nspn2cagxKvoqdY1LqGZhws+Znyfw2DA69PJ/oic0w4=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=Z4DpZAzrKgMECGuTMkkzItsWfVcYgBEeD6kqWKwN7gS4eAooKSJ4hvPE3aHN76PvlgWelctyIYrFDmYIQxfIm1k7yR2ODN960c8YZE/fTE/9w8YDDaEaT4bc5JIa2WaiOB09/VHYHhIxt2GtcyRW3Jd1KlOLDQHVuA8FkP8rTJU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-51f3a49ff7dso622930e87.2 for ; Thu, 16 May 2024 01:35:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715848533; x=1716453333; 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=Ps3KEo3tuNAF2Rgl/TJLQEeKfyabhe9So4zHBtDC2i8=; b=OpHHVCLGSm80eqcX/qPCwosQp7a1HHwslG7WmyV6Di4AYJPFKN786lwJfftn+YbR61 sQbhhajoIvgxXiB1o8sjf3OBi2J1zGPZ6XtaCBgI9nAsCsxFflGJTuCp47kBh5qvflVH Dm9Hf6xp0zGhVHaRhGUs9A0ZbJQbfwvjypMqte0H2XKhM4sieZJ4frCpQ1WDfoLKR0vh 9OPlO+RCCaE4sMS7TpP211RgFOxfh36eHz7leDbu5US7idjwbtgulQSLrjutAlIdcpMA +mwsba80gxD6uSRDIcD9tGmty7/UQ3oakx6GN1MNoFF9x3sPVnbGJTXrX71p2HutbFyY l0+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715848533; x=1716453333; 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=Ps3KEo3tuNAF2Rgl/TJLQEeKfyabhe9So4zHBtDC2i8=; b=duFwz0wXiy3ql14y9oi7sm/xssr7+Ph2oJg27aG8OOATERGjry5ryUY0idTbUzij2G QCvvt92UFjDQ59lfV/XSBgmFnJYVvtUW53Bh4S5efFnr3x9pED/OnM0k0XY/aQ0bB6tB ke7ltiNl+aCod1Q2mQjQqjrW2pNMdXMbuTQXEPoFBGozCflsxr2tOzJMMmRmwrqsAIs9 4ArTxuPagsERy382Jr5L942sqb2dohqrorEcqhQBAFsRB/gJ5gIyGLO0qem8NxOwc/fP FAov8L+hVeIn2tJ6ffBfD5G4gyVN6kz6SRAODC9Jcy5CGCPsrUiNHVrNAGYGmpEivawB M4RA== X-Forwarded-Encrypted: i=1; AJvYcCVOjK9vhdKxIMD+7ZwEAM43nScXdWp3PTNuzxwjZW/+qgWP/ABdSakUbEltW41+CadZdW9MxzsC1uNg4I2iSNzBMaS0HMQXAQ== X-Gm-Message-State: AOJu0YyZraShzEf1IzZZ/9yE+hqVbsOqGrSkRswByh2ME/k3nT9LRnqF JkBrZY+SM9xamPm+WMk+OqsF57hU7HqGKwM8k0vlJrMYvc1uqJ/jDlNeySByXy73eellH1yrDUu 5m+wzGfFQ2l7UJFWWHCAlGFaPPLw= X-Google-Smtp-Source: AGHT+IFX0hz90gPcmUx9PaHsM8Cf9eQ6YRIuQwgXjuxtMEMbqiiUjYATg95fo2EEEtsNXs9ByBzNlTK6lxl0ABArAVY= X-Received: by 2002:a19:5f56:0:b0:51a:f596:9d53 with SMTP id 2adb3069b0e04-5221016e9cbmr11240712e87.42.1715848532614; Thu, 16 May 2024 01:35:32 -0700 (PDT) MIME-Version: 1.0 References: <20240405122625.847311-1-manolis.tsamis@vrull.eu> In-Reply-To: From: Richard Biener Date: Thu, 16 May 2024 10:35:21 +0200 Message-ID: Subject: Re: [PATCH] Add extra copy of the ifcombine pass after pre [PR102793] To: Andrew Pinski Cc: Manolis Tsamis , 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=-7.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,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 8:14=E2=80=AFPM Andrew Pinski wr= ote: > > On Fri, Apr 5, 2024 at 5:28=E2=80=AFAM 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. > > I do think we should have something similar to re-running > ssa-ifcombine but I think it should be much later, like after the loop > optimizations are done. > Maybe just a simplified version of it (that does the combining and not > the optimizations part) included in isel or pass_optimize_widening_mul > (which itself should most likely become part of isel or renamed since > it handles more than just widening multiply these days). I've long wished we had a (late?) pass that can also undo if-conversion (basically do what RTL expansion would later do). Maybe gimple-predicate-analysis.cc (what's used by uninit analysis) can represent mixed CFG + if-converted conditions so we can optimize it and code-gen the condition in a more optimal manner much like we have if-to-switch, switch-conversion and switch-expansion. That said, I agree that re-running ifcombine should be later. And there's still the old task of splitting tail-merging from PRE (and possibly making it more effective). Richard. > > Thanks, > Andrew Pinski > > > > > > 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 > > +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 */); > > 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" } */ > > - > > 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 > >