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?<br>
<br><div class="gmail_quote">On Wed, Oct 3, 2012 at 5:39 AM, Hans Wennborg <span dir="ltr"><<a href="mailto:hans@chromium.org" target="_blank">hans@chromium.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Wed, Oct 3, 2012 at 12:51 PM, Duncan Sands <<a href="mailto:baldrick@free.fr">baldrick@free.fr</a>> wrote:<br>
> Hi Hans,<br>
><br>
><br>
>> A patch [1] by Craig earlier this week pointed out that Clang fails to<br>
>> build lookup tables for switches like this:<br>
>><br>
>>    switch(x) {<br>
>>      case 1: return 5;<br>
>>      case 2: return 42;<br>
>>      case 3: case 4: case 5:<br>
>>        return x - 123;<br>
>>      default: return 123;<br>
>>    }<br>
>><br>
>> Where the resulting value for the 3, 4, 5 cases is "x - 123", rather<br>
>> than a constant.<br>
><br>
><br>
> maybe it is better to do this as part of some more generic switch<br>
> simplification<br>
> logic rather than during table construction.<br>
<br>
</div>That would mean cloning the basic block with "return x - 123" into one<br>
block for each case, and then constant propagation could take care of<br>
it. Or rather, we should only clone it if it can get constant folded.<br>
<br>
Would that always be profitable, though? If the switch doesn't get<br>
turned into a lookup table, we've replaced one basic block with lots<br>
of small ones. At least for code size, it seems that could be counter<br>
productive?<br>
<br>
Thanks,<br>
Hans<br>
<div class="HOEnZb"><div class="h5">_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>~Craig<br>