[LLVMbugs] [Bug 21807] New: Minor code difference building with/without -g

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Dec 10 07:14:36 PST 2014


            Bug ID: 21807
           Summary: Minor code difference building with/without -g
           Product: tools
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: llc
          Assignee: unassignedbugs at nondot.org
          Reporter: russell_gallop at sn.scee.net
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 13451
  --> http://llvm.org/bugs/attachment.cgi?id=13451&action=edit
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.

# 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
<   1b: 89 da                   mov    %ebx,%edx
<   1d: 41 89 d8                mov    %ebx,%r8d
>   1b: 41 89 d8                mov    %ebx,%r8d
>   1e: 89 da                   mov    %ebx,%edx

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
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))
+        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

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20141210/05939598/attachment.html>

More information about the llvm-bugs mailing list