fix for rs6000 branch shortening

Geoff Keating geoffk@geoffk.org
Wed Dec 27 03:00:00 GMT 2000


The attached patch and testcase fixes two bugs in the rs6000 branch
shortening code.

The testcase does take a little while to compile, but I think it's
worth it to more thoroughly test this part of the compiler.

Tested on powerpc-eabisim.

-- 
- Geoffrey Keating <geoffk@geoffk.org>

===File ~/patches/cygnus/rs6000-lengthbug.patch=============
2000-12-27  Geoffrey Keating  <geoffk@redhat.com>

	* config/rs6000/rs6000.md (define_attr "length"): Correct
	calculation.

2000-12-26  Geoffrey Keating  <geoffk@redhat.com>

	* gcc.c-torture/compile/20001226-1.c: New test.

Index: config/rs6000/rs6000.md
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/rs6000.md,v
retrieving revision 1.107
diff -u -p -r1.107 rs6000.md
--- rs6000.md	2000/12/03 07:08:48	1.107
+++ rs6000.md	2000/12/27 10:57:29
@@ -41,12 +41,14 @@
   (const_string "integer"))
 
 ;; Length (in bytes).
+; '(pc)' in the following doesn't include the instruction itself; it is 
+; calculated as if the instruction had zero size.
 (define_attr "length" ""
   (if_then_else (eq_attr "type" "branch")
-		(if_then_else (and (ge (minus (pc) (match_dup 0))
+		(if_then_else (and (ge (minus (match_dup 0) (pc))
 				       (const_int -32768))
-				   (lt (minus (pc) (match_dup 0))
-				       (const_int 32767)))
+				   (lt (minus (match_dup 0) (pc))
+				       (const_int 32764)))
 			      (const_int 4)
 			      (const_int 8))
 		(const_int 4)))
Index: testsuite/gcc.c-torture/compile/20001226-1.c
===================================================================
RCS file: 20001226-1.c
diff -N 20001226-1.c
--- /dev/null	Tue May  5 13:32:27 1998
+++ 20001226-1.c	Wed Dec 27 02:57:29 2000
@@ -0,0 +1,26 @@
+/* This testcase exposed two branch shortening bugs on powerpc.  */
+
+#define C(a,b) \
+  if (a > b)  goto gt; \
+  if (a < b)  goto lt;
+
+#define C4(x,b) C((x)[0], b) C((x)[1],b) C((x)[2],b) C((x)[3],b)
+#define C16(x,y) C4(x, (y)[0]) C4(x, (y)[1]) C4(x, (y)[2]) C4(x, (y)[3])
+
+#define C64(x,y) C16(x,y) C16(x+4,y) C16(x+8,y) C16(x+12,y)
+#define C256(x,y) C64(x,y) C64(x,y+4) C64(x,y+8) C64(x,y+12)
+
+#define C1024(x,y) C256(x,y) C256(x+16,y) C256(x+32,y) C256(x+48,y)
+#define C4096(x,y) C1024(x,y) C1024(x,y+16) C1024(x,y+32) C1024(x,y+48)
+
+unsigned foo(int x[64], int y[64])
+{
+  C4096(x,y);
+  
+  return 0x01234567;
+ gt:
+  return 0x12345678;
+ lt:
+  return 0xF0123456;
+}
+
============================================================


More information about the Gcc-patches mailing list