<html><head></head><body><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>Hi Zide,</div><div><br></div><div>the scope of opt is limited to the LLVM-IR, which is meant to be always target independent.</div><div>In order to apply backend optimizations you need to lower the representation to something closer to the machine-level.</div><div>I would suggest you to measure performance on machine code, not LLVM-IR.<br></div><div>To this end, please refer to the setup Emanuele is using.</div><div><br></div><div>However, I may not have properly understood your test.</div><div><span><div style="color: rgb(0, 0, 0); font-family: "bookman old style", "new york", times, serif; font-size: 16px;">lli is the LLVM-IR interpreter and it is meant more for functional testing rather than performance testing.</div></span>Are you comparing the performance of machine code generated by clang -O3 against the performance of lli optimized_IR.bc ?</div><div><br></div><div>Best regards,</div><div><br></div><div>Stefano Cherubin</div><div><br></div><div><br></div>
        
        </div><div id="ydpcc5e3842yahoo_quoted_4516679350" class="ydpcc5e3842yahoo_quoted">
            <div style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;color:#26282a;">
                
                <div>
                    On Friday, 17 August 2018, 03:55:52 CEST, cszide <cszide@163.com> wrote:
                </div>
                <div><br></div>
                <div><br></div>
                <div><div id="ydpcc5e3842yiv3325660149"><div>Hi, Stefano<br clear="none">I also have the problem as described by Emanuele. You say that clang schedules target-independent and target-dependent passes. <br clear="none">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 clear="none">So, are there some special operations by -O3 option? I read the source code of opt, but I cannot find the reason.<br clear="none"><br clear="none">Best regards<br clear="none">Zide<br clear="none"><br clear="none">At 2018-08-16 22:13:14, "Stefano Cherubin via llvm-dev" <llvm-dev@lists.llvm.org> wrote:<br clear="none"> <div class="ydpcc5e3842yiv3325660149yqt4830241314" id="ydpcc5e3842yiv3325660149yqt99140"><blockquote id="ydpcc5e3842yiv3325660149isReplyContent" 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 clear="none"></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 clear="none"></div><div>The most common use case when someone wants to test its own pass/work within the LLVM toolchain is the following<br clear="none"></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 clear="none"></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 clear="none"></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 clear="none"></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 clear="none"></div><div>Kind regards,</div><div><br clear="none"></div><div>Stefano Cherubin</div><div><br clear="none"></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 clear="none"></div><div><br clear="none"></div><div><br clear="none"></div><div><br clear="none"></div><div><br clear="none"></div>
        
        </div></div></div><div class="ydpcc5e3842yiv3325660149ydp8cb328fayahoo_quoted" id="ydpcc5e3842yiv3325660149ydp8cb328fayahoo_quoted_5100480480">
            <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 shape="rect" href="mailto:llvm-dev@lists.llvm.org" rel="nofollow" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:
                </div>
                <div><br clear="none"></div>
                <div><br clear="none"></div>
                <div><div id="ydpcc5e3842yiv3325660149ydp8cb328fayiv4757402819">

 


<div dir="ltr">
<div dir="ltr" id="ydpcc5e3842yiv3325660149ydp8cb328fayiv4757402819divtagdefaultwrapper" 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 shape="rect" class="ydpcc5e3842yiv3325660149ydp8cb328fayiv4757402819x_OWAAutoLink" href="https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html" 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 clear="none">
</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 clear="none">
</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 clear="none">
</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 clear="none">
</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 clear="none">
<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 clear="none">LLVM Developers mailing list<br clear="none"><a shape="rect" href="mailto:llvm-dev@lists.llvm.org" rel="nofollow" target="_blank">llvm-dev@lists.llvm.org</a><br clear="none"><a shape="rect" 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 clear="none"></div>
            </div>
        </div></div></blockquote></div><br clear="none"><br clear="none"><span title="neteasefooter"></span><p> </p></div></div></div>
            </div>
        </div></div></body></html>