re PR target/67745 ([ARM] wrong alignments when __attribute__ ((optimize,target,align...
authorChristian Bruel <christian.bruel@st.com>
Fri, 16 Oct 2015 13:37:14 +0000 (15:37 +0200)
committerChristian Bruel <chrbr@gcc.gnu.org>
Fri, 16 Oct 2015 13:37:14 +0000 (15:37 +0200)
2015-10-16  Christian Bruel  <christian.bruel@st.com>

PR target/67745
* config/arm/arm.h (FUNCTION_BOUNDARY): Move optimize_size condition to:
* config/arm/arm.c (arm_option_override_internal): Call
arm_override_options_after_change_1.
(arm_override_options_after_change): New function.
(arm_override_options_after_change_1): Likewise.
(TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE): Define hook.

From-SVN: r228904

gcc/ChangeLog
gcc/config/arm/arm.c
gcc/config/arm/arm.h
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/arm/attr-align1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/arm/attr-align2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/arm/attr-align3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/arm/no-align.c [new file with mode: 0644]

index 9c9cc65cb9874be92a45eba7ff89512f5b40ef91..24deaaccef39a9a78301f9de4e75db928a7a6bc8 100644 (file)
@@ -1,3 +1,13 @@
+2015-10-16  Christian Bruel  <christian.bruel@st.com>
+
+       PR target/67745
+       * config/arm/arm.h (FUNCTION_BOUNDARY): Move optimize_size condition to:
+       * config/arm/arm.c (arm_option_override_internal): Call
+       arm_override_options_after_change_1.
+       (arm_override_options_after_change): New function.
+       (arm_override_options_after_change_1): Likewise.
+       (TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE): Define hook.
+
 2015-10-11  Jan Hubicka  <hubicka@ucw.cz>
 
        Revert:
index 0bf1164845cc7bbb34de4f9e3bab74c855c2800c..2c8215cb5133ef63f6b40185284728ae2aab17a6 100644 (file)
@@ -246,6 +246,7 @@ static tree arm_build_builtin_va_list (void);
 static void arm_expand_builtin_va_start (tree, rtx);
 static tree arm_gimplify_va_arg_expr (tree, tree, gimple_seq *, gimple_seq *);
 static void arm_option_override (void);
+static void arm_override_options_after_change (void);
 static void arm_option_print (FILE *, int, struct cl_target_option *);
 static void arm_set_current_function (tree);
 static bool arm_can_inline_p (tree, tree);
@@ -407,6 +408,9 @@ static const struct attribute_spec arm_attribute_table[] =
 #undef  TARGET_OPTION_OVERRIDE
 #define TARGET_OPTION_OVERRIDE arm_option_override
 
+#undef TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE
+#define TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE arm_override_options_after_change
+
 #undef TARGET_OPTION_PRINT
 #define TARGET_OPTION_PRINT arm_option_print
 
@@ -2810,11 +2814,29 @@ static GTY(()) bool thumb_flipper;
 /* Options after initial target override.  */
 static GTY(()) tree init_optimize;
 
+static void
+arm_override_options_after_change_1 (struct gcc_options *opts)
+{
+  if (opts->x_align_functions <= 0)
+    opts->x_align_functions = TARGET_THUMB_P (opts->x_target_flags)
+      && opts->x_optimize_size ? 2 : 4;
+}
+
+/* Implement targetm.override_options_after_change.  */
+
+static void
+arm_override_options_after_change (void)
+{
+  arm_override_options_after_change_1 (&global_options);
+}
+
 /* Reset options between modes that the user has specified.  */
 static void
 arm_option_override_internal (struct gcc_options *opts,
                              struct gcc_options *opts_set)
 {
+  arm_override_options_after_change_1 (opts);
+
   if (TARGET_THUMB_P (opts->x_target_flags)
       && !(ARM_FSET_HAS_CPU1 (insn_flags, FL_THUMB)))
     {
index 87c9f904894f0367fb245b4a7f1e89c780dcc75c..9715969a5e560135629d114535c69962354d1173 100644 (file)
@@ -565,7 +565,7 @@ extern int arm_arch_crc;
 #define PREFERRED_STACK_BOUNDARY \
     (arm_abi == ARM_ABI_ATPCS ? 64 : STACK_BOUNDARY)
 
-#define FUNCTION_BOUNDARY  ((TARGET_THUMB && optimize_size) ? 16 : 32)
+#define FUNCTION_BOUNDARY           (TARGET_THUMB ? 16 : 32)
 
 /* The lowest bit is used to indicate Thumb-mode functions, so the
    vbit must go into the delta field of pointers to member
index 3d5ad170ac93660f6745788cb6f5b98dc0b2038c..8701cb44988e818b8a0732fdaf4397dd30495054 100644 (file)
@@ -1,3 +1,11 @@
+2015-10-16  Christian Bruel  <christian.bruel@st.com>
+
+       PR target/67745
+        * gcc.target/arm/no-align.c: New test.
+        * gcc.target/arm/attr-align1.c: New test.
+        * gcc.target/arm/attr-align2.c: New test.
+        * gcc.target/arm/attr-align3.c: New test.
+
 2015-10-11  Jan Hubicka  <hubicka@ucw.cz>
 
        * gcc.c-torture/compile/icfmatch.c: Add testcase
diff --git a/gcc/testsuite/gcc.target/arm/attr-align1.c b/gcc/testsuite/gcc.target/arm/attr-align1.c
new file mode 100644 (file)
index 0000000..96d29a9
--- /dev/null
@@ -0,0 +1,27 @@
+/* PR target/67745
+   Verify alignment when both attribute optimize and target are used.  */
+/* { dg-do compile } */
+/* { dg-skip-if "" { ! { arm_thumb1_ok || arm_thumb2_ok } } } */
+
+void
+__attribute__ ((target ("arm")))
+bar()
+{
+}
+
+void
+__attribute__ ((target ("thumb")))
+__attribute__ ((optimize ("Os")))
+foo()
+{
+}
+
+void
+__attribute__ ((target ("thumb")))
+__attribute__ ((optimize ("O2")))
+rab()
+{
+}
+
+/* { dg-final { scan-assembler-times ".align\[ \t]2" 2 } } */
+/* { dg-final { scan-assembler ".align\[ \t]1" } } */
diff --git a/gcc/testsuite/gcc.target/arm/attr-align2.c b/gcc/testsuite/gcc.target/arm/attr-align2.c
new file mode 100644 (file)
index 0000000..2086f11
--- /dev/null
@@ -0,0 +1,15 @@
+/* PR target/67745
+   Verify alignment when attribute optimize is used.  */
+/* { dg-do compile } */
+/* { dg-skip-if "" { ! { arm_thumb1_ok || arm_thumb2_ok } } } */
+/* { dg-options "-O2 -mthumb" }  */
+
+/* Check that thumb code is always 2 bytes aligned for -Os.  */
+
+void
+__attribute__ ((optimize("Os")))
+foo()
+{
+}
+
+/* { dg-final { scan-assembler ".align\[ \t]1" } } */
diff --git a/gcc/testsuite/gcc.target/arm/attr-align3.c b/gcc/testsuite/gcc.target/arm/attr-align3.c
new file mode 100644 (file)
index 0000000..edcf64b
--- /dev/null
@@ -0,0 +1,13 @@
+/* PR target/67745
+   Verify alignment when attribute target is used.  */
+/* { dg-do compile } */
+/* { dg-skip-if "" { ! { arm_thumb1_ok || arm_thumb2_ok } } } */
+/* { dg-options "-Os -mthumb" }  */
+
+/* Check that arm code is always 4 bytes aligned.  */
+void  __attribute__ ((target ("arm")))
+c(void)
+{
+}
+
+/* { dg-final { scan-assembler-not ".align\[ \t]1" } } */
diff --git a/gcc/testsuite/gcc.target/arm/no-align.c b/gcc/testsuite/gcc.target/arm/no-align.c
new file mode 100644 (file)
index 0000000..03811c3
--- /dev/null
@@ -0,0 +1,12 @@
+/* PR target/67745
+   Verify that -mthumb code is not aligned.  */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mthumb -fno-align-functions" }  */
+/* { dg-skip-if "" { ! { arm_thumb1_ok || arm_thumb2_ok } } } */
+
+void
+foo()
+{
+}
+
+/* { dg-final { scan-assembler-not ".align\[ \t]2" } } */