<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - load instruction erroneously removed by GVN"
   href="https://llvm.org/bugs/show_bug.cgi?id=24426">24426</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>load instruction erroneously removed by GVN
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>tools
          </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>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>opt
          </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>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I have the following program:

declare void @check(i8)

declare void @write(i8* %res)

define i8 @TEST1() {
  %buf = alloca [10 x i8]
  %_tmp30 = bitcast [10 x i8]* %buf to i8*

  call void @write(i8* %_tmp30)

  %_tmp33 = load i8, i8* %_tmp30
  call void @check(i8 %_tmp33)

  ret i8 0
}

and I run opt on it with
build-all/bin/opt -S -memcpyopt -mldst-motion -gvn -O3 ./f2.ll

and then the load is removed by GVN and %_tmp33 is replaced with undef.

GVN iteration: 0
GVN removed:   %_tmp33 = load i8, i8* %_tmp30


I notice that if I change TEST1 slightly, and rewrite it as

define i8 @TEST2() {
  %buf = alloca i8

  call void @write(i8* %buf)

  %_tmp33 = load i8, i8* %buf
  call void @check(i8 %_tmp33)

  ret i8 0
}

then the load is left intact

GVN iteration: 0
GVN: load i8 %_tmp33 is clobbered by   call void @write(i8* %buf.17)

In this case it seems to be the code

  if (llvm::PointerMayBeCapturedBefore(Object, /* ReturnCaptures */ true,
                                       /* StoreCaptures */ true, I, DT,
                                       /* include Object */ true,
                                       /* OrderedBasicBlock */ OBB))
    return MRI_ModRef;

in AliasAnalysis::callCapturesBefore that saves the load, which it doesn't in
the first case.</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>