<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Switches with too large ranges check these one after another"
   href="http://llvm.org/bugs/show_bug.cgi?id=18349">18349</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Switches with too large ranges check these one after another
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.3
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Common Code Generator Code
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jn@sirrida.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Similar to <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Switches with large ranges may generate excessively large jump tables"
   href="show_bug.cgi?id=18348">bug 18348</a> a switch statement with many large ranges are not handled
satisfactorily. In this case I tested large ranges which have more than 64
elements. What I found was that these are tested one after another where a
decision tree would have been much more adequate and as usually happens with
smaller ranges.

As a test case the following program can be compiled with clang -O3 -S:

int main(int argc, char **argv) {
  switch (argc) {
    case 5000 ... 5064: return 100;
    case 5100 ... 5164: return 200;
    case 5200 ... 5264: return 300;
    case 5300 ... 5364: return 400;
    case 5400 ... 5464: return 500;
    case 5500 ... 5564: return 600;
    default: return -1;
    }
  }

The special case for ranges with more than 64 elements seems to artificial as
is also discussed in <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Should enhance LLVM switch instruction to take case ranges"
   href="show_bug.cgi?id=1255">bug #1255</a>.
Also, the 64 ought to be configurable with a switch (if necessary at all).
The offending code of 3.3 can be found in lib/CodeGen/CGStmt.cpp; I could not
locate it in trunk (currently 3.4 RC3), however this version compiles to the
same result.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>