[PATCH] D21291: [SimplifyCFG] Range reduce switches
James Molloy via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 13 07:53:53 PDT 2016
jmolloy created this revision.
jmolloy added reviewers: mcrosier, sbaranga, sanjoy.
jmolloy added a subscriber: llvm-commits.
jmolloy set the repository for this revision to rL LLVM.
If a switch is sparse and all the cases (once sorted) are in arithmetic progression, we can extract the common factor out of the switch and create a dense switch. For example:
switch (i) {
case 5: ...
case 9: ...
case 13: ...
case 17: ...
}
can become:
if ( (i - 5) % 4 ) goto default;
switch ((i - 5) / 4) {
case 0: ...
case 1: ...
case 2: ...
case 3: ...
}
The division and remainder operations could be costly so we only do this if the factor is a power of two. Dense switches can be lowered significantly better than sparse switches and can even be transformed into lookup tables.
Repository:
rL LLVM
http://reviews.llvm.org/D21291
Files:
lib/Transforms/Utils/SimplifyCFG.cpp
test/Transforms/SimplifyCFG/rangereduce.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21291.60524.patch
Type: text/x-patch
Size: 5911 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160613/fb2eb582/attachment.bin>
More information about the llvm-commits
mailing list