public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Andrew Macleod <amacleod@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-5449] Use case label type to create case range.
Date: Tue, 14 Nov 2023 15:33:40 +0000 (GMT) [thread overview]
Message-ID: <20231114153340.DA8353858D35@sourceware.org> (raw)
https://gcc.gnu.org/g:8f331be42991aa4d58ac770faf993accfcce882b
commit r14-5449-g8f331be42991aa4d58ac770faf993accfcce882b
Author: Andrew MacLeod <amacleod@redhat.com>
Date: Mon Nov 13 09:58:10 2023 -0500
Use case label type to create case range.
Create a range from the label type, and cast it to the required type.
PR tree-optimization/112509
gcc/
* tree-vrp.cc (find_case_label_range): Create range from case labels.
gcc/testsuite/
* gcc.dg/pr112509.c: New.
Diff:
---
gcc/testsuite/gcc.dg/pr112509.c | 22 ++++++++++++++++++++++
gcc/tree-vrp.cc | 6 +-----
2 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/gcc/testsuite/gcc.dg/pr112509.c b/gcc/testsuite/gcc.dg/pr112509.c
new file mode 100644
index 00000000000..b733780bdc7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr112509.c
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-tree-vrp -fno-tree-fre -fno-tree-forwprop" } */
+
+struct S {
+ unsigned j : 3;
+};
+int k, l, m_1 = {0};
+void f(int l, struct S x) {
+ unsigned int k_1;
+ while (m_1 % 8) switch (x.j) {
+ case 1:
+ case 3:
+ case 4:
+ case 6:
+ case 2:
+ case 5: l = m_1;
+ case 7:
+ case 0: k_1 = 0;
+ default: break;
+ }
+}
+void foo(struct S x) { f(l, x); }
diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc
index 19d8f995d70..917fa873714 100644
--- a/gcc/tree-vrp.cc
+++ b/gcc/tree-vrp.cc
@@ -886,8 +886,6 @@ find_case_label_range (gswitch *switch_stmt, const irange *range_of_op)
size_t i, j;
tree op = gimple_switch_index (switch_stmt);
tree type = TREE_TYPE (op);
- unsigned prec = TYPE_PRECISION (type);
- signop sign = TYPE_SIGN (type);
tree tmin = wide_int_to_tree (type, range_of_op->lower_bound ());
tree tmax = wide_int_to_tree (type, range_of_op->upper_bound ());
find_case_label_range (switch_stmt, tmin, tmax, &i, &j);
@@ -900,9 +898,7 @@ find_case_label_range (gswitch *switch_stmt, const irange *range_of_op)
= CASE_HIGH (label) ? CASE_HIGH (label) : CASE_LOW (label);
wide_int wlow = wi::to_wide (CASE_LOW (label));
wide_int whigh = wi::to_wide (case_high);
- int_range_max label_range (type,
- wide_int::from (wlow, prec, sign),
- wide_int::from (whigh, prec, sign));
+ int_range_max label_range (TREE_TYPE (case_high), wlow, whigh);
if (!types_compatible_p (label_range.type (), range_of_op->type ()))
range_cast (label_range, range_of_op->type ());
label_range.intersect (*range_of_op);
reply other threads:[~2023-11-14 15:33 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=20231114153340.DA8353858D35@sourceware.org \
--to=amacleod@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).