public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] Drop tree overflow in irange setter.
@ 2021-11-15 16:32 Aldy Hernandez
  0 siblings, 0 replies; only message in thread
From: Aldy Hernandez @ 2021-11-15 16:32 UTC (permalink / raw)
  To: GCC patches

Drop meaningless overflow that may creep into the IL.

Tested on x86-64 Linux.

gcc/ChangeLog:

	PR tree-optimization/103207
	* value-range.cc (irange::set): Drop overflow.

gcc/testsuite/ChangeLog:

	* gcc.dg/pr103207.c: New test.
---
 gcc/testsuite/gcc.dg/pr103207.c | 15 +++++++++++++++
 gcc/value-range.cc              |  8 ++++++++
 2 files changed, 23 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/pr103207.c

diff --git a/gcc/testsuite/gcc.dg/pr103207.c b/gcc/testsuite/gcc.dg/pr103207.c
new file mode 100644
index 00000000000..69c0f555f86
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr103207.c
@@ -0,0 +1,15 @@
+// { dg-do compile }
+// { dg-options "-O2 --param case-values-threshold=1 -w" }
+
+int f (int i)
+{
+  switch (i) {
+  case 2147483647:
+    return 1;
+  case 9223372036854775807L:
+    return 2;
+  case (2147483647*4)%4:
+    return 4;
+  }
+  return 0;
+}
diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index caef2498959..82509fa55a7 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -270,6 +270,14 @@ irange::irange_set_anti_range (tree min, tree max)
 void
 irange::set (tree min, tree max, value_range_kind kind)
 {
+  if (kind != VR_UNDEFINED)
+    {
+      if (TREE_OVERFLOW_P (min))
+	min = drop_tree_overflow (min);
+      if (TREE_OVERFLOW_P (max))
+	max = drop_tree_overflow (max);
+    }
+
   if (!legacy_mode_p ())
     {
       if (kind == VR_RANGE)
-- 
2.31.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-11-15 16:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-15 16:32 [COMMITTED] Drop tree overflow in irange setter Aldy Hernandez

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).