Skip to content

Instantly share code, notes, and snippets.

@minjang
Created November 28, 2016 10:41
Show Gist options
  • Save minjang/89ee4cd6a040dfda0d7dc23603b3c8c3 to your computer and use it in GitHub Desktop.
Save minjang/89ee4cd6a040dfda0d7dc23603b3c8c3 to your computer and use it in GitHub Desktop.
LLVM -O3 optimization passes
$ ./opt -O3 -debug-pass=Structure -o swap.opt.bc swap.bc
Pass Arguments: -tti -tbaa -scoped-noalias -assumption-cache-tracker -targetlibinfo -verify -simplifycfg -domtree -sroa -early-cse -basicaa -aa -memdep -memoryssa -gvn-hoist -lower-expect
Target Transform Information
Type-Based Alias Analysis
Scoped NoAlias Alias Analysis
Assumption Cache Tracker
Target Library Information
FunctionPass Manager
Module Verifier
Simplify the CFG
Dominator Tree Construction
SROA
Early CSE
Basic Alias Analysis (stateless AA impl)
Function Alias Analysis Results
Memory Dependence Analysis
Memory SSA
Early GVN Hoisting of Expressions
Lower 'expect' Intrinsics
Pass Arguments: -targetlibinfo -tti -tbaa -scoped-noalias -assumption-cache-tracker -profile-summary-info -forceattrs -inferattrs -ipsccp -globalopt -domtree -mem2reg -deadargelim -domtree -basicaa -aa -instcombine -simplifycfg -pgo-icall-prom -basiccg -globals-aa -prune-eh -inline -functionattrs -argpromotion -domtree -sroa -early-cse -speculative-execution -lazy-value-info -jump-threading -correlated-propagation -simplifycfg -domtree -basicaa -aa -instcombine -libcalls-shrinkwrap -tailcallelim -simplifycfg -reassociate -domtree -loops -loop-simplify -lcssa-verification -lcssa -basicaa -aa -scalar-evolution -loop-rotate -licm -loop-unswitch -simplifycfg -domtree -basicaa -aa -instcombine -loops -loop-simplify -lcssa-verification -lcssa -scalar-evolution -indvars -loop-idiom -loop-deletion -loop-unroll -mldst-motion -aa -memdep -gvn -basicaa -aa -memdep -memcpyopt -sccp -domtree -demanded-bits -bdce -basicaa -aa -instcombine -lazy-value-info -jump-threading -correlated-propagation -domtree -basicaa -aa -memdep -dse -loops -loop-simplify -lcssa-verification -lcssa -aa -scalar-evolution -licm -postdomtree -adce -simplifycfg -domtree -basicaa -aa -instcombine -barrier -elim-avail-extern -basiccg -rpo-functionattrs -globals-aa -float2int -domtree -loops -loop-simplify -lcssa-verification -lcssa -basicaa -aa -scalar-evolution -loop-rotate -loop-accesses -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -loop-distribute -loop-simplify -lcssa-verification -lcssa -branch-prob -block-freq -scalar-evolution -basicaa -aa -loop-accesses -demanded-bits -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -loop-vectorize -loop-simplify -scalar-evolution -aa -loop-accesses -loop-load-elim -basicaa -aa -instcombine -scalar-evolution -demanded-bits -slp-vectorizer -simplifycfg -domtree -basicaa -aa -instcombine -loops -loop-simplify -lcssa-verification -lcssa -scalar-evolution -loop-unroll -instcombine -loop-simplify -lcssa-verification -lcssa -scalar-evolution -licm -alignment-from-assumptions -strip-dead-prototypes -globaldce -constmerge -domtree -loops -branch-prob -block-freq -loop-simplify -lcssa-verification -lcssa -basicaa -aa -scalar-evolution -branch-prob -block-freq -loop-sink -instsimplify -verify -write-bitcode
Target Library Information
Target Transform Information
Type-Based Alias Analysis
Scoped NoAlias Alias Analysis
Assumption Cache Tracker
Profile summary info
ModulePass Manager
Force set function attributes
Infer set function attributes
Interprocedural Sparse Conditional Constant Propagation
Global Variable Optimizer
Unnamed pass: implement Pass::getPassName()
FunctionPass Manager
Dominator Tree Construction
Promote Memory to Register
Dead Argument Elimination
FunctionPass Manager
Dominator Tree Construction
Basic Alias Analysis (stateless AA impl)
Function Alias Analysis Results
Combine redundant instructions
Simplify the CFG
PGOIndirectCallPromotion
CallGraph Construction
Globals Alias Analysis
Call Graph SCC Pass Manager
Remove unused exception handling info
Function Integration/Inlining
Deduce function attributes
Promote 'by reference' arguments to scalars
FunctionPass Manager
Dominator Tree Construction
SROA
Early CSE
Speculatively execute instructions if target has divergent branches
Lazy Value Information Analysis
Jump Threading
Value Propagation
Simplify the CFG
Dominator Tree Construction
Basic Alias Analysis (stateless AA impl)
Function Alias Analysis Results
Combine redundant instructions
Conditionally eliminate dead library calls
Tail Call Elimination
Simplify the CFG
Reassociate expressions
Dominator Tree Construction
Natural Loop Information
Canonicalize natural loops
LCSSA Verifier
Loop-Closed SSA Form Pass
Basic Alias Analysis (stateless AA impl)
Function Alias Analysis Results
Scalar Evolution Analysis
Loop Pass Manager
Rotate Loops
Loop Invariant Code Motion
Unswitch loops
Simplify the CFG
Dominator Tree Construction
Basic Alias Analysis (stateless AA impl)
Function Alias Analysis Results
Combine redundant instructions
Natural Loop Information
Canonicalize natural loops
LCSSA Verifier
Loop-Closed SSA Form Pass
Scalar Evolution Analysis
Loop Pass Manager
Induction Variable Simplification
Recognize loop idioms
Delete dead loops
Unroll loops
MergedLoadStoreMotion
Function Alias Analysis Results
Memory Dependence Analysis
Global Value Numbering
Basic Alias Analysis (stateless AA impl)
Function Alias Analysis Results
Memory Dependence Analysis
MemCpy Optimization
Sparse Conditional Constant Propagation
Dominator Tree Construction
Demanded bits analysis
Bit-Tracking Dead Code Elimination
Basic Alias Analysis (stateless AA impl)
Function Alias Analysis Results
Combine redundant instructions
Lazy Value Information Analysis
Jump Threading
Value Propagation
Dominator Tree Construction
Basic Alias Analysis (stateless AA impl)
Function Alias Analysis Results
Memory Dependence Analysis
Dead Store Elimination
Natural Loop Information
Canonicalize natural loops
LCSSA Verifier
Loop-Closed SSA Form Pass
Function Alias Analysis Results
Scalar Evolution Analysis
Loop Pass Manager
Loop Invariant Code Motion
Post-Dominator Tree Construction
Aggressive Dead Code Elimination
Simplify the CFG
Dominator Tree Construction
Basic Alias Analysis (stateless AA impl)
Function Alias Analysis Results
Combine redundant instructions
A No-Op Barrier Pass
Eliminate Available Externally Globals
CallGraph Construction
Deduce function attributes in RPO
Globals Alias Analysis
FunctionPass Manager
Float to int
Dominator Tree Construction
Natural Loop Information
Canonicalize natural loops
LCSSA Verifier
Loop-Closed SSA Form Pass
Basic Alias Analysis (stateless AA impl)
Function Alias Analysis Results
Scalar Evolution Analysis
Loop Pass Manager
Rotate Loops
Loop Access Analysis
Lazy Branch Probability Analysis
Lazy Block Frequency Analysis
Optimization Remark Emitter
Loop Distribution
Canonicalize natural loops
LCSSA Verifier
Loop-Closed SSA Form Pass
Branch Probability Analysis
Block Frequency Analysis
Scalar Evolution Analysis
Basic Alias Analysis (stateless AA impl)
Function Alias Analysis Results
Loop Access Analysis
Demanded bits analysis
Lazy Branch Probability Analysis
Lazy Block Frequency Analysis
Optimization Remark Emitter
Loop Vectorization
Canonicalize natural loops
Scalar Evolution Analysis
Function Alias Analysis Results
Loop Access Analysis
Loop Load Elimination
Basic Alias Analysis (stateless AA impl)
Function Alias Analysis Results
Combine redundant instructions
Scalar Evolution Analysis
Demanded bits analysis
SLP Vectorizer
Simplify the CFG
Dominator Tree Construction
Basic Alias Analysis (stateless AA impl)
Function Alias Analysis Results
Combine redundant instructions
Natural Loop Information
Canonicalize natural loops
LCSSA Verifier
Loop-Closed SSA Form Pass
Scalar Evolution Analysis
Loop Pass Manager
Unroll loops
Combine redundant instructions
Canonicalize natural loops
LCSSA Verifier
Loop-Closed SSA Form Pass
Scalar Evolution Analysis
Loop Pass Manager
Loop Invariant Code Motion
Alignment from assumptions
Strip Unused Function Prototypes
Dead Global Elimination
Merge Duplicate Global Constants
FunctionPass Manager
Dominator Tree Construction
Natural Loop Information
Branch Probability Analysis
Block Frequency Analysis
Canonicalize natural loops
LCSSA Verifier
Loop-Closed SSA Form Pass
Basic Alias Analysis (stateless AA impl)
Function Alias Analysis Results
Scalar Evolution Analysis
Branch Probability Analysis
Block Frequency Analysis
Loop Pass Manager
Loop Sink
Remove redundant instructions
Module Verifier
Bitcode Writer
Pass Arguments: -domtree
FunctionPass Manager
Dominator Tree Construction
@Wangzhengjing
Copy link

