This code was copied and reindented from tree-vrp.c. It looks like in that process the second conditional moved inside the true arm of the first conditional, which was wrong.
It won't cause incorrect code, just missed optimizations. I also verified that the code is still live -- it triggers during a bootstrap when building the Fortran front-end for example. Given that I just fixed it on the trunk. I don't think there's much value in fixing on the release branches. Bootstrapped and regression tested on x86_64-linux-gnu. Installed on the trunk. jeff
commit f60e7cee5700a9f9515ab4e2a922c325149c49e1 Author: law <law@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Sun Jul 7 18:42:45 2019 +0000 PR tree-optimization/91090 * tree-ssa-dom.c (simplify_stmt_for_jump_threading): Fix logic error in handling of ranges to simplify switch statements. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@273184 138bc75d-0d04-0410-961f-82ee72b054a4 diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0ef7eb6b93b..9f83f75b0bf 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2019-07-07 Jeff Law <l...@redhat.com> + + PR tree-optimization/91090 + * tree-ssa-dom.c (simplify_stmt_for_jump_threading): Fix logic error + in handling of ranges to simplify switch statements. + 2019-07-07 Iain Sandoe <i...@sandoe.co.uk> * config/darwin.c (darwin_override_options): Make a final check on PIC diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c index b0d56fcf3e3..17c852d5299 100644 --- a/gcc/tree-ssa-dom.c +++ b/gcc/tree-ssa-dom.c @@ -913,21 +913,26 @@ simplify_stmt_for_jump_threading (gimple *stmt, find_case_label_range (switch_stmt, vr->min (), vr->max (), &i, &j); + /* Is there only one such label? */ if (i == j) { tree label = gimple_switch_label (switch_stmt, i); tree singleton; + /* The i'th label will only be taken if the value range of the + operand is entirely within the bounds of this label. */ if (CASE_HIGH (label) != NULL_TREE ? (tree_int_cst_compare (CASE_LOW (label), vr->min ()) <= 0 && tree_int_cst_compare (CASE_HIGH (label), vr->max ()) >= 0) : (vr->singleton_p (&singleton) && tree_int_cst_equal (CASE_LOW (label), singleton))) return label; - - if (i > j) - return gimple_switch_label (switch_stmt, 0); } + + /* If there are no such labels, then the default label + will be taken. */ + if (i > j) + return gimple_switch_label (switch_stmt, 0); } if (vr->kind () == VR_ANTI_RANGE)