<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><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 !important;">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 !important"><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>
</body>
</html>