[llvm-commits] [Patch] Switch-to-lookup tables: do simple constant propagation

Craig Topper craig.topper at gmail.com
Wed Oct 3 09:34:28 PDT 2012


If a lookup table isn't formed, it may also be useful to merge blocks to
create a subtract(or some similar calculation) even it wasn't written in
the code? So maybe we could splits the blocks and then recombine them if
lookup table doesn't work?

On Wed, Oct 3, 2012 at 5:39 AM, Hans Wennborg <hans at chromium.org> wrote:

> On Wed, Oct 3, 2012 at 12:51 PM, Duncan Sands <baldrick at free.fr> wrote:
> > Hi Hans,
> >
> >
> >> A patch [1] by Craig earlier this week pointed out that Clang fails to
> >> build lookup tables for switches like this:
> >>
> >>    switch(x) {
> >>      case 1: return 5;
> >>      case 2: return 42;
> >>      case 3: case 4: case 5:
> >>        return x - 123;
> >>      default: return 123;
> >>    }
> >>
> >> Where the resulting value for the 3, 4, 5 cases is "x - 123", rather
> >> than a constant.
> >
> >
> > maybe it is better to do this as part of some more generic switch
> > simplification
> > logic rather than during table construction.
>
> That would mean cloning the basic block with "return x - 123" into one
> block for each case, and then constant propagation could take care of
> it. Or rather, we should only clone it if it can get constant folded.
>
> Would that always be profitable, though? If the switch doesn't get
> turned into a lookup table, we've replaced one basic block with lots
> of small ones. At least for code size, it seems that could be counter
> productive?
>
> Thanks,
> Hans
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>



-- 
~Craig
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121003/a35f4b6e/attachment.html>


More information about the llvm-commits mailing list