<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"bookman old style";
        panose-1:2 5 6 4 5 5 5 2 2 4;}
@font-face
        {font-family:"Helvetica Neue";
        panose-1:2 0 5 3 0 0 0 2 0 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Hi Stefano,<o:p></o:p></p>
<p class="MsoNormal">Thank you for the suggestions!<o:p></o:p></p>
<p class="MsoNormal">Actually, I tried to compile the same input file with and without -O3 at llc level, and I noticed no difference (the binary was the same), but I will double check it with a different input code.<o:p></o:p></p>
<p class="MsoNormal">I will also collapse step 3, 4, 5 as you suggested.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks again!<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Best regards<o:p></o:p></p>
<p class="MsoNormal">Emanuele Del Sozzo<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:12.0pt;color:black">From: </span></b><span style="font-size:12.0pt;color:black">Stefano Cherubin <stefano.cherubin@polimi.it><br>
<b>Reply-To: </b>Stefano Cherubin <stefano.cherubin@polimi.it><br>
<b>Date: </b>Saturday, August 18, 2018 at 12:34 PM<br>
<b>To: </b>Emanuele Del Sozzo <Emanuele.DelSozzo@arm.com><br>
<b>Cc: </b>"llvm-dev@lists.llvm.org" <llvm-dev@lists.llvm.org><br>
<b>Subject: </b>Re: Re:Re: [llvm-dev] Replication -O3 optimizations manually<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif">Hi Emanuele,<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif">The first thing I would highlight in your compilation flow is the absence of any optimization level in the compilation step 3.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif">If your goal is to compare code and performance against clang -O3, you would probably need to add -O3 also to the llc command.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif">I honestly don't know on which other steps the optimization level of clang may impact.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif">If the difference, after the aforementioned fix is not negligible, I can suggest you to replace step 3,4,5 with a simpler<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif">clang -O3 main.bc -o exe -lm<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif">Best regards,<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif">Stefano Cherubin<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif"><o:p> </o:p></span></p>
</div>
</div>
<div id="ydp5a2f8e9fyahoo_quoted_4709556182">
<div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Helvetica Neue";color:#26282A">On Friday, 17 August 2018, 11:12:36 CEST, Emanuele Del Sozzo <Emanuele.DelSozzo@arm.com> wrote:
<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Helvetica Neue";color:#26282A"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Helvetica Neue";color:#26282A"><o:p> </o:p></span></p>
</div>
<div>
<div id="ydp5a2f8e9fyiv3169070053">
<div>
<div id="ydp5a2f8e9fyiv3169070053divtagdefaultwrapper">
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black">Hi Stefano,<o:p></o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black">first of all, thank you for your reply!<o:p></o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black">Here the compilation steps I am currently applying:<o:p></o:p></span></p>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black">1) clang main.c -Xclang -disable-O0-optnone -fomit-frame-pointer -Xclang -vectorize-loops -Xclang -vectorize-slp -momit-leaf-frame-pointer -S -emit-llvm -o main.ll<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black">2) opt main.ll $myPasses -o main.bc<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black">3) llc main.bc -o main.s<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black">4) clang -c main.s<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black">5) clang main.o -lm -o exe -mno-relax-all<o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black">With respect to each step:<o:p></o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black">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.<o:p></o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black">Moreover, using the following command: <o:p></o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black">clang file.c -xc -O3 -o /dev/null -### <o:p></o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black">I noticed that some clang activates some optimization flags (e.g. -vectorize-loops, -vectorize-slp), that, otherwise, are not enabled by -O0<o:p></o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black">2) $myPasses contains all the optimization passes extracted using this command:<o:p></o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black">llvm-as < /dev/null | opt -O3 -disable-output -debug-pass=Arguments<o:p></o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black">I also tried using the passes provided by this command:<o:p></o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black">clang -O3 -mllvm -debug-pass=Arguments file.c <o:p></o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black">but, as I said before, some of the optimization passes generate an error<o:p></o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black">5) -mno-relax-all comes again from the fact that -mrelax-all is enabled using -O0, while it is not using -O3.<o:p></o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black">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.<o:p></o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black">I also tried to compared the IR generated by step 2) against the one generated by the foloowing command:<o:p></o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black">clang main.c -S -emit-llvm<o:p></o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black">and, of course, they are different. I noticed that the latter also contains more metadata.<o:p></o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black">Am I missing any optimizations?<o:p></o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black">Thank you for your help!<o:p></o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black">Best regards<o:p></o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt"><span style="font-size:12.0pt;color:black">Emanuele Del Sozzo<o:p></o:p></span></p>
</div>
<div class="MsoNormal" align="center" style="text-align:center"><span style="font-size:10.0pt;font-family:"Helvetica Neue";color:#26282A">
<hr size="2" width="98%" align="center">
</span></div>
<div id="ydp5a2f8e9fyiv3169070053yqt63038">
<div id="ydp5a2f8e9fyiv3169070053divRplyFwdMsg">
<p class="MsoNormal"><b><span style="color:black">From:</span></b><span style="color:black"> 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</span><span style="font-size:10.0pt;font-family:"Helvetica Neue";color:#26282A">
<o:p></o:p></span></p>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Helvetica Neue";color:#26282A"> <o:p></o:p></span></p>
</div>
</div>
</div>
</div>
<div id="ydp5a2f8e9fyiv3169070053yqt14739">
<div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Helvetica Neue";color:#26282A">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>
<br>
<o:p></o:p></span></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A">Hello Emanuele,<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A">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.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A">Indeed, it schedules target-independent and target-dependent passes.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A">Moreover, IIRC, the optimization level is also used in the later stages of the code generation to apply target-dependent optimizations (i.e. vectorizer).<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A">The most common use case when someone wants to test its own pass/work within the LLVM toolchain is the following<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A">- use clang to generate a LLVM-IR file<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A">- use opt to run your desired pass / pass sequence and output another LLVM-IR file<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A">- use clang -O3 to compile to executable machine code<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A">However, with this approach you will run the passes on the LLVM-IR twice.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A">There are use cases when this could invalidate your results.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A">As 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).<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A">An extensive list of tools/commands you can use is available at [0].<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A">For your specific case, I would suggest you to have a look at this restricted schema [1].<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A">Yet there is another way to get into even fine grain detail.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A">You can check which are the clang DriverActions you are running with a given command line. See [2].<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A">From that point you can rebuild the exact whole sequence of commands that the clang driver triggers.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A">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.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A">Kind regards,<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A">Stefano Cherubin<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A">[0] http://llvm.org/docs/CommandGuide/<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A">[1] https://github.com/skeru/LLVM-intro/blob/master/img/03/toolchain.pdf<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A">[2] https://clang.llvm.org/docs/DriverInternals.html#driver-stages<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"bookman old style",serif;color:#26282A"><o:p> </o:p></span></p>
</div>
</div>
</div>
</div>
<div id="ydp5a2f8e9fyiv3169070053x_ydp8cb328fayahoo_quoted_5100480480">
<div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Helvetica Neue";color:#26282A">On Thursday, 16 August 2018, 12:46:04 CEST, Emanuele Del Sozzo via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>>
 wrote: <o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Helvetica Neue";color:#26282A"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Helvetica Neue";color:#26282A"><o:p> </o:p></span></p>
