Performance of Clang vs llc

Hello,

I’m trying to investigate a performance issue in my compiler, and I noticed that the issue boils down to llc taking much longer to compile the same file than clang does.
I called clang with the -O2 option as this was the default LLC option, and the difference with -O0 is negligible.
The difference I noticed on one project was LLC taking around 70s and clang taking 40s to compile the same code. Another project was taking 70s on LLC, while only taking about 2s on clang
I created a gist with the IR files and the performance results :
https://gist.github.com/ghaith/90401c64683a790c9fecebc126ffad87

I’m not sure how to achieve similar performance, or what exactly is the difference here, so any help would be appreciated
Thank you

Clang’s definition of O2 and llc’s definition of O2 are different. I haven’t looked at the timing reports you posted but I expect you’ll find that the list of passes is not the same. That is probably the source of the difference you are seeing.

ˋllc` only runs the codegen and not the LLVM optimizer, it is likely that the IR is simplified before hitting the codegen in the clang case.

1 Like

Indeed, clang calls different optimisations. I have not yet looked into all of the differences, but the bulk of the time consumed by LLC is in DAG->DAG Instruction Selection which is also executed by clang.

Would you know how to call the extra IR optimization here? Is it clang specific or is it one of the extra passes clang calls?

It should roughly be running the IR through opt -O2 before llc -O2. It isn’t strictly equivalent to clang but should be very close.

That does indeed bring the result close to clang (40s compile from optimized IR, but still about 8s to optimise that IR)
Thank you for that tip!
I am wondering if there is a way to call opt from the C-API (or possibly C++ if C won’t do) to integrate into my module, is it just a matter of running all the opt passes it runs?

LLVMRunPasses in the C API can run optimizations like opt does.