thank you for the more detailed clarification of your setup.
As far as I can see, the only difference between your a) steps and b) steps lies in the sequence of passes you provide them.
Obviously the sequence of passes you get from  is not the same as the sequence of passes opt runs on your main.ll
I suggest you to use the same command as  with the actual input of your benchmark as input for opt. See .
I crafted a main.c file with an empty main and I run your step 1 to generate the LLVM-IR.
I compared the output of  against the output of  and I noticed a small difference.
Indeed,  schedules one more pass (-targetpassconfig) with respect to .
I also tried to craft another main.ll file via llvm-stress (LLVM utility to generate random valid LLVM-IR test files).
In this case  and  do not differ.
I guess the difference of scheduled passes is due to source code metadata which have been transferred to the IR from the source file.
I suspect that if you feed  with a full benchmark (I don’t know which one you are using) you may get a slightly different sequence of passes.
I hope this could help you.
 llvm-as < /dev/null | opt -O3 -disable-output -debug-pass=Arguments
 opt -O3 -disable-output -debug-pass=Arguments main.ll
Thank you for your replay!
I cannot replicate -O3 result using LLVM 6.0 with the command you provide. Actually, I previously use the following command
clang -O3 -Xclang -disable-llvm-passes -S -emit-llvm main.c -o main.ll to generate the IR file, which is equal to your command.
Currently, I want to test the passes in LLVM. The performance of the pass or passes sequence is considered, so I choose the performance
of -O3 as a baseline.
The experiment steps are as following:
- clang -O3 -Xclang -disable-llvm-passes -S -emit-llvm main.c -o main.ll
2.a. opt -O3 main.ll -o main-opt1.ll
2.b. opt (the same passes sequence as O3) main.ll -o main-opt2.ll
3.a llc main-opt1.ll -o main-opt1.s
3.b llc main-opt2.ll -o main-opt2.s
4.a clang main-opt1.s -o main-opt1
4.b clang main-opt2.s -o main-opt2
$ time ./main-opt1
$ time ./main-opt2
where the same passes sequence is generated by the following command:
llvm-as < /dev/null | opt -O3 -disable-output -debug-pass=Arguments
From the results, we can see the execution time of main-opt2 is 13% lower than that of the main-opt1.
As Stefano said, clang schedules target-independent and target-dependent passes. So I use lli to execute main-opt1.ll and main-opt2.ll
to reduce the influence of target-dependent passes, the results are the same as the above.
$ time lli main-opt1.ll
$ time lli main-opt2.ll
Thus, for my purpose, if I cannot get the same results using -O3 and the passes sequence as -O3, respectively, I cannot say
that the performance comparisons between other passes sequence and -O3 are fair.
I do not know whether I make some mistakes.
In addition, I find that the passes sequences “-early-cse-memssa -lcssa-verification -early-cse-memssa”,
“-early-cse-memssa -verify -early-cse-memssa”, “-early-cse-memssa -demanded-bits -early-cse-memssa” and “-early-cse-memssa -early-cse-memssa”
will cause the following error for LLVM version 6.0.0.
LLVMSymbolizer: error reading file: No such file or directory
#0 0x0000000001a68794 (opt+0x1a68794)
#1 0x0000000001a68a76 (opt+0x1a68a76)
#2 0x00007f96a098c390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
#3 0x00000000015fc64e (opt+0x15fc64e)
#4 0x000000000160065d (opt+0x160065d)
#5 0x00000000015fdb08 (opt+0x15fdb08)
#6 0x000000000075aaa6 (opt+0x75aaa6)
#7 0x00007f969f924830 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x20830)
#8 0x000000000074c1b9 (opt+0x74c1b9)
0. Program arguments: opt -early-cse-memssa -lcssa-verification -early-cse-memssa main.bc -o main-opt.bc
Segmentation fault (core dumped)
If possible, please try these passes sequences in your system using LLVM version 5.0.2. If these sequences also cause the same error in your system,
it could be a bug for LLVM.
Thank you for both your help and your time!