Hello all,
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.
A possible solution is to weight an isolated single switch label 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;
}
}
Best regards
Jasper Neumann
Would you mind reporting a bug in llvm.org/bugs? Thanks On 24 December 2013 17:42, Jasper Neumann <jasper.neumann at web.de> wrote:> Hello all, > > 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. > > A possible solution is to weight an isolated single switch label 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; > } > } > > Best regards > Jasper Neumann > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Hello Rafael, hello all! > Would you mind reporting a bug in llvm.org/bugs? I have already done so, see the following entries: http://llvm.org/bugs/show_bug.cgi?id=18347 http://llvm.org/bugs/show_bug.cgi?id=18348 http://llvm.org/bugs/show_bug.cgi?id=18349 Best regards Jasper Neumann