From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by sourceware.org (Postfix) with ESMTPS id 6D98A3858031 for ; Mon, 22 Nov 2021 11:34:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6D98A3858031 Received: by mail-ed1-x52d.google.com with SMTP id r11so75333414edd.9 for ; Mon, 22 Nov 2021 03:34:19 -0800 (PST) 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=36m7rsgcIdUvj4VSLp4EACEIuYpwUHJwUooDaHYbtp0=; b=jnOp9AN3JOLzYJTiJyjQJH6Q2uSKAMecrwookAqHn1UbYf1o2b61qBQoarJROd00tj BW37b6VBoU527H13AKGqJV4e+bP676Soc5tnmlIWJ7TYU1VVa5lkaWbFNHXAmFR+N+nv jVlTSJfRs2bkpNSJU9kqPYcGaKnJhosfKqPi4YeHpHFZYLl0KeuFndDUKwovGe2rVS++ ZMS2CfoU0Y8Xow0uRYlF9umDWFKVJO9f9ijdNx68sAnwmYzY2SsUpZHhl0cXiokXLoT7 9EWBQE+jpNewcX7d/Hxw9t8wyQRGloaGSwIFpnhZjsDbUisihxZGUwa/p2CM/UOTaLKe KgGg== X-Gm-Message-State: AOAM5337Z6XWqgR98qWRN64NTPq/4XHP2g8aJEK3IEbq2fop5xpZ7dH3 L1h6QKBCzduJUcCleorlft8P9QOdiO7WnaApUFI= X-Google-Smtp-Source: ABdhPJyoalasZ5abSH0Czypweb3SttAskXCTWnO+eIOBipSXTL60VAD4B0KsoVBzrXC5qYezTyvWIGsRWYT09xyB+Ms= X-Received: by 2002:a17:906:c301:: with SMTP id s1mr39269393ejz.56.1637580858360; Mon, 22 Nov 2021 03:34:18 -0800 (PST) MIME-Version: 1.0 References: <1637562290-15155-1-git-send-email-apinski@marvell.com> <1637562290-15155-2-git-send-email-apinski@marvell.com> In-Reply-To: <1637562290-15155-2-git-send-email-apinski@marvell.com> From: Richard Biener Date: Mon, 22 Nov 2021 12:34:07 +0100 Message-ID: Subject: Re: [PATCH 2/2] tree-optimization: [PR92342] Move b & -(a==c) optimization to the gimple level To: Andrew Pinski Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.5 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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, 22 Nov 2021 11:34:20 -0000 On Mon, Nov 22, 2021 at 7:26 AM apinski--- via Gcc-patches wrote: > > From: Andrew Pinski > > Combine disabled this optimization in r10-254-gddbb5da5199fb42 but it makes > sense to do this on the gimple level and then let expand decide which way is > better. So this adds the transformation on the gimple level (late like was > done for the multiply case). > > OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. > > PR tree-optimization/92342 > > gcc/ChangeLog: > > * match.pd (b & -(a CMP c) -> (a CMP c)?b:0): New pattern. > > gcc/testsuite/ChangeLog: > > * gcc.dg/tree-ssa/andnegcmp-1.c: New test. > * gcc.dg/tree-ssa/andnegcmp-2.c: New test. > --- > gcc/match.pd | 8 +++++++- > gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-1.c | 14 ++++++++++++++ > gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-2.c | 14 ++++++++++++++ > 3 files changed, 35 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-1.c > create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-2.c > > diff --git a/gcc/match.pd b/gcc/match.pd > index ed43c321cbc..b55cbc91b57 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -1794,7 +1794,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > (for cmp (tcc_comparison) > (simplify > (mult:c (convert (cmp @0 @1)) @2) > - (cond (cmp @0 @1) @2 { build_zero_cst (type); })))) > + (cond (cmp @0 @1) @2 { build_zero_cst (type); })) > +/* (-(m1 CMP m2)) & d -> (m1 CMP m2) ? d : 0 */ > + (simplify > + (bit_and:c (negate (convert (cmp @0 @1))) @2) I think you need to guard against signed bools (and vector compares, and allow view_convert for vector compare results?)? > + (cond (cmp @0 @1) @2 { build_zero_cst (type); })) > + ) > +) > > /* For integral types with undefined overflow and C != 0 fold > x * C EQ/NE y * C into x EQ/NE y. */ > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-1.c b/gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-1.c > new file mode 100644 > index 00000000000..6f16783f169 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-1.c > @@ -0,0 +1,14 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-optimized" } */ > +/* PR tree-optimization/92342 */ > + > +int > +f (int m1, int m2, int c) > +{ > + int d = m1 == m2; > + d = -d; > + int e = d & c; > + return e; > +} > + > +/* { dg-final { scan-tree-dump-times "\\? c_\[0-9\]\\(D\\) : 0" 1 "optimized" } } */ > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-2.c b/gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-2.c > new file mode 100644 > index 00000000000..0e25c8abc39 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-2.c > @@ -0,0 +1,14 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-optimized" } */ > +/* PR tree-optimization/92342 */ > + > +int > +f (int m1, int m2, int c) > +{ > + int d = m1 < m2; > + d = -d; > + int e = c & d; > + return e; > +} > + > +/* { dg-final { scan-tree-dump-times "\\? c_\[0-9\]\\(D\\) : 0" 1 "optimized" } } */ > -- > 2.17.1 >