<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:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
span.EmailStyle20
{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:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
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" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Have you tried using -print-after-all option (you can add it both to opt and llc, and I guess you can use “-mllvm -print-after-all” in the clang++ only case).<o:p></o:p></p>
<p class="MsoNormal">That way I guess you could compare the result to find out where it starts to differ.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">It would be much easier to understand your problem if you for example could determine that the difference appear in opt, or llc, or even later. If the diff is in debug info, or the code, or a data section, or something else. Using print-after-all
code perhaps help out in doing that.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Sometimes it could be helpful to also use -debug-pass=Executions (with legacy PM) or -debug-pass-manager (with new PM) to see a bit more about pass invocations, or to get some more anchors when comparing the print-after-all output (but
as I think Mehdi hinted earlier, just because a pass is run it might have been configured slightly differently depending on other options etc). But it could help out identifying something obvious such as not running the same passes in your two scenarios.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Regards,<o:p></o:p></p>
<p class="MsoNormal">Björn<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b>From:</b> llvm-dev <llvm-dev-bounces@lists.llvm.org> <b>On Behalf Of
</b>Jiayu Zhao via llvm-dev<br>
<b>Sent:</b> den 23 mars 2021 03:46<br>
<b>To:</b> Mircea Trofin <mtrofin@google.com><br>
<b>Cc:</b> llvm-dev@lists.llvm.org<br>
<b>Subject:</b> Re: [llvm-dev] How to produce the same result of clang++ -Oz through opt -Oz<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black">Hi Mircea,<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black">Thank you for your response. I need to run opt +my own pass +llc. <o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black">And I really want to know why llvm produces different object files (.o) and executable files (.out) compared to clang.<o:p></o:p></span></p>
</div>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="2" width="98%" align="center">
</div>
<div id="divRplyFwdMsg">
<p class="MsoNormal"><b><span style="color:black">From:</span></b><span style="color:black"> Mircea Trofin <<a href="mailto:mtrofin@google.com">mtrofin@google.com</a>><br>
<b>Sent:</b> 23 March 2021 1:17<br>
<b>To:</b> Jiayu Zhao <<a href="mailto:scjzh@leeds.ac.uk">scjzh@leeds.ac.uk</a>><br>
<b>Cc:</b> Mehdi AMINI <<a href="mailto:joker.eph@gmail.com">joker.eph@gmail.com</a>>;
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a> <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>><br>
<b>Subject:</b> Re: [llvm-dev] How to produce the same result of clang++ -Oz through opt -Oz</span>
<o:p></o:p></p>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">Hello Jiayu, <o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">could you detail your scenario a bit more - do you need to run opt + llc, or would this be acceptable:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">(assuming non thinlto build)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">1) from your original clang call, e.g. clang <blah>, do clang -v <blah>. copy the command line (starts with -cc1)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">2) clang -cc1 <....> <span style="font-size:9.0pt;font-family:Consolas;color:#032F62">
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:Consolas;color:#032F62">-fembed-bitcode=all</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:Consolas;color:#032F62"><br>
<br>
<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:Consolas;color:#032F62">ok, now you can take the resulting .o, let's call it 'file.o', and do this:</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:Consolas;color:#032F62"><br>
<br>
<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:Consolas;color:#032F62">3)</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:Consolas;color:#032F62">llvm-objcopy<o:p></o:p></span></p>
<p class="MsoNormal">--dump-section=.llvmbc=/some/path/file.bc file.o /dev/null<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:Consolas;color:#032F62">llvm-objcopy<o:p></o:p></span></p>
<p class="MsoNormal">--dump-section=.llvmcmd=/some/path/file.cmd file.o /dev/null<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">You get 2 files, /some/path/file.bc and /some/path/file.cmd. The .cmd file contains the command line flags separated by '\0'. The .bc file is the IR.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">If you re-issue now clang with those options (in the .cmd file*) over the .bc, you should get a bit-identical file.o<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Note that clang will skip over compiler directives like "-I" or -D or -U, or paths to pch files or modules (since it now picks up the compilation from IR). You can basically take the IR file and recompile it with the .cmd command line arguments
on a different machine, away from the build directory structure where it came from.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">* you need to split the .cmd file 'line' by \0, of course.<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Mon, Mar 22, 2021 at 4:43 PM Jiayu Zhao via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<div>
<div>
<p class="MsoNormal"><span style="font-size:14.0pt;color:black">Thank you for your reply. The default optimization level of llc is -O2. What's more, I found the executable file (.out) produced by clang directly and llvm opt will be the same in most cases,
but the object file (.o) will be different, both for -O3 and -Oz.</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:14.0pt;color:black;background:white">Use the following commands to produce object files (.o) :</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:14.0pt;color:black;background:white">1. Produce the object file of llvm opt -Oz
<o:p></o:p></span></p>
<div>
<blockquote>
<div>
<p class="MsoNormal"><b><i><span style="font-size:14.0pt;color:black;background:white">clang++ -Oz -Xclang -disable-llvm-optzns -emit-llvm -c raytracer.cpp -o raytracer.bc</span></i></b><span style="font-size:12.0pt;color:black;background:white"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><b><i><span style="font-size:14.0pt;color:black;background:white">opt -Oz raytracer.bc -o tmp.bc</span></i></b><span style="font-size:12.0pt;color:black;background:white"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><b><i><span style="font-size:14.0pt;color:black;background:white">llc -filetype=obj tmp.bc -o tmp.o</span></i></b><span style="font-size:12.0pt;color:black;background:white"><o:p></o:p></span></p>
</div>
</blockquote>
<div>
<p class="MsoNormal"><span style="font-size:14.0pt;color:black;background:white">2. Produce the object file of clang++ directly</span><span style="font-size:12.0pt;color:black;background:white"><o:p></o:p></span></p>
</div>
<blockquote>
<div>
<p class="MsoNormal"><b><i><span style="font-size:14.0pt;color:#323130;background:white">clang++ -Oz -c raytracer.cpp -o raytracer.o</span></i></b><span style="font-size:12.0pt;color:black;background:white"><o:p></o:p></span></p>
</div>
</blockquote>
<div>
<p class="MsoNormal"><span style="font-size:14.0pt;color:#323130;background:white">3. compare </span><span style="font-size:12.0pt;color:black;background:white"><o:p></o:p></span></p>
</div>
<blockquote>
<p class="MsoNormal"><b><i><span style="font-size:14.0pt;color:#323130;background:white">diff tmp.o raytracer.o</span></i></b><span style="font-size:12.0pt;color:black;background:white"><o:p></o:p></span></p>
</blockquote>
</div>
<p class="MsoNormal"><span style="font-size:14.0pt;color:black;background:white">It always shows 'Binary files tmp.o and raytracer.o differ'.</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:14.0pt;color:black;background:white">Use the following commands to produce executable files (.out) :</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:14.0pt;color:black;background:white">1. Produce theexecutable file of llvm opt -Oz </span><span style="font-size:12.0pt;color:black">
<o:p></o:p></span></p>
<div>
<blockquote>
<div>
<p class="MsoNormal"><b><i><span style="font-size:14.0pt;color:black;background:white">clang++ -Oz -Xclang -disable-llvm-optzns -emit-llvm -c raytracer.cpp -o raytracer.bc</span></i></b><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><b><i><span style="font-size:14.0pt;color:black">opt -Oz raytracer.bc -o tmp.bc</span></i></b><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><b><i><span style="font-size:14.0pt;color:black">llc tmp.bc -o tmp.s</span></i></b><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><b><i><span style="font-size:14.0pt;color:black;background:white">clang++ tmp.s -o tmp.out</span></i></b><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
</blockquote>
<div>
<p class="MsoNormal"><span style="font-size:14.0pt;color:black">2. Produce theexecutable file of clang++ directly</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<blockquote>
<div>
<p class="MsoNormal"><b><i><span style="font-size:14.0pt;color:#323130;background:white">clang++ -Oz raytracer.cpp -o raytracer.out</span></i></b><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
</blockquote>
<div>
<p class="MsoNormal"><span style="font-size:14.0pt;color:#323130;background:white">3. compare </span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<blockquote>
<div>
<p class="MsoNormal"><b><i><span style="font-size:14.0pt;color:#323130;background:white">diff tmp.outraytracer.out</span></i></b><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
</blockquote>
</div>
<div>
<p class="MsoNormal"><span style="font-size:14.0pt;color:#323130;background:white">We can find the two files are the same in most cases. However, sometimes they are also different. I guess it is because clang has its own optimizations, and these optimizations
are not always before the llvm optimizations. If we use ' </span><b><i><span style="font-size:14.0pt;color:black;background:white">clang -Oz -Xclang -disable-llvm-optzns'
</span></i></b><span style="font-size:14.0pt;color:black;background:white">to disable<b><i> </i></b></span><span style="font-size:14.0pt;color:#323130;background:white">llvm passes and then use opt to apply llvm passes, the order of all optimizations will be
different.</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:14.0pt;color:black">Jiayu Zhao</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="2" width="98%" align="center">
</div>
<div id="x_gmail-m_-6256806022248349175divRplyFwdMsg">
<p class="MsoNormal"><b><span style="color:black">From:</span></b><span style="color:black"> Mehdi AMINI <<a href="mailto:joker.eph@gmail.com" target="_blank">joker.eph@gmail.com</a>><br>
<b>Sent:</b> 21 March 2021 4:13<br>
<b>To:</b> Jiayu Zhao <<a href="mailto:scjzh@leeds.ac.uk" target="_blank">scjzh@leeds.ac.uk</a>><br>
<b>Cc:</b> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a> <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
<b>Subject:</b> Re: [llvm-dev] How to produce the same result of clang++ -Oz through opt -Oz</span>
<o:p></o:p></p>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal">In general you'll find many cases where O3 does not reproduce either.
<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Have you tried `llc -O2` in your case? Clang sets the backend optimization level that way for Oz/Os/O2: <a href="https://protect2.fireeye.com/v1/url?k=2d2267fa-72b95eb9-2d222761-861fcb972bfc-a8105d213b6995c9&q=1&e=14f51ef9-b34e-413a-9ac4-fcb9f0237738&u=https%3A%2F%2Fgithub.com%2Fllvm%2Fllvm-project%2Fblob%2Fmain%2Fclang%2Flib%2FCodeGen%2FBackendUtil.cpp%23L430" target="_blank">https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/BackendUtil.cpp#L430</a><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">-- <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Mehdi<o:p></o:p></p>
</div>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Sat, Mar 20, 2021 at 9:06 PM Jiayu Zhao <<a href="mailto:scjzh@leeds.ac.uk" target="_blank">scjzh@leeds.ac.uk</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black">Hi,<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black">I can </span><span style="font-size:11.5pt;color:#201F1E;background:white">reproduce the results of clang++ -O3 by opt -O3. But I cannot reproduce the results of clang++ -Oz by opt -Oz.</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.5pt;color:#201F1E;background:white">Just see the previous commands I used to produce the result of opt -O3.</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="2" width="98%" align="center">
</div>
<div id="x_gmail-m_-6256806022248349175x_gmail-m_-4523415073551340736divRplyFwdMsg">
<p class="MsoNormal"><b><span style="color:black">From:</span></b><span style="color:black"> Mehdi AMINI <<a href="mailto:joker.eph@gmail.com" target="_blank">joker.eph@gmail.com</a>><br>
<b>Sent:</b> 21 March 2021 3:23<br>
<b>To:</b> Jiayu Zhao <<a href="mailto:scjzh@leeds.ac.uk" target="_blank">scjzh@leeds.ac.uk</a>><br>
<b>Cc:</b> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a> <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
<b>Subject:</b> Re: [llvm-dev] How to produce the same result of clang++ -Oz through opt -Oz</span>
<o:p></o:p></p>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">Hi, <o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">This is a known issue: clang -O3 is slightly different from `opt -O3` and it is hard to reproduce exactly. It'd be great to refactor it all so that LLVM exposes a common way for frontend to run the exact same thing.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">-- <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Mehdi<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Sat, Mar 20, 2021 at 9:17 AM Jiayu Zhao via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">Dear developers,</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">I am trying to use 'opt' command with different Optlevels -O3 and -Oz to an IR file to reproduce the results of directly applying clang++ -O3 and -Oz to a source c++ file.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">1. Firstly I use the following commands to produce the result of opt -O3:</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><b><i><span style="font-size:12.0pt">clang++ -O3 -Xclang -disable-llvm-optzns -emit-llvm -c raytracer.cpp -o raytracer.bc</span></i></b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><b><i><span style="font-size:12.0pt">opt -O3 raytracer.bc -o tmp.bc
</span></i></b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><b><i><span style="font-size:12.0pt">llc -O3 tmp.bc -o tmp.s</span></i></b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><b><i><span style="font-size:12.0pt">clang++ tmp.s -o tmp.out</span></i></b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">2. Then I use clang -O3 directly:</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><b><i><span style="font-size:12.0pt">clang++ -O3 raytracer.cpp -o raytracer.out</span></i></b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">3. Finally I compare the two files tmp.o and raytracer.o:</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><b><i><span style="font-size:12.0pt">diff tmp.out raytracer.out</span></i></b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">We can find the two files are exactly the same.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">However, things are different in -Oz level</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">1. I use the following commands to produce the result of opt -Oz:</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><b><i><span style="font-size:12.0pt">clang++ -Oz -Xclang -disable-llvm-optzns -emit-llvm -c raytracer.cpp -o raytracer.bc</span></i></b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><b><i><span style="font-size:12.0pt">opt -Oz raytracer.bc -o tmp.bc </span></i></b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><b><i><span style="font-size:12.0pt">llc -filetype=obj tmp.bc -o tmp.o (there is no -Oz option for llc)</span></i></b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">2. Then I use clang -Oz directly:</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><b><i><span style="font-size:12.0pt">clang++ -Oz -c raytracer.cpp -o raytracer.o</span></i></b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">3. Finally I compare the two files tmp.o and raytracer.o:</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><b><i><span style="font-size:12.0pt">diff tmp.o raytracer.o</span></i></b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">It shows 'Binary files tmp.o and raytracer.o differ'</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">why 'opt -Oz' cannot produce the same result as '<span style="color:black;background:white">clang++ -Oz' and how to solve it ? I use LLVM 10.0.1 and CentOS 7.6.</span></span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">I'd very much appreciate if you could help me with this. Thank you.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">Kind Regards,</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">Jiayu Zhao</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
<p class="MsoNormal">_______________________________________________<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="https://protect2.fireeye.com/v1/url?k=719e63ef-2e055aac-719e2374-861fcb972bfc-f494a6a3b07110e1&q=1&e=14f51ef9-b34e-413a-9ac4-fcb9f0237738&u=https%3A%2F%2Flists.llvm.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fllvm-dev" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
<p class="MsoNormal">_______________________________________________<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="https://protect2.fireeye.com/v1/url?k=001c389d-5f8701de-001c7806-861fcb972bfc-b6bf8df11e908cf3&q=1&e=14f51ef9-b34e-413a-9ac4-fcb9f0237738&u=https%3A%2F%2Flists.llvm.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fllvm-dev" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
</div>
</body>
</html>