[COMMITTED] Drop tree overflow in irange setter.
Aldy Hernandez
aldyh@redhat.com
Mon Nov 15 16:32:28 GMT 2021
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
More information about the Gcc-patches
mailing list