Mehdi AMINI via llvm-dev
2021-Mar-21 03:23 UTC
[llvm-dev] How to produce the same result of clang++ -Oz through opt -Oz
Hi, This is a known issue: clang -O3 is slightly different from `opt -O3` and it is hard to reproduce exactly. It'd be great to refactor it all so that LLVM exposes a common way for frontend to run the exact same thing. -- Mehdi On Sat, Mar 20, 2021 at 9:17 AM Jiayu Zhao via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Dear developers, > > I am trying to use 'opt' command with different Optlevels -O3 and -Oz to > an IR file to reproduce the results of directly applying clang++ -O3 and > -Oz to a source c++ file. > > 1. Firstly I use the following commands to produce the result of opt -O3: > *clang++ -O3 -Xclang -disable-llvm-optzns -emit-llvm -c raytracer.cpp -o > raytracer.bc* > *opt -O3 raytracer.bc -o tmp.bc * > *llc -O3 tmp.bc -o tmp.s* > *clang++ tmp.s -o tmp.out* > > 2. Then I use clang -O3 directly: > *clang++ -O3 raytracer.cpp -o raytracer.out* > > 3. Finally I compare the two files tmp.o and raytracer.o: > *diff tmp.out raytracer.out* > > We can find the two files are exactly the same. > > However, things are different in -Oz level > > 1. I use the following commands to produce the result of opt -Oz: > *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 (there is no -Oz option for llc)* > > 2. Then I use clang -Oz directly: > *clang++ -Oz -c raytracer.cpp -o raytracer.o* > > 3. Finally I compare the two files tmp.o and raytracer.o: > *diff tmp.o raytracer.o* > > It shows 'Binary files tmp.o and raytracer.o differ' > > why 'opt -Oz' cannot produce the same result as 'clang++ -Oz' and how to > solve it ? I use LLVM 10.0.1 and CentOS 7.6. > > I'd very much appreciate if you could help me with this. Thank you. > > Kind Regards, > Jiayu Zhao > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210320/1ad56bfb/attachment.html>
Jiayu Zhao via llvm-dev
2021-Mar-21 04:05 UTC
[llvm-dev] How to produce the same result of clang++ -Oz through opt -Oz
Hi, I can reproduce the results of clang++ -O3 by opt -O3. But I cannot reproduce the results of clang++ -Oz by opt -Oz. Just see the previous commands I used to produce the result of opt -O3. ________________________________ From: Mehdi AMINI <joker.eph at gmail.com> Sent: 21 March 2021 3:23 To: Jiayu Zhao <scjzh at leeds.ac.uk> Cc: llvm-dev at lists.llvm.org <llvm-dev at lists.llvm.org> Subject: Re: [llvm-dev] How to produce the same result of clang++ -Oz through opt -Oz Hi, This is a known issue: clang -O3 is slightly different from `opt -O3` and it is hard to reproduce exactly. It'd be great to refactor it all so that LLVM exposes a common way for frontend to run the exact same thing. -- Mehdi On Sat, Mar 20, 2021 at 9:17 AM Jiayu Zhao via llvm-dev <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>> wrote: Dear developers, I am trying to use 'opt' command with different Optlevels -O3 and -Oz to an IR file to reproduce the results of directly applying clang++ -O3 and -Oz to a source c++ file. 1. Firstly I use the following commands to produce the result of opt -O3: clang++ -O3 -Xclang -disable-llvm-optzns -emit-llvm -c raytracer.cpp -o raytracer.bc opt -O3 raytracer.bc -o tmp.bc llc -O3 tmp.bc -o tmp.s clang++ tmp.s -o tmp.out 2. Then I use clang -O3 directly: clang++ -O3 raytracer.cpp -o raytracer.out 3. Finally I compare the two files tmp.o and raytracer.o: diff tmp.out raytracer.out We can find the two files are exactly the same. However, things are different in -Oz level 1. I use the following commands to produce the result of opt -Oz: 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 (there is no -Oz option for llc) 2. Then I use clang -Oz directly: clang++ -Oz -c raytracer.cpp -o raytracer.o 3. Finally I compare the two files tmp.o and raytracer.o: diff tmp.o raytracer.o It shows 'Binary files tmp.o and raytracer.o differ' why 'opt -Oz' cannot produce the same result as 'clang++ -Oz' and how to solve it ? I use LLVM 10.0.1 and CentOS 7.6. I'd very much appreciate if you could help me with this. Thank you. Kind Regards, Jiayu Zhao _______________________________________________ LLVM Developers mailing list llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210321/da4ae2c1/attachment.html>