Why is it that when the same llvm bitcode is converted to object through clang -c, the resulting binary is not as good as llc

First, post my test steps

# 1. generate llvm bitcode
clang demo.c -c -O3 -emit-llvm -o demo.c.bc
# Generate object through clang and llc respectively
llc -O3 demo.c.bc -filetype=obj -o demo_from_llc
clang demo.c.bc -c -O3 -o demo_from_calng

Then I run the following test

time ./demo_from_llc 500000000 # real 0m0.452s
time ./demo_from_clang 500000000 # real 0m0.545s

Why is there such a gap?

Let me explain again why I ask such a strange question. Because I saw a project CompilerGym on GitHub. I will try to use different passes for bitcode and try to find a better combination. If my understanding is correct.

Appendix

clang version 10.0.0

demo.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;
}
0

There are 0 answers