Patchwork IVOPT improvement patch

login
register
mail settings
Submitter H.J. Lu
Date July 29, 2010, 4:09 p.m.
Message ID <AANLkTi=5+a+ZFwwzeAJfJ5UTPgErZFbKTy1wxb_CKBh7@mail.gmail.com>
Download mbox | patch
Permalink /patch/60277/
State New
Headers show

Comments

H.J. Lu - July 29, 2010, 4:09 p.m.
On Thu, Jul 29, 2010 at 8:22 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Wed, Jul 28, 2010 at 9:32 PM, Xinliang David Li <davidxl@google.com> wrote:
>> The attached patch should fix the problem -- it reverts a small part
>> of the last patch that is needed for fixing sixtrack performance
>> regression caused by wrong iv-use costs because address offset range
>> is conservatively computed. I will revert the change first and
>> investigate better fix (Suggestions are welcome).
>>
>
> Since "gcc -m32" works on Linux/x86-64 and goes into an infinite loop,
> it sounds like a HOST_WIDE_INT issue.
>

Here is the patch.  OK for trunk?

Thanks.

Patch

diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index 1d65b4a..92e19d1 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -3207,7 +3207,7 @@  multiplier_allowed_in_address_p (HOST_WIDE_INT ratio, enum machine_mode mode,
 
 typedef struct
 {
-  HOST_WIDE_INT min_offset, max_offset;
+  HOST_WIDEST_INT min_offset, max_offset;
   unsigned costs[2][2][2][2];
 } *address_cost_data;
 
@@ -3240,10 +3240,10 @@  get_address_cost (bool symbol_present, bool var_present,
   data = VEC_index (address_cost_data, address_cost_data_list, data_index);
   if (!data)
     {
-      HOST_WIDE_INT i;
-      HOST_WIDE_INT start = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
-      HOST_WIDE_INT rat, off;
-      int old_cse_not_expected;
+      HOST_WIDEST_INT i;
+      HOST_WIDEST_INT start = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
+      HOST_WIDEST_INT rat, off;
+      int old_cse_not_expected, width;
       unsigned sym_p, var_p, off_p, rat_p, add_c;
       rtx seq, addr, base;
       rtx reg0, reg1;
@@ -3252,8 +3252,10 @@  get_address_cost (bool symbol_present, bool var_present,
 
       reg1 = gen_raw_REG (address_mode, LAST_VIRTUAL_REGISTER + 1);
 
+      width = (GET_MODE_BITSIZE (address_mode) <  HOST_BITS_PER_WIDE_INT - 2)
+          ? GET_MODE_BITSIZE (address_mode) : HOST_BITS_PER_WIDE_INT - 2;
       addr = gen_rtx_fmt_ee (PLUS, address_mode, reg1, NULL_RTX);
-      for (i = start; i <= 1 << 20; i <<= 1)
+      for (i = start; i <= 1ll << width; i <<= 1)
 	{
 	  XEXP (addr, 1) = gen_int_mode (i, address_mode);
 	  if (!memory_address_addr_space_p (mem_mode, addr, as))
@@ -3262,7 +3264,7 @@  get_address_cost (bool symbol_present, bool var_present,
       data->max_offset = i == start ? 0 : i >> 1;
       off = data->max_offset;
 
-      for (i = start; i <= 1 << 20; i <<= 1)
+      for (i = start; i <= 1ll << width; i <<= 1)
 	{
 	  XEXP (addr, 1) = gen_int_mode (-i, address_mode);
 	  if (!memory_address_addr_space_p (mem_mode, addr, as))
@@ -3273,12 +3275,14 @@  get_address_cost (bool symbol_present, bool var_present,
       if (dump_file && (dump_flags & TDF_DETAILS))
 	{
 	  fprintf (dump_file, "get_address_cost:\n");
-	  fprintf (dump_file, "  min offset %s %d\n",
+	  fprintf (dump_file, "  min offset %s "
+		   HOST_WIDEST_INT_PRINT_DEC "\n",
 		   GET_MODE_NAME (mem_mode),
-		   (int) data->min_offset);
-	  fprintf (dump_file, "  max offset %s %d\n",
+		   data->min_offset);
+	  fprintf (dump_file, "  max offset %s "
+		   HOST_WIDEST_INT_PRINT_DEC "\n",
 		   GET_MODE_NAME (mem_mode),
-		   (int) data->max_offset);
+		   data->max_offset);
 	}
 
       rat = 1;