<div dir="ltr">Hello Jiayu,<div><br></div><div>could you detail your scenario a bit more - do you need to run opt + llc, or would this be acceptable:</div><div><br></div><div>(assuming non thinlto build)</div><div><br></div><div>1) from your original clang call, e.g. clang <blah>, do clang -v <blah>. copy the command line (starts with -cc1)</div><div>2) clang -cc1 <....> <span style="color:rgb(3,47,98);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre">-fembed-bitcode=all</span></div><div><span style="color:rgb(3,47,98);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre"><br></span></div><div><span style="color:rgb(3,47,98);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre">ok, now you can take the resulting .o, let's call it 'file.o', and do this:</span></div><div><span style="color:rgb(3,47,98);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre"><br></span></div><div><span style="color:rgb(3,47,98);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre">3)</span></div><div><span style="color:rgb(3,47,98);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre">llvm-objcopy </span>--dump-section=.llvmbc=/some/path/file.bc   file.o /dev/null</div><div><span style="color:rgb(3,47,98);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre">llvm-objcopy </span>--dump-section=.llvmcmd=/some/path/file.cmd   file.o /dev/null<br></div><div><br></div><div>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.</div><div><br></div><div>If you re-issue now clang with those options (in the .cmd file*) over the .bc, you should get a bit-identical file.o</div><div><br></div><div>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.</div><div><br></div><div><br></div><div>* you need to split the .cmd file 'line' by \0, of course.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">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:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">




<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span style="font-size:14pt;font-family:Calibri,Helvetica,sans-serif">Thank you for your reply. The default optimization level of llc is -O2.  What's more, </span><span style="color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif;font-size:14pt">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></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span style="color:rgb(50,49,48);background-color:rgb(255,255,255);font-size:14pt;display:inline"><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif;color:rgb(0,0,0);background-color:rgb(255,255,255)">Use
 the following commands to produce</span><span style="margin:0px;font-size:14pt;font-family:Calibri,Arial,Helvetica,sans-serif;color:rgb(0,0,0);background-color:rgb(255,255,255);display:inline"><span style="background-color:rgb(255,255,255);font-size:14pt;font-family:Calibri,Helvetica,sans-serif;display:inline"> object
 files (.o)</span><span style="background-color:rgb(255,255,255);display:inline"><span style="font-size:14pt;font-family:Calibri,Helvetica,sans-serif"> </span></span></span><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif;color:rgb(0,0,0);background-color:rgb(255,255,255);display:inline">:</span><br>
</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span style="color:rgb(50,49,48);background-color:rgb(255,255,255);font-size:14pt;display:inline"><span style="margin:0px;font-size:14pt;font-family:Calibri,Arial,Helvetica,sans-serif;color:rgb(0,0,0);background-color:rgb(255,255,255);display:inline"><span style="margin:0px;font-size:12pt"><span style="margin:0px;font-size:14pt;background-color:rgb(255,255,255);font-family:Calibri,Helvetica,sans-serif;display:inline">1.
 Produce the </span><span style="margin:0px;font-size:14pt;background-color:rgb(255,255,255);display:inline"><span style="margin:0px;background-color:rgb(255,255,255);font-size:14pt;font-family:Calibri,Helvetica,sans-serif;display:inline"><span style="background-color:rgb(255,255,255);display:inline">object
</span>file </span></span><span style="margin:0px;font-size:14pt;background-color:rgb(255,255,255);font-family:Calibri,Helvetica,sans-serif;display:inline">of llvm opt -Oz </span></span>
<div style="margin:0px;font-size:12pt">
<blockquote style="margin-top:0px;margin-bottom:0px">
<div style="margin:0px"><b><span style="margin:0px;font-size:15px;color:rgb(50,49,48);background-color:rgb(255,255,255)"><span style="margin:0px;font-size:12pt"><i></i></span></span><span style="margin:0px;font-size:15px;background-color:rgb(255,255,255)"><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif"><i>clang++
 -Oz -Xclang -disable-llvm-optzns -emit-llvm -c raytracer.cpp -o raytracer.bc</i></span><i><br>
</i></span></b></div>
<div style="margin:0px"><b><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif"><i>opt -Oz
</i></span><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif"><i>raytracer</i></span><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif"><i>.bc -o tmp.bc</i></span><i><br>
</i></b></div>
<div style="margin:0px"><b><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif"><i>llc
</i></span><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif"><i>-filetype=obj
</i></span><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif"><i>tmp.bc -o tmp.o</i></span><i><br>
</i></b></div>
</blockquote>
<div style="margin:0px"><i style="color:inherit;font-family:inherit;font-size:14pt;font-variant-ligatures:inherit;font-variant-caps:inherit;font-weight:inherit"><span style="font-style:normal;font-size:14pt;font-family:Calibri,Helvetica,sans-serif">2.
 Produce the </span><span style="font-style:normal;font-size:14pt;font-family:Calibri,Helvetica,sans-serif"><span style="background-color:rgb(255,255,255);display:inline">object </span>file </span><span style="font-style:normal;font-size:14pt;font-family:Calibri,Helvetica,sans-serif"><i style="font-family:Calibri,Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)"><span style="margin:0px;font-style:normal;font-size:14pt;font-family:Calibri,Helvetica,sans-serif">of
 clang++ directly</span></i></span></i><br>
