<div dir="ltr">-disable-O0-optnone has no effect with anything other than -O0.<div><br></div><div>-O0 being passed to clang also causes all functions to be marked noinline. I don't know if there is a command line option to turn that off.</div><div><br></div><div>I recommend passing "-O1 <span style="font-size:12.8px">-Xclang -disable-llvm-passes" to clang. Passing -O0 very specifically means disable optimizations.</span></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature">~Craig</div></div>
<br><div class="gmail_quote">On Sat, Jan 6, 2018 at 12:25 PM, toddy wang <span dir="ltr"><<a href="mailto:wenwangtoddy@gmail.com" target="_blank">wenwangtoddy@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"><div>@Craig and @Michael</div><div><br></div>After installing clang-5.0 (download from <a href="http://releases.llvm.org" target="_blank">http://releases.llvm.org</a>, does not have Flang build's slowdown mention above),<div><br></div><div>1. clang++ -O0 -Xclang -disable-O0-optnone -Xclang -disable-llvm-passes -c -emit-llvm -o a.bc LULESH.cc; opt -O3 a.bc -o b.bc; llc -O3 -filetype=obj b.bc -o b.o ; clang++ b.o -o b.out; ./b.out 20<br></div><div>runtime: 2.354069e+01</div><div><br></div><div>2. clang++ -O1 -Xclang -disable-O0-optnone -Xclang -disable-llvm-passes -c -emit-llvm -o a.bc LULESH.cc; opt -O3 a.bc -o b.bc; llc -O3 -filetype=obj b.bc -o b.o ; clang++ b.o -o b.out; ./b.out 20</div><div>runtime: 9.046271e+00</div><div><br></div><div>3. clang++ -O3 LULESH.cc</div><div>runtime: 9.118835e+00</div><div><br></div><div>4. clang++ -O2 -Xclang -disable-O0-optnone -Xclang -disable-llvm-passes -c -emit-llvm -o a.bc LULESH.cc; opt -O3 a.bc -o b.bc; llc -O3 -filetype=obj b.bc -o b.o ; clang++ b.o -o b.out; ./b.out 20</div><div>runtime: 9.091278e+00</div><div><br></div><div><div>5. clang++ -O3 -Xclang -disable-O0-optnone -Xclang -disable-llvm-passes -c -emit-llvm -o a.bc LULESH.cc; opt -O3 a.bc -o b.bc; llc -O3 -filetype=obj b.bc -o b.o ; clang++ b.o -o b.out; ./b.out 20</div><div>runtime: 9.096919e+00</div></div><div><br></div><div>Apparently, clang++ -O0 -Xclang -disable-O0-optnone does not work as expected.</div><div><br></div><div>The conclusion seems to be  -Xclang -disable-O0-optnone works when clang optimization level is O1/O2/O3, not O0.</div><div><br></div><div>Any comments?</div><div><br></div><div><br></div><div><br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jan 6, 2018 at 2:30 AM, toddy wang <span dir="ltr"><<a href="mailto:wenwangtoddy@gmail.com" target="_blank">wenwangtoddy@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">What I am trying is to compile a program with different sets of optimization flags.<div>If there is no fine-grained control over clang optimization flags, it would be impossible to achieve what I intend.</div><div><br></div><div>Although there is fine-grained control via opt, for a large-scale projects, clang-opt-llc pipeline may not be a drop-in solution.</div></div><div class="m_-790160743136134571HOEnZb"><div class="m_-790160743136134571h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 5, 2018 at 10:00 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">I don't think "clang -help" prints options about optimizations. Clang itself doesn't have direct support for fine grained optimization control. Just the flag for levels -O0/-O1/-O2/-O3. This is intended to be simple and sufficient interface for most users who just want to compile their code. So I don't think there's a way to pass just -dse to clang.<div><br></div><div>opt on the other hand is more of a utility for developers of llvm that provides fine grained control of optimizations for testing purposes.</div><span class="m_-790160743136134571m_-2991422856885004700HOEnZb"><font color="#888888"><div><br></div><div><br></div></font></span></div><div class="gmail_extra"><span class="m_-790160743136134571m_-2991422856885004700HOEnZb"><font color="#888888"><br clear="all"><div><div class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738gmail_signature" data-smartmail="gmail_signature">~Craig</div></div></font></span><div><div class="m_-790160743136134571m_-2991422856885004700h5">
<br><div class="gmail_quote">On Fri, Jan 5, 2018 at 5:41 PM, toddy wang <span dir="ltr"><<a href="mailto:wenwangtoddy@gmail.com" target="_blank">wenwangtoddy@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">Craig, thanks a lot!<div><br></div><div>I'm actually confused by clang optimization flags.</div><div><br></div><div>If I run clang -help, it will show many optimizations (denoted as set A)  and non-optimization options (denoted as set B). </div><div>If I run llvm-as < /dev/null | opt -O0/1/2/3 -disable-output -debug-pass=Arguments, it also shows many optimization flags (denote as set C).</div><div><br></div><div>There are many options in set C while not in set A, and also options in set A but not in set C.</div><div><br></div><div>The general question is:  what is the relationship between set A and set C, at the same optimization level O0/O1/O2/O3?</div><div>Another question is: how to specify an option in set C as a clang command line option, if it is not in A?</div><div><br></div><div>For example, -dse is in set C but not in set A, how can I specify it as a clang option? Or simply I cannot do that.</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div><div class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738HOEnZb"><div class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 5, 2018 at 7:55 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">O0 didn't start applying optnone until r304127 in May 2017 which is after the 4.0 family was branched. So only 5.0, 6.0, and trunk have that behavior. Commit message copied below<div><br></div><div>







