https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115520

            Bug ID: 115520
           Summary: Loop vectorization depends on variable names
           Product: gcc
           Version: 14.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: max.sagebaum at scicomp dot uni-kl.de
  Target Milestone: ---

Created attachment 58447
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58447&action=edit
Reproducer

I asked this question on gcc-help and got the reply that this is probably a
bug.
(https://gcc.gnu.org/pipermail/gcc-help/2024-June/143496.html)

Compiler options: -O3 -std=c++20 -fopt-info-vec-missed
Version: 14.1 (Compiler Explorer)
Reproducer on Compiler Explorer: https://godbolt.org/z/YEPzfx3eT

With the above options this loop vectorizes:
```
struct match_return {
  char* pos;
  bool matched;
};

bool func_is_vectorized (char*& cur, context& ctx)  {

    match_return r {cur, true};
    constexpr char str1[] =
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    if (!(std::distance(r.pos, ctx.end) < 50)) {return false;}

    for(int i = 0; i < 50; i += 1) {
        if (str1[i] != r.pos[i]) { r.matched = false; }
    }
    if (r.matched) {
        r.pos += 50;
    }
    return r.matched;

}
```

If I remove the match_return structure, then the loop no longer vectorizes. The
message is: 
not vectorized: relevant phi not supported: matched_21 = PHI <_20(6),
1(5)>

The "new" code is:
```
bool func_is_also_not_vectorized (char*& cur, context& ctx)  {

    bool matched = true;
    constexpr char str1[] =
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    if (!(std::distance(cur, ctx.end) < 50)) {return false;}

    for(int i = 0; i < 50; i += 1) {
        if (str1[i] != cur[i]) { matched = false; }
    }
    if (matched) {
        cur += 50;
    }
    return matched; 
}
```

The interesting part is. If I only replace `r.matched` with `matched`
and introduce the proper variable. The vectorizer is already failing.

Reply via email to