[PATCH] peephole optimization in switch table lookup: reuse the guarding table comparison if possible
Erik Eckstein
eeckstein at apple.com
Wed Nov 26 11:31:22 PST 2014
Hi hans,
This optimization tries to reuse the generated compare instruction, if there is a comparison agains the default value after the switch.
Example:
switch (x) {
case 0: r = 10; break;
case 1: r = 11; break;
...
default: r = 0; break; // 0 does not appear in any case value.
}
if (r == 0) {
do_something;
}
transforms to:
cond = x < table_size;
if (cond) {
r = table[x];
} else {
r = 0;
}
if (cond) {
do_something;
}
Jump threading can then eliminate the second if (cond):
if (x < table_size) {
r = table[x];
} else {
r = 0;
do_something;
}
http://reviews.llvm.org/D6423
Files:
lib/Transforms/Utils/SimplifyCFG.cpp
test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D6423.16660.patch
Type: text/x-patch
Size: 9475 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141126/6c3921fe/attachment.bin>
More information about the llvm-commits
mailing list