--- /dev/null
+/* { dg-do run } */
+
+/* Make sure a bit-field store of 0 cause the whole assignment become 0. */
+
+struct s1
+{
+ unsigned char c:1;
+ unsigned char d:7;
+};
+
+__attribute__((noinline))
+struct s1 f(struct s1 a)
+{
+ a.c = 0;
+ struct s1 t = a;
+ return t;
+}
+
+int main()
+{
+ struct s1 a = {1, 2};
+ struct s1 b = f(a);
+ if (b.c != 0)
+ __builtin_abort();
+ if (b.d != 2)
+ __builtin_abort();
+ return 0;
+}
--- /dev/null
+/* { dg-do run } */
+
+/* Make sure a bit-field store of 0 cause the whole assignment become 0. */
+
+struct s1
+{
+ unsigned char d:7;
+ unsigned char c:1;
+};
+
+__attribute__((noinline))
+struct s1 f(struct s1 a)
+{
+ a.c = 0;
+ struct s1 t = a;
+ return t;
+}
+
+int main()
+{
+ struct s1 a = {2, 1};
+ struct s1 b = f(a);
+ if (b.c != 0)
+ __builtin_abort();
+ if (b.d != 2)
+ __builtin_abort();
+ return 0;
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O1 -fno-tree-sra -fdump-tree-optimized -fdump-tree-forwprop1-details" } */
+
+extern void link_error (void);
+
+/* Check for copyprop on structs with zeroing. */
+#define vector16 __attribute__((vector_size(64)))
+
+struct g
+{
+ vector16 unsigned char t;
+};
+
+struct g f(void)
+{
+ struct g temp_struct1 ;
+ temp_struct1.t = (vector16 unsigned char){};
+ struct g temp_struct2 = temp_struct1;
+ struct g temp_struct3 = temp_struct2;
+ struct g temp_struct4 = temp_struct3;
+ return temp_struct4;
+}
+
+/* There should be no references to any of "temp_struct*"
+ temporaries. */
+/* { dg-final { scan-tree-dump-times "temp_struct" 0 "optimized" } } */
+/* Also check that forwprop pass did the copy prop. */
+/* { dg-final { scan-tree-dump-times "after previous" 4 "forwprop1" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O1 -fno-tree-sra -fdump-tree-optimized -fdump-tree-forwprop1-details" } */
+
+extern void link_error (void);
+
+struct g
+{
+ unsigned int t;
+};
+
+struct g f(void)
+{
+ struct g temp_struct1 ;
+ temp_struct1.t = 0;
+ struct g temp_struct2 = temp_struct1;
+ struct g temp_struct3 = temp_struct2;
+ struct g temp_struct4 = temp_struct3;
+ return temp_struct4;
+}
+
+/* There should be no references to any of "temp_struct*"
+ temporaries. */
+/* { dg-final { scan-tree-dump-times "temp_struct" 0 "optimized" } } */
+/* Also check that forwprop pass did the copy prop. */
+/* { dg-final { scan-tree-dump-times "after previous" 4 "forwprop1" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O1 -fno-tree-sra -fdump-tree-optimized -fdump-tree-forwprop1-details" } */
+
+extern void link_error (void);
+
+struct g
+{
+ _Complex unsigned int t;
+};
+
+struct g f(void)
+{
+ struct g temp_struct1 ;
+ temp_struct1.t = 0;
+ struct g temp_struct2 = temp_struct1;
+ struct g temp_struct3 = temp_struct2;
+ struct g temp_struct4 = temp_struct3;
+ return temp_struct4;
+}
+
+/* There should be no references to any of "temp_struct*"
+ temporaries. */
+/* { dg-final { scan-tree-dump-times "temp_struct" 0 "optimized" } } */
+/* Also check that forwprop pass did the copy prop. */
+/* { dg-final { scan-tree-dump-times "after previous" 4 "forwprop1" } } */
}
}
}
+ /* A store of integer (scalar, vector or complex) zeros is
+ a zero store. */
+ else if (gimple_store_p (stmt)
+ && gimple_assign_single_p (stmt)
+ && integer_zerop (gimple_assign_rhs1 (stmt)))
+ {
+ tree rhs = gimple_assign_rhs1 (stmt);
+ tree type = TREE_TYPE (rhs);
+ dest = gimple_assign_lhs (stmt);
+ ao_ref_init (&read, dest);
+ /* For integral types, the type precision needs to be a multiply of BITS_PER_UNIT. */
+ if (INTEGRAL_TYPE_P (type)
+ && (TYPE_PRECISION (type) % BITS_PER_UNIT) != 0)
+ dest = NULL_TREE;
+ }
else if (gimple_store_p (stmt)
&& gimple_assign_single_p (stmt)
&& TREE_CODE (gimple_assign_rhs1 (stmt)) == CONSTRUCTOR