<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/69410>69410</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Why bitcode to object, linked binary performance is bad?
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          zcfh
      </td>
    </tr>
</table>

<pre>
    # question
I'll explain my problem first, and I'll introduce the background later.
The problem I encountered is that I first executed `clang -c -O3 -emit-llvm demo.c -o demo.bc` to get a copy of the original bitcode.
After that, I used clang and llc respectively to convert the bitcode into a target file and generate an executable file.
```shell
# 1. use clang
clang -O3 -c demo.bc -o demo_from_clang.o
clang demo_from_clang.o -o demo_from_clang

# 2.use llc
llc -O3 -filetype=obj demo.bc -o demo_from_llc.o
clang demo_from_llc.o -o demo_from_llc
```
Finally I executed the same command to test
```shell
time ./demo_from_llc 500000000
# real 0m0.452s
time ./demo_from_clang 500000000
# real 0m0.545s
```
# Appendix
1. `clang version 10.0.0`
2. **demo.c**
```c++
const int size = 10000;
int val[10000] = {0};


int lib_func(int idx) {
 val[idx % size] += idx;
     return val[idx % size];
}

int func(int num) {
   int ret = 0;
   for (int i = 0; i < num; ++i) {
 ret += lib_func(i);
   }
   return ret;
}

int get_num(const char *p) {
   int ret = 0;
   while (*p != '\0') {
 ret *= 10;
     ret += *p - '0';
     p++;
   }
   return ret;
}


int main(int argc, char **argv) {
     int ret = func(get_num(argv[1]));
     return ret;
}
```


# background
Let me explain again why I ask such a strange question. Because I found a project [CompilerGym](https://github.com/facebookresearch/CompilerGym) on GitHub. CompilerGym will try to use different passes for bitcode and try to find a better combination. If my understanding is correct.
But I need to convert the final bitcode into a object file to complete the subsequent step. From the information I know so far, both llc and clang can be converted, but the performance difference here makes me a little confused.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycV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