hameeza ahmed via llvm-dev
2019-Oct-13 16:54 UTC
[llvm-dev] Replicate Individual O3 optimizations
Hello, I want to study the individual O3 optimizations. For this I am using following commands, but unable to replicate O3 behavior. 1. Documents/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang -O1 -Xclang -disable-llvm-passes -emit-llvm -S vecsum.c -o vecsum-noopt.ll 2. Documents/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang -O3 -mllvm -debug-pass=Arguments -emit-llvm -S vecsum.c 3. Documents/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/opt <optimization sequence obtained in step 2> -S vecsum-noopt.ll -S -o o3-chk.ll Why the IR obtained by above step i.e individual O3 sequences, is not same when O3 is passed? Where I am doing mistake? Please help. Thank You Regards -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191013/cc43faf7/attachment.html>
David Greene via llvm-dev
2019-Oct-17 18:21 UTC
[llvm-dev] Replicate Individual O3 optimizations
hameeza ahmed via llvm-dev <llvm-dev at lists.llvm.org> writes:> Hello, > I want to study the individual O3 optimizations. For this I am using > following commands, but unable to replicate O3 behavior. > > 1. Documents/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang -O1 > -Xclang -disable-llvm-passes -emit-llvm -S vecsum.c -o vecsum-noopt.ll > > 2. Documents/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang -O3 > -mllvm -debug-pass=Arguments -emit-llvm -S vecsum.c > > 3. Documents/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/opt > <optimization sequence obtained in step 2> -S vecsum-noopt.ll -S -o > o3-chk.ll > > Why the IR obtained by above step i.e individual O3 sequences, is not same > when O3 is passed? > > Where I am doing mistake?I think you need to turn off LLVM optimizations when doing the -emit-llvm dump. Something like this: Documents/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang -O3 \ -mllvm -debug-pass=Arguments -Xclang -disable-llvm-optzns -emit-llvm \ -S vecsum.c Otherwise you are effectively running the O3 pipeline twice, as clang will emit LLVM IR after optimization, not before (this confused me too when I first tried it). That said, I'm not sure you will get the same IR out of opt as with clang -O3 even with the above. For example, clang sets TargetTransformInfo for the pass pipeline and the detailed information it uses may or may not be transmitted via the IR it dumps out. I have not personally tried to do this kind of thing in a while. -David
Mehdi AMINI via llvm-dev
2019-Oct-19 17:48 UTC
[llvm-dev] Replicate Individual O3 optimizations
On Thu, Oct 17, 2019 at 11:22 AM David Greene via llvm-dev < llvm-dev at lists.llvm.org> wrote:> hameeza ahmed via llvm-dev <llvm-dev at lists.llvm.org> writes: > > > Hello, > > I want to study the individual O3 optimizations. For this I am using > > following commands, but unable to replicate O3 behavior. > > > > 1. Documents/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang -O1 > > -Xclang -disable-llvm-passes -emit-llvm -S vecsum.c -o vecsum-noopt.ll > > > > 2. Documents/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang -O3 > > -mllvm -debug-pass=Arguments -emit-llvm -S vecsum.c > > > > 3. Documents/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/opt > > <optimization sequence obtained in step 2> -S vecsum-noopt.ll -S -o > > o3-chk.ll > > > > Why the IR obtained by above step i.e individual O3 sequences, is not > same > > when O3 is passed? > > > > Where I am doing mistake? >If you could provide the full reproducer, it could help to debug this.> > I think you need to turn off LLVM optimizations when doing the > -emit-llvm dump. Something like this: > > Documents/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang -O3 \ > -mllvm -debug-pass=Arguments -Xclang -disable-llvm-optzns -emit-llvm \ > -S vecsum.c > > Otherwise you are effectively running the O3 pipeline twice, as clang > will emit LLVM IR after optimization, not before (this confused me too > when I first tried it). >This is the common pitfall indeed! I think they are doing it correctly in step 1 though by including: `-Xclang -disable-llvm-passes`. That said, I'm not sure you will get the same IR out of opt as with> clang -O3 even with the above. For example, clang sets > TargetTransformInfo for the pass pipeline and the detailed information > it uses may or may not be transmitted via the IR it dumps out. I have > not personally tried to do this kind of thing in a while.I struggled as well to setup TTI and TLI the same way clang does :( It'd be nice to revisit our PassManagerBuilder setup and the opt integration to provide reproducibility (maybe could be a starter project for someone?). -- Mehdi -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191019/1bd12e26/attachment-0001.html>
Apparently Analagous Threads
- Replicate Individual O3 optimizations
- Replicate Individual O3 optimizations
- Issues with using scalar evolution with newer versions of LLVM IR
- [LLVMdev] [RFC] add Function Attribute to disable optimization
- [LLVMdev] [cfe-dev] [RFC] add Function Attribute to disable optimization