<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Minor code difference building with/without -g"
   href="http://llvm.org/bugs/show_bug.cgi?id=21807">21807</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Minor code difference building with/without -g
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>tools
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>llc
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>russell_gallop@sn.scee.net
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=13451" name="attach_13451" title="Original source and IR to reproduce">attachment 13451</a> <a href="attachment.cgi?id=13451&action=edit" title="Original source and IR to reproduce">[details]</a></span>
Original source and IR to reproduce

I've observed a small difference in the code generated from the attached cpp
differs depending on the -g flag. This is a non-functional change. I am using
revision 223924.

e.g.
# Without -g
clang -O2 -c test.cpp -o test.o
objdump -d test.o > test.od
# With -g
clang -O2 -c test.cpp -g -o testg.o
objdump -d testg.o > testg.od
# Compare
diff -I "file format" test.od testg.od
17,18c17,18
<   1b: 89 da                   mov    %ebx,%edx
<   1d: 41 89 d8                mov    %ebx,%r8d
---
<span class="quote">>   1b: 41 89 d8                mov    %ebx,%r8d
>   1e: 89 da                   mov    %ebx,%edx</span >

We've determined that with -g the machine scheduler uses a different scheduling
strategy based on the number of instructions in a schedule region.

The difference is likely because it does not exclude debug instructions from
the count. With the following patch we get the same instruction sequence
with/without -g.

diff --git a/lib/CodeGen/MachineScheduler.cpp
b/lib/CodeGen/MachineScheduler.cpp
index 261942f..cc8f3a0 100644
--- a/lib/CodeGen/MachineScheduler.cpp
+++ b/lib/CodeGen/MachineScheduler.cpp
@@ -430,9 +430,11 @@ void
MachineSchedulerBase::scheduleRegions(ScheduleDAGInstrs &Scheduler) {
       // instruction stream until we find the nearest boundary.
       unsigned NumRegionInstrs = 0;
       MachineBasicBlock::iterator I = RegionEnd;
-      for(;I != MBB->begin(); --I, --RemainingInstrs, ++NumRegionInstrs) {
+      for(;I != MBB->begin(); --I, --RemainingInstrs) {
         if (isSchedBoundary(std::prev(I), MBB, MF, TII, IsPostRA))
           break;
+        if (!I->isDebugValue())
+          ++NumRegionInstrs;
       }
       // Notify the scheduler of the region, even if we may skip scheduling
       // it. Perhaps it still needs to be bundled.


The difference can also be seen with the attached IR:
llc test.ll
llc testg.ll</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>