Clang Optimization Levels

In gcc, the manual explains that -O3 , -Os , etc. translate in terms of specific optimization arguments ( -funswitch-loops , -fcompare-elim , etc.)

I am looking for the same information for clang.

I looked online and in man clang , which gives general information ( -O2 optimized over -O1 , -Os optimized for speed, ...), and also looked here on Qaru and found this one , but I did not find anything significant in the cited source files.

Edit: I found the answer, but I'm still wondering if anyone has a link to a user guide that describes all the optimization passes and the passes selected by -Ox . Currently, I just found this list of passes, but said nothing about optimization levels.

+53
compiler-optimization clang user-manual
Mar 21 '13 at 12:48 on
source share
3 answers

I found this related question.

To summarize, find out about compiler optimization runs:

 llvm-as < /dev/null | opt -O3 -disable-output -debug-pass=Arguments 

As stated in Jeff Nixon's answer (+1), clang additionally performs some higher level optimizations that we can get with:

 echo 'int;' | clang -xc -O3 - -o /dev/null -\#\#\# 

Documentation of individual walkways is available here .







With version 3.8, the passes are as follows:

  • base level ( -O0 ):

    • opt installs: -targetlibinfo -tti -verify
    • clang adds: -mdisable-fp-elim -mrelax-all
  • -O1 based on -O0

    • opt adds: -globalopt -demanded-bits -branch-prob -inferattrs -ipsccp -dse -loop-simplify -scoped-noalias -barrier -adce -deadargelim -memdep -licm -globals-aa -rpo-functionattrs -basiccg -loop- idiom -forceattrs -mem2reg -simplifycfg -early-cse -instcombine -sccp -loop-unswitch -loop-vectorize -tailcallelim -functionattrs -loop-accesses -memcpyopt -loop-deletion -reassociate -strip-dead-prototypes -loopsbas correlated-propagation -lcssa -domtree -always-inline -aa -block-freq -float2int -lower-expect -sroa -loop-unroll -alignment-from-conditions -lazy-value-info -prune-eh -jump-threading - loop-rotate -indvars -bdce -scalar-evolution -tbaa -assumption-cache-tracker
    • clang adds: -momit-leaf-frame-pointer
    • clang drops: -mdisable-fp-elim -mrelax-all
  • -O2 based on -O1

    • opt adds: -elim-avail-extern -mldst-motion -slp-vectorizer -gvn -inline -globaldce -constmerge
    • opt drops: -allways-inline
    • clang adds: -vectorize-loops -vectorize-slp
  • -O3 based on -O2

    • opt adds: -argpromotion
  • -Ofast based on -O3 valid in clang but not in opt

    • clang adds: -fno-signed-zeros -freciprocal-math -ffp-contract = fast -menable-unsafe-fp-math -menable-no-nans -menable-no-infs
  • -Os matches -O2

  • -Oz based on -Os

    • opt drops: -slp-vectorizer
    • clang drops: -vectorize-loops

<h / ">

With version 3.7, passes follow (parsed command output above):

  • default (-O0): -targetlibinfo -verify -tti

  • -O1 is based on -O0

    • adds: -sccp -loop-simplify -float2int -lazy-value-info -correlated-propagating -bdce -lcssa -deadargelim -loop-unroll -loop-vectorize -barrier -memcpyopt -loop-accesses -assumption-cache- tracker -reassociate -loop-deletion -branch-prob -jump-threading -domtree -dse -loop-rotate -ipsccp -instcombine -scoped-noalias -licm -prune-eh -loop-unswitch -constraint -early- cse -inline -cost -simplifycfg -strip-dead-prototypes -tbaa -sroa -no-aa -adce -functionattrs -lower-expect -basiccg -loops -loop-idiom -tailcallelim -basicaa -indvars -globalopt -block-freq - scalar evolution - memdep -line-inline
  • -O2 is based on -01

    • adds: -elim-avail-extern -globaldce -inline -constmerge -mldst-motion -gvn -slp-vectorizer
    • deletes: -allways-inline
  • -O3 is based on -O2

    • adds: -argpromotion -verif
  • -Os is identical to -O2

  • -Oz is based on -Os

    • removes: -slp-vectorizer

<h / ">

For version 3.6, the passes correspond to the document in the GYUNGMIN KIM message.

<h / ">

With version 3.5, the following actions will take place (parsed output from the command above):

  • default (-O0): -targetlibinfo -verify -verify-di

  • -O1 is based on -O0

    • adds: -correlated-distribution -basiccg -simplifycfg -no-aa -jump-threading -sroa -loop-unswitch -ipsccp -instcombine -memdep -memcpyopt -barrier -block-freq -loop-simplify -loop-vectorize - inline-cost -branch-prob -early-cse -lazy-value-info -loop-rotate -strip-dead-prototypes -loop-deletion -tbaa -prune-eh -indvars -loop-unroll -reassociate -loops -sccp - always-inline -basicaa -dse -globalopt -tailcallelim -functionattrs -deadargelim -notti -scalar-evolution -lower-expect -licm -loop-idiom -adce -domtree -lcssa
  • -O2 is based on -01

    • adds: -gvn -constmerge -globaldce -slp-vectorizer -mldst-motion -inline
    • deletes: -allways-inline
  • -O3 is based on -O2

    • adds: -argpromotion
  • -Os is identical to -O2

  • -Oz is based on -Os

    • removes: -slp-vectorizer

<h / ">

