<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_CONFIRMED "
   title="CONFIRMED - [DebugInfo@O2] EarlyCSE accidentally deletes unused arguments"
   href="https://bugs.llvm.org/show_bug.cgi?id=40645">40645</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[DebugInfo@O2] EarlyCSE accidentally deletes unused arguments
          </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>CONFIRMED
          </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>Scalar Optimizations
          </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>chackz0x12@gmail.com, dblaikie@gmail.com, greg.bedwell@sony.com, international.phantom@gmail.com, llvm-bugs@lists.llvm.org, paul.robinson@am.sony.com
          </td>
        </tr>

        <tr>
          <th>Blocks</th>
          <td>38768
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Using LLVM/clang r352480 (10 days old) and the command line "-O2 -g -c" on the
code below, the 'nose' argument does not receive a location in the output
binary. However if one deletes the dead assignments of "shoe" and "boot", then
it does!

--------8<--------
struct chin {
  int a;
  int b;
};

int
foo(struct chin nose, int more)
{
  int shoe = nose.a;
  int boot = nose.b;
  more += 1;
  return more;
}
-------->8--------

I suspect the location appears when "nose" is never read because SROA doesn't
attempt to split it into fragments, instead issuing a 64-bit dbg.value for the
'nose' variable. But if there are reads in the program, two 32-bit dbg.values
and associated reading instructions are produced, then get lost. The culprit
appears to be EarlyCSE, which sets the operands of the 32-bit dbg.values to
undef:

  call void @llvm.dbg.value(metadata i32 %3, metadata !16, metadata
!DIExpression(DW_OP_LLVM_fragment, 0, 32)), !dbg !20

Becomes

  call void @llvm.dbg.value(metadata i32 undef, metadata !16, metadata
!DIExpression(DW_OP_LLVM_fragment, 0, 32)), !dbg !20

If one replaces the addition to 'more' with either shoe or boot, then the
corresponding field of 'nose' appears in the outputs debug location
information, however not the other field.</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>