<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0">Hi Stefano,</p>
<p style="margin-top:0;margin-bottom:0">first of all, thank you for your reply!</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">Here the compilation steps I am currently applying:</p>
<p style="margin-top:0;margin-bottom:0"></p>
<div>1) clang main.c -Xclang -disable-O0-optnone -fomit-frame-pointer -Xclang -vectorize-loops -Xclang -vectorize-slp -momit-leaf-frame-pointer <span style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px;">-S
-emit-llvm -o main.ll</span></div>
<div>2) opt main.ll $myPasses -o main.bc</div>
<div>3) llc main.bc -o main.s</div>
<div>4) clang -c main.s</div>
<div>5) clang main.o -lm -o exe -mno-relax-all</div>
<br>
<p></p>
<p style="margin-top:0;margin-bottom:0">With respect to each step:</p>
<p style="margin-top:0;margin-bottom:0">1) I use -disable-O0-optnone because I noticed that, when I do not use any -Olevel flag (I leave the default -O0), opt ignores most of the optimization passes I provide.</p>
<p style="margin-top:0;margin-bottom:0">Moreover, using the following command: </p>
<p style="margin-top:0;margin-bottom:0">c<span style="font-size: 12pt;">lang file.c -xc -O3 -o /dev/null -### </span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-size: 12pt;">I noticed that some clang activates some optimization flags (e.g. -vectorize-loops, -vectorize-slp), that, otherwise, are not enabled by -O0</span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-size: 12pt;">2) $myPasses contains all the optimization passes extracted using this command:</span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-size: 12pt;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;">llvm-as < /dev/null | opt -O3 -disable-output -debug-pass=Arguments</span><br>
</span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-size: 12pt;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;">I also tried using the passes provided by this command:</span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-size: 12pt;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;">clang
-O3 -mllvm -debug-pass=Arguments file.c </span><br>
</span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-size: 12pt;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;">but,
as I said before, some of the optimization passes generate an error</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-size: 12pt;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;">5)
-mno-relax-all comes again from the fact that -mrelax-all is enabled using -O0, while it is not using -O3.</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-size: 12pt;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;"><br>
</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-size: 12pt;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;">I
am currently measuring the performance in terms of execution time. I am using a suite of benchmarks that automatically provides the execution time of its benchmarks. In some cases, my execution times are close to the ones produced using -O3, while, in order
cases, my results are definitely worse.</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-size: 12pt;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;"><br>
</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-size: 12pt;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;">I
also tried to compared the IR generated by step 2) against the one generated by the foloowing command:</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-size: 12pt;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;">clang
main.c -S -emit-llvm</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-size: 12pt;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;">and,
of course, they are different. I noticed that the latter also contains more metadata.</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-size: 12pt;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;"><br>
</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-size: 12pt;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;">Am
I missing any optimizations?</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-size: 12pt;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;"><br>
</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-size: 12pt;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;">Thank
you for your help!</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-size: 12pt;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;"><br>
</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-size: 12pt;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;">Best
regards</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-size: 12pt;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;"><span style="font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 16px;">Emanuele
Del Sozzo</span></span></span></p>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> cszide <cszide@163.com><br>
<b>Sent:</b> Friday, August 17, 2018 2:55:30 AM<br>
<b>To:</b> Stefano Cherubin<br>
<b>Cc:</b> llvm-dev@lists.llvm.org; Emanuele Del Sozzo<br>
<b>Subject:</b> Re:Re: [llvm-dev] Replication -O3 optimizations manually</font>
<div> </div>
</div>
<meta content="text/html; charset=utf-8">
<div>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="x_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="x_ydp8cb328fayahoo_quoted_5100480480" class="x_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="x_ydp8cb328fayiv4757402819">
<div dir="ltr">
<div id="x_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="x_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></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.
</body>
</html>