[LLVMbugs] [Bug 18347] New: Sparse switches lowered to an else-if chain
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Mon Dec 30 14:31:11 PST 2013
http://llvm.org/bugs/show_bug.cgi?id=18347
Bug ID: 18347
Summary: Sparse switches lowered to an else-if chain
Product: libraries
Version: 3.3
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: Common Code Generator Code
Assignee: unassignedbugs at nondot.org
Reporter: jn at sirrida.de
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
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.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20131230/16dc7516/attachment.html>
More information about the llvm-bugs
mailing list