public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCHv2] Fix not 8-byte aligned ldrd/strd on ARMv5 (PR 89544)
@ 2019-03-10 12:51 Bernd Edlinger
  2019-03-19 14:01 ` [PING] " Bernd Edlinger
  2019-03-21 11:26 ` Richard Biener
  0 siblings, 2 replies; 50+ messages in thread
From: Bernd Edlinger @ 2019-03-10 12:51 UTC (permalink / raw)
  To: gcc-patches, Richard Biener, Richard Earnshaw,
	Ramana Radhakrishnan, Kyrill Tkachov, Eric Botcazou

[-- Attachment #1: Type: text/plain, Size: 1583 bytes --]

Hi,

This patch is an update to the previous patch, which takes into account that
the middle-end is not supposed to use the unaligned DI value directly which
was passed in an unaligned stack slot due to the AAPCS parameter passing rules.

The patch works by changing use_register_for_decl to return false if the
incoming RTL is not sufficiently aligned on a STRICT_ALIGNMENT target,
as if the address of the parameter was taken (which is TREE_ADDRESSABLE).
So not taking the address of the parameter is a necessary condition
for the wrong-code in PR 89544.

It works together with this check in assign_parm_adjust_stack_rtl:
  /* If we can't trust the parm stack slot to be aligned enough for its
     ultimate type, don't use that slot after entry.  We'll make another
     stack slot, if we need one.  */
  if (stack_parm
      && ((STRICT_ALIGNMENT
           && GET_MODE_ALIGNMENT (data->nominal_mode) > MEM_ALIGN (stack_parm))
...
    stack_param = NULL

This makes assign_parms use assign_parm_setup_stack instead of
assign_parm_setup_reg, and the latter does assign a suitably aligned
stack slot, because stack_param == NULL by now, and uses emit_block_move
which avoids the issue with the back-end.

Additionally, to prevent unnecessary performance regressions,
assign_parm_find_stack_rtl is enhanced to make use of a possible larger
alignment if the parameter was passed in an aligned stack slot without
the ABI requiring it.


Bootstrapped and reg-tested with all languages on arm-linux-gnueabihf.
Is it OK for trunk?


Thanks
Bernd.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch-arm-align-abi.diff --]
[-- Type: text/x-patch; name="patch-arm-align-abi.diff", Size: 3581 bytes --]

2019-03-05  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	PR middle-end/89544
	* function.c (use_register_for_decl): Avoid using unaligned stack
	values on strict alignment targets.
	(assign_parm_find_stack_rtl): Use larger alignment when possible.

testsuite:
2019-03-05  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.

Index: gcc/function.c
===================================================================
--- gcc/function.c	(revision 269264)
+++ gcc/function.c	(working copy)
@@ -2210,6 +2210,12 @@ use_register_for_decl (const_tree decl)
   if (DECL_MODE (decl) == BLKmode)
     return false;
 
+  if (STRICT_ALIGNMENT && TREE_CODE (decl) == PARM_DECL
+      && DECL_INCOMING_RTL (decl) && MEM_P (DECL_INCOMING_RTL (decl))
+      && GET_MODE_ALIGNMENT (DECL_MODE (decl))
+	 > MEM_ALIGN (DECL_INCOMING_RTL (decl)))
+    return false;
+
   /* If -ffloat-store specified, don't put explicit float variables
      into registers.  */
   /* ??? This should be checked after DECL_ARTIFICIAL, but tree-ssa
@@ -2698,8 +2704,20 @@ assign_parm_find_stack_rtl (tree parm, struct assi
      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 (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: gcc/testsuite/gcc.target/arm/unaligned-argument-1.c
===================================================================
--- gcc/testsuite/gcc.target/arm/unaligned-argument-1.c	(revision 0)
+++ gcc/testsuite/gcc.target/arm/unaligned-argument-1.c	(working copy)
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-marm -march=armv6 -mno-unaligned-access -mfloat-abi=soft -mabi=aapcs -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 "stmdb" 0 } } */
+/* { dg-final { scan-assembler-times "ldrd\[^\\n\]*\\\[sp\\\]" 1 } } */
+/* { dg-final { scan-assembler-times "ldrd" 1 } } */
+/* { dg-final { scan-assembler-times "strd" 1 } } */
Index: gcc/testsuite/gcc.target/arm/unaligned-argument-2.c
===================================================================
--- gcc/testsuite/gcc.target/arm/unaligned-argument-2.c	(revision 0)
+++ gcc/testsuite/gcc.target/arm/unaligned-argument-2.c	(working copy)
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-marm -march=armv6 -mno-unaligned-access -mfloat-abi=soft -mabi=aapcs -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 "stmdb" 1 } } */
+/* { dg-final { scan-assembler-times "ldrd\[^\\n\]*\\\[sp\\\]" 1 } } */
+/* { dg-final { scan-assembler-times "ldrd" 1 } } */
+/* { dg-final { scan-assembler-times "strd" 1 } } */

