public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/104595] New: unvectorized loop due to bool condition loaded from memory
@ 2022-02-18 10:05 linkw at gcc dot gnu.org
  2022-02-18 10:27 ` [Bug tree-optimization/104595] " rguenth at gcc dot gnu.org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: linkw at gcc dot gnu.org @ 2022-02-18 10:05 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104595
           Summary: unvectorized loop due to bool condition loaded from
                    memory
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: linkw at gcc dot gnu.org
  Target Milestone: ---

For the case:

#include "stdbool.h"
#define N 256
typedef char T;
extern T a[N];
extern T b[N];
extern T c[N];
extern bool pb[N];
extern char pc[N];

void predicate_by_bool() {
  for (int i = 0; i < N; i++)
    c[i] = pb[i] ? a[i] : b[i];
}

void predicate_by_char() {
  for (int i = 0; i < N; i++)
    c[i] = pc[i] ? a[i] : b[i];
}

Simply compiled with -Ofast -mcpu=power10, vectorizer can vectorize the 2nd
function predicate_by_char but can't vectorize the first. It seems currently
GCC just supports very limited case with bool types such as some patterns in
vect_recog_bool_pattern.

I guess here the size of bool seems to be a problem, for the size of bool, C
says "An object declared as type _Bool is large enough to store the values 0
and 1.", C++ says "The value of sizeof(bool) is implementation defined and
might differ from 1.". But the "implementation defined" looks to be compiler
defined? then compiler should be aware of it when compiling. If so, we can use
the equivalent size type for the load instead and make it compare with zero to
get the predicate just like the char variant, I think the expectation to see
both these loops vectorized is reasonable then?

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

end of thread, other threads:[~2022-05-05  8:39 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-18 10:05 [Bug tree-optimization/104595] New: unvectorized loop due to bool condition loaded from memory linkw at gcc dot gnu.org
2022-02-18 10:27 ` [Bug tree-optimization/104595] " rguenth at gcc dot gnu.org
2022-02-18 16:26 ` segher at gcc dot gnu.org
2022-02-20  3:52 ` pinskia at gcc dot gnu.org
2022-02-20  3:58 ` pinskia at gcc dot gnu.org
2022-02-21  7:54 ` rguenth at gcc dot gnu.org
2022-02-21 10:01 ` rguenth at gcc dot gnu.org
2022-02-21 13:26 ` rguenth at gcc dot gnu.org
2022-02-21 13:45 ` rguenth at gcc dot gnu.org
2022-02-23  7:18 ` linkw at gcc dot gnu.org
2022-02-23  7:41 ` rguenther at suse dot de
2022-02-23  8:55 ` linkw at gcc dot gnu.org
2022-05-05  8:37 ` cvs-commit at gcc dot gnu.org
2022-05-05  8:39 ` 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).