<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 - Not vectorizing due to memcpy between stack arrays of trivially copyable struct"
   href="https://bugs.llvm.org/show_bug.cgi?id=51377">51377</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Not vectorizing due to memcpy between stack arrays of trivially copyable struct
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </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>joachim@joameyer.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Hi all,

I work on an LLVM plugin performing loop fission. To keep state between loops,
I have to convert existing `alloca`s to arrays and also generate `alloca`
arrays for dependencies on SSA values.
I also mark the loops as being parallel and set vectorize.enable. This then
regularly generates a warning that at least the first loop can't be vectorized.
With -Rpass-analysis, -debug-only,.. I figured out that this mostly comes from
a trivially copyable type being passed to an inlined function (the source is
not used otherwise), which generates a llvm.memcpy... between two allocas. Due
to my transformations, these allocas become an array of type [1024 x
%"struct.."].
As soon as both allocas become arrays, this loop cannot be vectorized.

I took the IR and llvm-reduced it, the upper editor contains the code with both
allocas being arrays and the lower editor shows the IR with just the copied-to
alloca being an array, the latter case vectorizes fine:
<a href="https://godbolt.org/z/r68hnehz9">https://godbolt.org/z/r68hnehz9</a>

Running both examples with `-sroa` instead of `-O3` reveals that in the two
array case SROA doesn't do anything to the allocas but for the second case,
SROA kicks in.

Obviously, for this simple case, I can avoid this by analyzing the source
alloca's usage before turning it into an array, but I'm wondering whether this
case might come up in standard C++ code as well and thus should be handled.
(and with a preliminary optimization from my side in-place it still seems there
are some memcpys left, which lead to not vectorizing the whole loop, which is
pretty bad)

Hope the problem description is exhaustive enough, if not please ask for
clarifications. I'm happy to contribute to the resolution of this problem, if
given hints :)</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>