<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62016>62016</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
llvm-link some bitcodes compiled with "-O0 -Xclang -disable-O0-optnone" failed
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tr4v3ler
</td>
</tr>
</table>
<pre>
I am working on a program analysis project and my target is the bitcodes of some modules, which are linked together by llvm-link from some individual bitcode. Because I want to minimize the optimization during the compilation process to avoid affecting my analysis process, I use the "-O0" option. In order to optimize the linked bitcode with mem2reg in the future, I added "-Xclang -disable-O0-optnone" to compile the individual bitcode. However, many errors occurred during the llvm-link process, which would not happen without the "-Xclang -disable-O0-optnone" option. Is there any way to preserve the "-O0" option during the compilation process, successfully complete the llvm-link step, and perform mem2reg optimization afterwards? One method I already know is to manually remove the optnone attribute from the bitcode, but I do not like using this method. Is there any better way? By the way, I am using the legacy pass.
```
# case one: no error, but mem2reg is not effective
clang -O0 -emit-llvm -S demo1.c -o demo1.ll
clang -O0 -emit-llvm -S demo2.c -o demo2.ll
llvm-link -S demo1.ll demo2.ll -o demo.ll
opt -mem2reg -S demo.ll -o target.ll
# case two: many errors during llvm-link
clang -O0 -Xclang -disable-O0-optnone -emit-llvm -S demo1.c -o demo1.ll
clang -O0 -Xclang -disable-O0-optnone -emit-llvm -S demo2.c -o demo2.ll
llvm-link -S demo1.ll demo2.ll -o demo.ll
opt -mem2reg -S demo.ll -o target.ll
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VU1vpEYQ_TXMpcSIaebzwGGd1Sg--ZBLrg1dQMfdXag_BpFfHxVg7HU2u0oOkSwPoPp479XrahmC7hxilZ2estPXnUyxJ19Ff3yUBv2uJjVVzyAtjORfteuAHEgYPHVeWpBOminowB_-wCaCdArsBFH6DiPoALFHqHVsSGE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