<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 - MemCpyOptimizer should take the merged debug location"
   href="https://bugs.llvm.org/show_bug.cgi?id=49270">49270</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>MemCpyOptimizer should take the merged debug location
          </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>Scalar Optimizations
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=24554" name="attach_24554" title="old_debug.ll">attachment 24554</a> <a href="attachment.cgi?id=24554&action=edit" title="old_debug.ll">[details]</a></span>
old_debug.ll

Overview, the memcpyopt pass preserves the debug location of one instruction
when merging two stores, however, according to the LLVM debug info update
guide, the debug location should be merged and then applied.

Steps to reproduce:
$ clang++ --version
clang version 13.0.0 (<a href="https://github.com/llvm/llvm-project.git">https://github.com/llvm/llvm-project.git</a>
0b5d8d668c210f263a93821fd51c564313c96099)
Target: x86_64-unknown-linux-gnu
Thread model: posix

The IR file "old_debug.ll" is uploaded as an attachment.

$ opt -memcpyopt old_debug.ll -S > new.ll

In the original old_debug.ll file, the instruction "store i32 0, i32*
%arrayidx, align 4, !dbg !14" and "tail call void @llvm.memset.p0i8.i64(i8* %0,
i8 0, i64 11, i1 false), !dbg !17" are merged into one llvm.memset intrinsic in
the optimized file "new.ll". However the debug location "!dbg !17" of the
llvm.memset in the optimized file is actually the debug location of the
llvm.memset in the original IR file. According to my understanding of LLVM
debug info update guide:
<a href="https://llvm.org/docs/HowToUpdateDebugInfo.html#when-to-merge-instruction-locations">https://llvm.org/docs/HowToUpdateDebugInfo.html#when-to-merge-instruction-locations</a>,
when the pass tries to merge multiple block-local instructions into one, it
should apply the merged debug location instead of preserving one of the debug
locations.</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>