The following restricts the allowed conversions to those maintaining
the element type size.
PR tree-optimization/123537
* match.pd (REDUC (@0 & @1) -> @0[I] & @1[I]): Restrict
allowed conversions.
* gcc.dg/pr123537.c: New testcase.
unsigned int elt_bits = tree_to_uhwi (TYPE_SIZE (elt_type));
tree size = bitsize_int (elt_bits);
tree pos = bitsize_int (elt_bits * i); }
- (view_convert
- (bit_and:elt_type
- (BIT_FIELD_REF:elt_type @0 { size; } { pos; })
- { elt; })))))))
+ (if (compare_tree_int (TYPE_SIZE (type), elt_bits) == 0)
+ (view_convert
+ (bit_and:elt_type
+ (BIT_FIELD_REF:elt_type @0 { size; } { pos; })
+ { elt; }))))))))
/* Fold reduction of a single nonzero element constructor. */
(for reduc (IFN_REDUC_PLUS IFN_REDUC_IOR IFN_REDUC_XOR)
--- /dev/null
+/* { dg-do compile } */
+/* { dg-require-effective-target int128 } */
+/* { dg-options "-O2" } */
+
+typedef __attribute__((__vector_size__(16))) __int128 V;
+
+union {
+ _Complex long c;
+ V v;
+} u;
+
+__int128 j;
+int i;
+
+void
+foo()
+{
+ u.v &= 4;
+ i %= u.c ? 3 : j;
+}