_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
clang++ -Oz -Xclang -disable-llvm-optzns -emit-llvm -c raytracer.cpp -o raytracer.bc
opt -Oz raytracer.bc -o tmp.bc
llc -filetype=obj tmp.bc -o tmp.o
clang++ -Oz -c raytracer.cpp -o raytracer.o
diff tmp.o raytracer.o
clang++ -Oz -Xclang -disable-llvm-optzns -emit-llvm -c raytracer.cpp -o raytracer.bc
opt -Oz raytracer.bc -o tmp.bc
llc tmp.bc -o tmp.s
clang++ tmp.s -o tmp.out
clang++ -Oz raytracer.cpp -o raytracer.out
diff tmp.outraytracer.out
Thank you for your reply. The default optimization level of llc is -O2. What's more, I found the executable file (.out) produced by clang directly and llvm opt will be the same in most cases, but the object file (.o) will be different, both for -O3 and -Oz.
Use the following commands to produce object files (.o) :
1. Produce the object file of llvm opt -OzIt always shows 'Binary files tmp.o and raytracer.o differ'.clang++ -Oz -Xclang -disable-llvm-optzns -emit-llvm -c raytracer.cpp -o raytracer.bc
opt -Oz raytracer.bc -o tmp.bc
llc -filetype=obj tmp.bc -o tmp.o
2. Produce the object file of clang++ directly
clang++ -Oz -c raytracer.cpp -o raytracer.o
3. comparediff tmp.o raytracer.o
Use the following commands to produce executable files (.out) :
1. Produce theexecutable file of llvm opt -Ozclang++ -Oz -Xclang -disable-llvm-optzns -emit-llvm -c raytracer.cpp -o raytracer.bc
opt -Oz raytracer.bc -o tmp.bc
llc tmp.bc -o tmp.s
clang++ tmp.s -o tmp.out2. Produce theexecutable file of clang++ directlyclang++ -Oz raytracer.cpp -o raytracer.out
3. comparediff tmp.outraytracer.outWe can find the two files are the same in most cases.
However, sometimes they are also different. I guess it is because clang has its own optimizations,
and these optimizations are not always before the llvm optimizations. If we use ' clang -Oz -Xclang -disable-llvm-optzns' to disable llvm passes and then use opt to apply llvm passes, the order of all optimizations will be different.
clang++ -Oz -Xclang -disable-llvm-optzns -emit-llvm -c raytracer.cpp -o raytracer.bcopt -Oz raytracer.bc -o tmp.bc
clang++ -Oz -emit-llvm -c raytracer.cpp -o raytracer.bc
Have you tried using -print-after-all option (you can add it both to opt and llc, and I guess you can use “-mllvm -print-after-all” in the clang++ only case).
That way I guess you could compare the result to find out where it starts to differ.
It would be much easier to understand your problem if you for example could determine that the difference appear in opt, or llc, or even later. If the diff is in debug info, or the code, or a data section, or something else. Using print-after-all code perhaps help out in doing that.
Sometimes it could be helpful to also use -debug-pass=Executions (with legacy PM) or -debug-pass-manager (with new PM) to see a bit more about pass invocations, or to get some more anchors when comparing the print-after-all output (but as I think Mehdi hinted earlier, just because a pass is run it might have been configured slightly differently depending on other options etc). But it could help out identifying something obvious such as not running the same passes in your two scenarios.
Regards,
Björn