<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 10, 2017, at 5:21 PM, Craig Topper via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">clang -O0 does not disable all optimization passes modify the IR.; In fact it causes most functions to get tagged with noinline to prevent inlinining</div></div></blockquote><div><br class=""></div><div>It also disable lifetime instrinsics emission and TBAA, etc.</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">What you really need to do is</div><div class=""><br class=""></div><div class="">clang -O3 -c emit-llvm -o source.bc -v</div><div class=""><br class=""></div><div class="">Find the -cc1 command line from that output. Execute that command with --disable-llvm-passes. leave the -O3 and everything else.</div></div></div></blockquote><div><br class=""></div><div>That’s a bit complicated: CC1 options can be passed through with -Xclang, for example here just adding to the regular clang invocation ` -Xclang -disable-llvm-passes`</div><div><br class=""></div><div>Best,</div><div><br class=""></div><div>— </div><div>Mehdi</div><div><br class=""></div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">You should be able to feed the output from that command to opt/llc and get consistent results.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div></div><div class="gmail_extra"><br clear="all" class=""><div class=""><div class="gmail_signature" data-smartmail="gmail_signature">~Craig</div></div>
<br class=""><div class="gmail_quote">On Mon, Apr 10, 2017 at 4:57 PM, Peizhao Ou via llvm-dev <span dir="ltr" class=""><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">Hi folks,<div class=""><br class=""></div><div class="">I am wondering about the relationship clang, opt and llc. I understand that this has been asked, e.g., <a href="http://stackoverflow.com/questions/40350990/relationship-between-clang-opt-llc-and-llvm-linker" target="_blank" class="">http://stackoverflow.<wbr class="">com/questions/40350990/<wbr class="">relationship-between-clang-<wbr class="">opt-llc-and-llvm-linker</a>. Sorry for posting a similar question again, but I still have something that hasn't been resolved yet.</div><div class=""><br class=""></div><div class="">More specifically I am wondering about the following two approaches compiling optimized executable:</div><div class=""><br class=""></div><div class="">1. clang -O3 -c source.c -o source.o</div><div class=""> ...</div><div class=""> clang a.o b.o c.o ... -o executable</div><div class=""><br class=""></div><div class="">2. clang -O0 -c -emit-llvm -o source.bc</div><div class=""> opt -O3 source.bc -o source.bc</div><div class=""> llc -O3 -filetype=obj source.bc -o source.o</div><div class=""> ...</div><div class=""> clang a.o b.o c.o ... -o executable<br class=""></div><div class=""><br class=""></div><div class="">I took a look at the source code of the clang tool and the opt tool, they both seem to use the PassManagerBuilder::<wbr class="">populateModulePassManager() and PassManagerBuilder::<wbr class="">populateFunctionPassManager() functions to add passes to their optimization pipeline; and for the backend, the clang and llc both use the addPassesToEmitFile() function to generate object code.</div><div class=""><br class=""></div><div class="">So presumably the above two approaches to generating optimized executable file should do the same thing. However, I am seeing that the second approach is around 2% slower than the first approach (which is the way developers usually use) pretty consistently.</div><div class=""><br class=""></div><div class="">Can anyone point me to the reasons why this happens? Or even correct my wrong understanding of the relationship between these two approaches?</div><div class=""><br class=""></div><div class="">PS: I used the -debug-pass=Structure option to print out the passes, they seem the same except that the first approach has an extra pass called "-add-discriminator", but I don't think that's the reason.</div><div class=""><br class=""></div><div class="">Peizhao</div>
</div>
<br class="">______________________________<wbr class="">_________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/<wbr class="">mailman/listinfo/llvm-dev</a><br class="">
<br class=""></blockquote></div><br class=""></div>
_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class=""></div></blockquote></div><br class=""></body></html>