<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="gmail-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="gmail-s1" style="font-variant-ligatures:no-common-ligatures">Author: Mehdi Amini <<a href="mailto:joker.eph@gmail.com">joker.eph@gmail.com</a>></span></p>
<p class="gmail-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="gmail-s1" style="font-variant-ligatures:no-common-ligatures">Date: <span class="gmail-Apple-converted-space">  </span>Mon May 29 05:38:20 2017 +0000</span></p>
<p class="gmail-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="gmail-s1" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="gmail-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="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">    </span>IRGen: Add optnone attribute on function during O0</span></p>
<p class="gmail-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="gmail-s1" style="font-variant-ligatures:no-common-ligatures">    </span></p>
<p class="gmail-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="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">    </span>Amongst other, this will help LTO to correctly handle/honor files</span></p>
<p class="gmail-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="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">    </span>compiled with O0, helping debugging failures.</span></p>
<p class="gmail-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="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">    </span>It also seems in line with how we handle other options, like how</span></p>
<p class="gmail-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="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">    </span>-fnoinline adds the appropriate attribute as well.</span></p>
<p class="gmail-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="gmail-s1" style="font-variant-ligatures:no-common-ligatures">    </span></p>
<p class="gmail-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="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">    </span>Differential Revision: <a href="https://reviews.llvm.org/D28404">https://reviews.llvm.org/D28404</a></span></p><div><br></div><div><br></div></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 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="HOEnZb"><div class="h5"><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_2034229146786603789HOEnZb"><font color="#888888"><br clear="all"><div><div class="m_2034229146786603789m_-8339188297650556759gmail_signature" data-smartmail="gmail_signature">~Craig</div></div></font></span><div><div class="m_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_2034229146786603789m_-8339188297650556759HOEnZb"><div class="m_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_2034229146786603789m_-8339188297650556759m_9146112996686254187HOEnZb"><div class="m_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_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_2034229146786603789m_-8339188297650556759m_9146112996686254187m_-1208587949809955168HOEnZb"><font color="#888888"><div>Mehdi</div></font></span><div><div class="m_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_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>