<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 class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Mar 20, 2021 at 9:17 AM 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-width:1px;border-left-style:solid;border-left-color: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>