[llvm-bugs] [Bug 48844] New: Missed loop vectorization due to the presence of switch

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jan 22 06:25:46 PST 2021


https://bugs.llvm.org/show_bug.cgi?id=48844

            Bug ID: 48844
           Summary: Missed loop vectorization due to the presence of
                    switch
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: llvm-bugs at lists.llvm.org

#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).
https://godbolt.org/z/sY5oT9


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.
https://godbolt.org/z/jx4dqo



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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210122/b14acd8e/attachment.html>


More information about the llvm-bugs mailing list