[PATCH] Improving LowerSwitch behavior for contiguous ranges
Joerg Sonnenberger
joerg at britannica.bec.de
Wed Jun 11 09:13:58 PDT 2014
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
More information about the llvm-commits
mailing list