<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 - LICM does not move accesses out of loop; variable not promoted to register"
href="https://bugs.llvm.org/show_bug.cgi?id=44033">44033</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>LICM does not move accesses out of loop; variable not promoted to register
</td>
</tr>
<tr>
<th>Product</th>
<td>tools
</td>
</tr>
<tr>
<th>Version</th>
<td>8.0
</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>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>opt
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>uday@polymagelabs.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>For this piece of code, LICM doesn't move the memory accesses (on *s) out of
the loop when run with:
$ clang -O0 test.cpp -c -S -emit-llvm -o - | opt -O2
but it does when run as part of:
$ clang -O2 test.cpp
LICM runs in both cases, and I was expecting the register promotion for *s to
happen in either case (although the generated code may differ); but it doesn't
with opt's -O2 pipeline.
<a href="https://godbolt.org/z/nCHkaW">https://godbolt.org/z/nCHkaW</a>
==============
#include <stdlib.h>
#define N 100
void foo(int Y[N], int A[N][N], int X[N]) {
for (int i = 0; i < N; ++i) {
int *s = (int*)malloc((sizeof(int)));
*s = Y[i];
for (int j = 0; j < N; ++j) {
*s += A[i][j] * X[j];
}
Y[i] += *s;
free(s);
}
}
================
opt -version
LLVM (<a href="http://llvm.org/">http://llvm.org/</a>):
LLVM version 8.0.0
Optimized build.
Default target: x86_64-unknown-linux-gnu
Host CPU: skylake</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>