<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 - LLVM unable to optimize same associative addition in if-else condition in loop"
href="https://bugs.llvm.org/show_bug.cgi?id=50996">50996</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>LLVM unable to optimize same associative addition in if-else condition in loop
</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>TejasSanjay.Joshi@amd.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=25004" name="attach_25004" title="test case">attachment 25004</a> <a href="attachment.cgi?id=25004&action=edit" title="test case">[details]</a></span>
test case
For the same associative calculation in if and else conditions, LLVM seems
unable to recognize it:
void foo(int *a, int *b, int *c)
{
for (int i=0; i<100; ++i) {
if (c[i] > 0)
c[i] = a[i]+b[i];
else
c[i] = b[i]+a[i];
}
}
Even with -Ofast -fno-unroll-loops -ffast-math -S foo.c: Gives the following
main loop:
.LBB0_1:
cmpl $0, (%rdx,%rax,4)
movq %rsi, %r8
cmovgq %rdi, %r8
movq %rdi, %rcx
cmovgq %rsi, %rcx
movl (%rcx,%rax,4), %ecx
addl (%r8,%rax,4), %ecx
movl %ecx, (%rdx,%rax,4)
addq $1, %rax
cmpq $100, %rax
jne .LBB0_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>