<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - [DebugInfo@O2][Dexter] Vectorized code linenos step through loop even after completion"
   href="https://bugs.llvm.org/show_bug.cgi?id=39024">39024</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[DebugInfo@O2][Dexter] Vectorized code linenos step through loop even after completion
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

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

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

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

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

        <tr>
          <th>Keywords</th>
          <td>wrong-debug
          </td>
        </tr>

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

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

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>jeremy.morse.llvm@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Blocks</th>
          <td>38768
          </td>
        </tr></table>
      <p>
        <div>
        <pre>In the loop below, when vectorized, compiler generated code gets program line
numbers that have the potential to be misleading. My test setup is using
clang/llvm r342527, compiling "-O2 -g -fno-inline" targeting x86_64, and
running under gdb or lldb.

The code below sums the contents of a buffer (and is completely contrived); it
gets vectorized into a pair of vectorized/scalar loops as illustrated in the
comments here [0]. Awkwardly, instructions in the "middle block", which just
reduce the vector-accumulator registers down into a scalar register, get the
line numbers for a loop iteration. This causes the user to step through part of
the loop again, even if it's finished.

IMHO this is a defect: the middle block is compiler generated code to plumb
around the transformations that have been performed and shouldn't be stepped
through by the developer. It potentially misleads by suggesting that the loop
is still alive, because the developer can still step through part of it.

If one steps through this whole program you get the impression that the body
executes four times and has a different path through line numbers on each
iteration. Obviously vectorization puts a limit on how faithful debug data can
be to the original program, but IHMO this could be better.

[0]
<a href="https://github.com/llvm-mirror/llvm/blob/a858f4fe0bec699a58833b6277633b2c1b8f90d4/lib/Transforms/Vectorize/LoopVectorize.cpp#L2567">https://github.com/llvm-mirror/llvm/blob/a858f4fe0bec699a58833b6277633b2c1b8f90d4/lib/Transforms/Vectorize/LoopVectorize.cpp#L2567</a>

-------->8--------
#include <stdlib.h>
#include <string.h>

#define BUFSZ 256

int
foo(int argc, int init, int *bar)
{

  if (argc + 1 > BUFSZ)
    return 0;

  int tmp = argc;
  int bees;
  for (int j = 0; j < argc; j++) {
    bees = bar[j];
    tmp += bees;
  }

  return tmp;
}

int
main(int argc, char **argv)
{
  int bar[256];
  memset(bar, 1, 256);
  return foo(16, 1, bar);
}
--------8<--------</pre>
        </div>
      </p>

        <div id="referenced">
          <hr style="border: 1px dashed #969696">
          <b>Referenced Bugs:</b>
          <ul>
              <li>
                [<a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [meta][DebugInfo] Umbrella bug for poor debug experiences"
   href="https://bugs.llvm.org/show_bug.cgi?id=38768">Bug 38768</a>] [meta][DebugInfo] Umbrella bug for poor debug experiences
              </li>
          </ul>
        </div>
        <br>

      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>