MIPS: Fix failing branch range checks for micromips.
authorAndrew Bennett <andrew.bennett@imgtec.com>
Wed, 8 Jul 2015 09:40:35 +0000 (09:40 +0000)
committerAndrew Bennett <abennett@gcc.gnu.org>
Wed, 8 Jul 2015 09:40:35 +0000 (09:40 +0000)
The current branch range tests assume that the MIPS branch instructions
have a 16 bit branch offset which is shifted by 2.  Unfortunately for microMIPS
this offset is shifted by 1 which reduces the branch range and caused the
branch-*.c tests to fail.

testsuite/
* gcc.target/mips/branch-2.c: Change NOMIPS16 to NOCOMPRESSION.
* gcc.target/mips/branch-3.c: Ditto
* gcc.target/mips/branch-4.c: Ditto.
* gcc.target/mips/branch-5.c: Ditto.
* gcc.target/mips/branch-6.c: Ditto.
* gcc.target/mips/branch-7.c: Ditto.
* gcc.target/mips/branch-8.c: Ditto.
* gcc.target/mips/branch-9.c: Ditto.
* gcc.target/mips/branch-10.c: Ditto.
* gcc.target/mips/branch-11.c: Ditto.
* gcc.target/mips/branch-12.c: Ditto.
* gcc.target/mips/branch-13.c: Ditto.
* gcc.target/mips/umips-branch-5.c: New file.
* gcc.target/mips/umips-branch-6.c: New file.
* gcc.target/mips/umips-branch-7.c: New file.
* gcc.target/mips/umips-branch-8.c: New file.
* gcc.target/mips/umips-branch-9.c: New file.
* gcc.target/mips/umips-branch-10.c: New file.
* gcc.target/mips/umips-branch-11.c: New file.
* gcc.target/mips/umips-branch-12.c: New file.
* gcc.target/mips/umips-branch-13.c: New file.
* gcc.target/mips/umips-branch-14.c: New file.
* gcc.target/mips/umips-branch-15.c: New file.
* gcc.target/mips/umips-branch-16.c: New file.
* gcc.target/mips/branch-helper.h (OCCUPY_0x10000): New define.
(OCCUPY_0xfffc): New define.

From-SVN: r225540

26 files changed:
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/mips/branch-10.c
gcc/testsuite/gcc.target/mips/branch-11.c
gcc/testsuite/gcc.target/mips/branch-12.c
gcc/testsuite/gcc.target/mips/branch-13.c
gcc/testsuite/gcc.target/mips/branch-2.c
gcc/testsuite/gcc.target/mips/branch-3.c
gcc/testsuite/gcc.target/mips/branch-4.c
gcc/testsuite/gcc.target/mips/branch-5.c
gcc/testsuite/gcc.target/mips/branch-6.c
gcc/testsuite/gcc.target/mips/branch-7.c
gcc/testsuite/gcc.target/mips/branch-8.c
gcc/testsuite/gcc.target/mips/branch-9.c
gcc/testsuite/gcc.target/mips/branch-helper.h
gcc/testsuite/gcc.target/mips/umips-branch-10.c [new file with mode: 0644]
gcc/testsuite/gcc.target/mips/umips-branch-11.c [new file with mode: 0644]
gcc/testsuite/gcc.target/mips/umips-branch-12.c [new file with mode: 0644]
gcc/testsuite/gcc.target/mips/umips-branch-13.c [new file with mode: 0644]
gcc/testsuite/gcc.target/mips/umips-branch-14.c [new file with mode: 0644]
gcc/testsuite/gcc.target/mips/umips-branch-15.c [new file with mode: 0644]
gcc/testsuite/gcc.target/mips/umips-branch-16.c [new file with mode: 0644]
gcc/testsuite/gcc.target/mips/umips-branch-5.c [new file with mode: 0644]
gcc/testsuite/gcc.target/mips/umips-branch-6.c [new file with mode: 0644]
gcc/testsuite/gcc.target/mips/umips-branch-7.c [new file with mode: 0644]
gcc/testsuite/gcc.target/mips/umips-branch-8.c [new file with mode: 0644]
gcc/testsuite/gcc.target/mips/umips-branch-9.c [new file with mode: 0644]

