<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 - [ISel] Unused instructions referenced in debug data removed at O0"
   href="https://bugs.llvm.org/show_bug.cgi?id=41801">41801</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[ISel] Unused instructions referenced in debug data removed at O0
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

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

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

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Common Code Generator Code
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>stephen.tozer@sony.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Using LLVM/clang r360138 and the command line "-c -O0 -x ir" on the IR file
produced by the commands below, the debug data corresponding to "nose.b" and
"boot" is not present in the output object file. The issue appears to occur
during instruction selection, where the following register (which is only used
in debug expressions)is not present in the first pass to output MIR, either
"X86 DAG->DAG Instruction Selection" or "Expand ISel Pseudo-instructions"
depending on platform. This causes debug information to be lost due to an
optimization when -O0 is enabled.

To reproduce:

$ clang -v
clang version 9.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\dev\llvm-project\build\Debug\bin

$ cat reproduce.cpp
struct chin {
        int a;
        int b;
};

int foo(struct chin nose, int more) {
        int shoe = nose.a;
        int boot = nose.b;
        return more;
}

$ clang reproduce.cpp -o - -S -emit-llvm -g -O0 -Xclang -disable-O0-optnone |
opt -sroa -early-cse -S > reproduce.ll


The point at which the debug information for "boot" is lost can then be seen in
the output of the command:

$ clang reproduce.ll -o - -c -g -O0 -x ir -mllvm -print-after-all 2>&1
<span class="quote">>/dev/null</span ></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>