This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: IVOPT improvement patch
- From: Xinliang David Li <davidxl at google dot com>
- To: Zdenek Dvorak <rakdver at kam dot mff dot cuni dot cz>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Richard Guenther <richard dot guenther at gmail dot com>, Pat Haugen <pthaugen at us dot ibm dot com>, "H.J. Lu" <hjl dot tools at gmail dot com>
- Date: Mon, 9 Aug 2010 16:47:58 -0700
- Subject: Re: IVOPT improvement patch
- References: <AANLkTinguXaw6KR1xi2Tz3O+wpRxiwAqW28+g+yJC6Lf@mail.gmail.com> <AANLkTinNyB83vfkwZp0Lxu03H+DNpD-AvBt803pt=4qi@mail.gmail.com> <AANLkTikX01vs8_taOwuEnULBkXaRhr1rQHQR4KUMXuM7@mail.gmail.com> <AANLkTiktVKVmNnQRyp=OQfJ1+DAYkRQgTso3Qb-kV3nJ@mail.gmail.com> <AANLkTi=dFqKHoU=xkTuq6bKMvg9f2oGX4UaCot1XS-gP@mail.gmail.com> <AANLkTimEGjvDmFe1qjFvn5gfiNpnnt9ORM6RA6RCXpdY@mail.gmail.com> <AANLkTi=4HF2sKUPfhS5GRJTLW1g7rYRTn8iihkmYH6k2@mail.gmail.com> <AANLkTimk3b3tmDr3g8KKDGvJ6HczpPJXNdGoV9cE0a9A@mail.gmail.com> <AANLkTima5mV3OL=HuY_Sw54NtNU4-0RaY+z6jaNzA0Sc@mail.gmail.com> <AANLkTinXtucQKd-c1XLAFZj1Q25ibbTq1gDE4Xm1korU@mail.gmail.com> <20100809075525.GA16026@kam.mff.cuni.cz> <AANLkTi=1EV2b8ZLQ5wNtWbJmh-21xrLd_R1R3KdK62L+@mail.gmail.com>
Wrong patch in the last email. Here is the one.
David
On Mon, Aug 9, 2010 at 3:54 PM, Xinliang David Li <davidxl@google.com> wrote:
> You are right. The attached is the revised version. ?Ok this time
> (after testing is done)?
>
> Thanks,
>
> David
>
> On Mon, Aug 9, 2010 at 12:55 AM, Zdenek Dvorak <rakdver@kam.mff.cuni.cz> wrote:
>> Hi,
>>
>>> Compiler bootstrapped and tested with Lu's patch (with one minor
>>> change to initialize off variable) (x86-64/linux) -- also checked dump
>>> file that offsets are properly computed.
>>
>> in case that no offsets are allowed (or more hypotetically, if only offsets of
>> +1 or -1 are allowed), the code below will set min_offset to -2 and max_offset
>> to +2, thus incorrectly extending the range of allowed offsets.
>>
>> Zdenek
>>
>>> ? ? ? ?reg1 = gen_raw_REG (address_mode, LAST_VIRTUAL_REGISTER + 1);
>>>
>>> + ? ? ?width = GET_MODE_BITSIZE (address_mode) - 1;
>>> + ? ? ?if (width > (HOST_BITS_PER_WIDE_INT - 1))
>>> + ? ? width = HOST_BITS_PER_WIDE_INT - 1;
>>> ? ? ? ?addr = gen_rtx_fmt_ee (PLUS, address_mode, reg1, NULL_RTX);
>>> - ? ? ?for (i = start; i <= 1 << 20; i <<= 1)
>>> +
>>> + ? ? ?for (i = width; i; i--)
>>> ? ? ? {
>>> - ? ? ? XEXP (addr, 1) = gen_int_mode (i, address_mode);
>>> - ? ? ? if (!memory_address_addr_space_p (mem_mode, addr, as))
>>> + ? ? ? off = -((HOST_WIDE_INT) 1 << i);
>>> + ? ? ? XEXP (addr, 1) = gen_int_mode (off, address_mode);
>>> + ? ? ? if (memory_address_addr_space_p (mem_mode, addr, as))
>>> ? ? ? ? ? break;
>>> ? ? ? }
>>> - ? ? ?data->max_offset = i == start ? 0 : i >> 1;
>>> - ? ? ?off = data->max_offset;
>>> + ? ? ?data->min_offset = off;
>>>
>>> - ? ? ?for (i = start; i <= 1 << 20; i <<= 1)
>>> + ? ? ?for (i = width; i; i--)
>>> ? ? ? {
>>> - ? ? ? XEXP (addr, 1) = gen_int_mode (-i, address_mode);
>>> - ? ? ? if (!memory_address_addr_space_p (mem_mode, addr, as))
>>> + ? ? ? off = ((HOST_WIDE_INT) 1 << i) - 1;
>>> + ? ? ? XEXP (addr, 1) = gen_int_mode (off, address_mode);
>>> + ? ? ? if (memory_address_addr_space_p (mem_mode, addr, as))
>>> ? ? ? ? ? break;
>>> ? ? ? }
>>> - ? ? ?data->min_offset = i == start ? 0 : -(i >> 1);
>>> + ? ? ?data->max_offset = off;
>>>
>>> ? ? ? ?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_WIDE_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_WIDE_INT_PRINT_DEC "\n",
>>> ? ? ? ? ? ? ? ? ?GET_MODE_NAME (mem_mode),
>>> - ? ? ? ? ? ? ? ?(int) data->max_offset);
>>> + ? ? ? ? ? ? ? ?data->max_offset);
>>> ? ? ? }
>>>
>>> ? ? ? ?rat = 1;
>>
>>
>
Index: gcc/tree-ssa-loop-ivopts.c
===================================================================
--- gcc/tree-ssa-loop-ivopts.c (revision 162822)
+++ gcc/tree-ssa-loop-ivopts.c (working copy)
@@ -3241,9 +3241,8 @@ get_address_cost (bool symbol_present, b
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_WIDE_INT rat, off = 0;
+ 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,33 +3251,39 @@ get_address_cost (bool symbol_present, b
reg1 = gen_raw_REG (address_mode, LAST_VIRTUAL_REGISTER + 1);
+ width = GET_MODE_BITSIZE (address_mode) - 1;
+ if (width > (HOST_BITS_PER_WIDE_INT - 1))
+ width = HOST_BITS_PER_WIDE_INT - 1;
addr = gen_rtx_fmt_ee (PLUS, address_mode, reg1, NULL_RTX);
- for (i = start; i <= 1 << 20; i <<= 1)
+
+ for (i = width; i >= 0; i--)
{
- XEXP (addr, 1) = gen_int_mode (i, address_mode);
- if (!memory_address_addr_space_p (mem_mode, addr, as))
+ off = -((HOST_WIDE_INT) 1 << i);
+ XEXP (addr, 1) = gen_int_mode (off, address_mode);
+ if (memory_address_addr_space_p (mem_mode, addr, as))
break;
}
- data->max_offset = i == start ? 0 : i >> 1;
- off = data->max_offset;
+ data->min_offset = (i == -1? 0 : off);
- for (i = start; i <= 1 << 20; i <<= 1)
+ for (i = width; i >= 0; i--)
{
- XEXP (addr, 1) = gen_int_mode (-i, address_mode);
- if (!memory_address_addr_space_p (mem_mode, addr, as))
+ off = ((HOST_WIDE_INT) 1 << i) - 1;
+ XEXP (addr, 1) = gen_int_mode (off, address_mode);
+ if (memory_address_addr_space_p (mem_mode, addr, as))
break;
}
- data->min_offset = i == start ? 0 : -(i >> 1);
+ data->max_offset = (i == -1? 0 : off);
+ offset = data->max_offset;
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_WIDE_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_WIDE_INT_PRINT_DEC "\n",
GET_MODE_NAME (mem_mode),
- (int) data->max_offset);
+ data->max_offset);
}
rat = 1;