<div dir="ltr">Your script looks OK, though you won't want to use the -opt-bisect-limit= option until you've found a case where code-generation changes. Instead, that's a tool which you could use to narrow down the pass inside LLVM which is causing the change.<div><br></div><div>The problem is that your input code is far too simple to trigger any interesting optimisations. I'd suggest starting with either some code from the LLVM test suite (<a href="https://github.com/llvm/llvm-test-suite">https://github.com/llvm/llvm-test-suite</a>), or some code generated by csmith (<a href="https://embed.cs.utah.edu/csmith/">https://embed.cs.utah.edu/csmith/</a>). The former has the advantage of being (mostly) real code people actually write, and the latter can generate a large amount of complex code without any external dependencies (so it's easy to build).</div><div><br></div><div>I'd also suggest looking into creduce (<a href="https://embed.cs.utah.edu/creduce/">https://embed.cs.utah.edu/creduce/</a>), which will allow you to quickly reduce a large input file which triggers a bug down to a much smaller one.</div><div><br></div><div>Oliver</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 24 Jul 2019 at 01:18, Chris Ye via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="line-height:1.7;color:rgb(0,0,0);font-size:14px;font-family:Arial"><div>Hi Paul,</div><div>Thanks for your useful guidelines, may I confirm with you the steps list below is correct or not?</div><div><br></div><div>1. find sample code (.c)<br></div><div>2. using different options(pass) to compile sample code by clang with/without "-g"</div><div>3. objdump the output.o and outout-g.o</div><div>4. compare two file of text section check if there has any difference. <br></div><div>5. if find difference, great, file bug and fix it.</div><div><br></div><div>Please correct me if I miss something. <br></div><div><br></div><div>Follow the steps, <br></div><div>* I used sample code (foo.c) <br></div>------------------------------------------------------------------------------------------<div>int foo() { return 42; }<br>int bar() { return foo(); }</div><div>------------------------------------------------------------------------------------------</div><div><br></div><div>* created a compare tool (compare.sh)</div>------------------------------------------------------------------------------------------<div>#!/bin/bash<br><br>options=$1<br>file=$2<br>  <br>clang -c -ffunction-sections -fexceptions -mllvm -opt-bisect-limit=200 $1 $file -o output.o<br>clang -c -ffunction-sections -fexceptions -mllvm -opt-bisect-limit=200 $1 $file -o output-g.o<br>  <br>objdump -d output.o > output.objdump<br>objdump -d output-g.o > output-g.objdump<br>  <br>diff -uNar output.objdump output-g.objdump<br>------------------------------------------------------------------------------------------<br></div><div><br></div><div>* Then run the compassion tests<br></div><div>------------------------------------------------------------------------------------------</div><div>$ ./compare.sh -O0 foo.c</div><div>$ ./compare.sh -O1 foo.c</div><div>$ ./compare.sh -O2 foo.c</div><div>$ ./compare.sh -O3 foo.c</div><div>------------------------------------------------------------------------------------------</div><div><br></div><div>The diff result is the same. How can I find the bug? Do the sample code I used too simple? Or need I add other more pass options? Please help to correct my steps if I missed something. Thanks you very much.<br></div><br><div>Best Regards,</div><div>Chris Ye</div><div><br></div><div style="zoom:1"></div><div id="gmail-m_-4265127616452673202divNeteaseMailCard"></div><br>At 2019-07-17 01:40:43, <a href="mailto:paul.robinson@sony.com" target="_blank">paul.robinson@sony.com</a> wrote:<br> <blockquote id="gmail-m_-4265127616452673202isReplyContent" style="padding-left:1ex;margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204)">






<div class="gmail-m_-4265127616452673202WordSection1">
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Hi Chris,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">"Debug info should have no effect on codegen" would be a fine project for you; nobody is working on it that I know of.  Another way to contribute would be to
 go to our Bugzilla (<a href="http://bugs.llvm.org" target="_blank">bugs.llvm.org</a>) and search for open bugs with the "beginner" keyword.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Regarding the "debug info has no effect on codegen" project, unfortunately I am having IT issues that keep me from providing much in the way of specific suggestions,
 so what follows is fairly generic.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">In principle, you compile some piece of code with and without –g, and see if there is any difference in the generated instructions. My experience is that you
 want to compile to a .o file, and then use a disassembler to dump the text sections. This will give you a cleaner diff than using –S to generate assembler files.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">I also recommend compiling with `-ffunction-sections` and probably `-fexceptions`.  The former will put each compiled function into its own object-file section,
 so that differences in one function won't affect the disassembly of a later function.  The latter option should work around one fairly intractable known difference: -g will cause the compiler to emit directives to produce call-frame information, and these
 tend to act as instruction-scheduling barriers. Using –fexceptions (I am 95% sure that is the correct option) should cause the non-dash-g compilation to use the same directives, and avoid that known difference.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">You can repeat this experiment with different optimization levels, as differences are far more likely to show up with optimization.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Once you find a difference, you can begin experimenting with ways to identify specific compiler passes that are contributing to the difference. A very useful
 tool here is the backend option `-opt-bisect-limit=N` where N is the number of passes to execute. Because it is a backend option, you would use it this way:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">    clang –c –O2
</span><span style="font-size:11pt;font-family:Calibri,sans-serif;color:red">–mllvm –opt-bisect-limit=100
</span><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">foo.c –o foo.o<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">    clang –c –O2 –mllvm –opt-bisect-limit=100 foo.c –g –o foo-g.o<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Then disassemble and diff as usual.  After you have identified a problematic pass, you can try your hand at fixing it yourself, or you can file a bug (with
 a reduced reproducer if at all possible) and move on to another sample.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Of course you will need some sample source code to run experiments on.  This can be anything convenient. You could try it on any personal projects you have,
 or you could find a random code generator, or whatever you like.  Some people have recommended LLVM's own 'test-suite' project although I have not looked at it in any detail.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Good luck, and feel free to post additional questions on llvm-dev if you run into any problems.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">--paulr<u></u><u></u></span></p>
<p class="MsoNormal"><a name="m_-4265127616452673202__MailEndCompose"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></a></p>
<div style="border-top:none;border-right:none;border-bottom:none;border-left:1.5pt solid blue;padding:0in 0in 0in 4pt">
<div>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(181,196,223);padding:3pt 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10pt;font-family:Tahoma,sans-serif">From:</span></b><span style="font-size:10pt;font-family:Tahoma,sans-serif"> llvm-dev [mailto:<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a>]
<b>On Behalf Of </b>Chris Ye via llvm-dev<br>
<b>Sent:</b> Sunday, July 14, 2019 11:59 PM<br>
<b>To:</b> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<b>Subject:</b> [llvm-dev] How to contribute on LLVM project as beginner<u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:10.5pt;font-family:Arial,sans-serif;color:black">Hi LLVM project Leaders,<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.5pt;font-family:Arial,sans-serif;color:black">I am a software engineer working on several other open source projects, recently I am very interested in LLVM technology, espically on backend part. I have taken
 two months studying the documents from <a href="http://llvm.org" target="_blank">llvm.org</a> in my spare time. As a beginner, I would like to contribute some code to LLVM project, from the "<a name="m_-4265127616452673202_gsoc19">Google Summer of Code 2019</a>", I found one project "Debug Info should have no effect on codegen"
 that I may able to contribute, not sure if the project has already been completed? If there are still tasks exist, how can I join in? Or is that any other project I can work on? I would spend 10~20 hours on LLVM development every week as I want to gather experience
 to find a job as LLVM developer in the furture.  I am a quickly learning, I would be very appricate if you could help me and give me some guides, so that I would run faster on my way to LLVM field. Many thanks. <u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.5pt;font-family:Arial,sans-serif;color:black"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.5pt;font-family:Arial,sans-serif;color:black">-----------------------------------------------------------------<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.5pt;font-family:Arial,sans-serif;color:black">LLVM
<u></u><u></u></span></p>
<div>
<p class="MsoNormal"><a name="m_-4265127616452673202_debuginfo_codegen_mismatch"><span style="font-size:10.5pt;font-family:Arial,sans-serif;color:black">Debug Info should have no effect on codegen</span></a><span style="font-size:10.5pt;font-family:Arial,sans-serif;color:black">
<u></u><u></u></span></p>
</div>
<div>
<p><b><span style="font-size:10.5pt;font-family:Arial,sans-serif;color:black">Description of the project:</span></b><span style="font-size:10.5pt;font-family:Arial,sans-serif;color:black"> Adding Debug Info (compiling with `clang -g`) shouldn't change
 the generated code at all. Unfortunately we have bugs. These are usually not too hard to fix and a good way to discover new part of the codebase! We suggest building object files both ways and disassembling the text sections, which will give cleaner diffs
 than comparing .s files. <u></u><u></u></span></p>
<p><b><span style="font-size:10.5pt;font-family:Arial,sans-serif;color:black">Expected results:</span></b><span style="font-size:10.5pt;font-family:Arial,sans-serif;color:black"> Reduced test cases, bug reports with analysis (e.g., which pass is responsible),
 possibly patches.<u></u><u></u></span></p>
<p><b><span style="font-size:10.5pt;font-family:Arial,sans-serif;color:black">Confirmed Mentor:</span></b><span style="font-size:10.5pt;font-family:Arial,sans-serif;color:black"> Paul Robinson<u></u><u></u></span></p>
<p><b><span style="font-size:10.5pt;font-family:Arial,sans-serif;color:black">Desirable skills:</span></b><span style="font-size:10.5pt;font-family:Arial,sans-serif;color:black"> Intermediate knowledge of C++, some familiarity with x86 or ARM instruction
 set.<u></u><u></u></span></p>
<p><span style="font-size:10.5pt;font-family:Arial,sans-serif;color:black"><u></u> <u></u></span></p>
<p><span style="font-size:10.5pt;font-family:Arial,sans-serif;color:black">Best Regards,<u></u><u></u></span></p>
<p><span style="font-size:10.5pt;font-family:Arial,sans-serif;color:black">Chris Ye<u></u><u></u></span></p>
</div>
</div>
</div>
<p class="MsoNormal" style="margin-bottom:12pt"><u></u> <u></u></p>
<p> <u></u><u></u></p>
</div>
</div>


</blockquote></div><br><br><span title="neteasefooter"><p> </p></span>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>