Hi, Stefano<br>I also have the problem as described by Emanuele. You say that clang schedules target-independent and target-dependent passes. <br>However, when I use lli to execute bitcode generated by opt with -O3 or with the same optimization passes as -O3, the performance are still different.<br>So, are there some special operations by -O3 option? I read the source code of opt, but I cannot find the reason.<br><br>Best regards<br>Zide<br><br>At 2018-08-16 22:13:14, "Stefano Cherubin via llvm-dev" <llvm-dev@lists.llvm.org> wrote:<br> <blockquote id="isReplyContent" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><div style="font-family:bookman old style, new york, times, serif;font-size:16px;"><div style="font-family:bookman old style, new york, times, serif;font-size:16px;"><div style="font-family:bookman old style, new york, times, serif;font-size:16px;"><div style="font-family:bookman old style, new york, times, serif;font-size:16px;"><div></div>
<div>Hello Emanuele,</div><div><br></div><div>When you provide the optimization level -O3 to the clang driver, it does not simply schedule a sequence of passes to be run on the intermediate representation.</div><div>Indeed, it schedules target-independent and target-dependent passes.</div><div>Moreover, IIRC, the optimization level is also used in the later stages of the code generation to apply target-dependent optimizations (i.e. vectorizer).</div><div><br></div><div>The most common use case when someone wants to test its own pass/work within the LLVM toolchain is the following<br></div><div>- use clang to generate a LLVM-IR file</div><div>- use opt to run your desired pass / pass sequence and output another LLVM-IR file</div><div>- use clang -O3 to compile to executable machine code</div><div><br></div><div>However, with this approach you will run the passes on the LLVM-IR twice.</div><div>There are use cases when this could invalidate your results.</div><div>A<span></span>s opt stops at LLVM-IR level, I would suggest you to use also other LLVM tools to run individually the backend stages / sequence of passes which cannot be run by opt (such as llc / llvm-mc).</div><div>An extensive list of tools/commands you can use is available at [0].</div><div>For your specific case, I would suggest you to have a look at this restricted schema [1].</div><div><br></div><div>Yet there is another way to get into even fine grain detail.</div><div>You can check which are the clang DriverActions you are running with a given command line. See [2].</div><div>From that point you can rebuild the exact whole sequence of commands that the clang driver triggers.</div><div><br></div><div>If you can provide more details about what is your use case (measure performance, pass development and testing, flag selection, phase ordering), we can suggest the most suitable approach.</div><div><br></div><div>Kind regards,</div><div><br></div><div>Stefano Cherubin</div><div><br></div><div>[0] http://llvm.org/docs/CommandGuide/</div><div>[1] https://github.com/skeru/LLVM-intro/blob/master/img/03/toolchain.pdf</div><div>[2] https://clang.llvm.org/docs/DriverInternals.html#driver-stages<br></div><div><br></div><div><br></div><div><br></div><div><br></div>
</div></div></div><div id="ydp8cb328fayahoo_quoted_5100480480" class="ydp8cb328fayahoo_quoted">
<div style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;color:#26282a;">
<div>
On Thursday, 16 August 2018, 12:46:04 CEST, Emanuele Del Sozzo via llvm-dev <<A href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</A>> wrote:
</div>
<div><br></div>
<div><br></div>
<div><div id="ydp8cb328fayiv4757402819">
<div dir="ltr">
<div id="ydp8cb328fayiv4757402819divtagdefaultwrapper" dir="ltr" style="font-size:12pt;color:rgb(0, 0, 0);font-family:Calibri, Helvetica, sans-serif, EmojiFont, Color UI NotoColorEmoji, UI EmojiSymbols;">
<p style="margin-top:0;margin-bottom:0;"></p>
<p style="font-family:Calibri, Helvetica, sans-serif, serif, EmojiFont;font-size:16px;">
Hello llvm-dev,</p>
<p style="font-family:Calibri, Helvetica, sans-serif, serif, EmojiFont;font-size:16px;">
my name is Emanuele and I am an intern in ARM. As part of the project I am doing here, I would like to manually replicate the optimizations that LLVM applies when I type -O3. In other words, I would like to know what are the compilation flags/passes that -O3
triggers. </p>
<p style="font-family:Calibri, Helvetica, sans-serif, serif, EmojiFont;font-size:16px;">
I noticed that GCC reports, on its website, all the flags that are enforced by -O3 (<a href="https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html" class="ydp8cb328fayiv4757402819x_OWAAutoLink" rel="nofollow" target="_blank">https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html</a>),
but I wasn't able to find something similar within LLVM documentation. On the other hand, I found that this command displays all the optimization passes applied by opt when -O3 flag is on:</p>
<p style="font-family:Calibri, Helvetica, sans-serif, serif, EmojiFont;font-size:16px;">
llvm-as < /dev/null | opt -O3 -disable-output -debug-pass=Arguments</p>
<p style="font-family:Calibri, Helvetica, sans-serif, serif, EmojiFont;font-size:16px;">
I tried to apply the same optimization passes through opt, but, even though the performance are similar, the resulting binary is slower than the one generated using -O3 (also the binaries differ, of course).</p>
<p style="font-family:Calibri, Helvetica, sans-serif, serif, EmojiFont;font-size:16px;">
Again, I found this other command that does something similar (it lists the sequence of optimization passes applied):</p>
<p style="font-family:Calibri, Helvetica, sans-serif, serif, EmojiFont;font-size:16px;">
clang -O3 -mllvm -debug-pass=Arguments file.c </p>
<p style="font-family:Calibri, Helvetica, sans-serif, serif, EmojiFont;font-size:16px;">
In this case, the performance are still different and some of the optimization passes listed in the last block of passes (e.g. -machinemoduleinfo, -stack-protector, etc.) are unknown to opt.</p>
<p style="font-family:Calibri, Helvetica, sans-serif, serif, EmojiFont;font-size:16px;">
<br>
</p>
<p style="font-family:Calibri, Helvetica, sans-serif, serif, EmojiFont;font-size:16px;">
Said that, my question is: how can I find out what optimization passes/flags -O3 enforces in order to manually apply the same optimizations and have, hopefully, the same binary and performance?</p>
<p style="font-family:Calibri, Helvetica, sans-serif, serif, EmojiFont;font-size:16px;">
<br>
</p>
<p style="font-family:Calibri, Helvetica, sans-serif, serif, EmojiFont;font-size:16px;">
I am currently using <span style="font-size:12pt;">LLVM version 5.0.2.</span></p>
<p style="font-family:Calibri, Helvetica, sans-serif, serif, EmojiFont;font-size:16px;">
<span style="font-size:12pt;"><br>
</span></p>
<p style="font-family:Calibri, Helvetica, sans-serif, serif, EmojiFont;font-size:16px;">
<span style="font-size:12pt;">Thank you for both your help and your time!</span></p>
<p style="font-family:Calibri, Helvetica, sans-serif, serif, EmojiFont;font-size:16px;">
<span style="font-size:12pt;"><br>
</span></p>
<p style="font-family:Calibri, Helvetica, sans-serif, serif, EmojiFont;font-size:16px;">
<span style="font-size:12pt;">Best regards</span></p>
<p style="font-family:Calibri, Helvetica, sans-serif, serif, EmojiFont;font-size:16px;">
<span style="font-size:12pt;">Emanuele</span></p>
<br>
<p></p>
</div>
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose,
or store or copy the information in any medium. Thank you.
</div>
</div>_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:llvm-dev@lists.llvm.org" rel="nofollow" target="_blank">llvm-dev@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="nofollow" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br></div>
</div>
</div></div></blockquote><br><br><span title="neteasefooter"><p> </p></span>