Hi everyone, I am currently testing out a combination of IR->IR passes with opt to benchmark how they affect performance. The source code works fine if simply use the clang (-O0/-O3) to directly compile to object files and link them. However, when I use opt with a select set of passes and then use llc to compile them to binary, the compiled binary is wrong. That makes me wonder if there are any IR->IR passes that are indispensable and they are to guarantee the semantics? Here's my workflow just in case: ********************************************************************************* 1. Compile the source code to unoptimized IRs: clang -c -emit-llvm -O0 test.c -o test.bc 2. Run opt with a set of IR->IR passes, e.g., opt -simplifycfg -sroa -inferattrs -globalopt -instcombine -simplifycfg -prune-eh -inline -tailcallelim -simplifycfg -loop-simplify -lcssa -loop-rotate -licm -gvn -verify test.bc -o test.bc 3. Run llc with -O0: llc -file-type=obj test.bc -o test.o 4. Last link all the object files: clang -O0 test1.o test2.o -o test ********************************************************************************* Thanks, Peizhao -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170301/b8abed08/attachment.html>
>From my experience, I could not get llc to generate working object file. Ijust used clang on llvm IR to do that. Regards, Kevin On Wed, Mar 1, 2017 at 11:54 AM, Peizhao Ou via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Hi everyone, > > I am currently testing out a combination of IR->IR passes with opt to > benchmark how they affect performance. The source code works fine if simply > use the clang (-O0/-O3) to directly compile to object files and link them. > However, when I use opt with a select set of passes and then use llc to > compile them to binary, the compiled binary is wrong. > > That makes me wonder if there are any IR->IR passes that are indispensable > and they are to guarantee the semantics? > > Here's my workflow just in case: > ************************************************************ > ********************* > 1. Compile the source code to unoptimized IRs: > clang -c -emit-llvm -O0 test.c -o test.bc > 2. Run opt with a set of IR->IR passes, e.g., > opt -simplifycfg -sroa -inferattrs -globalopt -instcombine -simplifycfg > -prune-eh -inline -tailcallelim -simplifycfg -loop-simplify -lcssa > -loop-rotate -licm -gvn -verify test.bc -o test.bc > 3. Run llc with -O0: > llc -file-type=obj test.bc -o test.o > 4. Last link all the object files: > clang -O0 test1.o test2.o -o test > ************************************************************ > ********************* > > Thanks, > Peizhao > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://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/20170301/30be4422/attachment.html>
On 3/1/17 2:54 PM, Peizhao Ou via llvm-dev wrote:> Hi everyone, > > I am currently testing out a combination of IR->IR passes with opt to > benchmark how they affect performance. The source code works fine if > simply use the clang (-O0/-O3) to directly compile to object files and > link them. However, when I use opt with a select set of passes and > then use llc to compile them to binary, the compiled binary is wrong.Can you clarify what you mean by "binary is wrong"? Does the program not link, or does it produce incorrect results when executed? You might try running mem2reg before any other passes in your random list of optimizations. mem2reg does SSA construction; I'd bet that you're more likely to trigger a bug in other passes if you haven't run mem2reg first. That said, I don't think any passes are needed for correctness. You might also try using bugpoint to reduce the bug that you're seeing. As I said before, you may be triggering bugs that don't usually show up in the standard pass pipeline. Reducing the bug (and fixing it if you are willing and able) would help improve the quality of the code. Regards, John Criswell> > That makes me wonder if there are any IR->IR passes that are > indispensable and they are to guarantee the semantics? > > Here's my workflow just in case: > ********************************************************************************* > 1. Compile the source code to unoptimized IRs: > clang -c -emit-llvm -O0 test.c -o test.bc > 2. Run opt with a set of IR->IR passes, e.g., > opt -simplifycfg -sroa -inferattrs -globalopt -instcombine > -simplifycfg -prune-eh -inline -tailcallelim -simplifycfg > -loop-simplify -lcssa -loop-rotate -licm -gvn -verify test.bc -o test.bc > 3. Run llc with -O0: > llc -file-type=obj test.bc -o test.o > 4. Last link all the object files: > clang -O0 test1.o test2.o -o test > ********************************************************************************* > > Thanks, > Peizhao > > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev-- John Criswell Assistant Professor Department of Computer Science, University of Rochester http://www.cs.rochester.edu/u/criswell -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170301/b1b267e3/attachment.html>
On Wed, Mar 1, 2017 at 12:53 PM, John Criswell via llvm-dev < llvm-dev at lists.llvm.org> wrote:> On 3/1/17 2:54 PM, Peizhao Ou via llvm-dev wrote: > > Hi everyone, > > I am currently testing out a combination of IR->IR passes with opt to > benchmark how they affect performance. The source code works fine if simply > use the clang (-O0/-O3) to directly compile to object files and link them. > However, when I use opt with a select set of passes and then use llc to > compile them to binary, the compiled binary is wrong. > > > Can you clarify what you mean by "binary is wrong"? Does the program not > link, or does it produce incorrect results when executed? > > You might try running mem2reg before any other passes in your random list > of optimizations. mem2reg does SSA construction; I'd bet that you're more > likely to trigger a bug in other passes if you haven't run mem2reg first. > That said, I don't think any passes are needed for correctness. >SROA does this too (among other things). -- Sean Silva> > You might also try using bugpoint to reduce the bug that you're seeing. > As I said before, you may be triggering bugs that don't usually show up in > the standard pass pipeline. Reducing the bug (and fixing it if you are > willing and able) would help improve the quality of the code. > > Regards, > > John Criswell > > > > That makes me wonder if there are any IR->IR passes that are indispensable > and they are to guarantee the semantics? > > Here's my workflow just in case: > ************************************************************ > ********************* > 1. Compile the source code to unoptimized IRs: > clang -c -emit-llvm -O0 test.c -o test.bc > 2. Run opt with a set of IR->IR passes, e.g., > opt -simplifycfg -sroa -inferattrs -globalopt -instcombine -simplifycfg > -prune-eh -inline -tailcallelim -simplifycfg -loop-simplify -lcssa > -loop-rotate -licm -gvn -verify test.bc -o test.bc > 3. Run llc with -O0: > llc -file-type=obj test.bc -o test.o > 4. Last link all the object files: > clang -O0 test1.o test2.o -o test > ************************************************************ > ********************* > > Thanks, > Peizhao > > > > _______________________________________________ > LLVM Developers mailing listllvm-dev at lists.llvm.orghttp://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > > > > -- > John Criswell > Assistant Professor > Department of Computer Science, University of Rochesterhttp://www.cs.rochester.edu/u/criswell > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://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/20170301/68408fd4/attachment.html>
Hum, interesting. That would surprise me. I assumed them to do the same thing, but I am not exactly sure. I just tried to clang instead of llc, it seems like the problem remains. Peizhao On Wed, Mar 1, 2017 at 12:45 PM, Flamedoge <code.kchoi at gmail.com> wrote:> From my experience, I could not get llc to generate working object file. I > just used clang on llvm IR to do that. > > Regards, > Kevin > > On Wed, Mar 1, 2017 at 11:54 AM, Peizhao Ou via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> Hi everyone, >> >> I am currently testing out a combination of IR->IR passes with opt to >> benchmark how they affect performance. The source code works fine if simply >> use the clang (-O0/-O3) to directly compile to object files and link them. >> However, when I use opt with a select set of passes and then use llc to >> compile them to binary, the compiled binary is wrong. >> >> That makes me wonder if there are any IR->IR passes that are >> indispensable and they are to guarantee the semantics? >> >> Here's my workflow just in case: >> ************************************************************ >> ********************* >> 1. Compile the source code to unoptimized IRs: >> clang -c -emit-llvm -O0 test.c -o test.bc >> 2. Run opt with a set of IR->IR passes, e.g., >> opt -simplifycfg -sroa -inferattrs -globalopt -instcombine -simplifycfg >> -prune-eh -inline -tailcallelim -simplifycfg -loop-simplify -lcssa >> -loop-rotate -licm -gvn -verify test.bc -o test.bc >> 3. Run llc with -O0: >> llc -file-type=obj test.bc -o test.o >> 4. Last link all the object files: >> clang -O0 test1.o test2.o -o test >> ************************************************************ >> ********************* >> >> Thanks, >> Peizhao >> >> >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://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/20170301/67d41b10/attachment.html>
"binary is wrong" refers to it compiles & links but produces incorrect results. I actually tried another combination, in which I used -O3 for opt, and then -O0 for llc, the problem didn't go away, but when I use -O3 for llc, the binary produces expected results. Thanks for pointing out for the -mem2reg pass and using the bugpoint tool. BTW, the problem comes from compiling and running gcc in SPEC CPU2006. Best, Peizhao On Wed, Mar 1, 2017 at 12:53 PM, John Criswell <jtcriswel at gmail.com> wrote:> On 3/1/17 2:54 PM, Peizhao Ou via llvm-dev wrote: > > Hi everyone, > > I am currently testing out a combination of IR->IR passes with opt to > benchmark how they affect performance. The source code works fine if simply > use the clang (-O0/-O3) to directly compile to object files and link them. > However, when I use opt with a select set of passes and then use llc to > compile them to binary, the compiled binary is wrong. > > > Can you clarify what you mean by "binary is wrong"? Does the program not > link, or does it produce incorrect results when executed? > > You might try running mem2reg before any other passes in your random list > of optimizations. mem2reg does SSA construction; I'd bet that you're more > likely to trigger a bug in other passes if you haven't run mem2reg first. > That said, I don't think any passes are needed for correctness. > > You might also try using bugpoint to reduce the bug that you're seeing. > As I said before, you may be triggering bugs that don't usually show up in > the standard pass pipeline. Reducing the bug (and fixing it if you are > willing and able) would help improve the quality of the code. > > Regards, > > John Criswell > > > > That makes me wonder if there are any IR->IR passes that are indispensable > and they are to guarantee the semantics? > > Here's my workflow just in case: > ************************************************************ > ********************* > 1. Compile the source code to unoptimized IRs: > clang -c -emit-llvm -O0 test.c -o test.bc > 2. Run opt with a set of IR->IR passes, e.g., > opt -simplifycfg -sroa -inferattrs -globalopt -instcombine -simplifycfg > -prune-eh -inline -tailcallelim -simplifycfg -loop-simplify -lcssa > -loop-rotate -licm -gvn -verify test.bc -o test.bc > 3. Run llc with -O0: > llc -file-type=obj test.bc -o test.o > 4. Last link all the object files: > clang -O0 test1.o test2.o -o test > ************************************************************ > ********************* > > Thanks, > Peizhao > > > > _______________________________________________ > LLVM Developers mailing listllvm-dev at lists.llvm.orghttp://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > > > > -- > John Criswell > Assistant Professor > Department of Computer Science, University of Rochesterhttp://www.cs.rochester.edu/u/criswell > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170301/0ab35098/attachment.html>