<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 - Useless code generation with code that has no side effects"
href="https://bugs.llvm.org/show_bug.cgi?id=41907">41907</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Useless code generation with code that has no side effects
</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>gabravier@gmail.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=21954" name="attach_21954" title="Archive containing the file necessary to reproduce this bug and the relevant generated assembly files">attachment 21954</a> <a href="attachment.cgi?id=21954&action=edit" title="Archive containing the file necessary to reproduce this bug and the relevant generated assembly files">[details]</a></span>
Archive containing the file necessary to reproduce this bug and the relevant
generated assembly files
When compiling the attached code with -O3, the optimizer fails to recognize
that the code should be simplified a simple jump to "fn", and instead generates
useless code that needs not be present for the code to work. It also generates
some very weird code, such as
.LBB0_3: # =>This Inner Loop Header: Depth=1
cmp ecx, eax
jle .LBB0_4
# %bb.9: # in Loop: Header=BB0_3 Depth=1
cmp ecx, eax
jle .LBB0_10
This strange code generation remains when adding a statement that forces the
code to have a side effect, such as "return d;" at the end of the code.
This is entirely redundant and the second part of the code should be optimized
out.
(%bb.9 being a comment, no code jumps there)
Attached is a 7z archive containing :
- The source file
- The generated assembly file "test.s" when compiling with "clang -S test.c -O3
-masm=intel -m32 -o test32.s" and "clang -S test.c -O3 -masm=intel -o test64.s"
with "x86_64-unknown-linux-gnu" as the target (for which clang was built on my
computer) and with clang 8.0.0, from Fedora 30
PS : I originally found this while trying to analyse
<a href="http://www.ioccc.org/1984/laman/laman.c">http://www.ioccc.org/1984/laman/laman.c</a> using Godbolt, as seen here :
<a href="https://godbolt.org/z/1M_cJi">https://godbolt.org/z/1M_cJi</a>. I was also using trunk, which is why I'm filing
this under trunk ; the bug is reproducible there (note that GCC and ICC
(correctly ?) convert the entire code to a call to fn).
PPS : The weird comparison duplication disappears when removing the duplicate
loop, but the loop itself remains</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>