public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Xinliang David Li <davidxl@google.com>
Cc: Richard Guenther <richard.guenther@gmail.com>,
	Pat Haugen <pthaugen@us.ibm.com>,
		GCC Patches <gcc-patches@gcc.gnu.org>,
	Zdenek Dvorak <rakdver@kam.mff.cuni.cz>
Subject: Re: IVOPT improvement patch
Date: Fri, 30 Jul 2010 18:57:00 -0000	[thread overview]
Message-ID: <AANLkTimk3b3tmDr3g8KKDGvJ6HczpPJXNdGoV9cE0a9A@mail.gmail.com> (raw)
In-Reply-To: <AANLkTi=4HF2sKUPfhS5GRJTLW1g7rYRTn8iihkmYH6k2@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3116 bytes --]

On Fri, Jul 30, 2010 at 10:54 AM, Xinliang David Li <davidxl@google.com> wrote:
> Why is start offset not 1 to begin with? Let's assume it is correct,
> there are a couple of problems in this patch:
>
> 1) when the precision of the HOST_WIDE_INT is the same as the bitsize
> of the address_mode, max_offset = (HOST_WIDE_INT) 1 << width will
> produce a negative number
> 2) last_off should be initialized to 0 to match the original behavior
> 3) The i&& guard will make sure the loop terminates, but the offset
> compuation will be wrong -- i<<1 will first overflows to a negative
> number, then gets truncated to zero,  that means when this happens,
> the last_off will be negative when the loop terminates.
>
> David

I don't know exactly what get_address_cost is supposed to do. Here is
a new patch which avoids overflow and speeds up finding max/min offsets.


H.J.
---
>
> On Fri, Jul 30, 2010 at 10:27 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Fri, Jul 30, 2010 at 9:58 AM, Xinliang David Li <davidxl@google.com> wrote:
>>> There is a problem in this patch -- when i wraps to zero and terminate
>>> the loop, the maxoffset computed will be zero which is wrong.
>>>
>>> My previous patch won't have this problem.
>>
>> Your patch changed the start offset.  Here is the updated patch.
>>
>>
>> H.J.
>>>
>>> David
>>>
>>> On Fri, Jul 30, 2010 at 9:49 AM, Xinliang David Li <davidxl@google.com> wrote:
>>>> This looks fine to me -- Zdenek or other reviewers --- is this one ok?
>>>>
>>>> Thanks,
>>>>
>>>> David
>>>>
>>>> On Fri, Jul 30, 2010 at 8:45 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>> On Thu, Jul 29, 2010 at 6:04 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>>> It looks strange:
>>>>>>
>>>>>> +      width = (GET_MODE_BITSIZE (address_mode) <  HOST_BITS_PER_WIDE_INT - 1)
>>>>>> +          ? GET_MODE_BITSIZE (address_mode) : 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 = 1; i < width; i++)
>>>>>>        {
>>>>>> -         XEXP (addr, 1) = gen_int_mode (i, address_mode);
>>>>>> +          HOST_WIDE_INT offset = (1ll << i);
>>>>>> +         XEXP (addr, 1) = gen_int_mode (offset, address_mode);
>>>>>>          if (!memory_address_addr_space_p (mem_mode, addr, as))
>>>>>>            break;
>>>>>>        }
>>>>>>
>>>>>> HOST_WIDE_INT may be long or long long. "1ll" isn't always correct.
>>>>>> I think width can be >= 31. Depending on HOST_WIDE_INT,
>>>>>>
>>>>>> HOST_WIDE_INT offset = -(1ll << i);
>>>>>>
>>>>>> may have different values. The whole function looks odd to me.
>>>>>>
>>>>>>
>>>>>
>>>>> Here is a different approach to check address overflow.
>>>>>
>>>>>
>>>>> --
>>>>> H.J.
>>>>> --
>>>>> 2010-07-29  H.J. Lu  <hongjiu.lu@intel.com>
>>>>>
>>>>>        PR bootstrap/45119
>>>>>        * tree-ssa-loop-ivopts.c (get_address_cost): Re-apply revision
>>>>>        162652.  Check address overflow.
>>>>>
>>>>
>>>
>>
>>
>>
>> --
>> H.J.
>>
>



-- 
H.J.