With version 3.4, the following actions will take place (parsed output from the command above):

  • -O0: -targetlibinfo -preverify -domtree -verify

  • -O1 is based on -O0

    • adds: -adce -allways-inline -basicaa -basiccg -correlated-propagation -deadargelim -dse -early-cse -functionattrs -globalopt -indvars -inline-cost -instcombine -ipsccp -jump-threading -lazy-value- info -lcssa -licm -loop-deletion -loop-idiom -loop-rotate -loop-simplify -loop-unroll -loop-unswitch -loops -lower-expect -memcpyopt -memdep -no-aa -notti -prune-eh - reassociate -scalar -evolution -sccp -simplifycfg -sroa -strip-dead-prototypes -tailcallelim -tbaa
  • -O2 is based on -01

    • adds: -barrier -constmerge -domtree -globaldce -gvn -inline -loop-vectorize -preverify -slp-vectorizer -targetlibinfo -verify
    • deletes: -allways-inline
  • -O3 is based on -O2

    • adds: -argpromotion
  • -Os is identical to -O2

  • -Oz is based on -O2

    • removes: -barrier -loop-vectorize -slp-vectorizer

<h / ">

With version 3.2, passes follow (parsed output from the command above):

  • -O0: -targetlibinfo -preverify -domtree -verify

  • -O1 is based on -O0

    • adds: -sroa -early-cse -lower-expect -no-aa -tbaa -basicaa -globalopt -ipsccp -deadargelim -instcombine -simplifycfg -basiccg -prune-eh-always-inline -functionattrs -simplify-libcalls - lazy value -info -jump-threading -correlated-distribution -tailcallelim -reassociate -loops -loop-simplify -lcssa -loop-rotate -licm -loop-unswitch -scalar-evolution -indvars -loop-idiom -loop-deletion - loop-unroll -memdep -memcpyopt -sccp -dse -adce -strip-dead-prototypes
  • -O2 is based on -01

    • adds: -inline -globaldce -constmerge
    • deletes: -allways-inline
  • -O3 is based on -O2

    • adds: -argpromotion
  • -Os is identical to -O2

  • -Oz is identical to -Os

<h / ">

Edit [march 2014] Removed duplicates from lists.

Edit [April 2014] added documentation link + options for 3.4

Edit [September 2014] added options for 3.5

Edit [December 2015] added options for 3.7 and specify an existing answer for 3.6

Change [possibly 2016] added options for 3.8, for both opt and clang, and specify an existing answer for clang (versus opt)

+92
Mar 21 '13 at 12:55
source share

@ The answer to Antoine (and another related question) accurately describes the LLVM optimizations that are included, but there are several other Clang-specific options (that is, those that affect downgrading to AST) that are affected by -O[0|1|2|3|fast] flags.

You can look at them as follows:

echo 'int;' | clang -xc -O0 - -o /dev/null -\#\#\#

echo 'int;' | clang -xc -O1 - -o /dev/null -\#\#\#

echo 'int;' | clang -xc -O2 - -o /dev/null -\#\#\#

echo 'int;' | clang -xc -O3 - -o /dev/null -\#\#\#

echo 'int;' | clang -xc -Ofast - -o /dev/null -\#\#\#

For example, -O0 includes -mrelax-all , -O1 includes -vectorize-loops and -vectorize-slp , and -Ofast includes -menable-no-infs , -menable-no-nans , -menable-unsafe-fp-math , -ffp-contract=fast and -ffast-math .




@Techogrebo:

Yes, no other LLVM tools are needed. Try:

echo 'int;' | clang -xc - -o /dev/null -mllvm -print-all-options

In addition, there are more detailed parameters that you can study / change using Clang alone ... you just need to know how to get to them!

Try a few of them:

clang -help

clang -cc1 -help

clang -cc1 -mllvm -help

clang -cc1 -mllvm -help-list-hidden

clang -cc1as -help

+11
Dec 20 '14 at 4:09
source share

LLVM 3.6 <O> -O1

Pass Arguments: -targetlibinfo -no-aa -tbaa -scoped-noalias -assumption-cache-tracker -basicaa -notti -verify-di -ipsccp -globalopt -deadargelim -domtree -instcombine -simplifycfg -basiccg -prune-ehline cost -ways-inline -functionattrs -sroa -domtree -early-cse -lazy-value-info -jump-threading -correlated-propagation -simplifycfg -domtree -instcombine -tailcallelim -simplifycfg -reassociate -domtree -loops -loop -simplify - lcssa -loop-rotate -licm -loop-unswitch -instcombine -scalar-evolution -loop-simplify -lcssa -indvars -loop-idiom -loop-deletion -function_tti -loop-unroll -memdep -memcpyopt -sccp -domtree -instcombine - lazy-value-info -jump-threading -correlated-propagation -domtree -memdep -dse -adce -simplifycfg -domtree -instcombine -barrier -domtree -loops -loop-simplify -lcssa -branch-prob -block-freq -scalar- evolution -loop-vectorize -instcombine -simplifycfg -domtree -instcombine -loops -loop-simplify -lcssa -scalar-evolution -function_tti -loo p-unroll -alignment-fr om-assumptions -strip-dead-prototypes -verify -verify-di

-O2 base to -O1

add: -inline -mldst-motion -domtree -memdep -gvn -memdep -scalar-evolution -slp-vectorizer -globaldce -constmerge

and removes: -allways-inline

-O3 based on -O2

add: -argpromotion

+4
Aug 7 '15 at 7:14
source share



All Articles