public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch PR target/67366 0/2] Handle misaligned loads and stores for scalars on STRICT_ALIGNMENT targets
@ 2015-10-08 14:06 Ramana Radhakrishnan
  2015-10-08 14:06 ` [Patch PR target/67366 1/2] [ARM] - Add movmisalignhi / si patterns Ramana Radhakrishnan
  2015-10-08 14:11 ` [Patch PR target/67366 2/2] [gimple-fold.c] Support movmisalign optabs in gimple-fold.c Ramana Radhakrishnan
  0 siblings, 2 replies; 5+ messages in thread
From: Ramana Radhakrishnan @ 2015-10-08 14:06 UTC (permalink / raw)
  To: gcc-patches

This set of 2 patches attempts to fix PR target/67366 by introducing
use of the movmisalign optabs in gimple-fold.c to allow detecting
memcpys of the form shown in the testcase in the PR.

Patch 1/2 fixes the ARM backend to produce movmisalign patterns when
unaligned access is supported.

Patch 2/2 fixes gimple-fold.c to handle the appropriate cases
and deals with the testsuite fall out that this caused on ARM.

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

* [Patch PR target/67366 1/2] [ARM] - Add movmisalignhi / si patterns
  2015-10-08 14:06 [Patch PR target/67366 0/2] Handle misaligned loads and stores for scalars on STRICT_ALIGNMENT targets Ramana Radhakrishnan
@ 2015-10-08 14:06 ` Ramana Radhakrishnan
  2015-10-08 14:11 ` [Patch PR target/67366 2/2] [gimple-fold.c] Support movmisalign optabs in gimple-fold.c Ramana Radhakrishnan
  1 sibling, 0 replies; 5+ messages in thread
From: Ramana Radhakrishnan @ 2015-10-08 14:06 UTC (permalink / raw)
  To: gcc-patches

This adds movmisalignhi and movmisalignsi expanders when unaligned
access is allowed by the architecture. This allows the mid-end
to expand to misaligned loads and stored.

Compared code generated for the Linux kernel and
it changes code generation for a handful of files all for the better
basically by reducing the stack usage.

Tested by :

1. armhf bootstrap and regression test - no regressions.
2.. arm-none-eabi cross build and regression test for

    {-marm/-march=armv7-a/-mfpu=vfpv3-d16/-mfloat-abi=softfp}
    {-mthumb/-march=armv8-a/-mfpu=crypto-neon-fp-armv8/-mfloat-abi=hard}
    {-marm/-mcpu=arm7tdmi/-mfloat-abi=soft}
    {-mthumb/-mcpu=arm7tdmi/-mfloat-abi=soft}

Will apply to trunk once 2/2 is approved.

regards
Ramana

2015-09-15  Ramana Radhakrishnan  <ramana.radhakrishnan@arm.com>

	PR target/67366
	* config/arm/arm.md (movmisalign<mode>): New.
	* config/arm/iterators.md (HSI): New.
---
 gcc/config/arm/arm.md       | 35 +++++++++++++++++++++++++++++++++++
 gcc/config/arm/iterators.md |  3 +++
 2 files changed, 38 insertions(+)

diff --git a/gcc/config/arm/arm.md b/gcc/config/arm/arm.md
index b4c555b..9a3f7bd 100644
--- a/gcc/config/arm/arm.md
+++ b/gcc/config/arm/arm.md
@@ -11506,6 +11506,41 @@
   }"
 )
 
+;; movmisalign patterns for HImode and SImode.
+(define_expand "movmisalign<mode>"
+  [(match_operand:HSI 0 "general_operand")
+   (match_operand:HSI 1 "general_operand")]
+  "unaligned_access"
+{
+  /* This pattern is not permitted to fail during expansion: if both arguments
+     are non-registers (e.g. memory := constant), force operand 1 into a
+     register.  */
+  rtx (* gen_unaligned_load)(rtx, rtx);
+  rtx tmp_dest = operands[0];
+  if (!s_register_operand (operands[0], <MODE>mode)
+      && !s_register_operand (operands[1], <MODE>mode))
+    operands[1] = force_reg (<MODE>mode, operands[1]);
+
+  if (<MODE>mode == HImode)
+   {
+    gen_unaligned_load = gen_unaligned_loadhiu;
+    tmp_dest = gen_reg_rtx (SImode);
+   }
+  else
+    gen_unaligned_load = gen_unaligned_loadsi;
+
+  if (MEM_P (operands[1]))
+   {
+    emit_insn (gen_unaligned_load (tmp_dest, operands[1]));
+    if (<MODE>mode == HImode)
+      emit_move_insn (operands[0], gen_lowpart (HImode, tmp_dest));
+   }
+  else
+    emit_insn (gen_unaligned_store<mode> (operands[0], operands[1]));
+
+  DONE;
+})
+
 ;; Vector bits common to IWMMXT and Neon
 (include "vec-common.md")
 ;; Load the Intel Wireless Multimedia Extension patterns
