<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<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">Hello llvm-dev,</p>
<p style="margin-top:0;margin-bottom:0">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="margin-top:0;margin-bottom:0">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="OWAAutoLink">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="margin-top:0;margin-bottom:0">llvm-as < /dev/null | opt -O3 -disable-output -debug-pass=Arguments</p>
<p style="margin-top:0;margin-bottom:0">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="margin-top:0;margin-bottom:0">Again, I found this other command that does something similar (it lists the sequence of optimization passes applied):</p>
<p style="margin-top:0;margin-bottom:0">clang -O3 -mllvm -debug-pass=Arguments file.c </p>
<p style="margin-top:0;margin-bottom:0">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="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">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="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">I am currently using <span style="font-size: 12pt;">LLVM version 5.0.2.</span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-size: 12pt;"><br>
</span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-size: 12pt;">Thank you for both your help and your time!</span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-size: 12pt;"><br>
</span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-size: 12pt;">Best regards</span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-size: 12pt;">Emanuele</span></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.
</body>
</html>