public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@redhat.com>
To: GCC patches <gcc-patches@gcc.gnu.org>
Cc: Andrew MacLeod <amacleod@redhat.com>,
	drepper@redhat.com, Aldy Hernandez <aldyh@redhat.com>
Subject: [COMMITTED] [PR tree-optimization/107052] range-ops: Pass nonzero masks through cast.
Date: Wed,  5 Oct 2022 14:22:35 +0200	[thread overview]
Message-ID: <20221005122236.1579762-1-aldyh@redhat.com> (raw)

Track nonzero masks through a cast in range-ops.

We could also track through a truncating cast if the mask fits in the
outer type.  I will do that as a follow-up patch because I already have
this patchset tested.

	PR tree-optimization/107052

gcc/ChangeLog:

	* range-op.cc (operator_cast::fold_range): Set nonzero mask.
---
 gcc/range-op.cc | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 4f647abd91c..6fa27a8904e 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -2515,6 +2515,14 @@ operator_cast::fold_range (irange &r, tree type ATTRIBUTE_UNUSED,
       if (r.varying_p ())
 	return true;
     }
+
+  // Pass nonzero mask through the cast.
+  if (!truncating_cast_p (inner, outer))
+    {
+      wide_int nz = inner.get_nonzero_bits ();
+      nz = wide_int::from (nz, TYPE_PRECISION (type), TYPE_SIGN (inner.type ()));
+      r.set_nonzero_bits (nz);
+    }
   return true;
 }
 
-- 
2.37.1


             reply	other threads:[~2022-10-05 12:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-05 12:22 Aldy Hernandez [this message]
2022-10-05 12:22 ` [COMMITTED] [PR tree-optimization/107052] range-ops: Take into account nonzero mask in popcount Aldy Hernandez
  -- strict thread matches above, loose matches on Subject: below --
2022-10-05 12:21 [COMMITTED] [PR tree-optimization/107052] range-ops: Pass nonzero masks through cast Aldy Hernandez

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=20221005122236.1579762-1-aldyh@redhat.com \
    --to=aldyh@redhat.com \
    --cc=amacleod@redhat.com \
    --cc=drepper@redhat.com \
    --cc=gcc-patches@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).