From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by sourceware.org (Postfix) with ESMTPS id 4315E3875A31 for ; Mon, 25 Jul 2022 14:06:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4315E3875A31 Received: by mail-pj1-x1031.google.com with SMTP id b10so10561817pjq.5 for ; Mon, 25 Jul 2022 07:06:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=K5HeP5wGPnjkDqmKh30LmnWymj9PYiO20T40T4cereo=; b=tOulppF+IlaJlDk3U10CjcjHFYlJ5JMyLP/2Mg/eG8xMBOJeqDHMmX5T8Ig9NrRaCr cijY+JAwNEnFL6Pc7L1Ki9WjQ4YKel/u1GtfsJ0/dE9Bl4zCYwy4HcrTPTcupemrOvLb WdwFRAsgsQ88OPFzXVpMGGyzofikmklh5aBXKZ2c0cvHah8RDzPf5q09boSPjzNlxsWy 1eE65yHsjjIhAHU6AMivi1QXOHqDdZPawrIHPXGglMjnEL2aSBaNUeT/ypt1UdY7YOJd R6DIgi5RWEUbid3rUiDNEm+7wb76hilVmg4osxRev7d5FGiXj/C6OVkowxZEb7uOJguj 2ezQ== X-Gm-Message-State: AJIora8RNotWD6f15SuE8vGL05jNAtu5XvK/gxwebvLfzLE9sAw62iFW BOrSDGV1RCIfhq2GfCc9eFawTGo9XppMtE9Kxug= X-Google-Smtp-Source: AGRyM1skrpkjx8PjOqIr9YbvKsv40fSQSJ97pKP8+gDowhMEall8j/9HGmWGaJCmxg998U5wiPItaAfNrcwN1uetuLY= X-Received: by 2002:a17:903:2406:b0:16d:6b7a:57c6 with SMTP id e6-20020a170903240600b0016d6b7a57c6mr6800319plo.149.1658757987953; Mon, 25 Jul 2022 07:06:27 -0700 (PDT) MIME-Version: 1.0 References: <2EE7DF73-91E1-40BB-B52A-D7FAF2A57B10@suse.de> In-Reply-To: <2EE7DF73-91E1-40BB-B52A-D7FAF2A57B10@suse.de> From: "H.J. Lu" Date: Mon, 25 Jul 2022 07:05:52 -0700 Message-ID: Subject: Re: [PATCH] tree-optimization/106379 - add missing ~(a ^ b) folding for _Bool To: Richard Biener Cc: "H.J. Lu via Gcc-patches" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3024.6 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 autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Jul 2022 14:06:30 -0000 On Fri, Jul 22, 2022 at 11:10 PM Richard Biener via Gcc-patches wrote: > > > > > Am 22.07.2022 um 22:17 schrieb H.J. Lu via Gcc-patches : > > > > =EF=BB=BFOn Thu, Jul 21, 2022 at 4:24 AM Richard Biener via Gcc-patches > > wrote: > >> > >> The following makes sure to fold ~(a ^ b) to a =3D=3D b for truth > >> values (but not vectors, we'd have to check for vector support of > >> equality). That turns the PR106379 testcase into a ranger one. > >> > >> Note that while we arrive at ~(a ^ b) in a convoluted way from > >> original !a =3D=3D !b one can eventually write the expression this > >> way directly as well. > >> > >> Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. > >> > >> PR tree-optimization/106379 > >> * match.pd (~(a ^ b) -> a =3D=3D b): New pattern. > >> > >> * gcc.dg/pr106379-1.c: New testcase. > >> --- > >> gcc/match.pd | 6 ++++++ > >> gcc/testsuite/gcc.dg/pr106379-1.c | 9 +++++++++ > >> 2 files changed, 15 insertions(+) > >> create mode 100644 gcc/testsuite/gcc.dg/pr106379-1.c > >> > >> diff --git a/gcc/match.pd b/gcc/match.pd > >> index 8bbc0dbd5cd..88a1a5aa9cc 100644 > >> --- a/gcc/match.pd > >> +++ b/gcc/match.pd > >> @@ -1938,6 +1938,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > >> (if (tree_nop_conversion_p (type, TREE_TYPE (@0))) > >> (bit_not (bit_xor (view_convert @0) @1)))) > >> > >> +/* ~(a ^ b) is a =3D=3D b for truth valued a and b. */ > >> +(simplify > >> + (bit_not (bit_xor:s truth_valued_p@0 truth_valued_p@1)) > >> + (if (!VECTOR_TYPE_P (type)) > >> + (convert (eq @0 @1)))) > > > > For integers, isn't it wrong to convert ~(boolean exp) to boolean exp? > > That=E2=80=99s what the (convert. =E2=80=A6) should compensate for? Is ~(boolean exp) =3D=3D ~((int) (boolean exp)) or (int) (~(boolean exp))? > Richard > > > > >> /* (x & ~m) | (y & m) -> ((x ^ y) & m) ^ x */ > >> (simplify > >> (bit_ior:c (bit_and:cs @0 (bit_not @2)) (bit_and:cs @1 @2)) > >> diff --git a/gcc/testsuite/gcc.dg/pr106379-1.c b/gcc/testsuite/gcc.dg/= pr106379-1.c > >> new file mode 100644 > >> index 00000000000..7f2575e02dc > >> --- /dev/null > >> +++ b/gcc/testsuite/gcc.dg/pr106379-1.c > >> @@ -0,0 +1,9 @@ > >> +/* { dg-do compile } */ > >> +/* { dg-options "-O -fdump-tree-forwprop1" } */ > >> + > >> +_Bool foo (_Bool a, _Bool b) > >> +{ > >> + return !a =3D=3D !b; > >> +} > >> + > >> +/* { dg-final { scan-tree-dump "\[ab\]_\[0-9\]+\\(D\\) =3D=3D \[ba\]_= \[0-9\]+\\(D\\)" "forwprop1" } } */ > >> -- > >> 2.35.3 > > > > > > > > -- > > H.J. --=20 H.J.