LLVM Discussion Forums

Optimization sequences doesn't change the code

I want to observe the effect of different optimization on passes in llvm.

So basically, I choose a cipher based c++ program and converted it to IR without any optimization (-O1, -O2, -O3) by using the following command:
clang++ cypher.cpp -o cypher.cpp.ll -emit-llvm -S
Then I used 32 best optimization sequences from this paper [1] by following command:
opt -S <best_optimization_sequences> cypher.cpp.ll -o cypher.cpp.ll.opt
Then converted it to bitcode and finally assembly by following commands:
llvm-as cypher.cpp.ll.opt -o cypher.cpp.opt.bc
llc cypher.cpp.opt.bc -o cypher.cpp.opt.s

But unfortunately, I found that most of the codes are the same, and I didn’t see any impact on the sequence. But in this paper [1] it says these sequences are very effective in optimizing the code.

Please give me an idea of how can I overcome this situation. I am giving a link to a doc file where the bash script and the optimization sequences located for any further references.

Reference:

  1. SURESH PURINI and LAKSHYA JAIN, ACM Transactions on Architecture and Code OptimizationJanuary 2013. Finding good optimization sequences covering program space.

This is equivalent to -O0 emits function with optnone attribute, disabling optimizations.

The way to generate the IR is:

clang++ cypher.cpp -o cypher.cpp.ll -emit-llvm -S -Xclang -disable-llvm-passes -O3

Note that you should emit the IR with -Os or -Oz if you want the optimization for size: again I invite you to diff the output IR, using Os/Oz will change the way the function are annotated which impacts the optimization heuristics.

1 Like

Thank you so much for your quick reply. By using your command it works so far.

But I had a question regarding the -O3 optimization. Why we use -O3 here? And why not -O1/-O2 ? I generated the IR without -O3 and after using a series of opt sequences I didn’t observe any impact in assembly codes.

Thanks again.

I “probably” does not make a different which O level you’re using (other than Os and Oz which have the function annotation), but you can’t be sure :slight_smile:

1 Like

Thank you again :slight_smile: