<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 - GVNHoist should drop debug location according to the debug info guide"
   href="https://bugs.llvm.org/show_bug.cgi?id=49099">49099</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>GVNHoist should drop debug location according to the debug info guide
          </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=24497" name="attach_24497" title="abc_debug.ll">attachment 24497</a> <a href="attachment.cgi?id=24497&action=edit" title="abc_debug.ll">[details]</a></span>
abc_debug.ll

Overview, the GVNHoist pass preserves the debug location, however, according to
the LLVM debug info update guide, the debug location should be dropped.

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 complete IR file abc_debug.ll is attached.

$ cat abc_debug.ll
...... (irrelevant content omitted)
entry:
  call void @llvm.dbg.value(metadata i32 0, metadata !9, metadata
!DIExpression()), !dbg !11
  switch i32 %c1, label %exit1 [
    i32 0, label %sw0
    i32 1, label %sw1
  ], !dbg !11

sw0:                                              ; preds = %entry
  store i32 1, i32* @G, align 4, !dbg !12
  br label %exit, !dbg !13

sw1:                                              ; preds = %entry
  store i32 1, i32* @G, align 4, !dbg !14
  br label %exit, !dbg !15

exit1:                                            ; preds = %entry
  store i32 1, i32* @G, align 4, !dbg !16
  ret void, !dbg !17
......


The gvn hoist will hoist the identical store instructions to the predecessor
basic block.

$ opt -gvn-hoist abc_debug.ll > result.bc
$ llvm-dis  result.bc 
$ cat result.ll
......(omit irrelevant content)
entry:
  call void @llvm.dbg.value(metadata i32 0, metadata !9, metadata
!DIExpression()), !dbg !11
  store i32 1, i32* @G, align 4, !dbg !12
  switch i32 %c1, label %exit1 [
    i32 0, label %sw0
    i32 1, label %sw1
  ], !dbg !11

sw0:                                              ; preds = %entry
  br label %exit, !dbg !13

sw1:                                              ; preds = %entry
  br label %exit, !dbg !14

exit1:                                            ; preds = %entry
  ret void, !dbg !15
......


However, according to the LLVM debug info update guide:
<a href="https://llvm.org/docs/HowToUpdateDebugInfo.html">https://llvm.org/docs/HowToUpdateDebugInfo.html</a>, "Hoisting identical
instructions which appear in several successor blocks into a predecessor block.
In this case there is no single merged instruction. The rule for dropping
locations applies". It seems that the debug location should be dropped instead
of preserving the "!dbg !12"</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>