</div>
<blockquote style="margin-top:0px;margin-bottom:0px">
<div style="margin:0px"><span style="margin:0px;font-size:15px;background-color:rgb(255,255,255)"><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif"><i><i style="color:rgb(50,49,48);background-color:rgb(255,255,255)"><b>clang++
 -Oz -c r</b></i></i></span><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif"><i><i style="color:rgb(50,49,48);background-color:rgb(255,255,255)"><b>​</b></i></i></span><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif"><i><i style="color:rgb(50,49,48);background-color:rgb(255,255,255)"><b>aytracer.cpp
 -o raytracer.o</b></i></i></span><span style="margin:0px;font-size:14pt"><i><br>
</i></span></span></div>
</blockquote>
<div style="margin:0px"><span style="margin:0px;font-size:15px;background-color:rgb(255,255,255)"><span style="margin:0px;font-size:14pt"><span style="margin:0px;font-family:Calibri,Helvetica,sans-serif;color:rgb(50,49,48);background-color:rgb(255,255,255);font-size:14pt">3.
 compare </span></span></span></div>
<blockquote style="margin-top:0px;margin-bottom:0px"><span style="margin:0px"><span style="margin:0px;font-size:15px;background-color:rgb(255,255,255)"><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif"><i><i style="color:rgb(50,49,48);background-color:rgb(255,255,255)"><i style="background-color:rgb(255,255,255)"><b>diff
 tmp.o raytracer.o</b></i></i></i></span></span></span></blockquote>
</div>
It always shows 'Binary files tmp.o and raytracer.o differ'.<br>
</span></span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span style="color:rgb(50,49,48);background-color:rgb(255,255,255);font-size:14pt;display:inline"><span style="margin:0px;font-size:14pt;font-family:Calibri,Arial,Helvetica,sans-serif;color:rgb(0,0,0);background-color:rgb(255,255,255);display:inline"><br>
</span></span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif;background-color:rgb(255,255,255)">Use the following commands to produce </span><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif;background-color:rgb(255,255,255);display:inline">executable
 files </span><span style="margin:0px;font-size:14pt;background-color:rgb(255,255,255);display:inline"><span style="margin:0px;font-family:Calibri,Helvetica,sans-serif;background-color:rgb(255,255,255);display:inline">(.out)</span><span style="margin:0px;background-color:rgb(255,255,255);display:inline"><span style="margin:0px;font-family:Calibri,Helvetica,sans-serif"> </span></span></span><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif;background-color:rgb(255,255,255);display:inline">:</span><br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span style="margin:0px;font-size:12pt"><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif;background-color:rgb(255,255,255);display:inline">1. Produce the</span><span style="margin:0px;font-size:14pt;background-color:rgb(255,255,255);display:inline"><span style="margin:0px;font-family:Calibri,Helvetica,sans-serif;background-color:rgb(255,255,255);display:inline">executable
 file </span></span><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif;background-color:rgb(255,255,255);display:inline">of llvm opt -Oz </span></span>
<div style="margin:0px;font-size:12pt">
<blockquote style="margin-top:0px;margin-bottom:0px">
<div style="margin:0px"><b><span style="margin:0px;font-size:15px;color:rgb(50,49,48);background-color:rgb(255,255,255)"><span style="margin:0px;font-size:12pt"><i></i></span></span><span style="margin:0px;font-size:15px;background-color:rgb(255,255,255)"><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif"><i>clang++
 -Oz -Xclang -disable-llvm-optzns -emit-llvm -c raytracer.cpp -o raytracer.bc</i></span><i><br>
</i></span></b></div>
<div style="margin:0px"><b><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif"><i>opt -Oz raytracer.bc -o tmp.bc</i></span><i><br>
</i></b></div>
<div style="margin:0px"><b><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif"><i>llc tmp.bc -o tmp.s</i></span><i><br>
</i></b></div>
<div style="margin:0px"><span style="margin:0px;font-size:15px;background-color:rgb(255,255,255)"><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif"><i><b>clang++ tmp.s -o tmp.out</b></i></span></span></div>
</blockquote>
<div style="margin:0px"><span style="margin:0px;font-size:14pt"><i><span style="margin:0px;font-style:normal;font-family:Calibri,Helvetica,sans-serif">2. Produce the</span><span style="margin:0px;font-style:normal;font-family:Calibri,Helvetica,sans-serif">executable
 file </span><span style="margin:0px;font-style:normal;font-family:Calibri,Helvetica,sans-serif">of clang++ directly</span></i></span></div>
<blockquote style="margin-top:0px;margin-bottom:0px">
<div style="margin:0px"><span style="margin:0px;font-size:15px;background-color:rgb(255,255,255)"><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif"><i><i style="color:rgb(50,49,48);background-color:rgb(255,255,255)"><b>clang++
 -Oz raytracer.cpp -o raytracer.out</b></i></i></span><span style="margin:0px;font-size:14pt"><i><br>
</i></span></span></div>
</blockquote>
<div style="margin:0px"><span style="margin:0px;font-size:15px;background-color:rgb(255,255,255)"><span style="margin:0px;font-size:14pt"><span style="margin:0px;font-family:Calibri,Helvetica,sans-serif;color:rgb(50,49,48);background-color:rgb(255,255,255)">3.
 compare </span></span></span></div>
<blockquote style="margin-top:0px;margin-bottom:0px">
<div style="margin:0px"><span style="margin:0px;font-size:15px;background-color:rgb(255,255,255)"><b><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif"><i><i style="color:rgb(50,49,48);background-color:rgb(255,255,255)"><i style="background-color:rgb(255,255,255)">diff
 tmp.out</i></i></i></span><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif"><i><i style="color:rgb(50,49,48);background-color:rgb(255,255,255)"><i style="background-color:rgb(255,255,255)">raytracer</i></i></i></span><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif"><i><i style="color:rgb(50,49,48);background-color:rgb(255,255,255)"><i style="background-color:rgb(255,255,255)">.out</i></i></i></span></b></span></div>
</blockquote>
</div>
<div style="margin:0px;font-size:12pt"><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif;color:rgb(50,49,48);background-color:rgb(255,255,255);display:inline">We can find the two files are the same in most cases.
 However, sometimes they are also different. I guess it is because <span style="background-color:rgb(255,255,255);display:inline">
clang<span> has </span></span>its own optimizations, and these optimizations are not always before the llvm
<span style="background-color:rgb(255,255,255);display:inline">optimizations</span>. If we use ' <span style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)"><span style="margin:0px;font-size:15px;background-color:rgb(255,255,255)"><span style="margin:0px;font-size:14pt;font-family:Calibri,Helvetica,sans-serif"><b style="font-style:italic">clang
 -Oz -Xclang -disable-llvm-optzns' </b>to disable<span style="font-style:italic;font-weight:bold"> </span></span></span></span>llvm <span style="background-color:rgb(255,255,255);display:inline">passes and then use opt to apply llvm passes,
 the order of all optimizations will be different.</span></span></div>
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span style="font-family:Calibri,Helvetica,sans-serif;font-size:14pt">Jiayu Zhao</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span style="color:rgb(50,49,48);background-color:rgb(255,255,255);font-size:14pt;display:inline"><span style="margin:0px;font-size:14pt;font-family:Calibri,Arial,Helvetica,sans-serif;color:rgb(0,0,0);background-color:rgb(255,255,255);display:inline"><br>
</span></span></div>
<div id="gmail-m_-6256806022248349175appendonsend"></div>
<hr style="display:inline-block;width:98%">
<div id="gmail-m_-6256806022248349175divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> 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</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div dir="ltr">In general you'll find many cases where O3 does not reproduce either.
<div><br>
</div>
<div>Have you tried `llc -O2` in your case? Clang sets the backend optimization level that way for Oz/Os/O2: <a href="https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/BackendUtil.cpp#L430" target="_blank">https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/BackendUtil.cpp#L430</a></div>
<div><br>
</div>
<div>-- </div>
<div>Mehdi</div>
</div>
</div>
<br>
<div>
<div dir="ltr">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:<br>
</div>
<blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Hi,</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
I can <span style="color:rgb(32,31,30);font-size:15px;background-color:rgb(255,255,255);display:inline">reproduce<span> the results of clang++ -O3 by opt -O3. But I cannot <span style="background-color:rgb(255,255,255);display:inline">reproduce</span><span style="margin:0px"> <span style="background-color:rgb(255,255,255);display:inline">the
 results of<span> </span></span><span style="background-color:rgb(255,255,255);display:inline">clang++ -Oz by opt -Oz.</span></span></span></span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span style="color:rgb(32,31,30);font-size:15px;background-color:rgb(255,255,255);display:inline"><span><span style="margin:0px"><span style="background-color:rgb(255,255,255);display:inline"><br>
