[LLVMdev] llc -O# / opt -O# differences

Nick Lewycky nicholas at mxc.ca
Sat Jun 30 13:28:06 PDT 2012


Dimitri Tcaciuc wrote:
> Is the llc/opt difference expected?

Yes. "opt" runs the optimizers, which take LLVM IR as input and produce 
LLVM IR as output. "opt -O2 -debug-pass=Arguments" will show you a list 
of the individual optimizations (and analyses) that opt -O2 performs. 
It's possible to run them individually (opt -scalarrepl -instcombine) to 
create a list that's better for your own compiler, but -O2 has the ones 
we think are good for a C/C++ compiler.

"llc" is the code generator, which takes LLVM IR in and produces machine 
code. There are some places in the code generator where it has the 
choice between spending compile time to produce good code, or getting 
the code out quickly, and the -O flag to llc specifies that choice. For 
example, you can do register allocation by trying to figure out the most 
efficient registers that minimize the number of spills, or you can just 
pick the registers starting from one, and spill it if it's already used. 
Any optimizations llc does are things that can't possibly happen in an 
IR-to-IR pass (since the IR is SSA form, we can't do register allocation 
there).

If you want optimized code, you'd run the IR optimizers and ask the code 
generator to spend time producing good code. Or if you want unoptimized 
code, don't run any IR optimizers and ask the code generator to produce 
code as quickly as it can. You can of course choose some other 
combination by running opt and llc yourself, as you noticed.

Nick



More information about the llvm-dev mailing list