From: Richard Biener Date: Fri, 22 Jan 2021 13:32:39 +0000 (+0100) Subject: middle-end/98793 - properly handle BLKmode vectors in vector_element_bits X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4be156d6bef317b8704052f11431457a577ed564;p=gcc.git middle-end/98793 - properly handle BLKmode vectors in vector_element_bits The previous change made AVX512 mask vectors correct but disregarded the possibility of generic (BLKmode) boolean vectors which are exposed by the frontends already. 2021-01-22 Richard Biener PR middle-end/98793 * tree.c (vector_element_bits): Key single-bit bool vector on integer mode rather than not vector mode. * gcc.dg/pr98793.c: New testcase. --- diff --git a/gcc/testsuite/gcc.dg/pr98793.c b/gcc/testsuite/gcc.dg/pr98793.c new file mode 100644 index 00000000000..bb1ae9cc7b1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr98793.c @@ -0,0 +1,38 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -Wno-psabi" } */ + +typedef unsigned char u8; +typedef unsigned char __attribute__((__vector_size__ (8))) v64u8; +typedef unsigned char __attribute__((__vector_size__ (64))) v512u8; +typedef unsigned long long u64; + +u64 gx; +v512u8 gu; +v512u8 gv; + +v64u8 __attribute__((__noipa__)) foo0 (u8 ax, v512u8 au, u64 ay) +{ + u8 lx = ax && (u8) ay; + v512u8 lc = 7 <= au; + v512u8 ld = (u8) (ay && gx) == gu; + v512u8 le = (v512u8) ld + (v512u8) gv; + v512u8 lf = le + lc; + return (((union + { + v512u8 a; + v64u8 b[8]; + }) lf).b[3]) + lx; +} + +int +main (void) +{ + v64u8 x = foo0 (2, (v512u8) { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15 + }, + 2); + for (unsigned i = 0; i < sizeof (x); i++) + if (x[i] != (i ? 0 : 0xff)) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree.c b/gcc/tree.c index 061fe43aa31..87862be9273 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -14028,11 +14028,11 @@ vector_element_bits (const_tree type) gcc_checking_assert (VECTOR_TYPE_P (type)); if (VECTOR_BOOLEAN_TYPE_P (type)) { - if (VECTOR_MODE_P (TYPE_MODE (type))) + if (SCALAR_INT_MODE_P (TYPE_MODE (type))) + return 1; + else return vector_element_size (tree_to_poly_uint64 (TYPE_SIZE (type)), TYPE_VECTOR_SUBPARTS (type)); - else - return 1; } return tree_to_uhwi (TYPE_SIZE (TREE_TYPE (type))); }