On Fri, Dec 16, 2016 at 03:16:14PM +0100, Marek Polacek wrote:
> On Fri, Dec 16, 2016 at 02:58:59PM +0100, Richard Biener wrote:
> > On Fri, Dec 16, 2016 at 2:03 PM, Bernd Schmidt <bschm...@redhat.com> wrote:
> > > On 12/16/2016 12:49 PM, Marek Polacek wrote:
> > >
> > >> But as this testcase shows, this breaks when the default label shares a
> > >> label
> > >> with another case.  On this testcase, when we reach the switch, we know
> > >> that
> > >> argc is either 1, 2, or 3.  So by the time we reach vrp2, the IR will 
> > >> have
> > >> been optimized to
> > >>
> > >>   switch (argc) {
> > >>     default:
> > >>     case 3:
> > >>       // argc will be considered 1 despite the case 3
> > >>       break;
> > >>     case 2:
> > >>       ...
> > >>    }
> > >
> > >
> > > Shouldn't we just remove the "case 3:" from the switch in this case? Would
> > > that fix things?
> > 
> > We probably should indeed.  But can we rely on this?
> 
> I think we should do both -- apply my fix + investigated why we kept case 3
> around.  I'm willing to look into this.

This is work of simplify_switch_using_ranges and then
11293   /* Update SWITCH_EXPR case label vector.  */
11294   FOR_EACH_VEC_ELT (to_update_switch_stmts, i, su)
11295     {
11296       size_t j;
11297       size_t n = TREE_VEC_LENGTH (su->vec);
11298       tree label;
11299       gimple_switch_set_num_labels (su->stmt, n);
11300       for (j = 0; j < n; j++)
11301         gimple_switch_set_label (su->stmt, j, TREE_VEC_ELT (su->vec, j));
11302       /* As we may have replaced the default label with a regular one
11303          make sure to make it a real default label again.  This ensures
11304          optimal expansion.  */
11305       label = gimple_switch_label (su->stmt, 0);
11306       CASE_LOW (label) = NULL_TREE;
11307       CASE_HIGH (label) = NULL_TREE;
            ^^^^^^ this

But only after I wrote a patch I noticed that cfgcleanup merges default: and
case 3: before we reach .optimized, so I think there's nothing to do here.

        Marek

Reply via email to