middle-end/112740 - vector boolean CTOR expansion issue

The optimization to expand uniform boolean vectors by sign-extension
works only for dense masks but it failed to check that.

	PR middle-end/112740
	* expr.cc (store_constructor): Check the integer vector
	mask has a single bit per element before using sign-extension
	to expand an uniform vector.

	* gcc.dg/pr112740.c: New testcase.
This commit is contained in:
Richard Biener 2024-01-10 14:54:10 +01:00
parent 1a51886a79
commit e1f2d58a1e
2 changed files with 24 additions and 3 deletions

View file

@ -7841,10 +7841,12 @@ store_constructor (tree exp, rtx target, int cleared, poly_int64 size,
break;
}
/* Use sign-extension for uniform boolean vectors with
integer modes. Effectively "vec_duplicate" for bitmasks. */
if (!TREE_SIDE_EFFECTS (exp)
integer modes and single-bit mask entries.
Effectively "vec_duplicate" for bitmasks. */
if (elt_size == 1
&& !TREE_SIDE_EFFECTS (exp)
&& VECTOR_BOOLEAN_TYPE_P (type)
&& SCALAR_INT_MODE_P (mode)
&& SCALAR_INT_MODE_P (TYPE_MODE (type))
&& (elt = uniform_vector_p (exp))
&& !VECTOR_TYPE_P (TREE_TYPE (elt)))
{

View file

@ -0,0 +1,19 @@
/* { dg-do run { target { int128 } } } */
/* { dg-options "" } */
typedef unsigned __int128 __attribute__((__vector_size__ (16))) V;
V
foo (unsigned c, V v)
{
return (V) (c <= v) == 0;
}
int
main (void)
{
V x = foo (0, (V) { });
if (x[0])
__builtin_abort ();
return 0;
}