public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-3027] Do not pessimize range in set_nonzero_bits.
Date: Mon,  3 Oct 2022 11:08:49 +0000 (GMT)	[thread overview]
Message-ID: <20221003110849.2E0AE385C40F@sourceware.org> (raw)

https://gcc.gnu.org/g:c0129d6b2a5f2b3cfedd213d48c95581f75312aa

commit r13-3027-gc0129d6b2a5f2b3cfedd213d48c95581f75312aa
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Sun Oct 2 10:46:47 2022 +0200

    Do not pessimize range in set_nonzero_bits.
    
    Currently if we have a range of [0,0] and we set the nonzero bits to
    1, the current code pessimizes the range to [0,1] because it assumes
    the range is [1,1] plus the possibility of 0.  This fixes the
    oversight.
    
    gcc/ChangeLog:
    
            * value-range.cc (irange::set_nonzero_bits): Do not pessimize range.
            (range_tests_nonzero_bits): New test.

Diff:
---
 gcc/value-range.cc | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index e1066f4946e..6e196574de9 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -2934,6 +2934,14 @@ irange::set_nonzero_bits (const wide_int_ref &bits)
   // range immediately.
   if (wi::popcount (bits) == 1)
     {
+      // Make sure we don't pessimize the range.
+      tree tbits = wide_int_to_tree (type (), bits);
+      if (!contains_p (tbits))
+	{
+	  set_nonzero_bits (tbits);
+	  return;
+	}
+
       bool has_zero = contains_p (build_zero_cst (type ()));
       set (type (), bits, bits);
       if (has_zero)
@@ -3628,6 +3636,11 @@ range_tests_nonzero_bits ()
   r1.set_nonzero_bits (0xff);
   r0.union_ (r1);
   ASSERT_TRUE (r0.varying_p ());
+
+  // Test that setting a nonzero bit of 1 does not pessimize the range.
+  r0.set_zero (integer_type_node);
+  r0.set_nonzero_bits (1);
+  ASSERT_TRUE (r0.zero_p ());
 }
 
 // Build an frange from string endpoints.

                 reply	other threads:[~2022-10-03 11:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20221003110849.2E0AE385C40F@sourceware.org \
    --to=aldyh@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).