aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2016-12-16 14:19:44 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2016-12-16 14:19:44 +0000
commit6b520e8d4a24036508ad59eadf725437d2717a84 (patch)
treeee8280c2dd57fb2d8ff965d646a7cfff34eaf2be
parented2def05fefdf59e42ad6f13262e5323030e1610 (diff)
downloadgcc-6b520e8d4a24036508ad59eadf725437d2717a84.zip
gcc-6b520e8d4a24036508ad59eadf725437d2717a84.tar.gz
gcc-6b520e8d4a24036508ad59eadf725437d2717a84.tar.bz2
re PR tree-optimization/78819 (Wrong code with VRP caused by register assertions along default switch labels)
PR tree-optimization/78819 * tree-vrp.c (find_switch_asserts): Return if the insertion limit is 0. Don't register an assertion if the default case shares a label with another case. * gcc.dg/tree-ssa/vrp112.c: New test. From-SVN: r243746
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/vrp112.c31
-rw-r--r--gcc/tree-vrp.c9
4 files changed, 52 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index bdbadd3..2a443d0 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2016-12-16 Marek Polacek <polacek@redhat.com>
+
+ PR tree-optimization/78819
+ * tree-vrp.c (find_switch_asserts): Return if the insertion limit is 0.
+ Don't register an assertion if the default case shares a label with
+ another case.
+
2016-12-16 Wilco Dijkstra <wdijkstr@arm.com>
* config/arm/arm.md (subsi3_carryin): Add Thumb-2 RSC #0.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index afd90ee..3307b2e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2016-12-16 Marek Polacek <polacek@redhat.com>
+
+ PR tree-optimization/78819
+ * gcc.dg/tree-ssa/vrp112.c: New test.
+
2016-12-16 Eric Botcazou <ebotcazou@adacore.com>
* gnat.dg/opt61.adb: New test.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp112.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp112.c
new file mode 100644
index 0000000..fdc6711
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp112.c
@@ -0,0 +1,31 @@
+/* PR tree-optimization/78819 */
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+__attribute__((noinline, noclone)) void
+foo (int argc)
+{
+ if (argc <= 0 || argc > 3)
+ return;
+
+ switch (argc)
+ {
+ case 1:
+ case 3:
+ if (argc != 3)
+ __builtin_abort ();
+ break;
+ case 2:
+ asm ("");
+ break;
+ default:
+ __builtin_abort ();
+ }
+}
+
+int
+main (void)
+{
+ foo (3);
+ return 0;
+}
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 97e9953..31b6b7d 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -6051,10 +6051,17 @@ find_switch_asserts (basic_block bb, gswitch *last)
/* Now register along the default label assertions that correspond to the
anti-range of each label. */
int insertion_limit = PARAM_VALUE (PARAM_MAX_VRP_SWITCH_ASSERTIONS);
+ if (insertion_limit == 0)
+ return;
+
+ /* We can't do this if the default case shares a label with another case. */
+ tree default_cl = gimple_switch_default_label (last);
for (idx = 1; idx < n; idx++)
{
tree min, max;
tree cl = gimple_switch_label (last, idx);
+ if (CASE_LABEL (cl) == CASE_LABEL (default_cl))
+ continue;
min = CASE_LOW (cl);
max = CASE_HIGH (cl);
@@ -6065,6 +6072,8 @@ find_switch_asserts (basic_block bb, gswitch *last)
{
tree next_min, next_max;
tree next_cl = gimple_switch_label (last, idx);
+ if (CASE_LABEL (next_cl) == CASE_LABEL (default_cl))
+ break;
next_min = CASE_LOW (next_cl);
next_max = CASE_HIGH (next_cl);