From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by sourceware.org (Postfix) with ESMTPS id 12CCD3858D32 for ; Tue, 2 Jan 2024 17:34:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 12CCD3858D32 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 12CCD3858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::529 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704216858; cv=none; b=gaNoogCwsL+JCqR1vF3vGZEswWquq05Z7tyTD14Cy4ok8cTFUrm3NG/CzfQlbMJCubip6xXgXdudh3jx92oBMFmJRZ8o9aM1a/W5fq1IfAY4YsCI/b87AgQvkDbmg0Ic2LAugblWeWARHVZoOUGkgWtnEQxFI0shsSP91cgIk5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704216858; c=relaxed/simple; bh=IwH17KZK/balp3fug+JxLLnq8BOU7Xm4UjMK3WJtvvA=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=SPv285zxl9aFf2saom0CwR2HUxE7JTQhUXbOZUIr8lfbVNCUlXOrz2rfn2vWWhR8Gk3vYYrHifBp6fYrPhBiNZCjXtbWOiG6HVkwUPtx9Vd/q/ooejJABld2c1LS/vXetKvtTNjs2Xjqr0u/uWJ+x6xlGj9wC7+HasmjVFBY6qQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-5c229dabbb6so2438758a12.0 for ; Tue, 02 Jan 2024 09:34:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704216855; x=1704821655; 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=BmUS6CIkj+V+MgRTLomcQjHb/NsVdXZEMJpDoOLHz78=; b=dtm6/JvWO4GXoUSHoOs/CmnANPczMT8UOZR7lDQw0wSHeWraSmUg8+TzSUl2TLF+iY t7X7eWzBuVYoq/ghmBYz4bo/wBoepF2tljFhDg8jSZ9L39gbYCnfl7w4r+5t3hyju0Qn 98xLTw8uh/aZN3H6Y0+M5rWf/Jd+2P3qEs5AypbCT9f1vwt222ZwbLBMjzdoqrVS+CF5 ShBy/T/7gkQoYsrAcVxrojMNneO9N80gdST7/syDTVdYFxBjZz6tOwPFGO5krYRTaHMb 36hgXIXJDos59y8J6pqInwZVFPxTqr9oOvse60z7A/7IS0xEpuAZXDM9EkKuD/oPICqi SpVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704216855; x=1704821655; 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=BmUS6CIkj+V+MgRTLomcQjHb/NsVdXZEMJpDoOLHz78=; b=bwIp2bU3joCrrf92wmln2tzrxNlo4BSFwQaZtGsR26ilM4RIgtQTpYN+koj7FTb2Jn Ef/lkBI1VpNswyH7Y3iFIi+eTJBl69R7N/nlySV8q8NeeecDo0V8n5XOshDbRUfnA20p rTTTr3SwdIEweZqcg2nQutiNS2znCeoFpv/ngOjDdxZ77ipo3psTGiaOnP5LWrgzJTvb 9ZwhXAD/eJcan4l4ycdAPAA0Zoa4nRyuND8Dx3554seWAlw23dO0JIf7WuHBYF1FtlVD /YdZO7nHdUz3ZXkm/qhkkd2WYa3Eg/rAPNaK9lzDx+LXoMOp4My6T96mqEu8saJO/tu6 nVbg== X-Gm-Message-State: AOJu0YxSFmk5JWEhVSg31fIH0wJ8nq5SK9xDiHvQY86LNCNoqf8Lnjd3 kHRuEQeg3BUGEkYbHcAtWVEBrawptPNN1ofFXMc= X-Google-Smtp-Source: AGHT+IEl3AbgdV2NPyHBx3H108NU+b6JEIV/EJuHWPdB7DoQ/dga17OthswZfe7B1BygDIuJk6NuohrHrK8wmtY7lVU= X-Received: by 2002:a17:90a:5c82:b0:28c:2e1f:8bf2 with SMTP id r2-20020a17090a5c8200b0028c2e1f8bf2mr4651867pji.84.1704216854813; Tue, 02 Jan 2024 09:34:14 -0800 (PST) MIME-Version: 1.0 References: <20231212082129.2556235-1-quic_apinski@quicinc.com> In-Reply-To: <20231212082129.2556235-1-quic_apinski@quicinc.com> From: Andrew Pinski Date: Tue, 2 Jan 2024 09:34:03 -0800 Message-ID: Subject: Re: [PATCH] aarch64/expr: Use ccmp when the outer expression is used twice [PR100942] 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=-6.1 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,T_SCC_BODY_TEXT_LINE,URIBL_BLACK,URIBL_SBL 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 Tue, Dec 12, 2023 at 12:22=E2=80=AFAM Andrew Pinski wrote: > > Ccmp is not used if the result of the and/ior is used by both > a GIMPLE_COND and a GIMPLE_ASSIGN. This improves the code generation > here by using ccmp in this case. > Two changes is required, first we need to allow the outer statement's > result be used more than once. > The second change is that during the expansion of the gimple, we need > to try using ccmp. This is needed because we don't use expand the ssa > name of the lhs but rather expand directly from the gimple. > > A small note on the ccmp_4.c testcase, we should be able to get slightly > better than with this patch but it is one extra instruction compared to > before. > > Bootstraped and tested on aarch64-linux-gnu with no regressions. Ping? > > PR target/100942 > > gcc/ChangeLog: > > * ccmp.cc (ccmp_candidate_p): Add outer argument. > Allow if the outer is true and the lhs is used more > than once. > (expand_ccmp_expr): Update call to ccmp_candidate_p. > * cfgexpand.cc (expand_gimple_stmt_1): Try using ccmp > for binary assignments. > > gcc/testsuite/ChangeLog: > > * gcc.target/aarch64/ccmp_3.c: New test. > * gcc.target/aarch64/ccmp_4.c: New test. > > Signed-off-by: Andrew Pinski > --- > gcc/ccmp.cc | 9 +++--- > gcc/cfgexpand.cc | 25 ++++++++++++++++ > gcc/testsuite/gcc.target/aarch64/ccmp_3.c | 20 +++++++++++++ > gcc/testsuite/gcc.target/aarch64/ccmp_4.c | 35 +++++++++++++++++++++++ > 4 files changed, 85 insertions(+), 4 deletions(-) > create mode 100644 gcc/testsuite/gcc.target/aarch64/ccmp_3.c > create mode 100644 gcc/testsuite/gcc.target/aarch64/ccmp_4.c > > diff --git a/gcc/ccmp.cc b/gcc/ccmp.cc > index 1bd6fadea35..a274f8c3d53 100644 > --- a/gcc/ccmp.cc > +++ b/gcc/ccmp.cc > @@ -92,7 +92,7 @@ ccmp_tree_comparison_p (tree t, basic_block bb) > > /* Check whether G is a potential conditional compare candidate. */ > static bool > -ccmp_candidate_p (gimple *g) > +ccmp_candidate_p (gimple *g, bool outer =3D false) > { > tree lhs, op0, op1; > gimple *gs0, *gs1; > @@ -109,8 +109,9 @@ ccmp_candidate_p (gimple *g) > lhs =3D gimple_assign_lhs (g); > op0 =3D gimple_assign_rhs1 (g); > op1 =3D gimple_assign_rhs2 (g); > - if ((TREE_CODE (op0) !=3D SSA_NAME) || (TREE_CODE (op1) !=3D SSA_NAME) > - || !has_single_use (lhs)) > + if ((TREE_CODE (op0) !=3D SSA_NAME) || (TREE_CODE (op1) !=3D SSA_NAME)= ) > + return false; > + if (!outer && !has_single_use (lhs)) > return false; > > bb =3D gimple_bb (g); > @@ -284,7 +285,7 @@ expand_ccmp_expr (gimple *g, machine_mode mode) > rtx_insn *last; > rtx tmp; > > - if (!ccmp_candidate_p (g)) > + if (!ccmp_candidate_p (g, true)) > return NULL_RTX; > > last =3D get_last_insn (); > diff --git a/gcc/cfgexpand.cc b/gcc/cfgexpand.cc > index b860be8bb77..0f9aad8e3eb 100644 > --- a/gcc/cfgexpand.cc > +++ b/gcc/cfgexpand.cc > @@ -74,6 +74,7 @@ along with GCC; see the file COPYING3. If not see > #include "output.h" > #include "builtins.h" > #include "opts.h" > +#include "ccmp.h" > > /* Some systems use __main in a way incompatible with its use in gcc, in= these > cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__M= AIN to > @@ -3972,6 +3973,30 @@ expand_gimple_stmt_1 (gimple *stmt) > if (GET_CODE (target) =3D=3D SUBREG && SUBREG_PROMOTED_VAR_P = (target)) > promoted =3D true; > > + /* Try to expand conditonal compare. */ > + if (targetm.gen_ccmp_first > + && gimple_assign_rhs_class (assign_stmt) =3D=3D GIMPLE_BI= NARY_RHS) > + { > + machine_mode mode =3D TYPE_MODE (TREE_TYPE (lhs)); > + gcc_checking_assert (targetm.gen_ccmp_next !=3D NULL); > + temp =3D expand_ccmp_expr (stmt, mode); > + if (temp) > + { > + if (promoted) > + { > + int unsignedp =3D SUBREG_PROMOTED_SIGN (target); > + convert_move (SUBREG_REG (target), temp, unsigned= p); > + } > + else > + { > + temp =3D force_operand (temp, target); > + if (temp !=3D target) > + emit_move_insn (target, temp); > + } > + return; > + } > + } > + > ops.code =3D gimple_assign_rhs_code (assign_stmt); > ops.type =3D TREE_TYPE (lhs); > switch (get_gimple_rhs_class (ops.code)) > diff --git a/gcc/testsuite/gcc.target/aarch64/ccmp_3.c b/gcc/testsuite/gc= c.target/aarch64/ccmp_3.c > new file mode 100644 > index 00000000000..a2b47fbee14 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/aarch64/ccmp_3.c > @@ -0,0 +1,20 @@ > +/* { dg-options "-O2" } */ > +/* PR target/100942 */ > + > +void foo(void); > +int f1(int a, int b) > +{ > + int c =3D a =3D=3D 0 || b =3D=3D 0; > + if (c) foo(); > + return c; > +} > + > +/* We should get one cmp followed by ccmp and one cset. */ > +/* { dg-final { scan-assembler "\tccmp\t" } } */ > +/* { dg-final { scan-assembler-times "\tcset\t" 1 } } */ > +/* { dg-final { scan-assembler-times "\tcmp\t" 1 } } */ > +/* And not get 2 cmps and 2 (or more cset) and orr and a cbnz. */ > +/* { dg-final { scan-assembler-not "\torr\t" } } */ > +/* { dg-final { scan-assembler-not "\tcbnz\t" } } */ > +/* { dg-final { scan-assembler-not "\tcbz\t" } } */ > + > diff --git a/gcc/testsuite/gcc.target/aarch64/ccmp_4.c b/gcc/testsuite/gc= c.target/aarch64/ccmp_4.c > new file mode 100644 > index 00000000000..bc0f57a7c59 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/aarch64/ccmp_4.c > @@ -0,0 +1,35 @@ > +/* { dg-options "-O2" } */ > +/* PR target/100942 */ > + > +void foo(void); > +int f1(int a, int b, int d) > +{ > + int c =3D a < 8 || b < 9; > + int e =3D d < 11 || c; > + if (e) foo(); > + return c; > +} > + > +/* > + We really should get: > + cmp w0, 7 > + ccmp w1, 8, 4, gt > + cset w0, le > + ccmp w2, 10, 4, gt > + ble .L11 > + > + But we currently get: > + cmp w0, 7 > + ccmp w1, 8, 4, gt > + cset w0, le > + cmp w0, 0 > + ccmp w2, 10, 4, eq > + ble .L11 > + The middle cmp is not needed. > + */ > + > +/* We should end up with only one cmp and 2 ccmp and 1 cset but currentl= y we get 2 cmp > + though. */ > +/* { dg-final { scan-assembler-times "\tccmp\t" 2 } } */ > +/* { dg-final { scan-assembler-times "\tcset\t" 1 } } */ > +/* { dg-final { scan-assembler-times "\tcmp\t" 1 { xfail *-*-* } } } */ > -- > 2.39.3 >