<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 - wrong code with opt -loop-rotate -licm"
href="https://bugs.llvm.org/show_bug.cgi?id=36262">36262</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>wrong code with opt -loop-rotate -licm
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</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>Loop Optimizer
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>paulsson@linux.vnet.ibm.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=19822" name="attach_19822" title="opt input for test case as seen in the description">attachment 19822</a> <a href="attachment.cgi?id=19822&action=edit" title="opt input for test case as seen in the description">[details]</a></span>
opt input for test case as seen in the description
Csmith generated a program, which was later reduced by creduce into:
int a = 0, b = 0, c = 0, e = 11, f = 0, h = 0;
long d = 0;
short *g = &f;
int *i = 0;
main() {
int *j = &b;
for (; e; e--) {
d = 9;
for (; d; d--)
*j = 8;
*g = h;
for (; a <= 9; a++)
i = &h;
j = i;
}
c = j;
printf("checksum = %X\n", f);
}
The correct output is "checksum = 80000", per gcc -O0/-O1 etc.
It seems that licm / loop-rotate is doing something wrong:
bin/opt -mtriple=s390x-linux-gnu -mcpu=z13 -S -o out.opt.ll tc_licm_rotate.ll
-tbaa -sroa
bin/llc -mtriple=s390x-linux-gnu -mcpu=z13 -O0 out.opt.ll -o out.s
rm ./a.out; bin/clang -O0 -march=z13 out.s -o a.out; ./a.out
checksum = 80000
bin/opt -mtriple=s390x-linux-gnu -mcpu=z13 -S -o out.opt.ll tc_licm_rotate.ll
-tbaa -sroa -loop-rotate -licm
bin/llc -mtriple=s390x-linux-gnu -mcpu=z13 -O0 out.opt.ll -o out.s
rm ./a.out; bin/clang -O0 -march=z13 out.s -o a.out; ./a.out
checksum = 0
In particular, the store of immediate 8 to f via *g never happens.
- *g points to f throughout function
- first iteration: *g is assigned value of h, which is 0. *i is set to point to
h, as is *j, via *i.
- second iteration: *j now points to h, so h gets value 8. f, via *g, should
then also get the same value.
With loop rotation and invariant code motion, the load of @h has been hoisted
to outside the outer loop, which is then stored just to @g just once after the
loop. This must be wrong.</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>