^ permalink raw reply	[flat|nested] 50+ messages in thread

end of thread, other threads:[~2019-09-06 10:18 UTC | newest]

Thread overview: 50+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-10 12:51 [PATCHv2] Fix not 8-byte aligned ldrd/strd on ARMv5 (PR 89544) Bernd Edlinger
2019-03-19 14:01 ` [PING] " Bernd Edlinger
2019-03-21 11:26 ` Richard Biener
2019-03-22 17:47   ` Bernd Edlinger
2019-03-25  9:28     ` Richard Biener
2019-07-30 22:13       ` [PATCHv3] " Bernd Edlinger
2019-07-31 13:17         ` Richard Earnshaw (lists)
2019-08-01 11:19           ` Bernd Edlinger
2019-08-02  9:10             ` Richard Earnshaw (lists)
2019-08-02 13:11         ` Richard Biener
2019-08-02 19:01           ` Bernd Edlinger
2019-08-08 14:20             ` [PATCHv4] " Bernd Edlinger
2019-08-14 10:54               ` [PING] " Bernd Edlinger
2019-08-14 12:27               ` Richard Biener
2019-08-14 22:26                 ` Bernd Edlinger
2019-08-15  8:58                   ` Richard Biener
2019-08-15 12:38                     ` Bernd Edlinger
2019-08-15 13:03                       ` Richard Biener
2019-08-15 14:33                         ` Richard Biener
2019-08-15 15:28                         ` Bernd Edlinger
2019-08-15 17:42                           ` Richard Biener
2019-08-15 21:19                             ` [PATCHv5] " Bernd Edlinger
2019-08-20  5:38                               ` Jeff Law
2019-08-20 15:04                               ` John David Anglin
     [not found]                                 ` <0d39b64f-67d9-7857-cf4e-36f09c0dc15e@bell.net>
2019-08-20 16:03                                   ` Fwd: " Bernd Edlinger
2019-09-04 12:53                               ` Richard Earnshaw (lists)
2019-09-04 13:29                                 ` Bernd Edlinger
2019-09-04 14:14                                   ` Richard Earnshaw (lists)
2019-09-04 15:00                                     ` Bernd Edlinger
2019-09-04 15:48                                       ` Richard Earnshaw (lists)
2019-09-05  9:21                                         ` Richard Earnshaw (lists)
2019-09-05  9:35                                           ` Bernd Edlinger
2019-09-06 10:15                                 ` Bernd Edlinger
2019-09-06 10:18                                   ` Richard Earnshaw (lists)
2019-08-15 21:27                             ` [PATCH] Sanitizing the middle-end interface to the back-end for strict alignment Bernd Edlinger
2019-08-17 10:11                               ` Bernd Edlinger
2019-08-23  0:01                                 ` Jeff Law
2019-08-23  0:05                               ` Jeff Law
2019-08-23 15:15                                 ` [PING] " Bernd Edlinger
2019-08-27 10:07                               ` Kyrill Tkachov
2019-08-28 11:50                                 ` Bernd Edlinger
2019-08-28 12:01                                   ` Kyrill Tkachov
2019-08-28 13:54                                     ` Christophe Lyon
2019-08-28 21:48                                       ` Bernd Edlinger
2019-08-29  9:09                                         ` Kyrill Tkachov
2019-08-29 10:00                                           ` Christophe Lyon
2019-08-29 22:57                                             ` Bernd Edlinger
2019-08-30 10:07                                               ` Kyrill Tkachov
2019-08-30 15:22                                               ` Christophe Lyon
2019-08-14 11:56             ` [PATCHv3] Fix not 8-byte aligned ldrd/strd on ARMv5 (PR 89544) Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).