https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89983

            Bug ID: 89983
           Summary: Missing debug info for final loop IV value
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rguenth at gcc dot gnu.org
  Target Milestone: ---

For

void foo(int n)
{
  if (n == 0)
    return;
  int i = 0;
  do
    {
      ++i;
    }
  while (i < n);
  __asm__ volatile ("" : : "g" (i) : "memory");
}

int main() { foo(5); return 0; }

if you compile this with optimization but final-value replacement disabled
(-fno-tree-scev-cprop or simply when using -Og) gdb only prints
<optimized out> for i when breaking at the inline asm.  It is actually
the 'ret' instruction that is associated with that line (and line
association in the loop is generally weird, with no assembly instruction
associated with the loop condition...).

.debug_loc shows

    00000002 v000000000000000 v000000000000001 views at 00000000 for:
             0000000000000009 0000000000000010 (DW_OP_reg0 (rax))

that's just for the add if I deciper correctly.  The issue might be that
we have

  <bb 3> [local count: 1073741824]:
  # i_1 = PHI <[t.c:5:7] 0(2), [t.c:8:7] i_4(3)>
  # DEBUG i => i_1
  [t.c:6:3] # DEBUG BEGIN_STMT
  [t.c:8:7] # DEBUG BEGIN_STMT
  [t.c:8:7] i_4 = i_1 + 1;
  [t.c:8:7] # DEBUG i => i_4
  [t.c:10:3] if (n_3(D) > i_4)
    goto <bb 3>; [89.00%]
  else
    goto <bb 4>; [11.00%]

  <bb 4> [local count: 118111601]:
  [t.c:11:3] # DEBUG BEGIN_STMT
  [t.c:11:3] __asm__ __volatile__("" :  : "g" i_4 : "memory");

thus refer to the value before and after the increment (but we have
only one instruction).  Still there's the compare and branch to have
the new value (in same register) plus of course the ret.

Note the RTL seems to reflect things correctly at var-tracking time
but then var-tracking has

(note 41 21 42 (var_location i (nil)) NOTE_INSN_VAR_LOCATION)
(note 42 41 24 (var_location n (reg:SI 5 di [ n ])) NOTE_INSN_VAR_LOCATION)

between the asm and the simple-return.  Somehow the asm itself has
a REG_DEAD note on ax (well, it's the last use).  Using a nop in the
asm "fixes" the debug experience.

This will be gcc.dg/guality/loop-1.c (but with a nop).

The testcase as in the testsuite also fails at -O3 because of unknown reasons.

Reply via email to