From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by sourceware.org (Postfix) with ESMTPS id DA1833858C52 for ; Fri, 26 Aug 2022 08:38:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DA1833858C52 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-ej1-x635.google.com with SMTP id lx1so1796670ejb.12 for ; Fri, 26 Aug 2022 01:38:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=DDoFWAFfbQqGolBTcj/f6RwkYvOLNom7RTU4k8fn4C0=; b=i5bhLg7Vq3FHaGFZNMPN25ynXwCX19fNb/IGHHcqQmsudZCSWv1TvADC7EsgCwb5Sz WzCd3Xy4FeSQhPlQ8MXUwhY1u/tPCAHiITETYBIBSloTnTxGa8ye52EyrYVHLZx4wwCY VfNWBT50IPx61qDGd3J05n3bAB62H593JW/02xxpkm9UAKqzTdyRpKrBPWepOg+Od29R L+vPQW5wP2DfM8DO6jZocFeQ8QYf16gBUFyOWFAjZlkXnnmlPgsxvb3blF3cev3eFn4K XdimqHhsNThN7gM1G1RTOI9Wl1MWWz1vDySLBLe/8iczTSjPzVCcQjetcndcPIIjyKyz M/XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=DDoFWAFfbQqGolBTcj/f6RwkYvOLNom7RTU4k8fn4C0=; b=u6WgqDw0vO53du66d6mwXYjpROGknw+O+PyB7NMnGH5iHubRNWZ7QFTYCSOTCmeSOb Zx53qTV6+jVmyTccigSKvGZgUWXGKxOXylsKkob57Geu5rI6AZH4iTEgW5BkIg5qewF0 ejOAKeyOgHYo/pkRy2LB1QbL1C+uOh1lQQeDkYLGYFDFO7sJPz3KzrWotqvJA11fHIII cT+W5wYobGxaZut6umiP3kt/3eIEKGZpIAjWK+cUJgb4/uBHs8v96qamj+uSeYs2peIq ITyhjG5GSnAej4g1XkU2Tji5QdEw8JCNmc554oZrdjnQNvfOM80XM8WIy4qTtXMbxPOZ bMrg== X-Gm-Message-State: ACgBeo3OXDy12zMOTgjRxKrubnmqVSU7XKZFovAfIzvEg1XzxNV06js6 zOYo6GQhGV8EjYq/+ZXrsh46Y3vzIU0JRTLfQ2s= X-Google-Smtp-Source: AA6agR4W55tm69HIJQY0p9Jaz4OZV3ZJ/ZuQlX7j/0JeznQ+NtwdsYnqVOSKFEP+NJBsL+giWe1ApZ7V+3N5vgxl0U8= X-Received: by 2002:a17:907:3e12:b0:738:fd2f:df80 with SMTP id hp18-20020a1709073e1200b00738fd2fdf80mr5047338ejc.29.1661503135579; Fri, 26 Aug 2022 01:38:55 -0700 (PDT) MIME-Version: 1.0 References: <20220810171000.2855425-1-sfeifer@redhat.com> In-Reply-To: <20220810171000.2855425-1-sfeifer@redhat.com> From: Richard Biener Date: Fri, 26 Aug 2022 10:38:43 +0200 Message-ID: Subject: Re: [PATCH] match.pd: Add abs with bitwise and pattern [PR106243] To: Sam Feifer Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.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,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 Wed, Aug 10, 2022 at 7:11 PM Sam Feifer via Gcc-patches wrote: > > This patch adds a simplification to match.pd that was discussed on the > thread for pr106243. It simplifies the pattern, abs(x) & 1, to x & 1. > > There are also tests for the simplification in this patch. I couldn't > figure out how to get abs to work with vectors. If a test for that is > necessary, could I get some guidance on using abs with vector types? > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? OK, and sorry for the delay. Thanks, Richard. > PR tree-optimization/106243 > > gcc/ChangeLog: > > * match.pd (abs(x) & 1): New simplification. > > gcc/testsuite/ChangeLog: > > * gcc.dg/pr106243-2.c: New test. > * gcc.dg/pr106243-3.c: New test. > --- > gcc/match.pd | 5 +++++ > gcc/testsuite/gcc.dg/pr106243-2.c | 31 +++++++++++++++++++++++++++++++ > gcc/testsuite/gcc.dg/pr106243-3.c | 18 ++++++++++++++++++ > 3 files changed, 54 insertions(+) > create mode 100644 gcc/testsuite/gcc.dg/pr106243-2.c > create mode 100644 gcc/testsuite/gcc.dg/pr106243-3.c > > diff --git a/gcc/match.pd b/gcc/match.pd > index f82f94ad1fe..c04e70f34c1 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -8071,3 +8071,8 @@ and, > (simplify > (bit_and (negate @0) integer_onep@1) > (bit_and @0 @1)) > + > +/* abs(x) & 1 -> x & 1. */ > +(simplify > + (bit_and (abs @0) integer_onep@1) > + (bit_and @0 @1)) > diff --git a/gcc/testsuite/gcc.dg/pr106243-2.c b/gcc/testsuite/gcc.dg/pr106243-2.c > new file mode 100644 > index 00000000000..27e66f59160 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr106243-2.c > @@ -0,0 +1,31 @@ > +/* PR tree-optimization/106243 */ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-optimized" } */ > + > +#include > + > +__attribute__((noipa)) int foo (int x) { > + return abs(x) & 1; > +} > + > +__attribute__((noipa)) int bar (int x) { > + return (0 - abs(x)) & 1; > +} > + > +/* Commutative property. */ > +__attribute__((noipa)) int baz (int x) { > + return 1 & abs(x); > +} > + > +/* Forward propogation. */ > +__attribute__((noipa)) int qux (int x) { > + int y = abs(x); > + return y & 1; > +} > + > +/* Should not simplify. */ > +__attribute__((noipa)) int thud (int x) { > + return abs(x) & -1; > +} > + > +/* { dg-final {scan-tree-dump-times " ABS_EXPR " 1 "optimized" } } */ > diff --git a/gcc/testsuite/gcc.dg/pr106243-3.c b/gcc/testsuite/gcc.dg/pr106243-3.c > new file mode 100644 > index 00000000000..68800868751 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr106243-3.c > @@ -0,0 +1,18 @@ > +/* PR tree-optimization/106243 */ > +/* { dg-do run } */ > +/* { dg-options "-O2" } */ > + > +#include "pr106243-2.c" > + > +int main () { > + > + if (foo(6) != 0 > + || bar(-3) != 1 > + || baz(32) != 0 > + || qux(-128) != 0 > + || foo (127) != 1) { > + __builtin_abort(); > + } > + > + return 0; > +} > > base-commit: be58bf98e98bb431ed26ca8be84586075fe8be82 > -- > 2.31.1 >