<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 - Miscompile of collapse(2) with non-rectangular loop nest"
href="https://bugs.llvm.org/show_bug.cgi?id=41572">41572</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Miscompile of collapse(2) with non-rectangular loop nest
</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>Windows NT
</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>OpenMP
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>llvm@meinersbur.de
</td>
</tr>
<tr>
<th>CC</th>
<td>a.bataev@hotmail.com, hfinkel@anl.gov, jdoerfert@anl.gov, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>The following program miscompiles on current trunk (r358973):
$ cat collapse.c
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
int n = 2;
bool executed = false;
#pragma omp parallel for collapse(2)
for (int i = 0; i < n; i += 1)
for (int j = i; j < n; j += 1)
executed = true;
printf("executed? %d\n", executed);
return EXIT_SUCCESS;
}
$ ~/build/llvm/release/bin/clang collapse.c -fopenmp -O3 -o collapse &&
./collapse
executed? 0
Emitting the output reveals that outlined function has been optimized away:
$ ~/build/llvm/release/bin/clang collapse.c -fopenmp -O3 -emit-llvm -S -o -
[...]
define internal void @.omp_outlined.(i32* noalias nocapture %.global_tid., i32*
noalias nocapture %.bound_tid., i32* nocapture dereferenceable(4) %n, i8*
nocapture dereferenceable(1) %executed) #2 {
entry:
ret void
}
[...]
The following do return the correct result:
$ ~/build/llvm/release/bin/clang collapse.c -o collapse -O3 && ./collapse
executed? 1
$ ~/build/llvm/release/bin/clang collapse.c -fopenmp -o collapse -O0 &&
./collapse
executed? 1
[...]
#pragma omp parallel for collapse(2)
for (int i = 0; i < n; i += 1)
for (int j = 0; j < n; j += 1) // <= rectangular loop nest
[...]
$ ~/build/llvm/release/bin/clang collapse-rect.c -fopenmp -o collapse-rect -O3
&& ./collapse-rect
executed? 1</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>