Catherine included an earlier version of this patch with the microMIPS
submission a couple years ago:
https://gcc.gnu.org/ml/gcc-patches/2012-07/msg00972.html
Richard's response was:
Looks like the wrong place to do this. Please treat this as a separate
patch and get a tree expert to comment.
So, here is the separate patch, finally. :-) Can a tree expert
comment? I dug around and didn't see another obvious hook to set
function alignment in a target-specific way depending on attributes of
the function.
Besides the new test cases, I regression-tested this on mips-sde-elf
using Mentor's usual assortment of multilibs, specifically including one
for microMIPS.
-Sandra
2014-05-19 Iain Sandoe <i...@codesourcery.com>
Catherine Moore <c...@codesourcery.com>
Sandra Loosemore <san...@codesourcery.com>
gcc/
* config/mips/mips.c (mips_set_current_function): Choose
function alignment once the current mode is known.
gcc/testsuite/
* gcc.target/mips/umips-align-1.c: New.
* gcc.target/mips/umips-align-2.c: New.
* gcc.target/mips/umips-align-3.c: New.
* gcc.target/mips/mips.exp: Add interlink-compressed to
-mfoo/-mno-foo options.
Index: gcc/config/mips/mips.c
===================================================================
--- gcc/config/mips/mips.c (revision 210478)
+++ gcc/config/mips/mips.c (working copy)
@@ -16822,6 +16822,13 @@ static void
mips_set_current_function (tree fndecl)
{
mips_set_compression_mode (mips_get_compress_mode (fndecl));
+
+ if (fndecl
+ && TARGET_MICROMIPS
+ && optimize_size
+ && !TARGET_INTERLINK_COMPRESSED
+ && !DECL_USER_ALIGN (fndecl))
+ DECL_ALIGN (fndecl) = 16;
}
/* Allocate a chunk of memory for per-function machine-dependent data. */
Index: gcc/testsuite/gcc.target/mips/umips-align-1.c
===================================================================
--- gcc/testsuite/gcc.target/mips/umips-align-1.c (revision 0)
+++ gcc/testsuite/gcc.target/mips/umips-align-1.c (revision 0)
@@ -0,0 +1,14 @@
+/* { dg-options "(-mmicromips) -mno-interlink-compressed" } */
+/* { dg-skip-if "code size optimization" { *-*-* } { "*" } { "-Os" } } */
+
+/* Check that microMIPS functions are aligned on 16-bit (2^1 byte)
+ boundaries with -Os. */
+
+int MICROMIPS
+f (int x)
+{
+ return x + 42;
+}
+
+/* { dg-final { scan-assembler "\t\\.align\t1" } } */
+
Index: gcc/testsuite/gcc.target/mips/umips-align-2.c
===================================================================
--- gcc/testsuite/gcc.target/mips/umips-align-2.c (revision 0)
+++ gcc/testsuite/gcc.target/mips/umips-align-2.c (revision 0)
@@ -0,0 +1,13 @@
+/* { dg-options "(-mmicromips) -minterlink-compressed" } */
+/* { dg-skip-if "code size optimization" { *-*-* } { "*" } { "-Os" } } */
+
+/* Check that -minterlink-compressed suppresses 16-bit alignment of
+ microMIPS functions with -Os. */
+
+int MICROMIPS
+f (int x)
+{
+ return x + 42;
+}
+
+/* { dg-final { scan-assembler-not "\t\\.align\t1" } } */
Index: gcc/testsuite/gcc.target/mips/umips-align-3.c
===================================================================
--- gcc/testsuite/gcc.target/mips/umips-align-3.c (revision 0)
+++ gcc/testsuite/gcc.target/mips/umips-align-3.c (revision 0)
@@ -0,0 +1,14 @@
+/* { dg-options "(-mmicromips) -mno-interlink-compressed" } */
+/* { dg-skip-if "code size optimization" { *-*-* } { "*" } { "-Os" } } */
+
+/* Check that explicit alignment attribute suppresses 16-bit alignment of
+ microMIPS functions with -Os. */
+
+int MICROMIPS
+__attribute__ ((aligned (16)))
+f (int x)
+{
+ return x + 42;
+}
+
+/* { dg-final { scan-assembler-not "\t\\.align\t1" } } */
Index: gcc/testsuite/gcc.target/mips/mips.exp
===================================================================
--- gcc/testsuite/gcc.target/mips/mips.exp (revision 210478)
+++ gcc/testsuite/gcc.target/mips/mips.exp (working copy)
@@ -260,6 +260,7 @@ foreach option {
fix-r10000
fix-vr4130
gpopt
+ interlink-compressed
local-sdata
long-calls
paired-single