<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 - [PGO] Consider enabling pre-cleanup passes before PGO instrumentation at -Os"
href="https://bugs.llvm.org/show_bug.cgi?id=47631">47631</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[PGO] Consider enabling pre-cleanup passes before PGO instrumentation at -Os
</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>All
</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>Interprocedural Optimizations
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>rnk@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>davidxl@google.com, llvm-bugs@lists.llvm.org, xur@google.com
</td>
</tr></table>
<p>
<div>
<pre>Rong Xu added a series of cleanup passes that run before PGO in this 2016
change:
<a href="https://reviews.llvm.org/D21405">https://reviews.llvm.org/D21405</a>
Chromium's build uses a mix of -O2 and -Os for different targets. We discovered
that with PGO, without the initial cleanup inliner pass, PGO-instrumented
object files are much, much larger than they should be. Switching from -Os to
-O2 everywhere reduced total object file inputs to link chrome.dll from ~20GB
to ~9GB, and greatly reduced linker memory usage.
If the inliner is not run before PGO instrumentation, every linkonce_odr
function ends up being retained. Consider this example:
$ cat t.cpp
void foo();
void bar();
inline void inlineMe(int x) {
if (x > 0)
foo();
else
bar();
}
int getVal();
int main() { inlineMe(getVal()); }
Normally, -Os and -O2 will inline away inlineMe, and then delete it.
However, if we do PGO instrumentation before the inliner can delete inlineMe,
the __profd_ data ends up recording the function address of all linkonce_odr
functions. This command line shows that it is retained with Os but not O2:
$ clang -S -emit-llvm -O2 t.cpp -o - -fprofile-generate |& grep
define.*inlineM
# nothing
$ clang -S -emit-llvm -Os t.cpp -o - -fprofile-generate |& grep
define.*inlineM
define linkonce_odr dso_local void @_Z8inlineMei(i32 %x) local_unnamed_addr #1
comdat {
The retention of all linkonce_odr functions by PGO instrumentation is
controlled here:
<a href="https://github.com/llvm/llvm-project/blob/master/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp#L830">https://github.com/llvm/llvm-project/blob/master/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp#L830</a>
David Li added it in this change:
<a href="http://github.com/llvm/llvm-project/commit/7008ce3f9891">http://github.com/llvm/llvm-project/commit/7008ce3f9891</a>
Almost every inline function in C++ is linkonce_odr, so this code ends up
retaining practically everything. This results in a lot of extra duplicate
sections and symbols that wouldn't normally make it to the final link in an
optimized build. In our case, the linker would run out of memory:
<a href="https://crbug.com/1058040">https://crbug.com/1058040</a>
We fixed the problem by switching to O2, but this behavior at Os seems
undesirable, so I am reporting it.</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>