From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 18724385842F; Fri, 18 Feb 2022 10:06:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 18724385842F From: "linkw at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/104595] New: unvectorized loop due to bool condition loaded from memory Date: Fri, 18 Feb 2022 10:05:59 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: linkw at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Feb 2022 10:06:00 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104595 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 =3D 0; i < N; i++) c[i] =3D pb[i] ? a[i] : b[i]; } void predicate_by_char() { for (int i =3D 0; i < N; i++) c[i] =3D pc[i] ? a[i] : b[i]; } Simply compiled with -Ofast -mcpu=3Dpower10, vectorizer can vectorize the 2= nd 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?=