re PR middle-end/89544 (Argument marshalling incorrectly assumes stack slots are...
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Tue, 20 Aug 2019 05:32:49 +0000 (05:32 +0000)
committerBernd Edlinger <edlinger@gcc.gnu.org>
Tue, 20 Aug 2019 05:32:49 +0000 (05:32 +0000)
2019-08-20  Bernd Edlinger  <bernd.edlinger@hotmail.de>

        PR middle-end/89544
        * function.c (assign_parm_find_stack_rtl): Use larger alignment
        when possible.

testsuite:
2019-08-20  Bernd Edlinger  <bernd.edlinger@hotmail.de>

        PR middle-end/89544
        * gcc.target/arm/unaligned-argument-1.c: New test.
        * gcc.target/arm/unaligned-argument-2.c: New test.

From-SVN: r274691

gcc/ChangeLog
gcc/function.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/arm/unaligned-argument-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/arm/unaligned-argument-2.c [new file with mode: 0644]

index 895e5f12792cb0120bedb30905f46d908a52890a..e22140ff3ca4e3eaeb2ac5ba1b5f5460f94eef94 100644 (file)
@@ -1,3 +1,9 @@
+2019-08-20  Bernd Edlinger  <bernd.edlinger@hotmail.de>
+
+       PR middle-end/89544
+       * function.c (assign_parm_find_stack_rtl): Use larger alignment
+       when possible.
+
 2019-08-19  Joel Hutton  <Joel.Hutton@arm.com>
 
        * config/aarch64/aarch64-protos.h (aarch64_fpconst_pow2_recip): New prototype
index e368f7c013ea143408f391deaaef473a73f34446..f8019513928f855725d329f08be7727849baec43 100644 (file)
@@ -2697,8 +2697,23 @@ assign_parm_find_stack_rtl (tree parm, struct assign_parm_data_one *data)
      intentionally forcing upward padding.  Otherwise we have to come
      up with a guess at the alignment based on OFFSET_RTX.  */
   poly_int64 offset;
-  if (data->locate.where_pad != PAD_DOWNWARD || data->entry_parm)
+  if (data->locate.where_pad == PAD_NONE || data->entry_parm)
     align = boundary;
+  else if (data->locate.where_pad == PAD_UPWARD)
+    {
+      align = boundary;
+      /* If the argument offset is actually more aligned than the nominal
+        stack slot boundary, take advantage of that excess alignment.
+        Don't make any assumptions if STACK_POINTER_OFFSET is in use.  */
+      if (poly_int_rtx_p (offset_rtx, &offset)
+         && STACK_POINTER_OFFSET == 0)
+       {
+         unsigned int offset_align = known_alignment (offset) * BITS_PER_UNIT;
+         if (offset_align == 0 || offset_align > STACK_BOUNDARY)
+           offset_align = STACK_BOUNDARY;
+         align = MAX (align, offset_align);
+       }
+    }
   else if (poly_int_rtx_p (offset_rtx, &offset))
     {
       align = least_bit_hwi (boundary);
index 6f0bec89379eec92b016148a1c2fca42544b1be9..1aeccfd64b053bf717f422f621d68ee16ead13fd 100644 (file)
@@ -1,3 +1,9 @@
+2019-08-20  Bernd Edlinger  <bernd.edlinger@hotmail.de>
+
+       PR middle-end/89544
+       * gcc.target/arm/unaligned-argument-1.c: New test.
+       * gcc.target/arm/unaligned-argument-2.c: New test.
+
 2019-08-19  Joel Hutton  <Joel.Hutton@arm.com>
 
        * gcc.target/aarch64/fmul_scvtf_1.c: New test.
diff --git a/gcc/testsuite/gcc.target/arm/unaligned-argument-1.c b/gcc/testsuite/gcc.target/arm/unaligned-argument-1.c
new file mode 100644 (file)
index 0000000..805a3a7
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target arm_arm_ok } */
+/* { dg-require-effective-target arm_ldrd_strd_ok } */
+/* { dg-options "-marm -mno-unaligned-access -O3" } */
+
+struct s {
+  int a, b;
+} __attribute__((aligned(8)));
+
+struct s f0;
+
+void f(int a, int b, int c, int d, struct s f)
+{
+  f0 = f;
+}
+
+/* { dg-final { scan-assembler-times "ldrd" 1 } } */
+/* { dg-final { scan-assembler-times "strd" 1 } } */
+/* { dg-final { scan-assembler-times "stm" 0 } } */
diff --git a/gcc/testsuite/gcc.target/arm/unaligned-argument-2.c b/gcc/testsuite/gcc.target/arm/unaligned-argument-2.c
new file mode 100644 (file)
index 0000000..a35ce3a
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target arm_arm_ok } */
+/* { dg-require-effective-target arm_ldrd_strd_ok } */
+/* { dg-options "-marm -mno-unaligned-access -O3" } */
+
+struct s {
+  int a, b;
+} __attribute__((aligned(8)));
+
+struct s f0;
+
+void f(int a, int b, int c, int d, int e, struct s f)
+{
+  f0 = f;
+}
+
+/* { dg-final { scan-assembler-times "ldrd" 0 } } */
+/* { dg-final { scan-assembler-times "strd" 0 } } */
+/* { dg-final { scan-assembler-times "stm" 1 } } */