<div dir="ltr">Thanks, Craig! That totally corrects my wrong understanding about the front end. I tried it and indeed now I can see almost the same results.<div><br></div><div>Best,</div><div>Peizhao</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 10, 2017 at 5:21 PM, Craig Topper <span dir="ltr"><<a href="mailto:craig.topper@gmail.com" target="_blank">craig.topper@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">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><br></div><div>What you really need to do is</div><div><br></div><div>clang -O3 -c emit-llvm -o source.bc -v</div><div><br></div><div>Find the -cc1 command line from that output. Execute that command with --disable-llvm-passes. leave the -O3 and everything else.</div><div><br></div><div>You should be able to feed the output from that command to opt/llc and get consistent results.</div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br clear="all"><div><div class="m_5719454700579579761gmail_signature" data-smartmail="gmail_signature">~Craig</div></div>
<br><div class="gmail_quote"><div><div class="h5">On Mon, Apr 10, 2017 at 4:57 PM, Peizhao Ou via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">Hi folks,<div><br></div><div>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">http://stackoverflow.com<wbr>/questions/40350990/relationsh<wbr>ip-between-clang-opt-llc-and-<wbr>llvm-linker</a>. Sorry for posting a similar question again, but I still have something that hasn't been resolved yet.</div><div><br></div><div>More specifically I am wondering about the following two approaches compiling optimized executable:</div><div><br></div><div>1. clang -O3 -c source.c -o source.o</div><div>    ...</div><div>    clang a.o b.o c.o ... -o executable</div><div><br></div><div>2. clang -O0 -c -emit-llvm -o source.bc</div><div>    opt -O3 source.bc -o source.bc</div><div>    llc -O3 -filetype=obj source.bc -o source.o</div><div>    ...</div><div>    clang a.o b.o c.o ... -o executable<br></div><div><br></div><div>I took a look at the source code of the clang tool and the opt tool, they both seem to use the PassManagerBuilder::populateMo<wbr>dulePassManager() and PassManagerBuilder::populateFu<wbr>nctionPassManager() 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><br></div><div>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><br></div><div>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><br></div><div>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><br></div><div>Peizhao</div>















</div>
<br></div></div>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>