<html>
<head>
<base href="https://bugs.llvm.org/">
</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 - Add pragma for loop aligning"
href="https://bugs.llvm.org/show_bug.cgi?id=49380">49380</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Add pragma for loop aligning
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</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>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>ibogosavljevic@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>On modern x86 CPUs, the performance of the loop can vary up to 50% if the loop
instructions are not aligned properly. Aligning the loop start on a 32-byte
boundary can help get the best performance out of my critical loop, but there
is no guarantee that CLANG will align the loops properly.
Workarounds: Putting assembler nops or assembler align directives doesn't help,
because the actual assembler loop can have a header of assembly instructions.
This issue is a very well known one, e.g.:
<a href="https://stackoverflow.com/questions/45298870/why-does-loop-alignment-on-32-byte-make-code-faster">https://stackoverflow.com/questions/45298870/why-does-loop-alignment-on-32-byte-make-code-faster</a>
Repro: I can provide a working example where the same code has different speeds
depending on the loop alignment.
Intel's compiler already has a similar pragma:
<a href="https://software.intel.com/content/www/us/en/develop/articles/intelr-compiler-170-new-feature-code-alignment-for-loops.html">https://software.intel.com/content/www/us/en/develop/articles/intelr-compiler-170-new-feature-code-alignment-for-loops.html</a>
E.g. pragma
for (int i = 0; i < len; i++) {
int min = a[i];
int min_index = i;
#pragma clang loop code_align(32)
for (int j = i+1; j < len; j++) {
if (a[j] < min) {
min = a[j];
min_index = j;
}
}
std::swap(a[i], a[min_index]);
}</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>