[-- Attachment #2: gcc-pr45119-4.patch --]
[-- Type: text/plain, Size: 2569 bytes --]

2010-07-29  H.J. Lu  <hongjiu.lu@intel.com>

	PR bootstrap/45119
	* tree-ssa-loop-ivopts.c (get_address_cost): Re-apply revision
	162652.  Avoid address overflow.

diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index 1d65b4a..b5ab63e 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -3241,9 +3241,8 @@ get_address_cost (bool symbol_present, bool var_present,
   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;
+      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,37 @@ 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 - 1)
+          ? GET_MODE_BITSIZE (address_mode) : 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;

  reply	other threads:[~2010-07-30 18:47 UTC|newest]

Thread overview: 100+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-11  6:35 Xinliang David Li
2010-05-11  7:18 ` Zdenek Dvorak
2010-05-11 17:29   ` Xinliang David Li
2010-05-25  0:17     ` Xinliang David Li
2010-05-25 10:46       ` Zdenek Dvorak
2010-05-25 17:39         ` Xinliang David Li
2010-05-25 18:25           ` Zdenek Dvorak
2010-05-25 23:30             ` Xinliang David Li
2010-05-26  2:35               ` Zdenek Dvorak
2010-05-26  3:17                 ` Xinliang David Li
2010-05-27  1:31                 ` Xinliang David Li
2010-05-27  9:12                   ` Zdenek Dvorak
2010-05-27 17:33                     ` Xinliang David Li
2010-05-28  9:14                       ` Zdenek Dvorak
2010-05-28 23:51                         ` Xinliang David Li
2010-05-29 16:57                           ` Zdenek Dvorak
2010-05-29 19:51                             ` Xinliang David Li
2010-05-29 20:18                               ` Zdenek Dvorak
2010-05-30  0:22                                 ` Xinliang David Li
     [not found]                                   ` <20100604105451.GB5105@kam.mff.cuni.cz>
2010-07-21  7:27                                     ` Xinliang David Li
2010-07-26 16:33                                       ` Sebastian Pop
2010-07-26 16:43                                         ` Xinliang David Li
2010-07-27 20:04                                           ` Pat Haugen
2010-07-27 20:25                                             ` Xinliang David Li
2010-07-29  3:50                                               ` H.J. Lu
2010-07-29  5:57                                                 ` H.J. Lu
2010-07-29  7:44                                                   ` Xinliang David Li
2010-07-29  8:28                                                     ` Zdenek Dvorak
2010-07-29 14:37                                                       ` H.J. Lu
2010-07-29 15:27                                                     ` H.J. Lu
2010-07-29 16:09                                                       ` H.J. Lu
2010-07-29 16:17                                                         ` Richard Guenther
2010-07-29 16:55                                                           ` H.J. Lu
2010-07-30  1:04                                                             ` Xinliang David Li
2010-07-30  2:06                                                               ` H.J. Lu
2010-07-30  5:41                                                                 ` Xinliang David Li
2010-07-30  7:19                                                                   ` Jakub Jelinek
2010-07-30 16:45                                                                     ` Xinliang David Li
2010-07-30 15:56                                                                 ` H.J. Lu
2010-07-30 16:58                                                                   ` Xinliang David Li
2010-07-30 17:07                                                                     ` Xinliang David Li
2010-07-30 17:43                                                                       ` H.J. Lu
2010-07-30 18:10                                                                         ` Xinliang David Li
2010-07-30 18:57                                                                           ` H.J. Lu [this message]
2010-07-30 21:04                                                                             ` H.J. Lu
2010-07-30 21:13                                                                               ` Xinliang David Li
2010-08-02 21:23                                                                               ` Xinliang David Li
2010-08-09  8:44                                                                                 ` Zdenek Dvorak
2010-08-09 23:07                                                                                   ` Xinliang David Li
2010-08-10  2:37                                                                                     ` Xinliang David Li
2010-08-10 13:13                                                                                       ` Zdenek Dvorak
2010-08-10 13:35                                                                                       ` H.J. Lu
2010-08-10 14:18                                                                                         ` H.J. Lu
2010-08-10 16:31                                                                                           ` Xinliang David Li
2010-08-10 16:38                                                                                             ` H.J. Lu
2010-08-10 17:13                                                                                               ` Xinliang David Li
2010-08-10 17:26                                                                                                 ` H.J. Lu
2010-08-10 17:42                                                                                                   ` Xinliang David Li
2010-08-11  0:45                                                                                                     ` Xinliang David Li
2010-07-30 17:01                                                                   ` Xinliang David Li
2010-07-29 16:11                                                       ` H.J. Lu
2010-07-29 14:17                                                   ` H.J. Lu
2010-07-29 17:00                                                     ` Xinliang David Li
2010-07-29 17:10                                                       ` H.J. Lu
2010-10-28 19:28                                                     ` H.J. Lu
2011-04-27 13:23                                                     ` H.J. Lu
2010-07-30 15:06                                                   ` H.J. Lu
2010-07-30 16:50                                                     ` Xinliang David Li
2010-07-30 18:28                                                       ` Bernd Schmidt
2010-07-30 18:34                                                         ` Xinliang David Li
2010-07-29  7:26                                                 ` Xinliang David Li
2010-12-30 17:23                                   ` H.J. Lu
2010-05-25 18:10       ` Toon Moene
2010-05-27  9:28       ` Zdenek Dvorak
2010-05-27 17:51         ` Xinliang David Li
2010-05-27 22:48           ` Zdenek Dvorak
2010-05-27 23:41             ` Xinliang David Li
2010-05-28  9:57       ` Zdenek Dvorak
2010-06-01 23:13         ` Xinliang David Li
2010-06-02 20:57           ` Zdenek Dvorak
2010-06-03  5:39             ` Xinliang David Li
2010-06-05  9:01       ` Zdenek Dvorak
2010-06-05 22:37         ` Xinliang David Li
2010-05-11  7:26 ` Steven Bosscher
2010-05-11 17:23   ` Xinliang David Li
2010-05-11  8:34 ` Richard Guenther
2010-05-11  9:48   ` Jan Hubicka
2010-05-11 10:04     ` Steven Bosscher
2010-05-11 14:24   ` Peter Bergner
2010-05-11 17:28   ` Xinliang David Li
2010-05-12  8:55     ` Richard Guenther
2010-05-11 17:19 ` Toon Moene
2010-05-11 17:49   ` Xinliang David Li
2010-05-11 21:52     ` Toon Moene
2010-05-11 22:31       ` Xinliang David Li
2010-05-11 22:44         ` Toon Moene
2010-05-13 13:00 ` Toon Moene
2010-05-13 13:30   ` Toon Moene
2010-05-13 16:23     ` Xinliang David Li
2010-05-14  4:26     ` Xinliang David Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AANLkTimk3b3tmDr3g8KKDGvJ6HczpPJXNdGoV9cE0a9A@mail.gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=davidxl@google.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=pthaugen@us.ibm.com \
    --cc=rakdver@kam.mff.cuni.cz \
    --cc=richard.guenther@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).