public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Roger Sayle <roger@nextmovesoftware.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Improved handling of MINUS_EXPR in bit CCP.
Date: Tue, 17 Aug 2021 12:17:20 +0200	[thread overview]
Message-ID: <CAFiYyc1Mmt96NM_WMv21Lz8EWK90z4n2M9OX6NbZMx1F8OHY4g@mail.gmail.com> (raw)
In-Reply-To: <050001d78f5f$b7d650e0$2782f2a0$@nextmovesoftware.com>

On Thu, Aug 12, 2021 at 11:52 AM Roger Sayle <roger@nextmovesoftware.com> wrote:
>
>
> This patch improves the bit bounds for MINUS_EXPR during tree-ssa's
> conditional constant propagation (CCP) pass (and as an added bonus
> adds support for POINTER_DIFF_EXPR).
>
> The pessimistic assumptions made by the current algorithm are
> demonstrated by considering 1 - (x&1).  Intuitively this should
> have possible values 0 and 1, and therefore an unknown mask of 1.
> Alas by treating subtraction as a negation followed by addition,
> the second operand first becomes 0 or -1, with an unknown mask
> of all ones, which results in the addition containing no known bits.
>
> Improved bounds are achieved by using the same approach used for
> PLUS_EXPR, determining the result with the minimum number of borrows,
> the result from the maximum number of borrows, and examining the bits
> they have in common.  One additional benefit of this approach
> is that it is applicable to POINTER_DIFF_EXPR, where previously the
> negation of a pointer didn't/doesn't make sense.
>
> A more convincing example, where a transformation missed by .032t.cpp
> isn't caught a few passes later by .038t.evrp, is the expression
> (7 - (x&5)) & 2, which (in the new test case) currently survives the
> tree-level optimizers but with this patch is now simplified to the
> constant value 2.
>
> This patch has been tested on x86_64-pc-linux-gnu with "make bootstrap"
> and "make -k check" with no new failures.
>
> Ok for mainline?

OK.

Thanks,
Richard.

> 2021-08-12  Roger Sayle  <roger@nextmovesoftware.com>
>
> gcc/ChangeLog
>         * tree-ssa-ccp.c (bit_value_binop) [MINUS_EXPR]: Use same
>         algorithm as PLUS_EXPR to improve subtraction bit bounds.
>         [POINTER_DIFF_EXPR]: Treat as synonymous with MINUS_EXPR.
>
> gcc/testsuite/ChangeLog
>         * gcc.dg/tree-ssa/ssa-ccp-40.c: New test case.
>
>
> Roger
> --
> Roger Sayle
> NextMove Software
> Cambridge, UK
>

      reply	other threads:[~2021-08-17 10:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-12  9:52 Roger Sayle
2021-08-17 10:17 ` Richard Biener [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFiYyc1Mmt96NM_WMv21Lz8EWK90z4n2M9OX6NbZMx1F8OHY4g@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=roger@nextmovesoftware.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).