From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by sourceware.org (Postfix) with ESMTPS id 2E2493858405 for ; Fri, 22 Jul 2022 20:16:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2E2493858405 Received: by mail-pj1-x1030.google.com with SMTP id v16-20020a17090abb9000b001f25244c65dso1701245pjr.2 for ; Fri, 22 Jul 2022 13:16:35 -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; bh=lsSYLHkdPnBoobAx6G/0N85e0JR3i5xRf2XQZJF0WSk=; b=DxoO/eHz8Cwx3gEvQQeHjjOlpPviNN78FS5qY+PY0XwY72GkcG0350D/dMDya2bn+X 6PbVk9aOcnlrgCm/NWgMz/pq6ANgQefoXEGA6EWoYFbwljUJ+Ckbd/Bj5YxWKWA5qyPC mq9awAjLP9cIORYB5gXnDYFoZjyALPZcLh9NsEarAiSmh4nV/UN3e211FM7fFz0Ok+xL 7P/6g5cpCJaO18XCZ6uIpIz0BfU8Tny8+kR1lI7Jb9de/JSJuItyW6ZcgOERiuzxuMJJ UV+1HZN0cdvt9VbVgUpTYqdRZ1mvqRqVBDqyw1cXYxqcQrykLhkDPiSi6LE1gC0w1g8Q oamA== X-Gm-Message-State: AJIora90peH/NdlQcxC3sHPr+r51I1C6VMwPWdX4EsS0bT91wR2dgIgi rORq8ChoRwVJZJKaNDVlpFG/Es5XxAB6Q9N0GOk= X-Google-Smtp-Source: AGRyM1uo9O1rGEs0ST5iTY78HlQK0UGsKKEvGy6epYD8FM0xoL0jFIig38DHSDWbjoD3wbUgYdONnoXNMOeV4wxBUKo= X-Received: by 2002:a17:90a:ba82:b0:1f2:5708:e796 with SMTP id t2-20020a17090aba8200b001f25708e796mr2339950pjr.10.1658520993906; Fri, 22 Jul 2022 13:16:33 -0700 (PDT) MIME-Version: 1.0 References: <20220721112338.7CEC113A1B@imap2.suse-dmz.suse.de> In-Reply-To: <20220721112338.7CEC113A1B@imap2.suse-dmz.suse.de> From: "H.J. Lu" Date: Fri, 22 Jul 2022 13:15:58 -0700 Message-ID: Subject: Re: [PATCH] tree-optimization/106379 - add missing ~(a ^ b) folding for _Bool To: Richard Biener Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3024.1 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: Fri, 22 Jul 2022 20:16:36 -0000 On Thu, Jul 21, 2022 at 4:24 AM Richard Biener via Gcc-patches wrote: > > The following makes sure to fold ~(a ^ b) to a == 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 == !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 == 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 == 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? > /* (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 == !b; > +} > + > +/* { dg-final { scan-tree-dump "\[ab\]_\[0-9\]+\\(D\\) == \[ba\]_\[0-9\]+\\(D\\)" "forwprop1" } } */ > -- > 2.35.3 -- H.J.