<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">On Jan 2, 2015, at 8:32 PM, David Callahan <<a href="mailto:dcallahan@fb.com">dcallahan@fb.com</a>> wrote:<br><div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; font-size: 14px; font-family: Calibri, sans-serif;"><div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Cambria;"><a name="OLE_LINK2"></a><a name="OLE_LINK1">Hi,<o:p></o:p></a></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Cambria;"><o:p> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Cambria;">I am new to the LLVM dev community so forgive a perhaps obvious question. I am looking at bug 17623 which is an LTO/optimizer interaction bug.  I am working on a Mac with Xcode installed but have also built the 3.6 LLVM binaries (from a few month old local branch).<o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Cambria;"><o:p> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Cambria;">The default version of “ld” from Apple supports an option “-save-temps” which I believe saves bitcode both before and after the optimizer (and the bug is visible as a difference between these two)<o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Cambria;"><o:p> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Cambria;"><span style="font-family: Consolas;">~/llvm-install/bin/clang -flto -O2 -c -o bug17623.o bug17623.c<o:p></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Cambria;"><span style="font-family: Consolas;">"/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.10.0 -lSystem /Users/dcallahan/llvm-install/bin/..\<o:p></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Cambria;"><span style="font-family: Consolas;">/lib/clang/3.6.0/lib/darwin/libclang_rt.osx.a -save-temps -o bug36 bug17623.o</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Cambria;"><o:p> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Cambria;">(this produces bug36.lto.bc and bug36.lto.opt.bc)<o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Cambria;"><o:p> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Cambria;">However, if I use “opt” to try and duplicate the actions run by “ld”, as in:<o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Cambria;"><o:p> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Cambria;"><span style="font-family: Consolas;">~/llvm-install/bin/opt -O2 -o bug36.opt.bc bug36.lto.bc<o:p></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Cambria;"><o:p> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Cambria;">This generates a different (much cleaner and correct!) output.<o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Cambria;"><o:p> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Cambria;">So my questions are:<o:p></o:p></div><div style="margin: 0in 0in 0.0001pt 0.5in; font-size: 12pt; font-family: Cambria; text-indent: -0.25in;">1.<span style="font-size: 7pt; font-family: 'Times New Roman';">    <span class="Apple-converted-space"> </span></span>Is it feasible to get “opt” to reproduce the behavior of “ld”?</div></div></div></blockquote><div><br></div><div>The optimizations that occur during LTO (the ‘ld’ command) are different from the “normal” optimizations that opt runs. For one, LLVM has a view of the whole program, not just one compilation unit at a time. If you want to look at some of the optimizations that it performs, you can use the “opt -std-link-opts” command.</div><br><blockquote type="cite"><div style="font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; font-size: 14px; font-family: Calibri, sans-serif;"><div><div style="margin: 0in 0in 0.0001pt 0.5in; font-size: 12pt; font-family: Cambria; text-indent: -0.25in;"><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt 0.5in; font-size: 12pt; font-family: Cambria; text-indent: -0.25in;">2.<span style="font-size: 7pt; font-family: 'Times New Roman';">    <span class="Apple-converted-space"> </span></span>Assuming I am just missing some parameters to “opt”, how do I determine what they should be?<o:p></o:p></div></div></div></blockquote><br></div><div>The link time optimizations are enabled via the "-std-link-opts” option.</div><div><br></div><div>-bw</div><br></body></html>