From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) by sourceware.org (Postfix) with ESMTPS id 36C093857BB9 for ; Mon, 20 Jun 2022 08:03:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 36C093857BB9 Received: by mail-qv1-xf31.google.com with SMTP id o43so14895997qvo.4 for ; Mon, 20 Jun 2022 01:03:41 -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=QwIPzcINQgN3YHdzYwQBuTzjA+5Uy5RInaCBkEmXfeI=; b=Q7/P210LnZ3jSNbNbwm19TQKYf4GZGAdn2GQMyY8oJYF3pshVyU5DLMjs68hQk/wpe wBBu1nsDPw8Dmg34kh+pEDdWaEehqwFlUPt1rHzIxHwUQnJI/g5Cp8/gvwssWPIVCFkT rd9x/cY4LUqPQUM33x18hX9EaZPXKjgGuM/andT3Co8IMP+Y2Ojcv51Q4uMjbcmw7UPD Sm1LUqfTlGGnraIp3LKLFzhCHMk7iqX42cQon35VJjPk+EnJXOEdShmELHc2yCdi3iQu 2jY/bOw1b7bLOkF1RfL7C3q2Hl0Z6xCDTEh2Rb4VrkhuQpNIJPFD3Hb3b3FpUhDx2GF0 mffA== X-Gm-Message-State: AJIora8CUmwONPUPbtLabFJSF7KPH4VOKYN7DWqJzkW29g93IbMk6nGz nhSrs7jnMswLz0UHcdXxj+HT1/yBJdp0W74e7og= X-Google-Smtp-Source: AGRyM1tNAm8UxwYsmDRFnFiDU93sFJVX/U7o3W+kuPGfYvT3YeCWawdGNkbGNgluw/fG7hjQmAGn2H8RG4GtaNlY+S0= X-Received: by 2002:ac8:5b50:0:b0:305:320d:c143 with SMTP id n16-20020ac85b50000000b00305320dc143mr18736649qtw.626.1655712220652; Mon, 20 Jun 2022 01:03:40 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Richard Biener Date: Mon, 20 Jun 2022 10:03:29 +0200 Message-ID: Subject: Re: [PATCH 1/2]middle-end: Simplify subtract where both arguments are being bitwise inverted. To: Tamar Christina Cc: GCC Patches , nd , Richard Guenther Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, LOTS_OF_MONEY, 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 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, 20 Jun 2022 08:03:48 -0000 On Thu, Jun 16, 2022 at 1:10 PM Tamar Christina via Gcc-patches wrote: > > Hi All, > > This adds a match.pd rule that drops the bitwwise nots when both arguments to a > subtract is inverted. i.e. for: > > float g(float a, float b) > { > return ~(int)a - ~(int)b; > } > > we instead generate > > float g(float a, float b) > { > return (int)a - (int)b; > } > > We already do a limited version of this from the fold_binary fold functions but > this makes a more general version in match.pd that applies more often. > > Bootstrapped Regtested on aarch64-none-linux-gnu and no issues. > > Ok for master? > > Thanks, > Tamar > > gcc/ChangeLog: > > * match.pd: New bit_not rule. > > gcc/testsuite/ChangeLog: > > * gcc.dg/subnot.c: New test. > > --- inline copy of patch -- > diff --git a/gcc/match.pd b/gcc/match.pd > index a59b6778f661cf9121dd3503f43472871e4da445..51b0a1b562409af535e53828a10c30b8a3e1ae2e 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -1258,6 +1258,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > (simplify > (bit_not (plus:c (bit_not @0) @1)) > (minus @0 @1)) > +/* (~X - ~Y) -> X - Y. */ > +(simplify > + (minus (bit_not @0) (bit_not @1)) > + (minus @0 @1)) It doesn't seem correct. (gdb) p/x ~-1 - ~0x80000000 $3 = 0x80000001 (gdb) p/x -1 - 0x80000000 $4 = 0x7fffffff where I was looking for a case exposing undefined integer overflow. Richard. > > /* ~(X - Y) -> ~X + Y. */ > (simplify > diff --git a/gcc/testsuite/gcc.dg/subnot.c b/gcc/testsuite/gcc.dg/subnot.c > new file mode 100644 > index 0000000000000000000000000000000000000000..d621bacd27bd3d19a010e4c9f831aa77d28bd02d > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/subnot.c > @@ -0,0 +1,9 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O -fdump-tree-optimized" } */ > + > +float g(float a, float b) > +{ > + return ~(int)a - ~(int)b; > +} > + > +/* { dg-final { scan-tree-dump-not "~" "optimized" } } */ > > > > > --