Optimizer takes very long

Dear All,

we are building a JIT compiler that uses LLVM as backend and are
running into issues with the compilation time. In the worst case,
compiling (i.e. optimizing and producing bytecode) a function with ~3k
lines takes up to 8-10 minutes. Note that we are not very concerned
with the actual performance of the JIT compiled code - anything binary
will be massively faster than what we have.

I am unsure how to proceed and what the issue might be. I found the
Performance Tips [1] and noticed that one of our building blocks has
almost 1000 predecessors, something that is disencouraged. Could that
be a problem? It's the result of a very long if-elseif-chain, where
all "else" branches branch to the first basic block after that
if-elseif chain.

Not adding any runs and setting OptLevel=0 already improves the
compilation time by a factor of 10 (from ~510 seconds to ~50 seconds).
Are there any other ways of debugging or inspecting what the cause
might be?

Thanks
- Eph

[1] https://llvm.org/docs/Frontend/PerformanceTips.html

First I'd double check that you're using an optimized binaries with
asserts turned off.

You can also use -time-passes in opt to take a look at how long
certain optimizations are taking.

-eric