<html>
<head>
<base href="https://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 --- - Degraded speed of generated output"
href="https://llvm.org/bugs/show_bug.cgi?id=27110">27110</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Degraded speed of generated output
</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>All
</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>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=16116" name="attach_16116" title="demo source code">attachment 16116</a> <a href="attachment.cgi?id=16116&action=edit" title="demo source code">[details]</a></span>
demo source code
I found there was a serious speed degrade for the output of clang when
compiling some specific kind of code since two weeks ago.
The attached file is a solver for 8-queen puzzle, it can be compiled with:
/opt/bin/clang -std=c99 -mssse3 -O3 -fomit-frame-pointer -fno-stack-protector
-fno-exceptions -o 8 8.c
Currently in my machine, it took 2.52s to run with eight queens:
$ time ./8 9
352 solutions
./8 9 2.52s user 0.01s system 99% cpu 2.545 total
But about two weeks ago, it took only ** 2.20s ** to finish the same input.
What is interesting is in the following function:
static inline int validate(const int* a, const int d)
{
for (int i = 0; i < d; ++i)
{
for (int j = i + 1, x = 1; j < d; ++j, ++x)
{
const int p = a[i] - a[j];
if (p == 0 || p == x || -p == x) return 0;
}
}
return 1;
}
Changing it to:
static inline int validate(const int* a, const int d)
{
for (int i = 0; i < d; ++i)
{
for (int j = i + 1, x = 1; j < d; ++j, ++x)
{
const int p = a[i] - a[j];
if (p == 0 || p == -x || p == -x) return 0; // <---
}
}
return 1;
}
could reduce the time from 2.52s to 2.31s (9% boost).
I checked the output assembly of gcc-5.3 and Intel compiler 2016.2, they both
did the optimization which splits the judgement statement to:
if (a[i] == a[j]) return 0;
const int p = a[i] - a[j];
if (p == -x || p == -x) return 0;
but clang didn't do this. If I manually rewrite the code, it took 2.15s (15%
boost).
---------
Comparing to gcc-5.3:
$ /opt/bin/gcc -std=c99 -mssse3 -O3 -fomit-frame-pointer -fno-stack-protector
-fno-exceptions -o 8 8.c
$ time ./8 9
352 solutions
./8 9 2.04s user 0.01s system 99% cpu 2.069 total
and Intel compiler 2016.2:
$ icc -std=c99 -mssse3 -O3 -fomit-frame-pointer -fno-stack-protector
-fno-exceptions -o 8 8.c
$ time ./8 9
352 solutions
./8 9 2.07s user 0.00s system 99% cpu 2.077 total</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>