[LLVMbugs] [Bug 22020] New: Form a switch from a loop if the loop is really switch-like

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Dec 23 14:16:32 PST 2014


http://llvm.org/bugs/show_bug.cgi?id=22020

            Bug ID: 22020
           Summary: Form a switch from a loop if the loop is really
                    switch-like
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: david.majnemer at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

consider:
int f(char C) {
  const char *Str = ",/\\:. \n\t\'-";
  for (int i = 0, e = 10; i < e; ++i) {
    if (Str[i] == C)
      return i;
  }
  return -1;
}

this is another way of writing:
int f(char C) {
  switch (C) {
  case ',':
    return 0;
  case '/':
    return 1;
  case '\\':
    return 2;
  case ':'
    return 3;
  case '.':
    return 4;
  case ' ':
    return 5;
  case '\n':
    return 6;
  case '\t':
    return 7;
  case '\'':
    return 8;
  case '-'
    return 9;
  }
  return -1;
}

we should canonicalize the first to the second.  pathalogical switches should
be *lower* back to loops for performance.

-- 
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/20141223/67a2c334/attachment.html>


More information about the llvm-bugs mailing list