hi minjang~ I have a question now and i have not figured it out, i just want to use clang to create bc file and use opt command to optimize the bc file, the opt command has the args list which are from 'llvm-as < /dev/null | opt -O3 -disable-output -debug-pass=Arguments', but the performance of the output from above is nothing like that of output from command 'clang -O3 ...', here is my steps:

  1. llvm-as < /dev/null | opt -O3 -disable-output -debug-pass=Arguments
Pass Arguments:  -tti -tbaa -scoped-noalias-aa -assumption-cache-tracker -targetlibinfo -verify -ee-instrument -undeflocal -simplifycfg -domtree -sroa -loops -scalar-evolution -flang-property -domtree -early-cse -lower-expect
Pass Arguments:  -targetlibinfo -tti -tbaa -scoped-noalias-aa -assumption-cache-tracker -profile-summary-info -forceattrs -inferattrs -domtree -callsite-splitting -ipsccp -called-value-propagation -globalopt -domtree -mem2reg -deadargelim -domtree -basic-aa -aa -loops -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -instcombine -simplifycfg -basiccg -globals-aa -prune-eh -inline -openmpopt -function-attrs -argpromotion -domtree -basic-aa -aa -memoryssa -early-cse-memssa -loops -scalar-evolution -flang-property -undeflocal -domtree -sroa -basic-aa -aa -memoryssa -early-cse-memssa -speculative-execution -aa -lazy-value-info -jump-threading -correlated-propagation -simplifycfg -domtree -aggressive-instcombine -basic-aa -aa -loops -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -instcombine -libcalls-shrinkwrap -loops -postdomtree -branch-prob -block-freq -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -pgo-memop-opt -basic-aa -aa -loops -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -tailcallelim -simplifycfg -reassociate -domtree -loops -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -loop-simplify -lcssa-verification -lcssa -basic-aa -aa -scalar-evolution -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -loop-rotate -propagateTBAA-summary -scev-aa -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -licm -analyze-partial-invar -opt-remark-emitter -analyze-partial-invar -loop-unswitch -simplifycfg -domtree -basic-aa -aa -loops -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -instcombine -lazy-value-info -jump-threading -simplifycfg -domtree -loops -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -loop-simplify -lcssa-verification -lcssa -basic-aa -aa -scalar-evolution -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -indvars -opt-remark-emitter -loop-idiom -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -loop-deletion -remove-tripcount-iv -domtree -loops -scalar-evolution -basic-aa -aa -scev-aa -loop-accesses -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -loop-distribute -basic-aa -aa -scalar-evolution -da -postdomtree -scev-aa -loop-accesses -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -loop-block -domtree -loops -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -loop-simplify -lcssa-verification -lcssa -basic-aa -aa -scalar-evolution -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -loop-rotate -flang-property-cleanup -propagateTBAA-summary -domtree -loops -scalar-evolution -basic-aa -scev-aa -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -loop-simplify -lcssa-verification -lcssa -aa -lazy-branch-prob -lazy-block-freq -propagateTBAA-summary -opt-remark-emitter -licm -analyze-partial-invar -opt-remark-emitter -analyze-partial-invar -loop-unswitch -simplifycfg -domtree -basic-aa -aa -lazy-value-info -jump-threading -simplifycfg -domtree -loops -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -loop-simplify -lcssa-verification -lcssa -basic-aa -aa -scalar-evolution -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -indvars -opt-remark-emitter -loop-idiom -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -loop-deletion -peephole-loop-simplify -domtree -loops -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -scalar-evolution -iter-prune -domtree -basic-aa -aa -memoryssa -loops -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -loop-simplify -lcssa-verification -lcssa -scalar-evolution -memoryssa -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -loop-unroll -sroa -aa -mldst-motion -phi-values -aa -memdep -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -gvn -phi-values -basic-aa -aa -memdep -memcpyopt -sccp -demanded-bits -bdce -aa -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -instcombine -lazy-value-info -jump-threading -correlated-propagation -postdomtree -adce -basic-aa -aa -memoryssa -dse -propagateTBAA-summary -loops -scalar-evolution -scev-aa -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -loop-simplify -lcssa-verification -lcssa -aa -lazy-branch-prob -lazy-block-freq -propagateTBAA-summary -opt-remark-emitter -licm -opt-remark-emitter -loop-deletion -postdomtree -adce -simplifycfg -domtree -basic-aa -aa -loops -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -instcombine -barrier -elim-avail-extern -basiccg -rpo-function-attrs -globalopt -globaldce -basiccg -globals-aa -domtree -float2int -lower-constant-intrinsics -domtree -loops -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -loop-simplify -lcssa-verification -lcssa -basic-aa -aa -scalar-evolution -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -loop-rotate -inject-tli-mappings -postdomtree -branch-prob -block-freq -scev-aa -loop-accesses -demanded-bits -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -loop-vectorize -vector-combine -early-cse -loop-simplify -scalar-evolution -aa -scev-aa -loop-accesses -lazy-branch-prob -lazy-block-freq -loop-load-elim -basic-aa -aa -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -instcombine -simplifycfg -domtree -loops -scalar-evolution -basic-aa -aa -demanded-bits -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -inject-tli-mappings -scev-aa -slp-vectorizer -vector-combine -opt-remark-emitter -instcombine -memoryssa -opt-remark-emitter -loop-simplify -lcssa-verification -lcssa -scalar-evolution -memoryssa -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -loop-unroll -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -instcombine -propagateTBAA-summary -scalar-evolution -scev-aa -opt-remark-emitter -loop-simplify -lcssa-verification -lcssa -lazy-branch-prob -lazy-block-freq -propagateTBAA-summary -opt-remark-emitter -licm -opt-remark-emitter -transform-warning -alignment-from-assumptions -postdomtree -memoryssa -dse -strip-dead-prototypes -globaldce -constmerge -cg-profile -domtree -loops -postdomtree -branch-prob -block-freq -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -loop-simplify -lcssa-verification -lcssa -basic-aa -aa -scalar-evolution -block-freq -lazy-branch-prob -lazy-block-freq -opt-remark-emitter -loop-sink -opt-remark-emitter -instsimplify -div-rem-pairs -simplifycfg -verify
Pass Arguments:  -domtree
Pass Arguments:  -targetlibinfo -domtree -loops -postdomtree -branch-prob -block-freq
Pass Arguments:  -targetlibinfo -domtree -loops -postdomtree -branch-prob -block-freq
Pass Arguments:  -targetlibinfo -domtree -loops -lazy-branch-prob -lazy-block-freq
  1. clang-12 -c -emit-llvm performance.c -o performance.bc
  2. opt -tti -tbaa -scoped-noalias-aa -assumption-cache-tracker ... performance.bc -o 1.bc
  3. opt -targetlibinfo -tti -tbaa -scoped-noalias-aa -assumption-cache-tracker ... 1.bc -o 2.bc
  4. opt -domtree 2.bc -o 3.bc
  5. opt -targetlibinfo -domtree -loops -postdomtree -branch-prob -block-freq 3.bc -o 4.bc
  6. opt -targetlibinfo -domtree -loops -postdomtree -branch-prob -block-freq 4.bc -o 5.bc
  7. opt -targetlibinfo -domtree -loops -lazy-branch-prob -lazy-block-freq 5.bc -o 6.bc
  8. llc -filetype=obj 6.bc -o performance.o
  9. clang performance.o -o performance_myopt

the source code is :

#include <stdio.h>

int main (void)
{
        int max = 10000;
        int sum = 0;

        for (int i = 0; i < max; i++) {
                for (int j = 0; j <= i; j++) {
                        for (int k = 0; k < i + j; k++) {
        sum += i * (j + k);
                        }
                }
        }

        printf("%d\n", sum);

        return 0;
}

the result is the performance_myopt needs long time to run~

but when i use the command 'clang -O3 performance.c -o performance_O3', the result is

$ time ./performance_O3
1884799684

real    0m0.077s
user    0m0.077s
sys     0m0.000s

is that right and what is the correct way ?
i have no idea what has happened to this example and i do not know why , can you give me some help, thanks~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment