This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix global.c ICE for atypical testcase.


While looking at the memory regression compiling the testcase in PR28071,
I noticed we ICE on powerpc64-linux due to the bit number calculation
overflowing an "int" because we have over 50K allocnos.  This somewhat
obvious patch fixes the overflow and has passed bootstrapping and
regtesting on powerpc64-linux.

Ok for mainline?

Peter

	* ra-conflict.c (partial_bitnum, max_bitnum): Change type of variables
	to HOST_WIDE_INT.
	(conflict_p, set_conflict, set_conflicts): Likewise.
	* global.c (global_alloc): Likewise.
	* ra.h: Update prototypes.

Index: ra-conflict.c
===================================================================
--- ra-conflict.c	(revision 129209)
+++ ra-conflict.c	(working copy)
@@ -49,8 +49,8 @@ int max_allocno;
 struct allocno *allocno;
 HOST_WIDEST_FAST_INT *conflicts;
 int *reg_allocno;
-int *partial_bitnum;
-int max_bitnum;
+HOST_WIDE_INT *partial_bitnum;
+HOST_WIDE_INT max_bitnum;
 alloc_pool adjacency_pool;
 adjacency_t **adjacency;
 
@@ -70,7 +70,7 @@ DEF_VEC_ALLOC_P(df_ref_t,heap);
 bool
 conflict_p (int allocno1, int allocno2)
 {
-  int bitnum;
+  HOST_WIDE_INT bitnum;
   HOST_WIDEST_FAST_INT word, mask;
 
 #ifdef ENABLE_CHECKING
@@ -104,7 +104,7 @@ conflict_p (int allocno1, int allocno2)
 static void
 set_conflict (int allocno1, int allocno2)
 {
-  int bitnum, index;
+  HOST_WIDE_INT bitnum, index;
   HOST_WIDEST_FAST_INT word, mask;
 
 #ifdef ENABLE_CHECKING
@@ -146,9 +146,9 @@ static void
 set_conflicts (int allocno1, sparseset live)
 {
   int i;
-  int bitnum, index;
+  HOST_WIDE_INT bitnum, index;
   HOST_WIDEST_FAST_INT word, mask;
-  int partial_bitnum_allocno1;
+  HOST_WIDE_INT partial_bitnum_allocno1;
 
 #ifdef ENABLE_CHECKING
   gcc_assert (allocno1 >= 0 && allocno1 < max_allocno);
Index: global.c
===================================================================
--- global.c	(revision 129209)
+++ global.c	(working copy)
@@ -389,7 +389,7 @@ global_alloc (void)
       }
 
   allocno = XCNEWVEC (struct allocno, max_allocno);
-  partial_bitnum = XNEWVEC (int, max_allocno);
+  partial_bitnum = XNEWVEC (HOST_WIDE_INT, max_allocno);
   num_allocnos_per_blk = XCNEWVEC (int, max_blk + 1);
 
   /* ...so we can sort them in the order we want them to receive
@@ -432,12 +432,14 @@ global_alloc (void)
     }
 
 #ifdef ENABLE_CHECKING
-  gcc_assert (max_bitnum <= ((max_allocno * (max_allocno - 1)) / 2));
+  gcc_assert (max_bitnum <=
+	      (((HOST_WIDE_INT) max_allocno *
+		((HOST_WIDE_INT) max_allocno - 1)) / 2));
 #endif
 
   if (dump_file)
     {
-      int num_bits, num_bytes, actual_bytes;
+      HOST_WIDE_INT num_bits, num_bytes, actual_bytes;
 
       fprintf (dump_file, "## max_blk:     %d\n", max_blk);
       fprintf (dump_file, "## max_regno:   %d\n", max_regno);
@@ -447,21 +449,23 @@ global_alloc (void)
       num_bytes = CEIL (num_bits, 8);
       actual_bytes = num_bytes;
       fprintf (dump_file, "## Compressed triangular bitmatrix size: ");
-      fprintf (dump_file, "%d bits, %d bytes\n", num_bits, num_bytes);
+      fprintf (dump_file, HOST_WIDE_INT_PRINT_DEC " bits, ", num_bits);
+      fprintf (dump_file, HOST_WIDE_INT_PRINT_DEC " bytes\n", num_bytes);
 
-      num_bits = (max_allocno * (max_allocno - 1)) / 2;
+      num_bits = ((HOST_WIDE_INT) max_allocno *
+		  ((HOST_WIDE_INT) max_allocno - 1)) / 2;
       num_bytes = CEIL (num_bits, 8);
       fprintf (dump_file, "## Standard triangular bitmatrix size:   ");
-      fprintf (dump_file, "%d bits, %d bytes [%.2f%%]\n",
-	       num_bits, num_bytes,
-	       100.0 * ((double) actual_bytes / (double) num_bytes));
+      fprintf (dump_file, HOST_WIDE_INT_PRINT_DEC " bits, ", num_bits);
+      fprintf (dump_file, HOST_WIDE_INT_PRINT_DEC " bytes [%.2f%%]\n",
+	       num_bytes, 100.0 * ((double) actual_bytes / (double) num_bytes));
 
-      num_bits = max_allocno * max_allocno;
+      num_bits = (HOST_WIDE_INT) max_allocno * (HOST_WIDE_INT) max_allocno;
       num_bytes = CEIL (num_bits, 8);
       fprintf (dump_file, "## Square bitmatrix size:                ");
-      fprintf (dump_file, "%d bits, %d bytes [%.2f%%]\n",
-	       num_bits, num_bytes,
-	       100.0 * ((double) actual_bytes / (double) num_bytes));
+      fprintf (dump_file, HOST_WIDE_INT_PRINT_DEC " bits, ", num_bits);
+      fprintf (dump_file, HOST_WIDE_INT_PRINT_DEC " bytes [%.2f%%]\n",
+	       num_bytes, 100.0 * ((double) actual_bytes / (double) num_bytes));
     }
 
   /* Calculate amount of usage of each hard reg by pseudos
Index: ra.h
===================================================================
--- ra.h	(revision 129209)
+++ ra.h	(working copy)
@@ -99,11 +99,11 @@ extern int *reg_allocno;
 /* Precalculated partial bit number in the compressed triangular bit matrix.
    For two allocnos, the final bit number is: partial_bitnum[LOW] + HIGH.  */
 
-extern int *partial_bitnum;
+extern HOST_WIDE_INT *partial_bitnum;
 
 /* Size in bits of the compressed triangular bit matrix.  */
 
-extern int max_bitnum;
+extern HOST_WIDE_INT max_bitnum;
 
 /* The pool to allocate the adjacency list elements from.  */
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]