<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 --- - trunk's optimizer generates slower code than 3.5"
   href="http://llvm.org/bugs/show_bug.cgi?id=22058">22058</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>trunk's optimizer generates slower code than 3.5
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </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>LLVM Codegen
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>191919@gmail.com
          </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>Created <span class=""><a href="attachment.cgi?id=13605" name="attach_13605" title="Assembly and executable files">attachment 13605</a> <a href="attachment.cgi?id=13605&action=edit" title="Assembly and executable files">[details]</a></span>
Assembly and executable files

clang 3.6 svn (trunk 224979 as the time I was to report this problem) generates
slower code than 3.5 (Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM
3.5svn)) for the following code.

It is a "8 queens puzzle" solver written as an educational example. As compiled
by both clang 3.5 and 3.6, it gave the correct answer, but clang 3.5 generates
code which runs 20% faster than 3.6.

##########################################
# clang 3.5 which comes with Xcode 6.1.1
##########################################
$ clang -O3 -mssse3 -fomit-frame-pointer -fno-stack-protector -fno-exceptions
-o 8 8.c
$ time ./8 9    # 9 queens
352 solutions
$ time ./8 10   # 10 queens
./8 9  1.63s user 0.00s system 99% cpu 1.632 total
724 solutions
./8 10  45.11s user 0.01s system 99% cpu 45.121 total

##########################################
# clang 3.6 svn trunk
##########################################
$ /opt/bin/clang -O3 -mssse3 -fomit-frame-pointer -fno-stack-protector
-fno-exceptions -o 8 8.c
$ time ./8 9    # 9 queens
352 solutions
./8 9  2.07s user 0.00s system 99% cpu 2.078 total
$ time ./8 10   # 10 queens
724 solutions
./8 10  56.63s user 0.02s system 99% cpu 56.650 total

The source code is below, I also attached the executable files as well as the
assembly code files for clang 3.5 and 3.6 by IDA.

```
#include <stdio.h>
#include <stdlib.h>

static inline int validate(int* a, int d)
{
        int i, j, x;
        for (i = 0; i < d; ++i)
        {
                for (j = i+1, x = 1; j < d; ++j, ++x)
                {
                        const int d = a[i] - a[j];
                        if (d == 0 || d == -x || d == x) return 0;
                }
        }
        return 1;
}

static inline int solve(int d)
{
        int r = 0;
        int* a = (int*) calloc(sizeof(int), d+1);
        int p = d - 1;

        for (;;)
        {
                a[p]++;

                if (a[p] > d-1)
                {
                        int bp = p - 1;
                        while (bp >= 0)
                        {
                                a[bp]++;
                                if (a[bp] <= d-1) break;
                                a[bp] = 0;
                                --bp;
                        }
                        if (bp < 0)
                                break;
                        a[p] = 0;
                }
                if (validate(a, d))
                {
                        ++r;
                }
        }

        free(a);
        return r;
}

int main(int argc, char** argv)
{
    if (argc != 2) return -1;
    int r = solve((int) strtol(argv[1], NULL, 10));
    printf("%d solutions\n", r);
}
```</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>