<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 --- - Missed store-load forwarding due to release fence" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D24156&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=VY0ZY8SS__TNLccITUKopiWpgJUHg1_xHDsMRxa9ROU&s=CeTqJQ9VRVtTE_mQzD6Hn0nqDd9rqU-VfEwPPlZPjB0&e=">24156</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missed store-load forwarding due to release fence
          </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>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>listmail@philipreames.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Given the following IR fragment:
define i32 @test(i32* %addr.i) {
  store i32 5, i32* %addr.i, align 4
  fence release
  %a = load i32, i32* %addr.i, align 4
  ret i32 %a
}

Neither GVN or EarlyCSE appears to be able to forward the value of the load in
question.  At least if my understanding of fence semantics is correct - which
it might not be - we should be able to forward the value of the store over the
release fence.  To phrase that differently, it's legal to reorder the load
before the release fence; it's not legal to reorder the store after the fence. 
The former is sufficient to allow the forwarding in this case.


My best guess is that we're being too conservative in two ways:
- In EarlyCSE, a fence is modelled as a mayWrite operation.  In practice, we
should only need to clear the last store, not the set of available loads.
- In MemoryDependenceAnalysis, I believe we just give up on fences.  We could
instead look past a release fence if the query value was a load.  I'm not sure
about the semantics of store QueryInst.</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>