<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 - Missing multiple store to single load forwarding"
   href="https://bugs.llvm.org/show_bug.cgi?id=52568">52568</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missing multiple store to single load forwarding
          </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>nikita.ppv@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The middle end optimizer is currently not able to forward multiple small stores
to a single large load at -O3 (<a href="https://llvm.godbolt.org/z/bxE1eKMK9">https://llvm.godbolt.org/z/bxE1eKMK9</a>):

define i64 @test(ptr %p) {
  store i32 0, ptr %p
  %p2 = getelementptr i8, ptr %p, i64 4
  store i32 1, ptr %p2
  %v = load i64, ptr %p
  ret i64 %v
}

In my specific use case the large load actually gets decomposed back down to
the two parts using trunc/lshr:

define i32 @test2(ptr %p, ptr %p.out) {
  store i32 0, ptr %p
  %p2 = getelementptr i8, ptr %p, i64 4
  store i32 1, ptr %p2
  %v = load i64, ptr %p
  %v1 = trunc i64 %v to i32
  store i32 %v1, ptr %p.out
  %v2 = lshr i64 %v, 32
  %v3 = trunc i64 %v2 to i32
  ret i32 %v3
}

I'm mentioning this because this case is potentially easier to solve, as one
could effectively forward directly to the trunc.

We do fold these at the DAG level, but by then it is too late to apply cross-BB
followup optimizations.</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>