From: Aldy Hernandez <aldyh@redhat.com>
To: GCC patches <gcc-patches@gcc.gnu.org>
Cc: Andrew MacLeod <amacleod@redhat.com>, Aldy Hernandez <aldyh@redhat.com>
Subject: [COMMITTED] [range-ops] Remove special case for handling bitmasks in casts.
Date: Wed, 26 Jul 2023 13:35:54 +0200 [thread overview]
Message-ID: <20230726113557.97035-1-aldyh@redhat.com> (raw)
Now that we can generically handle bitmasks for unary operators,
there's no need to special case them.
gcc/ChangeLog:
* range-op-mixed.h (class operator_cast): Add update_bitmask.
* range-op.cc (operator_cast::update_bitmask): New.
(operator_cast::fold_range): Call update_bitmask.
---
gcc/range-op-mixed.h | 2 ++
gcc/range-op.cc | 23 ++++++++---------------
2 files changed, 10 insertions(+), 15 deletions(-)
diff --git a/gcc/range-op-mixed.h b/gcc/range-op-mixed.h
index 6944742ecbc..91a4fcc3989 100644
--- a/gcc/range-op-mixed.h
+++ b/gcc/range-op-mixed.h
@@ -346,6 +346,8 @@ public:
relation_kind lhs_op1_relation (const irange &lhs,
const irange &op1, const irange &op2,
relation_kind) const final override;
+ void update_bitmask (irange &r, const irange &lh,
+ const irange &rh) const final override;
private:
bool truncating_cast_p (const irange &inner, const irange &outer) const;
bool inside_domain_p (const wide_int &min, const wide_int &max,
diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 6b5d4f2accd..be8f8c48d7c 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -2867,24 +2867,17 @@ operator_cast::fold_range (irange &r, tree type ATTRIBUTE_UNUSED,
return true;
}
- // Update the bitmask. Truncating casts are problematic unless
- // the conversion fits in the resulting outer type.
- irange_bitmask bm = inner.get_bitmask ();
- if (truncating_cast_p (inner, outer)
- && wi::rshift (bm.mask (),
- wi::uhwi (TYPE_PRECISION (outer.type ()),
- TYPE_PRECISION (inner.type ())),
- TYPE_SIGN (inner.type ())) != 0)
- return true;
- unsigned prec = TYPE_PRECISION (type);
- signop sign = TYPE_SIGN (inner.type ());
- bm = irange_bitmask (wide_int::from (bm.value (), prec, sign),
- wide_int::from (bm.mask (), prec, sign));
- r.update_bitmask (bm);
-
+ update_bitmask (r, inner, outer);
return true;
}
+void
+operator_cast::update_bitmask (irange &r, const irange &lh,
+ const irange &rh) const
+{
+ update_known_bitmask (r, CONVERT_EXPR, lh, rh);
+}
+
bool
operator_cast::op1_range (irange &r, tree type,
const irange &lhs,
--
2.41.0
reply other threads:[~2023-07-26 11:36 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=20230726113557.97035-1-aldyh@redhat.com \
--to=aldyh@redhat.com \
--cc=amacleod@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).