[LLVMbugs] [Bug 18349] New: Switches with too large ranges check these one after another

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Dec 31 17:43:38 PST 2013


            Bug ID: 18349
           Summary: Switches with too large ranges check these one after
           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

Similar to bug 18348 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 bug #1255.
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.

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/20140101/1a2c224d/attachment.html>

More information about the llvm-bugs mailing list