diff --git a/gcc/config/arm/iterators.md b/gcc/config/arm/iterators.md
index 47cc1ee..6a54125 100644
--- a/gcc/config/arm/iterators.md
+++ b/gcc/config/arm/iterators.md
@@ -33,6 +33,9 @@
 ;; A list of integer modes that are up to one word long
 (define_mode_iterator QHSI [QI HI SI])
 
+;; A list of integer modes that are half and one word long
+(define_mode_iterator HSI [HI SI])
+
 ;; A list of integer modes that are less than a word
 (define_mode_iterator NARROW [QI HI])
 
-- 
1.9.1

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

* [Patch PR target/67366 2/2] [gimple-fold.c] Support movmisalign optabs in gimple-fold.c
  2015-10-08 14:06 [Patch PR target/67366 0/2] Handle misaligned loads and stores for scalars on STRICT_ALIGNMENT targets Ramana Radhakrishnan
  2015-10-08 14:06 ` [Patch PR target/67366 1/2] [ARM] - Add movmisalignhi / si patterns Ramana Radhakrishnan
@ 2015-10-08 14:11 ` Ramana Radhakrishnan
  2015-10-09  9:20   ` Richard Biener
  2015-10-14 17:35   ` Jeff Law
  1 sibling, 2 replies; 5+ messages in thread
From: Ramana Radhakrishnan @ 2015-10-08 14:11 UTC (permalink / raw)
  To: gcc-patches

This patch by Richard allows for movmisalign optabs to be supported
in gimple-fold.c. This caused a bit of pain in the testsuite with strlenopt-8.c
in conjunction with the ARM support for movmisalign_optabs as the test
was coded up to do different things depending on whether the target
supported misaligned access or not. However now with unaligned access
being allowed for different levels of the architecture in the arm backend,
the concept of the helper function non_strict_align mapping identically
to the definition of STRICT_ALIGNMENT disappears.

Adjusted thusly for ARM. The testsuite/lib changes were tested with an
arm-none-eabi multilib that included architecture variants that did not
support unaligned access and architecture variants that did.

The testing matrix for this patch was:

1. x86_64 bootstrap and regression test - no regressions.
2. armhf bootstrap and regression test - no regressions.
3. arm-none-eabi cross build and regression test for

{-marm/-march=armv7-a/-mfpu=vfpv3-d16/-mfloat-abi=softfp}
{-mthumb/-march=armv8-a/-mfpu=crypto-neon-fp-armv8/-mfloat-abi=hard}
{-marm/-mcpu=arm7tdmi/-mfloat-abi=soft}
{-mthumb/-mcpu=arm7tdmi/-mfloat-abi=soft}

with no regressions.

Ok to apply ?

Ramana

2015-10-08  Richard Biener  <rguenth@suse.de>

	* gimple-fold.c (optabs-query.h): Include
	(gimple_fold_builtin_memory_op): Allow unaligned stores
	when movmisalign_optabs are available.

2015-10-08  Ramana Radhakrishnan  <ramana.radhakrishnan@arm.com>

	PR target/67366
	* lib/target-supports.exp (check_effective_target_non_strict_align):
	Adjust for arm*-*-*.
	* gcc.target/arm/pr67366.c: New test.
---
 gcc/gimple-fold.c                      | 11 +++++++++--
 gcc/testsuite/gcc.target/arm/pr67366.c | 14 ++++++++++++++
 gcc/testsuite/lib/target-supports.exp  |  9 +++++++++
 3 files changed, 32 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/arm/pr67366.c

diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index a6caaa4..59d496b 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -63,6 +63,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-eh.h"
 #include "gimple-match.h"
 #include "gomp-constants.h"
+#include "optabs-query.h"
+
 
 /* Return true when DECL can be referenced from current unit.
    FROM_DECL (if non-null) specify constructor of variable DECL was taken from.
@@ -709,7 +711,9 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi,
 		  /* If the destination pointer is not aligned we must be able
 		     to emit an unaligned store.  */
 		  && (dest_align >= GET_MODE_ALIGNMENT (TYPE_MODE (type))
-		      || !SLOW_UNALIGNED_ACCESS (TYPE_MODE (type), dest_align)))
+		      || !SLOW_UNALIGNED_ACCESS (TYPE_MODE (type), dest_align)
+		      || (optab_handler (movmisalign_optab, TYPE_MODE (type))
+			  != CODE_FOR_nothing)))
 		{
 		  tree srctype = type;
 		  tree desttype = type;
@@ -721,7 +725,10 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi,
 		    srcmem = tem;
 		  else if (src_align < GET_MODE_ALIGNMENT (TYPE_MODE (type))
 			   && SLOW_UNALIGNED_ACCESS (TYPE_MODE (type),
-						     src_align))
+						     src_align)
+			   && (optab_handler (movmisalign_optab,
+					      TYPE_MODE (type))
+			       == CODE_FOR_nothing))
 		    srcmem = NULL_TREE;
 		  if (srcmem)
 		    {
diff --git a/gcc/testsuite/gcc.target/arm/pr67366.c b/gcc/testsuite/gcc.target/arm/pr67366.c
new file mode 100644
index 0000000..1e8b672
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/pr67366.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target arm_unaligned } */
+/* { dg-options "-O2" } */
+
+typedef unsigned int u32;
+u32
+read32 (const void* ptr)
+{
+  u32 v;
+  __builtin_memcpy (&v, ptr, sizeof(v));
+  return v;
+}
+
+/* { dg-final { scan-assembler "@ unaligned" } } */
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 9057a27..4d5b0a3d 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -6262,6 +6262,15 @@ proc check_vect_support_and_set_flags { } {
 # Return 1 if the target does *not* require strict alignment.
 
 proc check_effective_target_non_strict_align {} {
+
+    # On ARM, the default is to use STRICT_ALIGNMENT, but there
+    # are interfaces defined for misaligned access and thus
+    # depending on the architecture levels unaligned access is
+    # available.
+    if [istarget "arm*-*-*"] {
+	return [check_effective_target_arm_unaligned]
+    }
+
     return [check_no_compiler_messages non_strict_align assembly {
 	char *y;
 	typedef char __attribute__ ((__aligned__(__BIGGEST_ALIGNMENT__))) c;

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

* Re: [Patch PR target/67366 2/2] [gimple-fold.c] Support movmisalign optabs in gimple-fold.c
  2015-10-08 14:11 ` [Patch PR target/67366 2/2] [gimple-fold.c] Support movmisalign optabs in gimple-fold.c Ramana Radhakrishnan
@ 2015-10-09  9:20   ` Richard Biener
  2015-10-14 17:35   ` Jeff Law
  1 sibling, 0 replies; 5+ messages in thread
From: Richard Biener @ 2015-10-09  9:20 UTC (permalink / raw)
  To: Ramana Radhakrishnan; +Cc: GCC Patches

On Thu, Oct 8, 2015 at 4:10 PM, Ramana Radhakrishnan
<ramana.radhakrishnan@arm.com> wrote:
> This patch by Richard allows for movmisalign optabs to be supported
> in gimple-fold.c. This caused a bit of pain in the testsuite with strlenopt-8.c
> in conjunction with the ARM support for movmisalign_optabs as the test
> was coded up to do different things depending on whether the target
> supported misaligned access or not. However now with unaligned access
> being allowed for different levels of the architecture in the arm backend,
> the concept of the helper function non_strict_align mapping identically
> to the definition of STRICT_ALIGNMENT disappears.
>
> Adjusted thusly for ARM. The testsuite/lib changes were tested with an
> arm-none-eabi multilib that included architecture variants that did not
> support unaligned access and architecture variants that did.
>
> The testing matrix for this patch was:
>
> 1. x86_64 bootstrap and regression test - no regressions.
> 2. armhf bootstrap and regression test - no regressions.
> 3. arm-none-eabi cross build and regression test for
>
> {-marm/-march=armv7-a/-mfpu=vfpv3-d16/-mfloat-abi=softfp}
> {-mthumb/-march=armv8-a/-mfpu=crypto-neon-fp-armv8/-mfloat-abi=hard}
> {-marm/-mcpu=arm7tdmi/-mfloat-abi=soft}
> {-mthumb/-mcpu=arm7tdmi/-mfloat-abi=soft}
>
> with no regressions.
>
> Ok to apply ?

Ok.

Thanks,
Richard.

> Ramana
>
> 2015-10-08  Richard Biener  <rguenth@suse.de>
>
>         * gimple-fold.c (optabs-query.h): Include
>         (gimple_fold_builtin_memory_op): Allow unaligned stores
>         when movmisalign_optabs are available.
>
> 2015-10-08  Ramana Radhakrishnan  <ramana.radhakrishnan@arm.com>
>
>         PR target/67366
>         * lib/target-supports.exp (check_effective_target_non_strict_align):
>         Adjust for arm*-*-*.
>         * gcc.target/arm/pr67366.c: New test.
> ---
>  gcc/gimple-fold.c                      | 11 +++++++++--
>  gcc/testsuite/gcc.target/arm/pr67366.c | 14 ++++++++++++++
>  gcc/testsuite/lib/target-supports.exp  |  9 +++++++++
>  3 files changed, 32 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/arm/pr67366.c
>
> diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
> index a6caaa4..59d496b 100644
> --- a/gcc/gimple-fold.c
> +++ b/gcc/gimple-fold.c
> @@ -63,6 +63,8 @@ along with GCC; see the file COPYING3.  If not see
>  #include "tree-eh.h"
>  #include "gimple-match.h"
>  #include "gomp-constants.h"
> +#include "optabs-query.h"
> +
>
>  /* Return true when DECL can be referenced from current unit.
>     FROM_DECL (if non-null) specify constructor of variable DECL was taken from.
> @@ -709,7 +711,9 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi,
>                   /* If the destination pointer is not aligned we must be able
>                      to emit an unaligned store.  */
>                   && (dest_align >= GET_MODE_ALIGNMENT (TYPE_MODE (type))
> -                     || !SLOW_UNALIGNED_ACCESS (TYPE_MODE (type), dest_align)))
> +                     || !SLOW_UNALIGNED_ACCESS (TYPE_MODE (type), dest_align)
> +                     || (optab_handler (movmisalign_optab, TYPE_MODE (type))
> +                         != CODE_FOR_nothing)))
>                 {
>                   tree srctype = type;
>                   tree desttype = type;
> @@ -721,7 +725,10 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi,
>                     srcmem = tem;
>                   else if (src_align < GET_MODE_ALIGNMENT (TYPE_MODE (type))
>                            && SLOW_UNALIGNED_ACCESS (TYPE_MODE (type),
> -                                                    src_align))
> +                                                    src_align)
> +                          && (optab_handler (movmisalign_optab,
> +                                             TYPE_MODE (type))
> +                              == CODE_FOR_nothing))
>                     srcmem = NULL_TREE;
>                   if (srcmem)
>                     {
> diff --git a/gcc/testsuite/gcc.target/arm/pr67366.c b/gcc/testsuite/gcc.target/arm/pr67366.c
> new file mode 100644
> index 0000000..1e8b672
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/arm/pr67366.c
> @@ -0,0 +1,14 @@
> +/* { dg-do compile } */
> +/* { dg-require-effective-target arm_unaligned } */
> +/* { dg-options "-O2" } */
> +
> +typedef unsigned int u32;
> +u32
> +read32 (const void* ptr)
> +{
> +  u32 v;
> +  __builtin_memcpy (&v, ptr, sizeof(v));
> +  return v;
> +}
> +
> +/* { dg-final { scan-assembler "@ unaligned" } } */
> diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
> index 9057a27..4d5b0a3d 100644
> --- a/gcc/testsuite/lib/target-supports.exp
> +++ b/gcc/testsuite/lib/target-supports.exp
> @@ -6262,6 +6262,15 @@ proc check_vect_support_and_set_flags { } {
>  # Return 1 if the target does *not* require strict alignment.
>
>  proc check_effective_target_non_strict_align {} {
> +
> +    # On ARM, the default is to use STRICT_ALIGNMENT, but there
> +    # are interfaces defined for misaligned access and thus
> +    # depending on the architecture levels unaligned access is
> +    # available.
> +    if [istarget "arm*-*-*"] {
> +       return [check_effective_target_arm_unaligned]
> +    }
> +
>      return [check_no_compiler_messages non_strict_align assembly {
>         char *y;
>         typedef char __attribute__ ((__aligned__(__BIGGEST_ALIGNMENT__))) c;

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

* Re: [Patch PR target/67366 2/2] [gimple-fold.c] Support movmisalign optabs in gimple-fold.c
  2015-10-08 14:11 ` [Patch PR target/67366 2/2] [gimple-fold.c] Support movmisalign optabs in gimple-fold.c Ramana Radhakrishnan
  2015-10-09  9:20   ` Richard Biener
@ 2015-10-14 17:35   ` Jeff Law
  1 sibling, 0 replies; 5+ messages in thread
From: Jeff Law @ 2015-10-14 17:35 UTC (permalink / raw)
  To: Ramana Radhakrishnan, gcc-patches

On 10/08/2015 08:10 AM, Ramana Radhakrishnan wrote:
> This patch by Richard allows for movmisalign optabs to be supported
> in gimple-fold.c. This caused a bit of pain in the testsuite with strlenopt-8.c
> in conjunction with the ARM support for movmisalign_optabs as the test
> was coded up to do different things depending on whether the target
> supported misaligned access or not. However now with unaligned access
> being allowed for different levels of the architecture in the arm backend,
> the concept of the helper function non_strict_align mapping identically
> to the definition of STRICT_ALIGNMENT disappears.
>
> Adjusted thusly for ARM. The testsuite/lib changes were tested with an
> arm-none-eabi multilib that included architecture variants that did not
> support unaligned access and architecture variants that did.
>
> The testing matrix for this patch was:
>
> 1. x86_64 bootstrap and regression test - no regressions.
> 2. armhf bootstrap and regression test - no regressions.
> 3. arm-none-eabi cross build and regression test for
>
> {-marm/-march=armv7-a/-mfpu=vfpv3-d16/-mfloat-abi=softfp}
> {-mthumb/-march=armv8-a/-mfpu=crypto-neon-fp-armv8/-mfloat-abi=hard}
> {-marm/-mcpu=arm7tdmi/-mfloat-abi=soft}
> {-mthumb/-mcpu=arm7tdmi/-mfloat-abi=soft}
>
> with no regressions.
>
> Ok to apply ?
>
> Ramana
>
> 2015-10-08  Richard Biener  <rguenth@suse.de>
>
> 	* gimple-fold.c (optabs-query.h): Include
> 	(gimple_fold_builtin_memory_op): Allow unaligned stores
> 	when movmisalign_optabs are available.
>
> 2015-10-08  Ramana Radhakrishnan  <ramana.radhakrishnan@arm.com>
>
> 	PR target/67366
> 	* lib/target-supports.exp (check_effective_target_non_strict_align):
> 	Adjust for arm*-*-*.
> 	* gcc.target/arm/pr67366.c: New test.
OK.
jeff

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

end of thread, other threads:[~2015-10-14 17:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-08 14:06 [Patch PR target/67366 0/2] Handle misaligned loads and stores for scalars on STRICT_ALIGNMENT targets Ramana Radhakrishnan
2015-10-08 14:06 ` [Patch PR target/67366 1/2] [ARM] - Add movmisalignhi / si patterns Ramana Radhakrishnan
2015-10-08 14:11 ` [Patch PR target/67366 2/2] [gimple-fold.c] Support movmisalign optabs in gimple-fold.c Ramana Radhakrishnan
2015-10-09  9:20   ` Richard Biener
2015-10-14 17:35   ` Jeff Law

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).