From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by sourceware.org (Postfix) with ESMTPS id 814433858CD1 for ; Mon, 31 Jul 2023 17:11:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 814433858CD1 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-pg1-x534.google.com with SMTP id 41be03b00d2f7-55b0e7efb1cso2907460a12.1 for ; Mon, 31 Jul 2023 10:11:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690823497; x=1691428297; 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=8TDgk/msKiASyy4EQeS3B+XrOmVGwOmHREOLc4zHtyI=; b=c/FITvj+uwwxUfK89ufZtU1x5crKBvfRU2ysxP0f6EA3OY+L2/VALY6QnqySLmJh6p r5T8WYe8IlyIt8hszX4yng5H6JEbn0ZlolkBAgqLhDef3RoKeBmzQajzF9I0N0Up9zah MY0+QFdFnuVoTjBFuBLe2g+gHzqLWq1qeRPSa4NoE5M0jVyorbI5P6KgJxaAS2qjx4/i Xxxwpj7K1fx4hauP6uZ906b/bbrdO+/VkdtB7/moPWt2nlrSWUQl9aY0kzA2uNhTOkmt UzKVjLNZPKW8I0xRoBHVgVxv5p8UNo8Ko1yT1aK9MQTcuxstGlIWIyL1bSo3Itij6tBR 40EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690823497; x=1691428297; 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=8TDgk/msKiASyy4EQeS3B+XrOmVGwOmHREOLc4zHtyI=; b=kJPmAYBI713cfTtGsrhyFr7ajcBuDiWY5nSPRta4y25N1tjun5KtBpipzQ38htIy3K ZFr3kgRBDGqjv+Pk2UgyBBw1YLhEwL+WAKeME8P31deTEMWBH9kvJ2QmT9p1GQOCfy3r lrw336PZr1uzjvUjNCX5TfWDL9/R6F6JQroEEUlTZaICyS1IF3T8ZgZU0wu2/iZuYRRm ch9oje1JVTQCc3oPwKuo2Bh86l1TGZIxDgu20181KlJGbfrizjSgew0c1HJn8y9seYiQ det1bm8d5/8nU3vssuRPsP0ryJUX7pF2hJk+wKJga4UdbW/8nBkQN1jrG4Ux5I6uVxtN pUtQ== X-Gm-Message-State: ABy/qLbad+vIGcBrLbOhN8ZTTeTqaevgQkI/5nk6XlfXWjeow3Y/+rCg PAnf34MF4xnVcMULFqKNzAfpLYW1Hk/wXutAP24= X-Google-Smtp-Source: APBJJlGgz+ox9bKPUTIAZgx64RRpDb6dTfFVS1+/dLHpKJbFKCN9Z2qSHD8OtHbU1iiVpc/roig/J+04XjBupeKx4HI= X-Received: by 2002:a17:90b:234a:b0:267:f758:15d4 with SMTP id ms10-20020a17090b234a00b00267f75815d4mr8076925pjb.48.1690823496680; Mon, 31 Jul 2023 10:11:36 -0700 (PDT) MIME-Version: 1.0 References: <20230731053412.2102672-1-apinski@marvell.com> <20230731053412.2102672-2-apinski@marvell.com> In-Reply-To: From: Andrew Pinski Date: Mon, 31 Jul 2023 10:11:24 -0700 Message-ID: Subject: Re: [PATCH 2/2] MATCH: Add `a == b | a cmp b` and `a != b & a cmp b` simplifications To: Richard Biener Cc: Andrew Pinski , gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.8 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 Mon, Jul 31, 2023 at 3:53=E2=80=AFAM Richard Biener via Gcc-patches wrote: > > On Mon, Jul 31, 2023 at 7:35=E2=80=AFAM Andrew Pinski via Gcc-patches > wrote: > > > > Even though these are done by combine_comparisons, we can add them to m= atch > > to allow simplifcations during match rather than just during reassoc/if= combine. > > > > OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. > > OK. Note we want to get rid of the GENERIC folding parts of > maybe_fold_{and,or}_comparisons which is what those passes rely on. Yes that was the idea here but there are still a few more cases that need to be handled: Floating point, and some integer constants due to `a <=3D 1` changing to `a < 0`. Thanks, Andrew > > Richard. > > > gcc/ChangeLog: > > > > PR tree-optimization/106164 > > * match.pd (`a !=3D b & a <=3D b`, `a !=3D b & a >=3D b`, > > `a =3D=3D b | a < b`, `a =3D=3D b | a > b`): Handle these cases > > too. > > > > gcc/testsuite/ChangeLog: > > > > PR tree-optimization/106164 > > * gcc.dg/tree-ssa/cmpbit-2.c: New test. > > --- > > gcc/match.pd | 32 +++++++++++++++++-- > > gcc/testsuite/gcc.dg/tree-ssa/cmpbit-2.c | 39 ++++++++++++++++++++++++ > > 2 files changed, 69 insertions(+), 2 deletions(-) > > create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/cmpbit-2.c > > > > diff --git a/gcc/match.pd b/gcc/match.pd > > index 00af5d99119..cf8057701ea 100644 > > --- a/gcc/match.pd > > +++ b/gcc/match.pd > > @@ -2832,7 +2832,21 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > > (switch > > (if (code1 =3D=3D EQ_EXPR && val) @3) > > (if (code1 =3D=3D EQ_EXPR && !val) { constant_boolean_node (fals= e, type); }) > > - (if (code1 =3D=3D NE_EXPR && !val) @4))))))) > > + (if (code1 =3D=3D NE_EXPR && !val) @4) > > + (if (code1 =3D=3D NE_EXPR > > + && code2 =3D=3D GE_EXPR > > + && cmp =3D=3D 0) > > + (gt @0 @1)) > > + (if (code1 =3D=3D NE_EXPR > > + && code2 =3D=3D LE_EXPR > > + && cmp =3D=3D 0) > > + (lt @0 @1)) > > + ) > > + ) > > + ) > > + ) > > + ) > > +) > > > > /* Convert (X OP1 CST1) && (X OP2 CST2). > > Convert (X OP1 Y) && (X OP2 Y). */ > > @@ -2917,7 +2931,21 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > > (switch > > (if (code1 =3D=3D EQ_EXPR && val) @4) > > (if (code1 =3D=3D NE_EXPR && val) { constant_boolean_node (true,= type); }) > > - (if (code1 =3D=3D NE_EXPR && !val) @3))))))) > > + (if (code1 =3D=3D NE_EXPR && !val) @3) > > + (if (code1 =3D=3D EQ_EXPR > > + && code2 =3D=3D GT_EXPR > > + && cmp =3D=3D 0) > > + (ge @0 @1)) > > + (if (code1 =3D=3D EQ_EXPR > > + && code2 =3D=3D LT_EXPR > > + && cmp =3D=3D 0) > > + (le @0 @1)) > > + ) > > + ) > > + ) > > + ) > > + ) > > +) > > > > /* Convert (X OP1 CST1) || (X OP2 CST2). > > Convert (X OP1 Y) || (X OP2 Y). */ > > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/cmpbit-2.c b/gcc/testsuite/g= cc.dg/tree-ssa/cmpbit-2.c > > new file mode 100644 > > index 00000000000..c4226ef01af > > --- /dev/null > > +++ b/gcc/testsuite/gcc.dg/tree-ssa/cmpbit-2.c > > @@ -0,0 +1,39 @@ > > +/* { dg-do compile } */ > > +/* { dg-options "-O1 -fno-tree-reassoc -fdump-tree-optimized-raw" } */ > > + > > +_Bool f(int a, int b) > > +{ > > + _Bool c =3D a =3D=3D b; > > + _Bool d =3D a > b; > > + return c | d; > > +} > > + > > +_Bool f1(int a, int b) > > +{ > > + _Bool c =3D a !=3D b; > > + _Bool d =3D a >=3D b; > > + return c & d; > > +} > > + > > +_Bool g(int a, int b) > > +{ > > + _Bool c =3D a =3D=3D b; > > + _Bool d =3D a < b; > > + return c | d; > > +} > > + > > +_Bool g1(int a, int b) > > +{ > > + _Bool c =3D a !=3D b; > > + _Bool d =3D a <=3D b; > > + return c & d; > > +} > > + > > + > > +/* We should be able to optimize these without reassociation too. */ > > +/* { dg-final { scan-tree-dump-not "bit_and_expr," "optimized" } } */ > > +/* { dg-final { scan-tree-dump-not "bit_ior_expr," "optimized" } } */ > > +/* { dg-final { scan-tree-dump-times "gt_expr," 1 "optimized" } } */ > > +/* { dg-final { scan-tree-dump-times "ge_expr," 1 "optimized" } } */ > > +/* { dg-final { scan-tree-dump-times "lt_expr," 1 "optimized" } } */ > > +/* { dg-final { scan-tree-dump-times "le_expr," 1 "optimized" } } */ > > -- > > 2.31.1 > >