<div dir="ltr"><div dir="ltr">Hi,<div><br></div><div>I don't see a clean solution to achieve this. A hacky way would be to modify the default constructors of those individual passes to replicate the same behavior as that when under O3. If the same pass is scheduled multiple times in different ways, then you could create new proxy passes(loop-unroll-simple, loop-unroll-O3) to run the same pass but with just different parameters.</div><div><br></div><div>(+ llvm-dev)</div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 14, 2019 at 7:13 PM Rahim Mammadli <<a href="mailto:rahim@mamed.li">rahim@mamed.li</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Dear Bhatu and Mehdi,<div><br></div><div>Thank you for your helpful suggestions. </div><div><br></div><div>Indeed -print-after-all option is quite useful to find out the differences between the two approaches. As Bhatu pointed out, when providing -O3 as an option some of the passes are initialized differently when compared to simply passing a list of passes to opt. Some of the passes even depend on OptLevel as a parameter which influences the behavior of a pass, e.g. the following passes directly depend on the OptLevel parameter:</div><div>* createSimpleLoopUnrollPass()</div><div>* createLoopUnrollAndJamPass()</div><div>* createLoopUnrollPass()</div><div><br></div><div>However, the only way of setting OptLevel and SizeLevel parameters through CLI is by providing -O<> optimization flag, which in turn results in all of the associated passes being added to the list of passes. Is there a way of setting OptLevel = 3 and SizeLevel = 0 without running all the passes associated with -O3? That would probably get me closest to replicating O3, but I cannot figure out how to do it.</div><div><br clear="all"><div><div dir="ltr" class="gmail-m_-2000995316006376752gmail_signature"><div dir="ltr"><div><div dir="ltr">Kind Regards,<div><br></div><div>Rahim Mammadli</div></div></div></div></div></div><br></div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 13 May 2019 at 09:49, Bhatu <<a href="mailto:CS12B1010@iith.ac.in" target="_blank">CS12B1010@iith.ac.in</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">I think this has to do with how the pass manager is populated when we give -O3 vs when we give particular pass names.<div>Some passes have multiple createXYZPass() methods that accept arguments too. These methods call non-default pass constructors, which in turn cause the passes to behave in a different manner.</div><div>eg:</div><div><div>Pass *llvm::createLICMPass() { return new LegacyLICMPass(); }</div><div>Pass *llvm::createLICMPass(unsigned LicmMssaOptCap,</div><div>                           unsigned LicmMssaNoAccForPromotionCap) {</div><div>  return new LegacyLICMPass(LicmMssaOptCap, LicmMssaNoAccForPromotionCap);</div><div>}</div></div><div>or</div><div><div>Pass *createLoopVectorizePass() { return new LoopVectorize(); }</div><div>Pass *createLoopVectorizePass(bool InterleaveOnlyWhenForced,</div><div>                              bool VectorizeOnlyWhenForced) {</div><div>  return new LoopVectorize(InterleaveOnlyWhenForced, VectorizeOnlyWhenForced);</div><div>}</div></div><div>When we give pass names, opt calls the default constructor (eg: LoopVectorize()) whereas when we give O3, it can call a different version.</div><div>You can check in PassManagerBuilder.cpp (populateModulePassManager, populateFunctionPassManager) to see where different versions are being populated. Those must be the points in the pipeline where the IR starts differing. </div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, May 11, 2019 at 10:09 PM Mehdi AMINI via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">Hi,</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, May 9, 2019 at 5:20 PM Rahim Mammadli via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Dear developers,<div><br></div><div>I am trying to reproduce the results of applying opt -O3 to a source file in the form of LLVM IR. I want to get the same IR by manually ordering the passes used by O3 and passing them to opt. </div><div><br></div><div>To illustrate what I am doing on an example, as an input I use linpack benchmark from the LLVM test suite[1]:</div><div><br></div><div>1. First I produce the intermediate representation using clang:</div><div>clang -O3 -Xclang -disable-llvm-optzns -emit-llvm -S linpack-pc.c -o linpack-pc.ll<br></div><div><br></div><div>2. Then I use opt to optimize the IR:</div><div>opt -S -O3 -o linpack-pc-3.ll linpack-pc.ll<br></div><div><br></div><div>Now my goal is to produce the IR identical to linpack-pc-3.ll by passing a sequence of optimizations to opt. To get the list of optimizations used by opt for O3, I run this:</div><div>opt -O3 -disable-output -debug-pass=Arguments linpack-pc.ll<br></div><div><br></div><div>Which produces (shortened to avoid wasting space):</div><div><div>Pass Arguments:  -tti -targetlibinfo -tbaa ...</div><div>Pass Arguments:  -targetlibinfo -tti -tbaa ...</div><div>Pass Arguments:  -domtree</div><div><br></div></div><div>So apparently there are three sequences of passes applied to IR as part of O3. I wasn't able to reproduce the same IR as linpack-pc-3.ll using these passes, I tried applying passes sequentially or concatenating them and passing as a single sequence to opt. Neither produced the needed output. Moreover the performance of the final executable downgraded by about 35%. I'm using LLVM 3.8 and my OS is Ubuntu 16.04.</div><div><br></div><div>[1] <a href="https://github.com/llvm/llvm-test-suite/blob/master/SingleSource/Benchmarks/Linpack/linpack-pc.c" target="_blank">https://github.com/llvm/llvm-test-suite/blob/master/SingleSource/Benchmarks/Linpack/linpack-pc.c</a></div><div> <br></div></div></div></div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div></div><div>I'd very much appreciate if you could help me with this. Thank you.</div></div></div></div></div></div></blockquote><div><br></div><div>Your approach seems sensible to me. I usually have been debugging this kind of problem by piping the output of the two runs with `-print-after-all` to files and diff them to find out where the difference pops in.</div><div><br></div><div>-- </div><div>Mehdi</div><div><br></div></div></div>
_______________________________________________<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="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail-m_-2000995316006376752gmail-m_-4677688217354519596gmail-m_3753848777816909818gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><font size="1"><span style="color:rgb(84,141,212);font-family:arial,helvetica,sans-serif">Regards</span><br></font></div><div><div dir="ltr"><font color="#000000" face="arial, helvetica, sans-serif" size="1"><font color="#548dd4">Bhatu</font></font></div></div></div></div></div></div></div></div></div></div>
</blockquote></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><font size="1"><span style="color:rgb(84,141,212);font-family:arial,helvetica,sans-serif">Regards</span><br></font></div><div><div dir="ltr"><font color="#000000" face="arial, helvetica, sans-serif" size="1"><font color="#548dd4">Bhatu</font></font></div></div></div></div></div></div></div></div></div></div>