public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/115520] New: Loop vectorization depends on variable names
@ 2024-06-17 11:24 max.sagebaum at scicomp dot uni-kl.de
  2024-06-17 15:25 ` [Bug tree-optimization/115520] Loop vectorization fails when bool variable instead of unsigned char pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: max.sagebaum at scicomp dot uni-kl.de @ 2024-06-17 11:24 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/115520] Loop vectorization fails when bool variable instead of unsigned char
  2024-06-17 11:24 [Bug c++/115520] New: Loop vectorization depends on variable names max.sagebaum at scicomp dot uni-kl.de
@ 2024-06-17 15:25 ` pinskia at gcc dot gnu.org
  2024-06-17 15:26 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-17 15:25 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Loop vectorization fails    |Loop vectorization fails
                   |when not using a struct     |when bool variable instead
                   |sometimes                   |of unsigned char
                 CC|                            |pinskia at gcc dot gnu.org

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I have seen this one recorded too.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/115520] Loop vectorization fails when bool variable instead of unsigned char
  2024-06-17 11:24 [Bug c++/115520] New: Loop vectorization depends on variable names max.sagebaum at scicomp dot uni-kl.de
  2024-06-17 15:25 ` [Bug tree-optimization/115520] Loop vectorization fails when bool variable instead of unsigned char pinskia at gcc dot gnu.org
@ 2024-06-17 15:26 ` pinskia at gcc dot gnu.org
  2024-06-17 18:19 ` max.sagebaum at scicomp dot uni-kl.de
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-17 15:26 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-06-17
           Severity|normal                      |enhancement
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note the reason why the struct case works is due to SRA "changing" bool type to
unsigned char.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/115520] Loop vectorization fails when bool variable instead of unsigned char
  2024-06-17 11:24 [Bug c++/115520] New: Loop vectorization depends on variable names max.sagebaum at scicomp dot uni-kl.de
  2024-06-17 15:25 ` [Bug tree-optimization/115520] Loop vectorization fails when bool variable instead of unsigned char pinskia at gcc dot gnu.org
  2024-06-17 15:26 ` pinskia at gcc dot gnu.org
@ 2024-06-17 18:19 ` max.sagebaum at scicomp dot uni-kl.de
  2024-06-17 18:26 ` pinskia at gcc dot gnu.org
  2024-06-18  6:25 ` rguenth at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: max.sagebaum at scicomp dot uni-kl.de @ 2024-06-17 18:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Max S. <max.sagebaum at scicomp dot uni-kl.de> ---
Ok, thanks for the hint with SRA. Know I know how to actually program it. 

I think the main problem is the warning/error message:
> not vectorized: relevant phi not supported: matched_21 = PHI <_20(6), 1(5)>

Is there some way to improve this?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/115520] Loop vectorization fails when bool variable instead of unsigned char
  2024-06-17 11:24 [Bug c++/115520] New: Loop vectorization depends on variable names max.sagebaum at scicomp dot uni-kl.de
                   ` (2 preceding siblings ...)
  2024-06-17 18:19 ` max.sagebaum at scicomp dot uni-kl.de
@ 2024-06-17 18:26 ` pinskia at gcc dot gnu.org
  2024-06-18  6:25 ` rguenth at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-17 18:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Max S. from comment #3)
> Ok, thanks for the hint with SRA. Know I know how to actually program it. 
> 
> I think the main problem is the warning/error message:
> > not vectorized: relevant phi not supported: matched_21 = PHI <_20(6), 1(5)>
> 
> Is there some way to improve this?

See PR 101639 which I think this is basically a dup of really.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/115520] Loop vectorization fails when bool variable instead of unsigned char
  2024-06-17 11:24 [Bug c++/115520] New: Loop vectorization depends on variable names max.sagebaum at scicomp dot uni-kl.de
                   ` (3 preceding siblings ...)
  2024-06-17 18:26 ` pinskia at gcc dot gnu.org
@ 2024-06-18  6:25 ` rguenth at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-06-18  6:25 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|NEW                         |RESOLVED

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
It's a dup.

*** This bug has been marked as a duplicate of bug 101639 ***

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-06-18  6:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-17 11:24 [Bug c++/115520] New: Loop vectorization depends on variable names max.sagebaum at scicomp dot uni-kl.de
2024-06-17 15:25 ` [Bug tree-optimization/115520] Loop vectorization fails when bool variable instead of unsigned char pinskia at gcc dot gnu.org
2024-06-17 15:26 ` pinskia at gcc dot gnu.org
2024-06-17 18:19 ` max.sagebaum at scicomp dot uni-kl.de
2024-06-17 18:26 ` pinskia at gcc dot gnu.org
2024-06-18  6:25 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).