<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 - GVN incorrectly optimizes away a non-local load"
   href="https://bugs.llvm.org/show_bug.cgi?id=45470">45470</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>GVN incorrectly optimizes away a non-local load
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </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>Scalar Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>changpeng.fang@amd.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=23321" name="attach_23321" title="opt -O1 -gcn bug.ll">attachment 23321</a> <a href="attachment.cgi?id=23321&action=edit" title="opt -O1 -gcn bug.ll">[details]</a></span>
opt -O1 -gcn bug.ll

GVN pass incorrectly optimized away the load. Actually the load should have a
dependence on the store inside the loop. but it looks like the memory
dependence is somehow skipped and the load is found to depend on the alloca,
and thus replaced with undef.

---------------------------
.preheader:                                       ; preds = %.preheader, %bb
  %phi.i = phi i32 [ %next.i, %.preheader ], [ undef, %bb ]
  %tmp1 = shl nuw nsw i32 %phi.i, 2
  %offset = or i32 %tmp1, 2
  %store.addr = getelementptr inbounds [16 x i16], [16 x i16] addrspace(5)*
%alloca, i32 0, i32 %offset
  store i16 11878, i16 addrspace(5)* %store.addr, align 2
  %next.i = add nuw nsw i32 %phi.i, 1
  %cmp = icmp ult i32 %next.i, 8
  br i1 %cmp, label %.preheader, label %.loopexit

.loopexit:                                        ; preds = %.preheader
  %addr = bitcast [16 x i16] addrspace(5)* %alloca to half addrspace(5)*
  %result = load half, half addrspace(5)* %addr, align 2
  call void @chfang(half %result)
  unreachable
--------------------

to reproduce:
  opt -O1 -gvn -S bug.ll
------------------------
You will find:
.loopexit:                                        ; preds = %.preheader
  %addr = bitcast [16 x i16] addrspace(5)* %alloca to half addrspace(5)*
  tail call void @chfang(half undef)
  unreachable

We don't think this non-local load should be optimized away.</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>