</span></span></span></span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span style="color:rgb(32,31,30);font-size:15px;background-color:rgb(255,255,255);display:inline"><span><span style="margin:0px"><span style="background-color:rgb(255,255,255);display:inline">Just see the previous commands I used to produce the result of
 opt -O3.</span></span></span></span></div>
<div id="gmail-m_-6256806022248349175x_gmail-m_-4523415073551340736appendonsend"></div>
<hr style="display:inline-block;width:98%">
<div id="gmail-m_-6256806022248349175x_gmail-m_-4523415073551340736divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> 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</font>
<div> </div>
</div>
<div>
<div dir="ltr">Hi,
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
<div>-- </div>
<div>Mehdi</div>
<div><br>
</div>
</div>
<br>
<div>
<div dir="ltr">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:<br>
</div>
<blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div><span style="font-size:12pt">Dear developers,</span><br>
</div>
<div><br>
</div>
<div><span style="font-size:12pt">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><br>
</div>
<div><br>
</div>
<div><span style="font-size:12pt">1. Firstly I use the following commands to produce the result of opt -O3:</span><br>
</div>
<div><span style="font-size:12pt"><i><b>clang++ -O3 -Xclang -disable-llvm-optzns -emit-llvm -c raytracer.cpp -o raytracer.bc</b></i></span><i><b><br>
</b></i></div>
<div><span style="font-size:12pt"><i><b>opt -O3 raytracer.bc -o tmp.bc </b></i></span><i><b><br>
</b></i></div>
<div><span style="font-size:12pt"><i><b>llc -O3 tmp.bc -o tmp.s</b></i></span><i><b><br>
</b></i></div>
<div><span style="font-size:12pt"><b><i>clang++ tmp.s -o tmp.out</i></b></span><b><br>
</b></div>
<div><br>
</div>
<div><span style="font-size:12pt">2. Then I use clang -O3 directly:</span><br>
</div>
<div><span style="font-size:12pt"><i><b>clang++ -O3 raytracer.cpp -o raytracer.out</b></i></span><br>
</div>
<div><br>
</div>
<div><span style="font-size:12pt">3. Finally I compare the two files tmp.o and raytracer.o:</span><br>
</div>
<div><span style="font-size:12pt"><i><b>diff tmp.out raytracer.out</b></i></span><br>
</div>
<div><br>
</div>
<div><span style="font-size:12pt">We can find the two files are exactly the same.</span><br>
</div>
<div><br>
</div>
<div><span style="font-size:12pt">However, things are different in -Oz level</span><br>
</div>
<div><br>
</div>
<div><span style="font-size:12pt">1. I use the following commands to produce the result of opt -Oz:</span><br>
</div>
<div><span style="font-size:12pt"><i><b>clang++ -Oz -Xclang -disable-llvm-optzns -emit-llvm -c raytracer.cpp -o raytracer.bc</b></i></span><i><b><br>
</b></i></div>
<div><span style="font-size:12pt"><i><b>opt -Oz raytracer.bc -o tmp.bc </b></i></span><i><b><br>
</b></i></div>
<div><span style="font-size:12pt"><i><b>llc -filetype=obj tmp.bc -o tmp.o (there is no -Oz option for llc)</b></i></span><br>
</div>
<div><br>
</div>
<div><span style="font-size:12pt">2. Then I use clang -Oz directly:</span><br>
</div>
<div><span style="font-size:12pt"><b><i>clang++ -Oz -c raytracer.cpp -o raytracer.o</i></b></span><b><i><br>
</i></b></div>
<div><br>
</div>
<div><span style="font-size:12pt">3. Finally I compare the two files tmp.o and raytracer.o:</span><br>
</div>
<div><span style="font-size:12pt"><b><i>diff tmp.o raytracer.o</i></b></span><b><i><br>
</i></b></div>
<div><br>
</div>
<div><span style="font-size:12pt">It shows 'Binary files tmp.o and raytracer.o differ'</span><br>
</div>
<div><br>
</div>
<div><span style="font-size:12pt">why 'opt -Oz' cannot produce the same result as '</span><span style="color:rgb(0,0,0);font-size:12pt;background-color:rgb(255,255,255);display:inline">clang++ -Oz' and how to solve it ? I use </span><span style="color:rgb(0,0,0);font-size:14px;background-color:rgb(255,255,255);display:inline"><span style="font-size:12pt">LLVM
 10.0.1 and CentOS 7.6.</span></span></div>
<div><br>
</div>
<div><span style="font-size:12pt">I'd very much appreciate if you could help me with this. Thank you.</span><br>
</div>
<div><br>
</div>
<div><span style="font-size:12pt">Kind Regards,</span><br>
</div>
<div><span style="font-size:12pt">Jiayu Zhao</span></div>
<div><br>
</div>
</div>
_______________________________________________<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://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>

_______________________________________________<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://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>