<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 - [SLPVectorizer] Optimisations depend on whether LLVM was built with libstdc++ or libc++"
   href="https://bugs.llvm.org/show_bug.cgi?id=50409">50409</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[SLPVectorizer] Optimisations depend on whether LLVM was built with libstdc++ or libc++
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>12.0
          </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>Loop Optimizer
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>harald@gigawatt.nl
          </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=24876" name="attach_24876" title="SLPVectorizer diff between two clang 12.0.0 builds">attachment 24876</a> <a href="attachment.cgi?id=24876&action=edit" title="SLPVectorizer diff between two clang 12.0.0 builds">[details]</a></span>
SLPVectorizer diff between two clang 12.0.0 builds

For the following reduced test case, we get different results from
SLPVectorizer in LLVM 12 depending on whether LLVM was built with libstdc++ or
libc++:

  struct a {
    long long b[2];
  } c, d;
  a e();
  bool f();
  void g() {
    a ak, am(d), ar;
    while (f()) {
      a aq = e();
      if (am.b[0])
        aq = am;
      ak = aq;
    }
    ar = e();
    ar.b[0] &= ak.b[0];
    ar.b[1] &= ak.b[1];
    ar.b[0] &= 8;
    a as = ak;
    if (as.b[0])
      c = ar;
  }

When compiled with -O2 for x86, see the attached diff for how this results in
different code depending on LLVM was built with GCC+libstdc++ or with
clang+libc++. I saw this with clang 12.0.0 but it looks like this should still
be an issue on main as well. This was noticed back in 2017 and fixed
(presumably) but the fix got reverted and no new fix was installed in its
place.

Fix:

<a href="https://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20171120/504117.html">https://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20171120/504117.html</a>

Revert:

<a href="https://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20180101/514219.html">https://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20180101/514219.html</a>

Unfortunately communication seems to have gone badly on both sides there and
this issue just got completely forgotten about, meaning we have more
stable_sorts with bad comparison functions now than we did back then: D82444
added another one. This means even if we were to want to reapply the original
fix, it is no longer a complete fix.</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>