[llvm-bugs] [Bug 47631] New: [PGO] Consider enabling pre-cleanup passes before PGO instrumentation at -Os
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Sep 23 16:49:33 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=47631
Bug ID: 47631
Summary: [PGO] Consider enabling pre-cleanup passes before PGO
instrumentation at -Os
Product: libraries
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: Interprocedural Optimizations
Assignee: unassignedbugs at nondot.org
Reporter: rnk at google.com
CC: davidxl at google.com, llvm-bugs at lists.llvm.org,
xur at google.com
Rong Xu added a series of cleanup passes that run before PGO in this 2016
change:
https://reviews.llvm.org/D21405
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:
https://github.com/llvm/llvm-project/blob/master/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp#L830
David Li added it in this change:
http://github.com/llvm/llvm-project/commit/7008ce3f9891
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:
https://crbug.com/1058040
We fixed the problem by switching to O2, but this behavior at Os seems
undesirable, so I am reporting it.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200923/41a7cbe9/attachment.html>
More information about the llvm-bugs
mailing list