</div>
<div>
<div id="ydp5a2f8e9fyiv3169070053x_ydp8cb328fayiv4757402819">
<div>
<div id="ydp5a2f8e9fyiv3169070053x_ydp8cb328fayiv4757402819divtagdefaultwrapper">
<p><span style="font-size:12.0pt;color:black">Hello llvm-dev,<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black">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. <o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black">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" 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:<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black">llvm-as < /dev/null | opt -O3 -disable-output -debug-pass=Arguments<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black">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).<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black">Again, I found this other command that does something similar (it lists the sequence of optimization passes applied):<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black">clang -O3 -mllvm -debug-pass=Arguments file.c <o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black">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.<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
<p><span style="font-size:12.0pt;color:black">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?<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
<p><span style="font-size:12.0pt;color:black">I am currently using LLVM version 5.0.2.<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
<p><span style="font-size:12.0pt;color:black">Thank you for both your help and your time!<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
<p><span style="font-size:12.0pt;color:black">Best regards<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black">Emanuele<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Helvetica Neue";color:#26282A">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.
<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Helvetica Neue";color:#26282A">_______________________________________________<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/mailman/listinfo/llvm-dev</a><o:p></o:p></span></p>
</div>
</div>
</div>
</div>
</blockquote>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Helvetica Neue";color:#26282A"><br>
<br>
<br>
<o:p></o:p></span></p>
<p><span style="font-size:10.0pt;font-family:"Helvetica Neue";color:#26282A"> <o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Helvetica Neue";color:#26282A">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.
<o:p></o:p></span></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</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>