<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 --- - Sparse switches lowered to an else-if chain"
href="http://llvm.org/bugs/show_bug.cgi?id=18347">18347</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Sparse switches lowered to an else-if chain
</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>in SelectionDAGBuilder::handleBTSplitSwitchCase
(lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp) seems to be a quirk which
can effectively create an else-if chain from a very sparse switch statement
instead of a balanced binary tree.
The reason is that a marginal single switch label is weighted too much causing
it to be split off; a possible solution is to weight it with 0. To do this one
can replace the assignments to LDensity und RDensity by:
volatile double LDensity =
(double)(LSize-1).roundToDouble() /
(LEnd - First + 1ULL).roundToDouble();
volatile double RDensity =
(double)(RSize-1).roundToDouble() /
(Last - RBegin + 1ULL).roundToDouble();
I replaced ?Size by (?Size-1).
Here is a more or less stupid test program (translate with "clang -O3 -S
test.cpp" and then look at test.s):
int main(int argc, char **argv) {
switch (argc) {
case 100: return 1;
case 200: return 2;
case 300: return 3;
case 400: return 4;
case 500: return 5;
case 600: return 6;
case 700: return 7;
case 800: return 8;
case 900: return 9;
default: return 0;
}
}
As far as I can see this quirk is also present in trunk.</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>