Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of the LLVM Optimization Levels

I recently started working with Clang/LLVM and would like to know if there is any particular documentation on what the -Ox optimization levels do?

I couldn't find much on the LLVM documentation page. Can someone share a few links?

Thanks.

like image 201
user2058668 Avatar asked Jan 30 '14 03:01

user2058668


People also ask

What is LLVM optimization?

DESCRIPTION. The opt command is the modular LLVM optimizer and analyzer. It takes LLVM source files as input, runs the specified optimizations or analyses on it, and then outputs the optimized file.

How many optimization levels are there in GCC?

Changing this value will make the code compilation take more time and will use much more memory, especially as the level of optimization is increased. There are seven -O settings: -O0 , -O1 , -O2 , -O3 , -Os , -Og , and -Ofast .

Is LLVM optimized?

LLVM features powerful intermodular optimizations which can be used at link time. Link Time Optimization (LTO) is another name for intermodular optimization when performed during the link stage. This document describes the interface and design between the LTO optimizer and the linker.

What is O3 optimization?

Optimization level -O3 -O3 instructs the compiler to optimize for the performance of generated code and disregard the size of the generated code, which might result in an increased code size. It also degrades the debug experience compared to -O2 .


1 Answers

Clang's command-line options documentation is indeed very poor, and in particular you are correct that there's almost no explanation of what the optimizations level do.

FreeBSD, however, does add a man page with a useful summary:

-O0 -O1 -O2 -Os -Oz -O3 -O4
Specify which optimization level to use. -O0 means "no optimization": this level compiles the fastest and generates the most debuggable code. -O2 is a moderate level of optimization which enables most optimizations. -Os is like -O2 with extra optimizations to reduce code size. -Oz is like -Os (and thus -O2), but reduces code size further. -O3 is like -O2, except that it enables optimizations that take longer to perform or that may generate larger code (in an attempt to make the program run faster). On supported platforms, -O4 enables link-time optimization; object files are stored in the LLVM bitcode file format and whole program optimization is done at link time. -O1 is somewhere between -O0 and -O2.

If you're looking to find the exact list of passes performed for each optimization, see this Stackoverflow question:

  • Clang optimization levels
like image 151
Oak Avatar answered Nov 07 '22 11:11

Oak