<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 - SIMD Misoptimization during "Promote 'by reference' arguments to scalars on SCC""
   href="https://bugs.llvm.org/show_bug.cgi?id=37358">37358</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>SIMD Misoptimization during "Promote 'by reference' arguments to scalars on SCC"
          </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>Windows NT
          </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>alex@crichton.co
          </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=20270" name="attach_20270" title="failing IR">attachment 20270</a> <a href="attachment.cgi?id=20270&action=edit" title="failing IR">[details]</a></span>
failing IR

We've got an upstream bug in rust-lang/rust at
<a href="https://github.com/rust-lang/rust/issues/50154">https://github.com/rust-lang/rust/issues/50154</a> where LLVM at opt-level=3 is
mis-optimizing promotion of an argument passed by reference to pass-by-value.
The attached IR exhibits the difference by looking at:


    $ opt -O2 tmp.ll -S | grep '^define.*m256'
    define internal fastcc void @_mm256_cmpgt_epi16(<4 x i64>* nocapture, <4 x
i64>* nocapture readonly %a, <4 x i64>* nocapture readonly %b) unnamed_addr #2
{
    $ opt -O3 tmp.ll -S | grep '^define.*m256'
    define internal fastcc void @_mm256_cmpgt_epi16(<4 x i64>* nocapture, <4 x
i64> %a.val, <4 x i64> %b.val) unnamed_addr #2 {



Note that at opt-level=2 the two arguments to this function continue to be
passed by reference, but at opt-level=3 they're promoted to being passed by
value. In this situation the target function, `_mm256_cmpgt_epi16`, has the
"avx2" feature enabled. The caller, `baseline`, does not have any extra target
features enabled (aka doesn't have "avx2" available). This means that if
attempting to pass by value this'll be an ABI mismatch at codegen time,
producing invalid results on optimized IR.

Using opt-bisect-limit I found that this happens during the "Promote 'by
reference' arguments to scalars on SCC" pass. Are we correct in thinking that
this optimization shouldn't happen? Or is this a valid optimization that we'll
need to work around on rustc's end?</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>