[llvm-commits] [Patch] Use bitmaps for switch lookup tables that fit in registers

Hans Wennborg hans at chromium.org
Wed Sep 19 10:32:01 PDT 2012


Hi all,

The attached batch updates the switch-to-lookup table transformation
in SimplifyCFG to put the lookup tables in a bitmap when they would
fit in a register on the target. This saves some space, and it also
allows for building tables that would otherwise be too sparse.

One interesting case that this hits is example 7 from
http://blog.regehr.org/archives/320. We currently generate good code
for this when lowering the switch to the selection DAG: we build a
bitmask to decide whether to jump to one block or the other. My patch
will result in the same bitmask, but it removes the need for the jump,
as the return value can just be retrieved from the mask.

This was part of my original lookup table patch [1], but it was
suggested in review that we should do it separately.

I tried this on a bootstrap build of Clang, and it reduced the binary
size with 8328 bytes (0.03%).

The patch also refactors the code to put the table-building
functionality in a separate class. I'm happy to break that out into a
separate patch if preferred.

Please take a look.

Thanks,
Hans

 [1]. http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20120903/149605.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: switch_table_bitmap.patch
Type: application/octet-stream
Size: 20411 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120919/e6d203a6/attachment.obj>


More information about the llvm-commits mailing list