<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 - -globals-aa affected by dbg intrinsic leading to different code after instcombine"
   href="https://bugs.llvm.org/show_bug.cgi?id=35899">35899</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>-globals-aa affected by dbg intrinsic leading to different code after instcombine
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </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>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>mikael.holmen@ericsson.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=19650" name="attach_19650" title="reproducer">attachment 19650</a> <a href="attachment.cgi?id=19650&action=edit" title="reproducer">[details]</a></span>
reproducer

opt -S -o - foo.ll -globals-aa -instcombine
and
opt -S -o - foo.ll -strip-debug -globals-aa -instcombine

yields different results on the attached foo.ll.

We get

define void @foo() {
  store i8 42, i8* @g, align 1
  call void @bar(i8 1)
  %_tmp = load i8, i8* @g, align 1
  call void @gaz(i8 %_tmp)
  ret void
}

and

define void @foo() {
  store i8 42, i8* @g, align 1
  call void @bar(i8 1)
  call void @gaz(i8 42)
  ret void
}

It seems like the

  call void @llvm.dbg.value(metadata i64 0, metadata !6, metadata
!DIExpression()), !dbg !13

in 

define void @bar(i8 %p) {
  call void @llvm.dbg.value(metadata i64 0, metadata !6, metadata
!DIExpression()), !dbg !13
  ret void
}
disturbs -globals-aa then leading to instcombine not doing the optimization.

I don't know -globals-aa at all, but I examined what happened in
GlobalsModRef.cpp a little bit and I found that if I do

-          if (isAllocationFn(&I, &TLI) || isFreeCall(&I, &TLI)) {
+          if (isa<DbgInfoIntrinsic>(I))
+            continue;
+          else if (isAllocationFn(&I, &TLI) || isFreeCall(&I, &TLI)) {

in GlobalsAAResult::AnalyzeCallGraph around line 578 then I don't get the
difference anymore. I've no idea if that's a sane fix or not though.</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>