[PATCH] peephole optimization in switch table lookup: reuse the guarding table comparison if possible

Joey Gouly joey.gouly at gmail.com
Tue Nov 18 09:28:15 PST 2014


The loop that checks 'ValuePair.second == DefaultValue' seems to be
constant across the loop where reuseTableCompare is called. Can you hoist
that above the loop?

Also a typo 'agains' should be 'against'.

Joey
On 18 Nov 2014 15:55, "Erik Eckstein" <eeckstein at apple.com> wrote:

Hi Hans,

I have another patch for the switch table lookup generation. It 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:

if (x < table_size) {
  r = table[x];
} else {
  r = 0;
  do_something;
}

Now I must admit, that this pattern is quite a corner case (only a single
occurrence in the test-suite). My trigger for this optimization is that in
our project we are generating such IR patterns.

Please let me know your comments.

Thanks,
Erik


_______________________________________________
llvm-commits mailing list
llvm-commits at cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141118/ac8940ba/attachment.html>


More information about the llvm-commits mailing list