<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: SCCP loses debug info for constant globals"
   href="https://bugs.llvm.org/show_bug.cgi?id=39900">39900</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>DebugInfo: SCCP loses debug info for constant globals
          </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>Linux
          </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>DebugInfo
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>dblaikie@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>aprantl@apple.com, jdevlieghere@apple.com, keith.walker@arm.com, llvm-bugs@lists.llvm.org, paul_robinson@playstation.sony.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Given this code:

  static int x = 3;
  int z() { return x; }

Unoptimized, the resulting DWARF describes the location of 'x'.

Once optimized by SCCP, the LLVM IR is not updated with a description of the
constant value of 'x', the value is lost entirely.

Looks like down in the final loop (line ~2140) in SCCP.cpp, that's deleting
globals - it could check if there's debug info attached to the GlobalVariable,
and rewrite it to a constant description using I->second.getConstant(), if the
constant is of a type (int or float? I think are the ones currently supported)
that can be encoded as a constant in the debug info metadata at the moment.

This may be incorrect in cases where this optimization fires & due to previous
passes eliminating dead stores to the variable (in which case the dead stores
wouldn't be reflected - though I suppose at that point describing the location
of the variable as being in the global is just as erroneous), but it looks
like, at least if you complicate the case by adding "x = 7;" to z() before the
return, it's not SCCP that optimizes away the GlobalVariable, but GlobalOpt. So
maybe fixing SCCP isn't an issue in this way.</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>