index 9ee034f4ed8b12329dc125085ef9bb8921e3be88..f02d3e5f167d9d97edef08c4b59e5cd7f03bb4e1 100644 (file)
@@ -1,3 +1,32 @@
+2015-07-08  Andrew Bennett  <andrew.bennett@imgtec.com>
+
+       * gcc.target/mips/branch-2.c: Change NOMIPS16 to NOCOMPRESSION.
+       * gcc.target/mips/branch-3.c: Ditto
+       * gcc.target/mips/branch-4.c: Ditto.
+       * gcc.target/mips/branch-5.c: Ditto.
+       * gcc.target/mips/branch-6.c: Ditto.
+       * gcc.target/mips/branch-7.c: Ditto.
+       * gcc.target/mips/branch-8.c: Ditto.
+       * gcc.target/mips/branch-9.c: Ditto.
+       * gcc.target/mips/branch-10.c: Ditto.
+       * gcc.target/mips/branch-11.c: Ditto.
+       * gcc.target/mips/branch-12.c: Ditto.
+       * gcc.target/mips/branch-13.c: Ditto.
+       * gcc.target/mips/umips-branch-5.c: New file.
+       * gcc.target/mips/umips-branch-6.c: New file.
+       * gcc.target/mips/umips-branch-7.c: New file.
+       * gcc.target/mips/umips-branch-8.c: New file.
+       * gcc.target/mips/umips-branch-9.c: New file.
+       * gcc.target/mips/umips-branch-10.c: New file.
+       * gcc.target/mips/umips-branch-11.c: New file.
+       * gcc.target/mips/umips-branch-12.c: New file.
+       * gcc.target/mips/umips-branch-13.c: New file.
+       * gcc.target/mips/umips-branch-14.c: New file.
+       * gcc.target/mips/umips-branch-15.c: New file.
+       * gcc.target/mips/umips-branch-16.c: New file.
+       * gcc.target/mips/branch-helper.h (OCCUPY_0x10000): New define.  
+       (OCCUPY_0xfffc): New define.
+
 2015-07-08  Renlin Li  <renlin.li@arm.com>
 
        * gcc.target/arm/unsigned-float.c: Different options for hf toolchain.
index e2b1b5f6baabd53a99c2a5c9fec5d0d743fc5fd5..eb21c16546266c3ee513f9c8a8627cd06ff302f2 100644 (file)
@@ -4,7 +4,7 @@
 
 #include "branch-helper.h"
 
