It was forming a jump table instead of just a constant lookup table because of the subtract in there making it so that not everything was a constant. Maybe there should be some way to detect that the subtract was only dependent on the switch value?<br>
<br>Even the jump table switch had problems because it seems nothing combines identical basic blocks except for some common tail merging that occurs in branch folding. But the tail folding has a threshold of 3 instructions in the tail folding and these duplicate basic blocks were all 2 instructions long. Maybe tail merging should ignore the threshold if the common tail of two blocks are the whole blocks and they aren't both laid out behind their predecessor?<br>
<br><div class="gmail_quote">On Mon, Oct 1, 2012 at 12:40 AM, Chandler Carruth <span dir="ltr"><<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="gmail_extra"><div class="gmail_quote">On Mon, Oct 1, 2012 at 12:33 AM, Craig Topper <span dir="ltr"><<a href="mailto:craig.topper@gmail.com" target="_blank">craig.topper@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: ctopper<br>
Date: Mon Oct  1 02:33:27 2012<br>
New Revision: 164926<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=164926&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=164926&view=rev</a><br>
Log:<br>
Use constants for all return values in switch. Allows clang to optimize it into a lookup table.<br>
<br>
Modified:<br>
    llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp<br>
<br>
Modified: llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp?rev=164926&r1=164925&r2=164926&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp?rev=164926&r1=164925&r2=164926&view=diff</a><br>


==============================================================================<br>
--- llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp (original)<br>
+++ llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp Mon Oct  1 02:33:27 2012<br>
@@ -243,9 +243,14 @@<br>
   case X86::R15: case X86::R15D: case X86::R15W: case X86::R15B:<br>
     return N86::EDI;<br>
<br>
-  case X86::ST0: case X86::ST1: case X86::ST2: case X86::ST3:<br>
-  case X86::ST4: case X86::ST5: case X86::ST6: case X86::ST7:<br>
-    return RegNo-X86::ST0;<br>
+  case X86::ST0: return 0;<br>
+  case X86::ST1: return 1;<br>
+  case X86::ST2: return 2;<br>
+  case X86::ST3: return 3;<br>
+  case X86::ST4: return 4;<br>
+  case X86::ST5: return 5;<br>
+  case X86::ST6: return 6;<br>
+  case X86::ST7: return 7;<br></blockquote><div><br></div><div>Out of curiosity, why are we unable to form the lookup table out of this? It seems like a common pattern that should be directly supported.</div><div><br></div>

</div></div>
</blockquote></div><br><br clear="all"><br>-- <br>~Craig<br>