<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 - Missed optimization: invariant code motion"
href="https://bugs.llvm.org/show_bug.cgi?id=37849">37849</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Missed optimization: invariant code motion
</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>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>Scalar Optimizations
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>m-takahiro@jp.fujitsu.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>I compiled the following code at -O3 with loop unrolling disabled to make it
easy to see generated IRs.
---------------------
void foo(float * restrict a, float * restrict b, const int N) {
for (int i = 1; i < N; ++i)
a[i] = a[0] + b[i];
}
---------------------
Clang version is as follows:
---------------------
$ clang --version
clang version 7.0.0 (trunk 335036)
---------------------
And generated IRs are as follows:
---------------------
; <label>:8: ; pre
%9 = phi i64 [ 1, %5 ], [ %15, %8 ]
%10 = load float, float* %0, align 4, !tbaa !2
%11 = getelementptr inbounds float, float* %1, i64 %9
%12 = load float, float* %11, align 4, !tbaa !2
%13 = fadd float %10, %12
%14 = getelementptr inbounds float, float* %0, i64 %9
store float %13, float* %14, align 4, !tbaa !2
%15 = add nuw nsw i64 %9, 1
%16 = icmp eq i64 %15, %6
br i1 %16, label %7, label %8
---------------------
'a[0]' (%10) is invariant inside the loop because an initial value of induction
variable is 1 and its value is incremented by 1. So, I think invariant code
motion can be applied.</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>