[LLVMbugs] [Bug 22058] New: trunk's optimizer generates slower code than 3.5

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Dec 29 22:21:50 PST 2014


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

            Bug ID: 22058
           Summary: trunk's optimizer generates slower code than 3.5
           Product: clang
           Version: trunk
          Hardware: PC
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: 191919 at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 13605
  --> http://llvm.org/bugs/attachment.cgi?id=13605&action=edit
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);
}
```

-- 
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/20141230/234831c7/attachment.html>


More information about the llvm-bugs mailing list