<div dir="ltr"><div>@Sean, here is my summary of several tools. </div><div><br></div><div>Format: (ID,tool, input->output, timing, customization, questions)<br></div><div><br></div>1. llc, 1 bc -> 1 obj, back-end compile-time (code generation and machine-dependent optimizations),  Difficult to customize pipeline, N/A<div>2. LLD:  all bc files and obj files -> 1 binary (passing -flto to clang for *.bc file generation),  back-end link-time optimizations and code generations and machine-dependent optimizations, Easy to customize pipeline w/ <span style="font-size:12.800000190734863px">-lto-newpm-passes, </span><span style="font-size:12.800000190734863px">what is the connection between </span><span style="font-size:12.800000190734863px">-lto-newpm-passes and</span><span style="font-size:12.800000190734863px">  -lto-newpm-aa-pipeline and how to use </span><span style="font-size:12.800000190734863px">-lto-newpm-passes to customize pipeline</span><span style="font-size:12.800000190734863px">?</span></div><div><span style="font-size:12.800000190734863px">3. gold: mixed obj files and bc files -> 1 binary (passing </span>-flto to clang for *.bc file generation)<span style="font-size:12.800000190734863px">, back-end link-time optimization w/ LLVMgold.so and code generation and machine-dependent optimizations, unaware of whether it is customizable by means of command line options, can we consider LLD a more customizable gold from perspective of pipeline customization?</span></div><div><span style="font-size:12.800000190734863px">4. </span>opt, 1 bc file -> 1 file at a time, middle-end machine-independent (may be others?), Easy to customize pipeline by means of command line options, N/A</div><div>5. llvm-link, many *bc file -> 1 bc file, link-time (unknown whether there is any optimization) and Unknown why it exists, unknown how to do customization, N/A</div><div><br></div><div>With above understandings, there are several ways to fine-grained tune clang/llvm optimization pipeline:</div><div>1. clang (c/c++  to bc translation, with minimal front-end optimizations, w/ -emit-llvm <span style="font-size:12.800000190734863px">-O1 </span><span style="font-size:12.8px">-Xclang -disable-llvm-passes</span>), --> opt (w/ customizable middle-end optimizations for each bc file independently) --> gold (un-customizable back-end link-time optimization and code generation)</div><div><div>2. clang (c/c++  to bc translation, with minimal front-end optimizations, w/ -flto) -->opt ( same as 1) --> lld (w/ <span style="font-size:12.800000190734863px">-lto-newpm-passes for link-time optimization pipeline customization, how?)</span></div></div><div><span style="font-size:12.800000190734863px">3. clang (c/c++ to *bc translation and optimization, </span><span style="font-size:12.800000190734863px">customizable by mean of clang command-line options, maybe including both front-end optimization and middle-end optimizations). W/O explicitly specifying opt optimization pipeline, there may still be middle-end optimizations happening; also w/o explicitly specifying linker, it may use GNU ld / GNU gold / lld as the linker and with whichever's default link-time optimization pipeline.</span></div><div><span style="font-size:12.800000190734863px"><br></span></div><div><span style="font-size:12.800000190734863px">So, it seems to me that 2 is the most customizable pipeline, with customizable middle-end and back-end pipeline independently, the 1 with only customizable middle-end optimization pipeline, and then 3 has the least amount of control of optimization pipeline by means of clang command-line.</span></div><div><span style="font-size:12.800000190734863px"><br></span></div><div><span style="font-size:12.800000190734863px">Thanks for your time and welcome to any comments!</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jan 7, 2018 at 12:40 AM, Sean Silva <span dir="ltr"><<a href="mailto:chisophugis@gmail.com" target="_blank">chisophugis@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="auto"><div>No, I meant LLD, the LLVM linker. This option for LLD is relevant for exploring different pass pipelines for link time optimization.</div><div dir="auto"><br></div><div dir="auto">It is essentially equivalent to the -passes flag for 'opt'.</div><div dir="auto"><br></div><div dir="auto">Such a flag doesn't make much sense for 'llc' because llc mostly runs backend passes, which are much more difficult to construct custom pipelines for (backend passes are often required for correctness or have complex ordering requirements).</div><span class="HOEnZb"><font color="#888888"><div dir="auto"><br></div></font></span><div dir="auto"><span class="HOEnZb"><font color="#888888">-- Sean Silva</font></span><div><div class="h5"><br><div class="gmail_extra" dir="auto"><br><div class="gmail_quote">On Jan 6, 2018 7:35 PM, "toddy wang" <<a href="mailto:wenwangtoddy@gmail.com" target="_blank">wenwangtoddy@gmail.com</a>> wrote:<br type="attribution"><blockquote class="m_3907133525831994090quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">@Sean, do you mean llc ?<div>For llc 4.0 and llc 5.0, I cannot find <span style="font-size:12.800000190734863px">-lto-newpm-passes option, is it a hidden one?</span></div></div><div class="m_3907133525831994090elided-text"><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jan 6, 2018 at 7:37 PM, Sean Silva <span dir="ltr"><<a href="mailto:chisophugis@gmail.com" target="_blank">chisophugis@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="auto"><span><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Jan 5, 2018 11:30 PM, "toddy wang via llvm-dev" <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br type="attribution"><blockquote class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277quote" 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></blockquote></div></div></div><div dir="auto"><br></div></span><div dir="auto">LLD has -lto-newpm-passes (and the corresponding -lto-newpm-aa-pipeline) which allows you to pass a custom pass pipeline with full control. At one point I was using a similar modification to clang (see <a href="https://reviews.llvm.org/D21954" target="_blank">https://reviews.llvm.org/<wbr>D21954</a>) that never landed.</div><span class="m_3907133525831994090m_-1140391782659658647HOEnZb"><font color="#888888"><div dir="auto"><br></div><div dir="auto">-- Sean Silva</div></font></span><div><div class="m_3907133525831994090m_-1140391782659658647h5"><div dir="auto"><br></div><div dir="auto"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><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_3907133525831994090m_-1140391782659658647m_6034123896947059277elided-text"><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_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426HOEnZb"><font color="#888888"><div><br></div><div><br></div></font></span></div><div class="gmail_extra"><span class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426HOEnZb"><font color="#888888"><br clear="all"><div><div class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_2174135488509756738gmail_signature" data-smartmail="gmail_signature">~Craig</div></div></font></span><div><div class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426h5">
<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_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_2174135488509756738HOEnZb"><div class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_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_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_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_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_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_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_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_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-s1" style="font-variant-ligatures:no-common-ligatures">Date: <span class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-Apple-converted-space">  </span>Mon May 29 05:38:20 2017 +0000</span></p>
<p class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_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_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-s1" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_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_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-Apple-converted-space">    </span>IRGen: Add optnone attribute on function during O0</span></p>
<p class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_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_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-s1" style="font-variant-ligatures:no-common-ligatures">    </span></p>
<p class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_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_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-Apple-converted-space">    </span>Amongst other, this will help LTO to correctly handle/honor files</span></p>
<p class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_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_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-Apple-converted-space">    </span>compiled with O0, helping debugging failures.</span></p>
<p class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_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_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_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_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_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_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-Apple-converted-space">    </span>-fnoinline adds the appropriate attribute as well.</span></p>
<p class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_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_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-s1" style="font-variant-ligatures:no-common-ligatures">    </span></p>
<p class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_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_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_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_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_2174135488509756738m_5669078264214194911HOEnZb"><font color="#888888"><div><br></div><div><br></div></font></span></div></div><div class="gmail_extra"><span class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_2174135488509756738m_5669078264214194911HOEnZb"><font color="#888888"><br clear="all"><div><div class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_2174135488509756738m_5669078264214194911m_-4997143994764681168gmail_signature" data-smartmail="gmail_signature">~Craig</div></div></font></span><div><div class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_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_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_2174135488509756738m_5669078264214194911m_-4997143994764681168HOEnZb"><div class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_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_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_2174135488509756738m_5669078264214194911m_-4997143994764681168m_2034229146786603789HOEnZb"><font color="#888888"><br clear="all"><div><div class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_2174135488509756738m_5669078264214194911m_-4997143994764681168m_2034229146786603789m_-8339188297650556759gmail_signature" data-smartmail="gmail_signature">~Craig</div></div></font></span><div><div class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_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_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_2174135488509756738m_5669078264214194911m_-4997143994764681168m_2034229146786603789m_-8339188297650556759HOEnZb"><div class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_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_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_2174135488509756738m_5669078264214194911m_-4997143994764681168m_2034229146786603789m_-8339188297650556759m_9146112996686254187HOEnZb"><div class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_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_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_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_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_2174135488509756738m_5669078264214194911m_-4997143994764681168m_2034229146786603789m_-8339188297650556759m_9146112996686254187m_-1208587949809955168HOEnZb"><font color="#888888"><div>Mehdi</div></font></span><div><div class="m_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_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_3907133525831994090m_-1140391782659658647m_6034123896947059277m_5023718488316049426m_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><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></div></div>
</blockquote></div><br></div>
</div></blockquote></div><br></div></div></div></div></div>
</blockquote></div><br></div>