diff options
author | Patrick Palka <ppalka@gcc.gnu.org> | 2016-08-05 17:21:00 +0000 |
---|---|---|
committer | Patrick Palka <ppalka@gcc.gnu.org> | 2016-08-05 17:21:00 +0000 |
commit | 1addb9e62b8970734343074e4a2b38f924954850 (patch) | |
tree | 3bdef0765785dff4bd123426fdbb1fc37f9af477 | |
parent | 1b62ed4f2638c59f30ff9480789b4cdeb740ddbe (diff) | |
download | gcc-1addb9e62b8970734343074e4a2b38f924954850.zip gcc-1addb9e62b8970734343074e4a2b38f924954850.tar.gz gcc-1addb9e62b8970734343074e4a2b38f924954850.tar.bz2 |
re PR tree-optimization/72810 (error: type mismatch for case label in switch statement)
Fix PR tree-optimization/72810
gcc/ChangeLog:
PR tree-optimization/72810
* tree-vrp.c (simplify_switch_using_ranges): Avoid changing
the type of the case labels when truncating.
gcc/testsuite/ChangeLog:
PR tree-optimization/72810
* gcc.dg/tree-ssa/vrp110.c: New test.
From-SVN: r239174
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/vrp110.c | 24 | ||||
-rw-r--r-- | gcc/tree-vrp.c | 43 |
4 files changed, 59 insertions, 19 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1925a05..10d7224 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2016-08-05 Patrick Palka <ppalka@gcc.gnu.org> + + PR tree-optimization/72810 + * tree-vrp.c (simplify_switch_using_ranges): Avoid changing + the type of the case labels when truncating. + 2016-08-05 James Greenhalgh <james.greenhalgh@arm.com> PR Target/72819 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c133af9..25af783 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-08-05 Patrick Palka <ppalka@gcc.gnu.org> + + PR tree-optimization/72810 + * gcc.dg/tree-ssa/vrp110.c: New test. + 2016-08-05 James Greenhalgh <james.greenhalgh@arm.com> PR Target/72819 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp110.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp110.c new file mode 100644 index 0000000..34d7eb4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp110.c @@ -0,0 +1,24 @@ +/* { dg-options "-O2" } */ + +extern void foo (void); +extern void bar (void); + +void +test (int i) +{ + if (i == 1) + return; + + typedef int t; + t j = i; + switch (j) + { + case 1: + case 2: + foo (); + break; + case 7: + bar (); + break; + } +} diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 7c7ad91..5573023 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -9644,61 +9644,66 @@ simplify_switch_using_ranges (gswitch *stmt) tree min_label = gimple_switch_label (stmt, min_idx); tree max_label = gimple_switch_label (stmt, max_idx); + /* Avoid changing the type of the case labels when truncating. */ + tree case_label_type = TREE_TYPE (CASE_LOW (min_label)); + tree vr_min = fold_convert (case_label_type, vr->min); + tree vr_max = fold_convert (case_label_type, vr->max); + if (vr->type == VR_RANGE) { /* If OP's value range is [2,8] and the low label range is 0 ... 3, truncate the label's range to 2 .. 3. */ - if (tree_int_cst_compare (CASE_LOW (min_label), vr->min) < 0 + if (tree_int_cst_compare (CASE_LOW (min_label), vr_min) < 0 && CASE_HIGH (min_label) != NULL_TREE - && tree_int_cst_compare (CASE_HIGH (min_label), vr->min) >= 0) - CASE_LOW (min_label) = vr->min; + && tree_int_cst_compare (CASE_HIGH (min_label), vr_min) >= 0) + CASE_LOW (min_label) = vr_min; /* If OP's value range is [2,8] and the high label range is 7 ... 10, truncate the label's range to 7 .. 8. */ - if (tree_int_cst_compare (CASE_LOW (max_label), vr->max) <= 0 + if (tree_int_cst_compare (CASE_LOW (max_label), vr_max) <= 0 && CASE_HIGH (max_label) != NULL_TREE - && tree_int_cst_compare (CASE_HIGH (max_label), vr->max) > 0) - CASE_HIGH (max_label) = vr->max; + && tree_int_cst_compare (CASE_HIGH (max_label), vr_max) > 0) + CASE_HIGH (max_label) = vr_max; } else if (vr->type == VR_ANTI_RANGE) { - tree one_cst = build_one_cst (TREE_TYPE (op)); + tree one_cst = build_one_cst (case_label_type); if (min_label == max_label) { /* If OP's value range is ~[7,8] and the label's range is 7 ... 10, truncate the label's range to 9 ... 10. */ - if (tree_int_cst_compare (CASE_LOW (min_label), vr->min) == 0 + if (tree_int_cst_compare (CASE_LOW (min_label), vr_min) == 0 && CASE_HIGH (min_label) != NULL_TREE - && tree_int_cst_compare (CASE_HIGH (min_label), vr->max) > 0) + && tree_int_cst_compare (CASE_HIGH (min_label), vr_max) > 0) CASE_LOW (min_label) - = int_const_binop (PLUS_EXPR, vr->max, one_cst); + = int_const_binop (PLUS_EXPR, vr_max, one_cst); /* If OP's value range is ~[7,8] and the label's range is 5 ... 8, truncate the label's range to 5 ... 6. */ - if (tree_int_cst_compare (CASE_LOW (min_label), vr->min) < 0 + if (tree_int_cst_compare (CASE_LOW (min_label), vr_min) < 0 && CASE_HIGH (min_label) != NULL_TREE - && tree_int_cst_compare (CASE_HIGH (min_label), vr->max) == 0) + && tree_int_cst_compare (CASE_HIGH (min_label), vr_max) == 0) CASE_HIGH (min_label) - = int_const_binop (MINUS_EXPR, vr->min, one_cst); + = int_const_binop (MINUS_EXPR, vr_min, one_cst); } else { /* If OP's value range is ~[2,8] and the low label range is 0 ... 3, truncate the label's range to 0 ... 1. */ - if (tree_int_cst_compare (CASE_LOW (min_label), vr->min) < 0 + if (tree_int_cst_compare (CASE_LOW (min_label), vr_min) < 0 && CASE_HIGH (min_label) != NULL_TREE - && tree_int_cst_compare (CASE_HIGH (min_label), vr->min) >= 0) + && tree_int_cst_compare (CASE_HIGH (min_label), vr_min) >= 0) CASE_HIGH (min_label) - = int_const_binop (MINUS_EXPR, vr->min, one_cst); + = int_const_binop (MINUS_EXPR, vr_min, one_cst); /* If OP's value range is ~[2,8] and the high label range is 7 ... 10, truncate the label's range to 9 ... 10. */ - if (tree_int_cst_compare (CASE_LOW (max_label), vr->max) <= 0 + if (tree_int_cst_compare (CASE_LOW (max_label), vr_max) <= 0 && CASE_HIGH (max_label) != NULL_TREE - && tree_int_cst_compare (CASE_HIGH (max_label), vr->max) > 0) + && tree_int_cst_compare (CASE_HIGH (max_label), vr_max) > 0) CASE_LOW (max_label) - = int_const_binop (PLUS_EXPR, vr->max, one_cst); + = int_const_binop (PLUS_EXPR, vr_max, one_cst); } } |