From 8e2be5aefcc78b213c2f44e50cbec2c799f40f8b Mon Sep 17 00:00:00 2001 From: "Maciej W. Rozycki" Date: Wed, 16 Nov 2016 21:05:01 +0000 Subject: [PATCH] microMIPS/GCC: Fix PIC call relaxation gcc/ * config/mips/mips.c (mips_output_jump): Output R_MICROMIPS_JALR rather than R_MIPS_JALR relocation in microMIPS code. Do not cancel short delay slots in PIC call relaxation. gcc/testsuite/ * gcc.target/mips/call-1.c (dg-options): Add `-mno-micromips'. (dg-final): Remove microMIPS JALRS mnemonic matching. * gcc.target/mips/call-2.c (dg-options): Add `-mno-micromips'. (dg-final): Remove microMIPS JALRS mnemonic matching. * gcc.target/mips/call-3.c (dg-options): Add `-mno-micromips'. (dg-final): Remove microMIPS JALRS mnemonic matching. * gcc.target/mips/call-4.c (dg-options): Add `-mno-micromips'. * gcc.target/mips/call-5.c (dg-options): Add `-mno-micromips'. * gcc.target/mips/call-6.c (dg-options): Add `-mno-micromips'. * gcc.target/mips/call-1u.c: New test case. * gcc.target/mips/call-2u.c: New test case. * gcc.target/mips/call-3u.c: New test case. * gcc.target/mips/call-4u.c: New test case. * gcc.target/mips/call-5u.c: New test case. * gcc.target/mips/call-6u.c: New test case. From-SVN: r242512 --- gcc/ChangeLog | 6 +++ gcc/config/mips/mips.c | 9 ++--- gcc/testsuite/ChangeLog | 18 +++++++++ gcc/testsuite/gcc.target/mips/call-1.c | 8 ++-- gcc/testsuite/gcc.target/mips/call-1u.c | 51 ++++++++++++++++++++++++ gcc/testsuite/gcc.target/mips/call-2.c | 4 +- gcc/testsuite/gcc.target/mips/call-2u.c | 13 ++++++ gcc/testsuite/gcc.target/mips/call-3.c | 4 +- gcc/testsuite/gcc.target/mips/call-3u.c | 12 ++++++ gcc/testsuite/gcc.target/mips/call-4.c | 2 +- gcc/testsuite/gcc.target/mips/call-4u.c | 12 ++++++ gcc/testsuite/gcc.target/mips/call-5.c | 2 +- gcc/testsuite/gcc.target/mips/call-5u.c | 53 +++++++++++++++++++++++++ gcc/testsuite/gcc.target/mips/call-6.c | 2 +- gcc/testsuite/gcc.target/mips/call-6u.c | 52 ++++++++++++++++++++++++ 15 files changed, 231 insertions(+), 17 deletions(-) create mode 100644 gcc/testsuite/gcc.target/mips/call-1u.c create mode 100644 gcc/testsuite/gcc.target/mips/call-2u.c create mode 100644 gcc/testsuite/gcc.target/mips/call-3u.c create mode 100644 gcc/testsuite/gcc.target/mips/call-4u.c create mode 100644 gcc/testsuite/gcc.target/mips/call-5u.c create mode 100644 gcc/testsuite/gcc.target/mips/call-6u.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 02a309f735f..4e437f0bb67 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2016-11-16 Maciej W. Rozycki + + * config/mips/mips.c (mips_output_jump): Output R_MICROMIPS_JALR + rather than R_MIPS_JALR relocation in microMIPS code. Do not + cancel short delay slots in PIC call relaxation. + 2016-11-16 Thomas Preud'homme * config/arm/arm.md (arm_addsi3): Add alternative for addition of diff --git a/gcc/config/mips/mips.c b/gcc/config/mips/mips.c index 10c20393ca4..d6464c50430 100644 --- a/gcc/config/mips/mips.c +++ b/gcc/config/mips/mips.c @@ -13618,12 +13618,9 @@ mips_output_jump (rtx *operands, int target_opno, int size_opno, bool link_p) s += sprintf (s, ".option\tpic0\n\t"); if (reg_p && mips_get_pic_call_symbol (operands, size_opno)) - { - s += sprintf (s, "%%*.reloc\t1f,R_MIPS_JALR,%%%d\n1:\t", size_opno); - /* Not sure why this shouldn't permit a short delay but it did not - allow it before so we still don't allow it. */ - short_delay = ""; - } + s += sprintf (s, "%%*.reloc\t1f,%s,%%%d\n1:\t", + TARGET_MICROMIPS ? "R_MICROMIPS_JALR" : "R_MIPS_JALR", + size_opno); else s += sprintf (s, "%%*"); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4c274d73148..0677079fb2b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,21 @@ +2016-11-16 Maciej W. Rozycki + + * gcc.target/mips/call-1.c (dg-options): Add `-mno-micromips'. + (dg-final): Remove microMIPS JALRS mnemonic matching. + * gcc.target/mips/call-2.c (dg-options): Add `-mno-micromips'. + (dg-final): Remove microMIPS JALRS mnemonic matching. + * gcc.target/mips/call-3.c (dg-options): Add `-mno-micromips'. + (dg-final): Remove microMIPS JALRS mnemonic matching. + * gcc.target/mips/call-4.c (dg-options): Add `-mno-micromips'. + * gcc.target/mips/call-5.c (dg-options): Add `-mno-micromips'. + * gcc.target/mips/call-6.c (dg-options): Add `-mno-micromips'. + * gcc.target/mips/call-1u.c: New test case. + * gcc.target/mips/call-2u.c: New test case. + * gcc.target/mips/call-3u.c: New test case. + * gcc.target/mips/call-4u.c: New test case. + * gcc.target/mips/call-5u.c: New test case. + * gcc.target/mips/call-6u.c: New test case. + 2016-11-16 Thomas Preud'homme * gcc.target/arm/empty_fiq_handler.c: New test. diff --git a/gcc/testsuite/gcc.target/mips/call-1.c b/gcc/testsuite/gcc.target/mips/call-1.c index 46a2536754b..9516e7ea89b 100644 --- a/gcc/testsuite/gcc.target/mips/call-1.c +++ b/gcc/testsuite/gcc.target/mips/call-1.c @@ -1,8 +1,8 @@ -/* { dg-options "-mrelax-pic-calls -mshared -foptimize-sibling-calls -mabi=32" } */ +/* { dg-options "-mno-micromips -mrelax-pic-calls -mshared -foptimize-sibling-calls -mabi=32" } */ /* { dg-skip-if "requires -foptimize-sibling-calls" { *-*-* } { "-O0" } { "" } } */ -/* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,normal\n1:\tjalrc?s?\t" } } */ -/* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,normal2\n1:\tjalrc?s?\t" } } */ -/* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,staticfunc\n1:\tjalrc?s?\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,normal\n1:\tjalrc?\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,normal2\n1:\tjalrc?\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,staticfunc\n1:\tjalrc?\t" } } */ /* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,tail\n1:\tjrc?\t" } } */ /* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,tail2\n1:\tjrc?\t" } } */ /* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,tail3\n1:\tjrc?\t" } } */ diff --git a/gcc/testsuite/gcc.target/mips/call-1u.c b/gcc/testsuite/gcc.target/mips/call-1u.c new file mode 100644 index 00000000000..d9700e26aee --- /dev/null +++ b/gcc/testsuite/gcc.target/mips/call-1u.c @@ -0,0 +1,51 @@ +/* { dg-options "-mmicromips -mrelax-pic-calls -mshared -foptimize-sibling-calls -mabi=32" } */ +/* { dg-skip-if "requires -foptimize-sibling-calls" { *-*-* } { "-O0" } { "" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MICROMIPS_JALR,normal\n1:\tjalrs?\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MICROMIPS_JALR,normal2\n1:\tjalrs?\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MICROMIPS_JALR,staticfunc\n1:\tjalrs?\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MICROMIPS_JALR,tail\n1:\tjrc?\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MICROMIPS_JALR,tail2\n1:\tjrc?\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MICROMIPS_JALR,tail3\n1:\tjrc?\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MICROMIPS_JALR,tail4\n1:\tjrc?\t" } } */ + +__attribute__ ((noinline)) static void staticfunc () { asm (""); } +int normal (); +void normal2 (); + +int +NOMIPS16 f (int *p) +{ + *p = normal (); + normal2 (); + staticfunc (); + return 1; +} + +int tail (); + +int +NOMIPS16 h () +{ + return tail (); +} + +void tail2 (); + +NOMIPS16 void g () +{ + tail2 (); +} + +__attribute__ ((visibility ("hidden"))) void tail3 (); + +NOMIPS16 void j () +{ + tail3 (); +} + +__attribute__ ((noinline)) static void tail4 () { asm (""); } + +NOMIPS16 void k () +{ + tail4 (); +} diff --git a/gcc/testsuite/gcc.target/mips/call-2.c b/gcc/testsuite/gcc.target/mips/call-2.c index 175933cbe77..916cc7b4650 100644 --- a/gcc/testsuite/gcc.target/mips/call-2.c +++ b/gcc/testsuite/gcc.target/mips/call-2.c @@ -1,6 +1,6 @@ /* See through some simple data-flow. */ -/* { dg-options "-mrelax-pic-calls" } */ -/* { dg-final { scan-assembler-times "\\.reloc\t1f,R_MIPS_JALR,g\n1:\tjalrc?s?\t" 2 } } */ +/* { dg-options "-mno-micromips -mrelax-pic-calls" } */ +/* { dg-final { scan-assembler-times "\\.reloc\t1f,R_MIPS_JALR,g\n1:\tjalrc?\t" 2 } } */ extern void g (void); diff --git a/gcc/testsuite/gcc.target/mips/call-2u.c b/gcc/testsuite/gcc.target/mips/call-2u.c new file mode 100644 index 00000000000..4f5903057e2 --- /dev/null +++ b/gcc/testsuite/gcc.target/mips/call-2u.c @@ -0,0 +1,13 @@ +/* See through some simple data-flow. */ +/* { dg-options "-mmicromips -mrelax-pic-calls" } */ +/* { dg-final { scan-assembler-times "\\.reloc\t1f,R_MICROMIPS_JALR,g\n1:\tjalrs?\t" 2 } } */ + +extern void g (void); + +int +NOMIPS16 f () +{ + g (); + g (); + return 1; +} diff --git a/gcc/testsuite/gcc.target/mips/call-3.c b/gcc/testsuite/gcc.target/mips/call-3.c index 08cf336a424..c52bc74d12b 100644 --- a/gcc/testsuite/gcc.target/mips/call-3.c +++ b/gcc/testsuite/gcc.target/mips/call-3.c @@ -1,5 +1,5 @@ -/* { dg-options "-mrelax-pic-calls -mno-shared" } */ -/* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,g\n1:\tjalrc?s?\t" } } */ +/* { dg-options "-mno-micromips -mrelax-pic-calls -mno-shared" } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,g\n1:\tjalrc?\t" } } */ /* { dg-require-visibility "" } */ __attribute__ ((visibility ("hidden"))) void g (); diff --git a/gcc/testsuite/gcc.target/mips/call-3u.c b/gcc/testsuite/gcc.target/mips/call-3u.c new file mode 100644 index 00000000000..f8d557d27c5 --- /dev/null +++ b/gcc/testsuite/gcc.target/mips/call-3u.c @@ -0,0 +1,12 @@ +/* { dg-options "-mmicromips -mrelax-pic-calls -mno-shared" } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MICROMIPS_JALR,g\n1:\tjalrs?\t" } } */ +/* { dg-require-visibility "" } */ + +__attribute__ ((visibility ("hidden"))) void g (); + +int +NOMIPS16 f () +{ + g (); + return 1; +} diff --git a/gcc/testsuite/gcc.target/mips/call-4.c b/gcc/testsuite/gcc.target/mips/call-4.c index bf357c7a5b0..eb79d0d2a25 100644 --- a/gcc/testsuite/gcc.target/mips/call-4.c +++ b/gcc/testsuite/gcc.target/mips/call-4.c @@ -1,5 +1,5 @@ /* See through some simple data-flow. */ -/* { dg-options "-mrelax-pic-calls" } */ +/* { dg-options "-mno-micromips -mrelax-pic-calls" } */ /* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,g\n1:\tjalrc?\t" } } */ extern void g (void); diff --git a/gcc/testsuite/gcc.target/mips/call-4u.c b/gcc/testsuite/gcc.target/mips/call-4u.c new file mode 100644 index 00000000000..70bc3993033 --- /dev/null +++ b/gcc/testsuite/gcc.target/mips/call-4u.c @@ -0,0 +1,12 @@ +/* See through some simple data-flow. */ +/* { dg-options "-mmicromips -mrelax-pic-calls" } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MICROMIPS_JALR,g\n1:\tjalrs?\t" } } */ + +extern void g (void); + +int +NOMIPS16 f (int i) +{ + while (i--) + g (); +} diff --git a/gcc/testsuite/gcc.target/mips/call-5.c b/gcc/testsuite/gcc.target/mips/call-5.c index f6ebae9db79..822dc77bc91 100644 --- a/gcc/testsuite/gcc.target/mips/call-5.c +++ b/gcc/testsuite/gcc.target/mips/call-5.c @@ -1,6 +1,6 @@ /* Like call-1.c, but for n32. We cannot use sibling calls for tail and tail2 in this case (PR target/57260). */ -/* { dg-options "-mrelax-pic-calls -mshared -foptimize-sibling-calls -mabi=n32" } */ +/* { dg-options "-mno-micromips -mrelax-pic-calls -mshared -foptimize-sibling-calls -mabi=n32" } */ /* { dg-skip-if "requires -foptimize-sibling-calls" { *-*-* } { "-O0" } { "" } } */ /* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,normal\n1:\tjalrc?\t" } } */ /* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,normal2\n1:\tjalrc?\t" } } */ diff --git a/gcc/testsuite/gcc.target/mips/call-5u.c b/gcc/testsuite/gcc.target/mips/call-5u.c new file mode 100644 index 00000000000..e98c059599d --- /dev/null +++ b/gcc/testsuite/gcc.target/mips/call-5u.c @@ -0,0 +1,53 @@ +/* Like call-1.c, but for n32. We cannot use sibling calls for tail and tail2 + in this case (PR target/57260). */ +/* { dg-options "-mmicromips -mrelax-pic-calls -mshared -foptimize-sibling-calls -mabi=n32" } */ +/* { dg-skip-if "requires -foptimize-sibling-calls" { *-*-* } { "-O0" } { "" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MICROMIPS_JALR,normal\n1:\tjalrs?\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MICROMIPS_JALR,normal2\n1:\tjalrs?\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MICROMIPS_JALR,staticfunc\n1:\tjalrs?\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MICROMIPS_JALR,tail\n1:\tjalrs?\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MICROMIPS_JALR,tail2\n1:\tjalrs?\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MICROMIPS_JALR,tail3\n1:\tjrc?\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MICROMIPS_JALR,tail4\n1:\tjrc?\t" } } */ + +__attribute__ ((noinline)) static void staticfunc () { asm (""); } +int normal (); +void normal2 (); + +int +NOMIPS16 f (int *p) +{ + *p = normal (); + normal2 (); + staticfunc (); + return 1; +} + +int tail (); + +int +NOMIPS16 h () +{ + return tail (); +} + +void tail2 (); + +NOMIPS16 void g () +{ + tail2 (); +} + +__attribute__ ((visibility ("hidden"))) void tail3 (); + +NOMIPS16 void j () +{ + tail3 (); +} + +__attribute__ ((noinline)) static void tail4 () { asm (""); } + +NOMIPS16 void k () +{ + tail4 (); +} diff --git a/gcc/testsuite/gcc.target/mips/call-6.c b/gcc/testsuite/gcc.target/mips/call-6.c index 00f4a1ef353..0267751773f 100644 --- a/gcc/testsuite/gcc.target/mips/call-6.c +++ b/gcc/testsuite/gcc.target/mips/call-6.c @@ -1,5 +1,5 @@ /* Like call-5.c, but for n64. */ -/* { dg-options "-mrelax-pic-calls -mshared -foptimize-sibling-calls -mabi=64" } */ +/* { dg-options "-mno-micromips -mrelax-pic-calls -mshared -foptimize-sibling-calls -mabi=64" } */ /* { dg-skip-if "requires -foptimize-sibling-calls" { *-*-* } { "-O0" } { "" } } */ /* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,normal\n1:\tjalrc?\t" } } */ /* { dg-final { scan-assembler "\\.reloc\t1f,R_MIPS_JALR,normal2\n1:\tjalrc?\t" } } */ diff --git a/gcc/testsuite/gcc.target/mips/call-6u.c b/gcc/testsuite/gcc.target/mips/call-6u.c new file mode 100644 index 00000000000..5d3b15ebf35 --- /dev/null +++ b/gcc/testsuite/gcc.target/mips/call-6u.c @@ -0,0 +1,52 @@ +/* Like call-5.c, but for n64. */ +/* { dg-options "-mmicromips -mrelax-pic-calls -mshared -foptimize-sibling-calls -mabi=64" } */ +/* { dg-skip-if "requires -foptimize-sibling-calls" { *-*-* } { "-O0" } { "" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MICROMIPS_JALR,normal\n1:\tjalrs?\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MICROMIPS_JALR,normal2\n1:\tjalrs?\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MICROMIPS_JALR,staticfunc\n1:\tjalrs?\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MICROMIPS_JALR,tail\n1:\tjalrs?\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MICROMIPS_JALR,tail2\n1:\tjalrs?\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MICROMIPS_JALR,tail3\n1:\tjrc?\t" } } */ +/* { dg-final { scan-assembler "\\.reloc\t1f,R_MICROMIPS_JALR,tail4\n1:\tjrc?\t" } } */ + +__attribute__ ((noinline)) static void staticfunc () { asm (""); } +int normal (); +void normal2 (); + +int +NOMIPS16 f (int *p) +{ + *p = normal (); + normal2 (); + staticfunc (); + return 1; +} + +int tail (); + +int +NOMIPS16 h () +{ + return tail (); +} + +void tail2 (); + +NOMIPS16 void g () +{ + tail2 (); +} + +__attribute__ ((visibility ("hidden"))) void tail3 (); + +NOMIPS16 void j () +{ + tail3 (); +} + +__attribute__ ((noinline)) static void tail4 () { asm (""); } + +NOMIPS16 void k () +{ + tail4 (); +} -- 2.30.2