-NOMIPS16 void
+NOCOMPRESSION void
 foo (int (*bar) (void), int *x)
 {
   *x = bar ();
index 962eb1b5d66a2ed99ee00adac51a9bb3ae829979..bd8e83418c00dadc01f3131f2dc663fb8d092c99 100644 (file)
@@ -8,7 +8,7 @@
 
 #include "branch-helper.h"
 
-NOMIPS16 void
+NOCOMPRESSION void
 foo (int (*bar) (void), int *x)
 {
   *x = bar ();
index 4aef160ade8a13a6dcb8356d43d5c31878114523..49446341ad29236c6582d91c4f1f59ceca2e6cab 100644 (file)
@@ -4,7 +4,7 @@
 
 #include "branch-helper.h"
 
-NOMIPS16 void
+NOCOMPRESSION void
 foo (int (*bar) (void), int *x)
 {
   *x = bar ();
index 8a6fb049f2444e569eed10b898c83dda8049edf1..f5269b9b33b7017efc697d984ec9d49be5bd1b5a 100644 (file)
@@ -8,7 +8,7 @@
 
 #include "branch-helper.h"
 
-NOMIPS16 void
+NOCOMPRESSION void
 foo (int (*bar) (void), int *x)
 {
   *x = bar ();
index 6409c4cc509e03154c31d1725b93253b33506d24..b60e9cd2e3ce8549c1f935a0d81b9a07a66f8221 100644 (file)
@@ -5,7 +5,7 @@
 
 #include "branch-helper.h"
 
-NOMIPS16 void
+NOCOMPRESSION void
 foo (volatile int *x)
 {
   if (__builtin_expect (*x == 0, 1))
index 5fcfece3e9abf3937db98337ce8c478172159692..69300f6417c3728314e9e57269467262c5e1dbab 100644 (file)
@@ -5,7 +5,7 @@
 
 #include "branch-helper.h"
 
-NOMIPS16 void
+NOCOMPRESSION void
 foo (volatile int *x)
 {
   if (__builtin_expect (*x == 0, 1))
index 31e4909e58fe3a54a0ba28362a83fd79d7a1694d..29f5c9f2be3e10a499c7a5ee411bd4840ecc19b0 100644 (file)
@@ -4,7 +4,7 @@
 
 #include "branch-helper.h"
 
-NOMIPS16 void
+NOCOMPRESSION void
 foo (volatile int *x)
 {
   if (__builtin_expect (*x == 0, 1))
index 1e9c120c8343d7a14cfffab47a2616147fc6a6ca..0538646210af8ae64290ff1c15067edc300822dc 100644 (file)
@@ -6,7 +6,7 @@
 
 #include "branch-helper.h"
 
-NOMIPS16 void
+NOCOMPRESSION void
 foo (volatile int *x)
 {
   if (__builtin_expect (*x == 0, 1))
index 77e0340eb2eb15a25fee3cebdcb965d72d9b4005..19baee1db9ff493e51abd9b690167f8478061266 100644 (file)
@@ -4,7 +4,7 @@
 
 #include "branch-helper.h"
 
-NOMIPS16 void
+NOCOMPRESSION void
 foo (volatile int *x)
 {
   if (__builtin_expect (*x == 0, 1))
index 8ad6808c8dfde3ab9bbb1577c486497f425f17f4..16c6d8e1ac65b64281b2fbd4b4f8bca6521a6374 100644 (file)
@@ -6,7 +6,7 @@
 
 #include "branch-helper.h"
 
-NOMIPS16 void
+NOCOMPRESSION void
 foo (volatile int *x)
 {
   if (__builtin_expect (*x == 0, 1))
index ba5f954378c8435d9f72c342b5713baf39c91a66..2e468448fe9a4478109e3c6d2834081d13ec9d49 100644 (file)
@@ -4,7 +4,7 @@
 
 #include "branch-helper.h"
 
-NOMIPS16 void
+NOCOMPRESSION void
 foo (int (*bar) (void), int *x)
 {
   *x = bar ();
index cad1c003c3ef3416aa1772efedc9279204342aed..b87f2ba675b5e842682f1231480d08acf86ba9e6 100644 (file)
@@ -9,7 +9,7 @@
 
 #include "branch-helper.h"
 
-NOMIPS16 void
+NOCOMPRESSION void
 foo (int (*bar) (void), int *x)
 {
   *x = bar ();
index 85399be4c7df5c5330c138c8ee8c958eb50c3596..3d033cc2cb8dab7ca476f506e2db97e2c5829682 100644 (file)
        D2 ("nop") "\n\t" \
        D1 ("nop"))
 
+/* Emit something that is 0xfffc bytes long, which is the largest
+   permissible range for microMIPS forward branches when branches
+   have delay slots.  */
+#define OCCUPY_0xfffc \
+  asm (D13 ("nop32") "\n\t" \
+       D12 ("nop32") "\n\t" \
+       D11 ("nop32") "\n\t" \
+       D10 ("nop32") "\n\t" \
+       D9 ("nop32") "\n\t" \
+       D8 ("nop32") "\n\t" \
+       D7 ("nop32") "\n\t" \
+       D6 ("nop32") "\n\t" \
+       D5 ("nop32") "\n\t" \
+       D4 ("nop32") "\n\t" \
+       D3 ("nop32") "\n\t" \
+       D2 ("nop32") "\n\t" \
+       D1 ("nop32") "\n\t" \
+       D0 ("nop32"))
 /* Likewise emit something that is 0x1fffc bytes long.  */
 #define OCCUPY_0x1fffc do { asm ("nop"); OCCUPY_0x1fff8; } while (0)
+/* Likewise emit something that is 0x10000 bytes long.  */
+#define OCCUPY_0x10000 do { asm ("nop32"); OCCUPY_0xfffc; } while (0)
diff --git a/gcc/testsuite/gcc.target/mips/umips-branch-10.c b/gcc/testsuite/gcc.target/mips/umips-branch-10.c
new file mode 100644 (file)
index 0000000..714691b
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-options "-mshared -mabi=64 -mmicromips" } */
+/* { dg-final { scan-assembler "\tdaddiu\t\\\$3,\\\$3,%lo\\(%neg\\(%gp_rel\\(foo\\)\\)\\)\n" } } */
+/* { dg-final { scan-assembler "\tld\t\\\$1,%got_page\\(\[^)\]*\\)\\(\\\$3\\)\\n" } } */
+/* { dg-final { scan-assembler "\tjr\t\\\$1\n" } } */
+/* { dg-final { scan-assembler-not "\\\$28" } } */
+
+#include "branch-helper.h"
+
+NOMIPS16 void
+foo (volatile int *x)
+{
+  if (__builtin_expect (*x == 0, 1))
+    OCCUPY_0x10000;
+}
diff --git a/gcc/testsuite/gcc.target/mips/umips-branch-11.c b/gcc/testsuite/gcc.target/mips/umips-branch-11.c
new file mode 100644 (file)
index 0000000..5050669
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-options "-mshared -mabi=32 -mmicromips" } */
+/* { dg-final { scan-assembler-not "(\\\$28|cpload|cprestore)" } } */
+/* { dg-final { scan-assembler-not "\tjrc?\t\\\$1\n" } } */
+
+#include "branch-helper.h"
+
+NOMIPS16 void
+foo (int (*bar) (void), int *x)
+{
+  *x = bar ();
+  if (__builtin_expect (*x == 0, 1))
+    OCCUPY_0xfffc;
+}
diff --git a/gcc/testsuite/gcc.target/mips/umips-branch-12.c b/gcc/testsuite/gcc.target/mips/umips-branch-12.c
new file mode 100644 (file)
index 0000000..a393de9
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-options "-mshared -mabi=32 -mmicromips" } */
+/* { dg-final { scan-assembler "\t\\.cpload\t\\\$25\n" } } */
+/* { dg-final { scan-assembler "\t\\.cprestore\t16\n" } } */
+/* { dg-final { scan-assembler "\tlw\t\\\$1,16\\(\\\$(fp|sp)\\)\n" } } */
+/* { dg-final { scan-assembler "\tlw\t\\\$1,%got\\(\[^)\]*\\)\\(\\\$1\\)\n" } } */
+/* { dg-final { scan-assembler "\taddiu\t\\\$1,\\\$1,%lo\\(\[^)\]*\\)\n" } } */
+/* { dg-final { scan-assembler "\tjr\t\\\$1\n" } } */
+/* { dg-final { scan-assembler-not "\\\$28" } } */
+
+#include "branch-helper.h"
+
+NOMIPS16 void
+foo (int (*bar) (void), int *x)
+{
+  *x = bar ();
+  if (__builtin_expect (*x == 0, 1))
+    OCCUPY_0x10000;
+}
diff --git a/gcc/testsuite/gcc.target/mips/umips-branch-13.c b/gcc/testsuite/gcc.target/mips/umips-branch-13.c
new file mode 100644 (file)
index 0000000..e84b462
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-options "-mshared -mabi=n32 -mmicromips" } */
+/* { dg-final { scan-assembler-not "(\\\$28|%gp_rel|%got)" } } */
+/* { dg-final { scan-assembler-not "\tjrc?\t\\\$1\n" } } */
+
+#include "branch-helper.h"
+
+NOMIPS16 void
+foo (int (*bar) (void), int *x)
+{
+  *x = bar ();
+  if (__builtin_expect (*x == 0, 1))
+    OCCUPY_0xfffc;
+}
diff --git a/gcc/testsuite/gcc.target/mips/umips-branch-14.c b/gcc/testsuite/gcc.target/mips/umips-branch-14.c
new file mode 100644 (file)
index 0000000..f9f30a7
--- /dev/null
@@ -0,0 +1,17 @@
+/* { dg-options "-mshared -mabi=n32 -mmicromips" } */
+/* { dg-final { scan-assembler "\tsd\t\\\$28," } } */
+/* { dg-final { scan-assembler "\tld\t\\\$28," } } */
+/* { dg-final { scan-assembler "\taddiu\t\\\$28,\\\$28,%lo\\(%neg\\(%gp_rel\\(foo\\)\\)\\)\n" } } */
+/* { dg-final { scan-assembler "\tlw\t\\\$1,%got_page\\(\[^)\]*\\)\\(\\\$28\\)\n" } } */
+/* { dg-final { scan-assembler "\taddiu\t\\\$1,\\\$1,%got_ofst\\(\[^)\]*\\)\n" } } */
+/* { dg-final { scan-assembler "\tjr\t\\\$1\n" } } */
+
+#include "branch-helper.h"
+
+NOMIPS16 void
+foo (int (*bar) (void), int *x)
+{
+  *x = bar ();
+  if (__builtin_expect (*x == 0, 1))
+    OCCUPY_0x10000;
+}
diff --git a/gcc/testsuite/gcc.target/mips/umips-branch-15.c b/gcc/testsuite/gcc.target/mips/umips-branch-15.c
new file mode 100644 (file)
index 0000000..6704aad
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-options "-mshared -mabi=64 -mmicromips" } */
+/* { dg-final { scan-assembler-not "(\\\$28|%gp_rel|%got)" } } */
+/* { dg-final { scan-assembler-not "\tjrc?\t\\\$1\n" } } */
+
+#include "branch-helper.h"
+
+NOMIPS16 void
+foo (int (*bar) (void), int *x)
+{
+  *x = bar ();
+  if (__builtin_expect (*x == 0, 1))
+    OCCUPY_0xfffc;
+}
diff --git a/gcc/testsuite/gcc.target/mips/umips-branch-16.c b/gcc/testsuite/gcc.target/mips/umips-branch-16.c
new file mode 100644 (file)
index 0000000..95f7db5
--- /dev/null
@@ -0,0 +1,17 @@
+/* { dg-options "-mshared -mabi=64 -mmicromips" } */
+/* { dg-final { scan-assembler "\tsd\t\\\$28," } } */
+/* { dg-final { scan-assembler "\tld\t\\\$28," } } */
+/* { dg-final { scan-assembler "\tdaddiu\t\\\$28,\\\$28,%lo\\(%neg\\(%gp_rel\\(foo\\)\\)\\)\n" } } */
+/* { dg-final { scan-assembler "\tld\t\\\$1,%got_page\\(\[^)\]*\\)\\(\\\$28\\)\n" } } */
+/* { dg-final { scan-assembler "\tdaddiu\t\\\$1,\\\$1,%got_ofst\\(\[^)\]*\\)\n" } } */
+/* { dg-final { scan-assembler "\tjr\t\\\$1\n" } } */
+
+#include "branch-helper.h"
+
+NOMIPS16 void
+foo (int (*bar) (void), int *x)
+{
+  *x = bar ();
+  if (__builtin_expect (*x == 0, 1))
+    OCCUPY_0x10000;
+}
diff --git a/gcc/testsuite/gcc.target/mips/umips-branch-5.c b/gcc/testsuite/gcc.target/mips/umips-branch-5.c
new file mode 100644 (file)
index 0000000..d124f91
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-options "-mshared -mabi=32 -mmicromips" } */
+/* { dg-final { scan-assembler-not "(\\\$25|\\\$28|cpload)" } } */
+/* { dg-final { scan-assembler-not "\tjr\t\\\$1\n" } } */
+/* { dg-final { scan-assembler-not "\\.cprestore" } } */
+
+#include "branch-helper.h"
+
+NOMIPS16 void
+foo (volatile int *x)
+{
+  if (__builtin_expect (*x == 0, 1))
+    OCCUPY_0xfffc;
+}
diff --git a/gcc/testsuite/gcc.target/mips/umips-branch-6.c b/gcc/testsuite/gcc.target/mips/umips-branch-6.c
new file mode 100644 (file)
index 0000000..d688bc9
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-options "-mshared -mabi=32 -mmicromips" } */
+/* { dg-final { scan-assembler "\t\\.cpload\t\\\$25\n" } } */
+/* { dg-final { scan-assembler "\tjr\t\\\$1\n" } } */
+/* { dg-final { scan-assembler-not "\\.cprestore" } } */
+
+#include "branch-helper.h"
+
+NOMIPS16 void
+foo (volatile int *x)
+{
+  if (__builtin_expect (*x == 0, 1))
+    OCCUPY_0x10000;
+}
diff --git a/gcc/testsuite/gcc.target/mips/umips-branch-7.c b/gcc/testsuite/gcc.target/mips/umips-branch-7.c
new file mode 100644 (file)
index 0000000..294805a
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-options "-mshared -mabi=n32 -mmicromips" } */
+/* { dg-final { scan-assembler-not "(\\\$25|\\\$28|%gp_rel|%got)" } } */
+/* { dg-final { scan-assembler-not "\tjrc?\t\\\$1\n" } } */
+
+#include "branch-helper.h"
+
+NOMIPS16 void
+foo (volatile int *x)
+{
+  if (__builtin_expect (*x == 0, 1))
+    OCCUPY_0xfffc;
+}
diff --git a/gcc/testsuite/gcc.target/mips/umips-branch-8.c b/gcc/testsuite/gcc.target/mips/umips-branch-8.c
new file mode 100644 (file)
index 0000000..02273cf
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-options "-mshared -mabi=n32 -mmicromips" } */
+/* { dg-final { scan-assembler "\taddiu\t\\\$3,\\\$3,%lo\\(%neg\\(%gp_rel\\(foo\\)\\)\\)\n" } } */
+/* { dg-final { scan-assembler "\tlw\t\\\$1,%got_page\\(\[^)\]*\\)\\(\\\$3\\)\\n" } } */
+/* { dg-final { scan-assembler "\tjr\t\\\$1\n" } } */
+/* { dg-final { scan-assembler-not "\\\$28" } } */
+
+#include "branch-helper.h"
+
+NOMIPS16 void
+foo (volatile int *x)
+{
+  if (__builtin_expect (*x == 0, 1))
+    OCCUPY_0x10000;
+}
diff --git a/gcc/testsuite/gcc.target/mips/umips-branch-9.c b/gcc/testsuite/gcc.target/mips/umips-branch-9.c
new file mode 100644 (file)
index 0000000..ab02e88
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-options "-mshared -mabi=64 -mmicromips" } */
+/* { dg-final { scan-assembler-not "(\\\$25|\\\$28|%gp_rel|%got)" } } */
+/* { dg-final { scan-assembler-not "\tjrc?\t\\\$1\n" } } */
+
+#include "branch-helper.h"
+
+NOMIPS16 void
+foo (volatile int *x)
+{
+  if (__builtin_expect (*x == 0, 1))
+    OCCUPY_0xfffc;
+}