/* Handle calls that pass values in multiple non-contiguous
locations. The Irix 6 ABI has examples of this. */
if (target == 0 || ! safe_from_p (target, exp, 1)
- || GET_CODE (target) == PARALLEL || modifier == EXPAND_STACK_PARM)
+ || GET_CODE (target) == PARALLEL || modifier == EXPAND_STACK_PARM
+ /* Also make a temporary if the store is to volatile memory, to
+ avoid individual accesses to aggregate members. */
+ || (GET_CODE (target) == MEM && MEM_VOLATILE_P (target)))
{
if (avoid_temp_mem)
return NULL_RTX;
--- /dev/null
+/* { dg-do compile } */
+/* { dg-require-effective-target size32plus } */
+/* { dg-options "-fdump-rtl-final -O2" } */
+
+/* Assignments to a whole struct of suitable size (32 bytes) must not be
+ picked apart into field accesses. */
+
+typedef struct {
+ unsigned int f0 : 4;
+ unsigned int f1 : 11;
+ unsigned int f2 : 10;
+ unsigned int f3 : 7;
+} t0;
+
+static t0 a0[] = {
+ { .f0 = 7, .f1 = 99, .f3 = 1, },
+ { .f0 = 7, .f1 = 251, .f3 = 1, },
+ { .f0 = 8, .f1 = 127, .f3 = 5, },
+ { .f0 = 5, .f1 = 1, .f3 = 1, },
+ { .f0 = 5, .f1 = 1, .f3 = 1, },
+ { .f0 = 5, .f1 = 1, .f3 = 1, },
+};
+
+void
+foo(void)
+{
+ __SIZE_TYPE__ i;
+ __SIZE_TYPE__ base = 0x000a0000;
+ for (i = 0; i < (sizeof (a0) / sizeof ((a0)[0])); i++) {
+ *(volatile t0 *) (base + 44 + i * 4) = a0[i];
+ }
+}
+
+/* The only volatile accesses should be the obvious writes. */
+/* { dg-final { scan-rtl-dump-times {\(mem/v} 6 "final" } } */
+/* { dg-final { scan-rtl-dump-times {\(set \(mem/v} 6 "final" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-require-effective-target size32plus } */
+/* { dg-options "-fdump-rtl-final -O2" } */
+
+/* Unrolled version of pr94600-1.c. */
+
+typedef struct {
+ unsigned int f0 : 4;
+ unsigned int f1 : 11;
+ unsigned int f2 : 10;
+ unsigned int f3 : 7;
+} t0;
+
+void
+bar(void)
+{
+ t0 a00 = { .f0 = 7, .f1 = 99, .f3 = 1, };
+ t0 a01 = { .f0 = 7, .f1 = 251, .f3 = 1, };
+ t0 a02 = { .f0 = 8, .f1 = 127, .f3 = 5, };
+ t0 a03 = { .f0 = 5, .f1 = 1, .f3 = 1, };
+ t0 a04 = { .f0 = 5, .f1 = 1, .f3 = 1, };
+ t0 a05 = { .f0 = 5, .f1 = 1, .f3 = 1, };
+ __SIZE_TYPE__ base = 0x000a0000;
+
+ *(volatile t0 *) ((base) + 44 + (0) * 4) = a00;
+ *(volatile t0 *) ((base) + 44 + (1) * 4) = a01;
+ *(volatile t0 *) ((base) + 44 + (2) * 4) = a02;
+ *(volatile t0 *) ((base) + 44 + (3) * 4) = a03;
+ *(volatile t0 *) ((base) + 44 + (4) * 4) = a04;
+ *(volatile t0 *) ((base) + 44 + (5) * 4) = a05;
+}
+
+/* { dg-final { scan-rtl-dump-times {\(mem/v} 6 "final" } } */
+/* { dg-final { scan-rtl-dump-times {\(set \(mem/v} 6 "final" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-require-effective-target size32plus } */
+/* { dg-options "-fdump-rtl-final -O2 -fno-unroll-loops" } */
+
+/* Same-address version of pr94600-1.c. */
+
+typedef struct {
+ unsigned int f0 : 4;
+ unsigned int f1 : 11;
+ unsigned int f2 : 10;
+ unsigned int f3 : 7;
+} t0;
+
+static t0 a0[] = {
+ { .f0 = 7, .f1 = 99, .f3 = 1, },
+ { .f0 = 7, .f1 = 251, .f3 = 1, },
+ { .f0 = 8, .f1 = 127, .f3 = 5, },
+ { .f0 = 5, .f1 = 1, .f3 = 1, },
+ { .f0 = 5, .f1 = 1, .f3 = 1, },
+ { .f0 = 5, .f1 = 1, .f3 = 1, },
+};
+
+void
+foo(void)
+{
+ __SIZE_TYPE__ i;
+ __SIZE_TYPE__ base = 0x000a0000;
+ for (i = 0; i < (sizeof (a0) / sizeof ((a0)[0])); i++) {
+ *(volatile t0 *) (base + 44) = a0[i];
+ }
+}
+
+/* The loop isn't unrolled. */
+/* { dg-final { scan-rtl-dump-times {\(mem/v} 1 "final" } } */
+/* { dg-final { scan-rtl-dump-times {\(set \(mem/v} 1 "final" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-require-effective-target size32plus } */
+/* { dg-options "-fdump-rtl-final -O2" } */
+
+/* Unrolled version of pr94600-2.c. */
+
+typedef struct {
+ unsigned int f0 : 4;
+ unsigned int f1 : 11;
+ unsigned int f2 : 10;
+ unsigned int f3 : 7;
+} t0;
+
+void
+bar(void)
+{
+ t0 a00 = { .f0 = 7, .f1 = 99, .f3 = 1, };
+ t0 a01 = { .f0 = 7, .f1 = 251, .f3 = 1, };
+ t0 a02 = { .f0 = 8, .f1 = 127, .f3 = 5, };
+ t0 a03 = { .f0 = 5, .f1 = 1, .f3 = 1, };
+ t0 a04 = { .f0 = 5, .f1 = 1, .f3 = 1, };
+ t0 a05 = { .f0 = 5, .f1 = 1, .f3 = 1, };
+ __SIZE_TYPE__ base = 0x000a0000;
+
+ *(volatile t0 *) ((base) + 44) = a00;
+ *(volatile t0 *) ((base) + 44) = a01;
+ *(volatile t0 *) ((base) + 44) = a02;
+ *(volatile t0 *) ((base) + 44) = a03;
+ *(volatile t0 *) ((base) + 44) = a04;
+ *(volatile t0 *) ((base) + 44) = a05;
+}
+
+/* { dg-final { scan-rtl-dump-times {\(mem/v} 6 "final" } } */
+/* { dg-final { scan-rtl-dump-times {\(set \(mem/v} 6 "final" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-require-effective-target size32plus } */
+/* { dg-options "-fdump-rtl-final -O2 -fno-unroll-loops" } */
+
+/* Target-as-parameter version of pr94600-1.c. */
+
+typedef struct {
+ unsigned int f0 : 4;
+ unsigned int f1 : 11;
+ unsigned int f2 : 10;
+ unsigned int f3 : 7;
+} t0;
+
+static t0 a0[] = {
+ { .f0 = 7, .f1 = 99, .f3 = 1, },
+ { .f0 = 7, .f1 = 251, .f3 = 1, },
+ { .f0 = 8, .f1 = 127, .f3 = 5, },
+ { .f0 = 5, .f1 = 1, .f3 = 1, },
+ { .f0 = 5, .f1 = 1, .f3 = 1, },
+ { .f0 = 5, .f1 = 1, .f3 = 1, },
+};
+
+void
+foo(volatile t0 *b)
+{
+ __SIZE_TYPE__ i;
+ for (i = 0; i < (sizeof (a0) / sizeof ((a0)[0])); i++) {
+ b[i+11] = a0[i];
+ }
+}
+
+/* The loop isn't unrolled. */
+/* { dg-final { scan-rtl-dump-times {\(mem/v} 1 "final" } } */
+/* { dg-final { scan-rtl-dump-times {\(set \(mem/v} 1 "final" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-require-effective-target size32plus } */
+/* { dg-options "-fdump-rtl-final -O2" } */
+
+/* Target-as-parameter version of pr94600-2.c. */
+
+typedef struct {
+ unsigned int f0 : 4;
+ unsigned int f1 : 11;
+ unsigned int f2 : 10;
+ unsigned int f3 : 7;
+} t0;
+
+void
+bar(volatile t0 *b)
+{
+ t0 a00 = { .f0 = 7, .f1 = 99, .f3 = 1, };
+ t0 a01 = { .f0 = 7, .f1 = 251, .f3 = 1, };
+ t0 a02 = { .f0 = 8, .f1 = 127, .f3 = 5, };
+ t0 a03 = { .f0 = 5, .f1 = 1, .f3 = 1, };
+ t0 a04 = { .f0 = 5, .f1 = 1, .f3 = 1, };
+ t0 a05 = { .f0 = 5, .f1 = 1, .f3 = 1, };
+
+ b[11+0] = a00;
+ b[11+1] = a01;
+ b[11+2] = a02;
+ b[11+3] = a03;
+ b[11+4] = a04;
+ b[11+5] = a05;
+}
+
+/* { dg-final { scan-rtl-dump-times {\(mem/v} 6 "final" } } */
+/* { dg-final { scan-rtl-dump-times {\(set \(mem/v} 6 "final" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-require-effective-target size32plus } */
+/* { dg-options "-fdump-rtl-final -O2 -fno-unroll-loops" } */
+
+/* Target-as-parameter version of pr94600-3.c. */
+
+typedef struct {
+ unsigned int f0 : 4;
+ unsigned int f1 : 11;
+ unsigned int f2 : 10;
+ unsigned int f3 : 7;
+} t0;
+
+static t0 a0[] = {
+ { .f0 = 7, .f1 = 99, .f3 = 1, },
+ { .f0 = 7, .f1 = 251, .f3 = 1, },
+ { .f0 = 8, .f1 = 127, .f3 = 5, },
+ { .f0 = 5, .f1 = 1, .f3 = 1, },
+ { .f0 = 5, .f1 = 1, .f3 = 1, },
+ { .f0 = 5, .f1 = 1, .f3 = 1, },
+};
+
+void
+foo(volatile t0 *b)
+{
+ __SIZE_TYPE__ i;
+ for (i = 0; i < (sizeof (a0) / sizeof ((a0)[0])); i++) {
+ b[11] = a0[i];
+ }
+}
+
+/* { dg-final { scan-rtl-dump-times {\(mem/v} 1 "final" } } */
+/* { dg-final { scan-rtl-dump-times {\(set \(mem/v} 1 "final" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-require-effective-target size32plus } */
+/* { dg-options "-fdump-rtl-final -O2" } */
+
+/* Unrolled version of pr94600-2.c. */
+
+typedef struct {
+ unsigned int f0 : 4;
+ unsigned int f1 : 11;
+ unsigned int f2 : 10;
+ unsigned int f3 : 7;
+} t0;
+
+void
+bar(volatile t0 *b)
+{
+ t0 a00 = { .f0 = 7, .f1 = 99, .f3 = 1, };
+ t0 a01 = { .f0 = 7, .f1 = 251, .f3 = 1, };
+ t0 a02 = { .f0 = 8, .f1 = 127, .f3 = 5, };
+ t0 a03 = { .f0 = 5, .f1 = 1, .f3 = 1, };
+ t0 a04 = { .f0 = 5, .f1 = 1, .f3 = 1, };
+ t0 a05 = { .f0 = 5, .f1 = 1, .f3 = 1, };
+
+ b[11] = a00;
+ b[11] = a01;
+ b[11] = a02;
+ b[11] = a03;
+ b[11] = a04;
+ b[11] = a05;
+}
+
+/* { dg-final { scan-rtl-dump-times {\(mem/v} 6 "final" } } */
+/* { dg-final { scan-rtl-dump-times {\(set \(mem/v} 6 "final" } } */