<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 --- - auto vectorizer makes code run slower"
href="https://llvm.org/bugs/show_bug.cgi?id=28128">28128</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>auto vectorizer makes code run slower
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.8
</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>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>albertnetymk@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>```
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
void tik()
{
static clock_t start, end;
static int flag = 0;
static float elapsed_time;
if (flag == 0) {
start = clock();
} else {
end = clock();
elapsed_time = (float)(end - start) / (float)CLOCKS_PER_SEC;
printf("Elapsed time: %f seconds\n", elapsed_time);
}
flag = 1 - flag;
}
typedef unsigned int uint;
static uint i_max = 64 * 1024 * 1024;
void test()
{
static uint acc[2] = {1, 1};
tik();
for (uint i = 0; i < i_max; ++i) {
acc[0] *= 3;
}
tik();
acc[0] = acc[1] = 1;
tik();
for (uint i = 0; i < i_max; ++i) {
acc[0] *= 3;
acc[1] *= 3;
}
tik();
acc[0] = acc[1] = 1;
tik();
#pragma clang loop vectorize(disable)
for (uint i = 0; i < i_max; ++i) {
acc[0] *= 3;
acc[1] *= 3;
}
tik();
acc[0] = acc[1] = 1;
tik();
for (uint i = 0; i < i_max; ++i) {
acc[0] *= 3;
}
for (uint i = 0; i < i_max; ++i) {
acc[1] *= 3;
}
tik();
}
int main (int argc, char** argv) {
test();
return 0;
}
```
Output:
```
$ clang -O vector.c; ./a.out
Elapsed time: 0.003569 seconds
Elapsed time: 0.011365 seconds
Elapsed time: 0.008421 seconds
Elapsed time: 0.005950 seconds
```
I was expecting the second case run ~2x slower than the first one, for it's
doing twice much work. The forth case's runtime is more reasonable.
ENV:
clang: 3.8.1-svn271127-1~exp1 (branches/release_38)
OS: xubuntu 14.04
CPU: Intel(R) Core(TM) i7-4600U CPU @ 2.10GHz</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>