return equal;
}
+/* Return the single non-zero element of a CONSTRUCTOR or NULL_TREE. */
+tree
+ctor_single_nonzero_element (const_tree t)
+{
+ unsigned HOST_WIDE_INT idx;
+ constructor_elt *ce;
+ tree elt = NULL_TREE;
+
+ if (TREE_CODE (t) != CONSTRUCTOR)
+ return NULL_TREE;
+ for (idx = 0; vec_safe_iterate (CONSTRUCTOR_ELTS (t), idx, &ce); idx++)
+ if (!integer_zerop (ce->value) && !real_zerop (ce->value))
+ {
+ if (elt)
+ return NULL_TREE;
+ elt = ce->value;
+ }
+ return elt;
+}
+
#if CHECKING_P
namespace selftest {
extern wide_int tree_nonzero_bits (const_tree);
extern int address_compare (tree_code, tree, tree, tree, tree &, tree &,
poly_int64 &, poly_int64 &, bool);
+extern tree ctor_single_nonzero_element (const_tree);
/* Return OFF converted to a pointer offset type suitable as offset for
POINTER_PLUS_EXPR. Use location LOC for this conversion. */
(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)
+ (simplify (reduc (CONSTRUCTOR@0))
+ (with { tree ctor = (TREE_CODE (@0) == SSA_NAME
+ ? gimple_assign_rhs1 (SSA_NAME_DEF_STMT (@0)) : @0);
+ tree elt = ctor_single_nonzero_element (ctor); }
+ (if (elt
+ && !HONOR_SNANS (type)
+ && !HONOR_SIGNED_ZEROS (type))
+ { elt; }))))
+
+/* Fold REDUC (@0 op VECTOR_CST) as REDUC (@0) op REDUC (VECTOR_CST). */
+(for reduc (IFN_REDUC_PLUS IFN_REDUC_MAX IFN_REDUC_MIN IFN_REDUC_FMAX
+ IFN_REDUC_FMIN IFN_REDUC_AND IFN_REDUC_IOR IFN_REDUC_XOR)
+ op (plus max min IFN_FMAX IFN_FMIN bit_and bit_ior bit_xor)
+ (simplify (reduc (op @0 VECTOR_CST@1))
+ (op (reduc:type @0) (reduc:type @1))))
+
(simplify
(vec_perm @0 @1 VECTOR_CST@2)
(with
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -ffast-math -fdump-tree-optimized" } */
+float foo (float x)
+{
+ int i;
+ float j;
+ float a = 0;
+ for (i = 0; i < 4; ++i)
+ {
+ for (j = 0; j < 4; ++j)
+ {
+ a += 1;
+ x += a;
+ }
+ }
+ return x;
+}
+
+/* { dg-final { scan-tree-dump-not "REDUC_PLUS" "optimized"} } */