<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 - Missed loop vectorization due to the presence of switch"
   href="https://bugs.llvm.org/show_bug.cgi?id=48844">48844</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missed loop vectorization due to the presence of switch
          </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>Loop Optimizer
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>david.bolvansky@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>#include <algorithm>
#include <vector>
#include <cstdint>

void replace_if_epi8(std::vector<int8_t>& v) {
    std::replace_if(v.begin(), v.end(), [](int8_t x){return x == 13 || x ==
-12; }, 42);
}

void replace_if_epi32(std::vector<int32_t>& v) {
    std::replace_if(v.begin(), v.end(), [](int8_t x){return x == 13 || x ==
-12; }, 42);
}



LLVM fails to vectorize this code - possibly due to presence of switch (OR cond
is converted to switch).
<a href="https://godbolt.org/z/sY5oT9">https://godbolt.org/z/sY5oT9</a>


Second example:
void replace_if_epi8(std::vector<int8_t>& v) {
    std::replace_if(v.begin(), v.end(), [](int8_t x){return x == 13 ; }, 42);
}

void replace_if_epi32(std::vector<int32_t>& v) {
    std::replace_if(v.begin(), v.end(), [](int8_t x){return x == 13; }, 42);
}


This code is nicely vectorized by LLVM.
<a href="https://godbolt.org/z/jx4dqo">https://godbolt.org/z/jx4dqo</a>



So either simplifycfg should not create switches before vectorizers (easy fix,
maybe profitable for other optimizations too?), and/or vectorizers should know
how to handle them.</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>