public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <jeffreyalaw@gmail.com>
To: Victor Tong <vitong@microsoft.com>,
	"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
	"pinskia@gcc.gnu.org" <pinskia@gcc.gnu.org>
Subject: Re: [PATCH] Propagate get_nonzero_bits information in division [PR77980]
Date: Sun, 22 Aug 2021 21:11:07 -0600	[thread overview]
Message-ID: <110f4be7-8be8-a5ab-5637-e7717a4a1d35@gmail.com> (raw)
In-Reply-To: <MWHPR2101MB0811F1402244BB86625AAB0ACCE99@MWHPR2101MB0811.namprd21.prod.outlook.com>



On 7/26/2021 6:45 PM, Victor Tong via Gcc-patches wrote:
> This change enables the "t1 != 0" check to be optimized away in this code:
>
> int x1 = 0;
> unsigned int x2 = 1;
>
> int main ()
> {
>      int t1 = x1*(1/(x2+x2));
>      if (t1 != 0) __builtin_abort();
>      return 0;
> }
>
> The change utilizes the VRP framework to propagate the get_nonzero_bits information from the "x2+x2" expression to the "1/(x2+x2)" division expression. Specifically, the framework knows that the least significant bit of the "x2+x2" expression must be zero.
>
> The get_nonzero_bits information of the left hand side and right hand side of expressions needed to be passed down to operator_div::wi_fold() in the VRP framework. The majority of this change involves adding two additional parameters to propagate this information. There are future opportunities to use the non zero bit information to perform better optimizations in other types of expressions.
>
> The changes were tested against x86_64-pc-linux-gnu and all tests in "make -k check" passed.
>
> The original approach was to implement a match.pd pattern to support this but the pattern wasn't being triggered. More context is available in: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77980
So you're going to want to sync with Aldy & Andrew as they're the 
experts on the Ranger design & implementation.  This hits the Ranger API 
as well as design questions about how best to tie in the nonzero_bits 
capabilities.

You might also want to reach out to Roger Sayle.  He's been poking 
around in a closely related area, though more focused on the bitwise 
conditional constant propagation rather than Ranger/VRP.  In fact, I 
just acked a patch of his that looks closely related.

https://gcc.gnu.org/pipermail/gcc-patches/2021-August/577888.html

Jeff

  reply	other threads:[~2021-08-23  3:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-27  0:45 Victor Tong
2021-08-23  3:11 ` Jeff Law [this message]
2021-08-30 20:33   ` [EXTERNAL] " Victor Tong

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=110f4be7-8be8-a5ab-5637-e7717a4a1d35@gmail.com \
    --to=jeffreyalaw@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=pinskia@gcc.gnu.org \
    --cc=vitong@microsoft.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).