[PATCH] Improving LowerSwitch behavior for contiguous ranges

Marcello Maggioni hayarms at gmail.com
Wed Jun 11 09:28:05 PDT 2014


Yeah, it is suboptimal, it doesn't take into consideration the fact that
the default is unreachable.

I'll a look at it later to see if it is easy to also take into
consideration this case and add it to the patch + test for the condition.

Marcello


2014-06-11 17:13 GMT+01:00 Joerg Sonnenberger <joerg at britannica.bec.de>:

> On Wed, Jun 11, 2014 at 04:32:52PM +0100, Marcello Maggioni wrote:
> > Looks like it gives the same result
>
> Looks suboptimal?
>
> > 2014-06-11 14:18 GMT+01:00 Joerg Sonnenberger <joerg at britannica.bec.de>:
> >
> > > On Wed, Jun 11, 2014 at 02:05:23AM +0100, Marcello Maggioni wrote:
> > > > Hello Joerg,
> > > >
> > > > by unreachable default you mean something like this?
> > > >
> > > > int foo(int a) {
> > > >   switch (a) {
> > > >   case 0:
> > > >     return 10;
> > > >   case 1:
> > > >     return 20;
> > > >   case 2:
> > > >     return 2;
> > > >   case 8:
> > > >     return 3;
> > > >   case 9:
> > > >     return 4;
> > > >   case 10:
> > > >     return 5;
> > > >   default:
> > > >     abort();
> > > >   }
> > > > }
> > >
> > > More like explicit __builtin_unreachable(), since abort() still has
> side
> > > effects. Practical use case is switching over an enum.
>
> I would expect something like:
>
> if (a >= 8) {
>   if (a >= 9) {
>     if (a >= 10)
>       return 5;
>     else
>       return 4;
>   } else {
>     return 3;
>   }
> } else {
>   if (a >= 1) {
>     if (a >= 2)
>       return 20;
>     return 2;
>   } else {
>     return 10;
>   }
> }
>
> Joerg
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140611/97320d30/attachment.html>


More information about the llvm-commits mailing list