<p class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(255,255,255);background-color:rgb(43,102,201)"><span class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-s1" style="font-variant-ligatures:no-common-ligatures">Author: Mehdi Amini <<a href="mailto:joker.eph@gmail.com" target="_blank">joker.eph@gmail.com</a>></span></p>
<p class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(255,255,255);background-color:rgb(43,102,201)"><span class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-s1" style="font-variant-ligatures:no-common-ligatures">Date: <span class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-Apple-converted-space">  </span>Mon May 29 05:38:20 2017 +0000</span></p>
<p class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(255,255,255);background-color:rgb(43,102,201);min-height:13px"><span class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-s1" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(255,255,255);background-color:rgb(43,102,201)"><span class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-Apple-converted-space">    </span>IRGen: Add optnone attribute on function during O0</span></p>
<p class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(255,255,255);background-color:rgb(43,102,201);min-height:13px"><span class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-s1" style="font-variant-ligatures:no-common-ligatures">    </span></p>
<p class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(255,255,255);background-color:rgb(43,102,201)"><span class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-Apple-converted-space">    </span>Amongst other, this will help LTO to correctly handle/honor files</span></p>
<p class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(255,255,255);background-color:rgb(43,102,201)"><span class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-Apple-converted-space">    </span>compiled with O0, helping debugging failures.</span></p>
<p class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(255,255,255);background-color:rgb(43,102,201)"><span class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-Apple-converted-space">    </span>It also seems in line with how we handle other options, like how</span></p>
<p class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(255,255,255);background-color:rgb(43,102,201)"><span class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-Apple-converted-space">    </span>-fnoinline adds the appropriate attribute as well.</span></p>
<p class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(255,255,255);background-color:rgb(43,102,201);min-height:13px"><span class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-s1" style="font-variant-ligatures:no-common-ligatures">    </span></p>
<p class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(255,255,255);background-color:rgb(43,102,201)"><span class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-Apple-converted-space">    </span>Differential Revision: <a href="https://reviews.llvm.org/D28404" target="_blank">https://reviews.llvm.org/D2840<wbr>4</a></span></p><span class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911HOEnZb"><font color="#888888"><div><br></div><div><br></div></font></span></div></div><div class="gmail_extra"><span class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911HOEnZb"><font color="#888888"><br clear="all"><div><div class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail_signature" data-smartmail="gmail_signature">~Craig</div></div></font></span><div><div class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911h5">
<br><div class="gmail_quote">On Fri, Jan 5, 2018 at 4:49 PM, toddy wang <span dir="ltr"><<a href="mailto:wenwangtoddy@gmail.com" target="_blank">wenwangtoddy@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"><div>@Zhaopei, thanks for the clarification.</div><div><br></div>@Craig and @Michael, for clang 4.0.1,  -Xclang -disable-O0-optnone gives the following error message. From which version -disable-O0-optnone gets supported?<div><br></div><div><div>[twang15@c89 temp]$ clang++ -O0 -Xclang -disable-O0-optnone -Xclang -disable-llvm-passes -c -emit-llvm -o a.bc LULESH.cc</div><div>error: unknown argument: '-disable-O0-optnone'</div><div><br></div><div>[twang15@c89 temp]$ clang++ --version</div><div>clang version 4.0.1 (tags/RELEASE_401/final)</div><div>Target: x86_64-unknown-linux-gnu</div></div></div><div class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168HOEnZb"><div class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 5, 2018 at 4:45 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">If you pass -O0 to clang, most functions will be tagged with an optnone function attribute that will prevent opt and llc even if you pass -O3 to opt and llc. This is the mostly likely cause for the slow down in 2.<div><br></div><div>You can disable the optnone function attribute behavior by passing "-Xclang -disable-O0-optnone" to clang</div></div><div class="gmail_extra"><span class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168m_2034229146786603789HOEnZb"><font color="#888888"><br clear="all"><div><div class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168m_2034229146786603789m_-8339188297650556759gmail_signature" data-smartmail="gmail_signature">~Craig</div></div></font></span><div><div class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168m_2034229146786603789h5">
<br><div class="gmail_quote">On Fri, Jan 5, 2018 at 1:19 PM, toddy wang 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><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I tried the following on LULESH1.0 serial version (<a href="https://codesign.llnl.gov/lulesh/LULESH.cc" target="_blank">https://codesign.llnl.gov/lul<wbr>esh/LULESH.cc</a>)<div><br></div><div>1. clang++ -O3 LULESH.cc; ./a.out 20</div><div>Runtime: 9.487353 second</div><div><br></div><div>2. clang++ -O0 -Xclang -disable-llvm-passes -c -emit-llvm -o a.bc LULESH.cc; opt -O3 a.bc -o b.bc; llc -O3 -filetype=obj b.bc -o b.o ; clang++ b.o -o b.out; ./b.out 20</div><div>Runtime: 24.15 seconds</div><div><br></div><div>3. clang++ -O3 -Xclang -disable-llvm-passes -c -emit-llvm -o a.bc LULESH.cc; opt -O3 a.bc -o b.bc; llc -O3 -filetype=obj b.bc -o b.o ; clang++ b.o -o b.out; ./b.out 20</div><div>Runtime: 9.53 seconds</div><div><br></div><div>1 and 3 have almost the same performance, while 2 is significantly worse, while I expect 1, 2 ,3 should have trivial difference.</div><div><br></div><div>Is this a wrong expectation?</div><div><br></div><div>@Peizhao, what did you try in your last post?</div></div><div class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168m_2034229146786603789m_-8339188297650556759HOEnZb"><div class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168m_2034229146786603789m_-8339188297650556759h5"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 11, 2017 at 12:15 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><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">It's really nice of you pointing out the -Xclang option, it makes things much easier. I really appreciate your help!<div><br></div><div>Best,</div><div>Peizhao</div></div><div class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168m_2034229146786603789m_-8339188297650556759m_9146112996686254187HOEnZb"><div class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168m_2034229146786603789m_-8339188297650556759m_9146112996686254187h5"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 10, 2017 at 10:12 PM, Mehdi Amini <span dir="ltr"><<a href="mailto:mehdi.amini@apple.com" target="_blank">mehdi.amini@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><span><blockquote type="cite"><div>On Apr 10, 2017, at 5:21 PM, Craig Topper via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168m_2034229146786603789m_-8339188297650556759m_9146112996686254187m_-1208587949809955168m_-6624049905980539258Apple-interchange-newline"><div><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></div></blockquote><div><br></div></span><div>It also disable lifetime instrinsics emission and TBAA, etc.</div><span><div><br></div><br><blockquote type="cite"><div><div dir="ltr"><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></div></blockquote><div><br></div></span><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></div><div>Best,</div><div><br></div><div>— </div><span class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168m_2034229146786603789m_-8339188297650556759m_9146112996686254187m_-1208587949809955168HOEnZb"><font color="#888888"><div>Mehdi</div></font></span><div><div class="m_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168m_2034229146786603789m_-8339188297650556759m_9146112996686254187m_-1208587949809955168h5"><div><br></div><div><br></div><br><blockquote type="cite"><div><div dir="ltr"><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_-790160743136134571m_-2991422856885004700m_2174135488509756738m_5669078264214194911m_-4997143994764681168m_2034229146786603789m_-8339188297650556759m_9146112996686254187m_-1208587949809955168m_-6624049905980539258gmail_signature" data-smartmail="gmail_signature">~Craig</div></div>
<br><div class="gmail_quote">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><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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-l<wbr>lvm-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>______________________________<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>
______________________________<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" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br></div></blockquote></div></div></div><br></div></blockquote></div><br></div>
</div></div><br>______________________________<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>
</div></div><br>______________________________<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></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>