public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Fix PR/46200 -- ivopt bug in test condition cost computation
@ 2010-10-29 23:10 Xinliang David Li
  2010-10-31  9:22 ` Zdenek Dvorak
  2010-11-05 20:40 ` H.J. Lu
  0 siblings, 2 replies; 11+ messages in thread
From: Xinliang David Li @ 2010-10-29 23:10 UTC (permalink / raw)
  To: GCC Patches; +Cc: Zdenek Dvorak

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

Hi, please review the patch attached. Regression and some performance
test is under going.

Thanks,

David


2010-10-29  Xinliang David Li  <davidxl@google.com>

	PR target/46200
	* tree-ssa-loop-ivopts.c (get_computation_cost_at):
	Adjust cbase if the use stmt is after iv update.

[-- Attachment #2: ivopt_46200.p --]
[-- Type: text/x-pascal, Size: 1702 bytes --]

Index: gcc/tree-ssa-loop-ivopts.c
===================================================================
--- gcc/tree-ssa-loop-ivopts.c	(revision 166032)
+++ gcc/tree-ssa-loop-ivopts.c	(working copy)
@@ -4027,6 +4027,8 @@ get_computation_cost_at (struct ivopts_d
   STRIP_NOPS (cbase);
   ctype = TREE_TYPE (cbase);
 
+  stmt_is_after_inc = stmt_after_increment (data->current_loop, cand, at);
+
   /* use = ubase + ratio * (var - cbase).  If either cbase is a constant
      or ratio == 1, it is better to handle this like
 
@@ -4045,8 +4047,24 @@ get_computation_cost_at (struct ivopts_d
     }
   else if (ratio == 1)
     {
+      tree real_cbase = cbase;
+
+      /* Check to see if any adjustment is needed.  */
+      if (cstepi == 0 && stmt_is_after_inc)
+        {
+          aff_tree real_cbase_aff;
+          aff_tree cstep_aff;
+
+          tree_to_aff_combination (cbase, TREE_TYPE (real_cbase),
+                                   &real_cbase_aff);
+          tree_to_aff_combination (cstep, TREE_TYPE (cstep), &cstep_aff);
+
+          aff_combination_add (&real_cbase_aff, &cstep_aff);
+          real_cbase = aff_combination_to_tree (&real_cbase_aff);
+        }
+
       cost = difference_cost (data,
-			      ubase, cbase,
+			      ubase, real_cbase,
 			      &symbol_present, &var_present, &offset,
 			      depends_on);
       cost.cost /= avg_loop_niter (data->current_loop);
@@ -4088,7 +4106,6 @@ get_computation_cost_at (struct ivopts_d
 
   /* If we are after the increment, the value of the candidate is higher by
      one iteration.  */
-  stmt_is_after_inc = stmt_after_increment (data->current_loop, cand, at);
   if (stmt_is_after_inc)
     offset -= ratio * cstepi;
 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Fix PR/46200 -- ivopt bug in test condition cost computation
  2010-10-29 23:10 Fix PR/46200 -- ivopt bug in test condition cost computation Xinliang David Li
@ 2010-10-31  9:22 ` Zdenek Dvorak
  2010-11-01  6:59   ` Xinliang David Li
  2010-11-05 20:40 ` H.J. Lu
  1 sibling, 1 reply; 11+ messages in thread
From: Zdenek Dvorak @ 2010-10-31  9:22 UTC (permalink / raw)
  To: Xinliang David Li; +Cc: GCC Patches

Hi,

> Hi, please review the patch attached. Regression and some performance
> test is under going.

it would be more consistent to either avoid using aff_combination functions
in get_computation_cost_at completely, or rewrite it to use aff_combination
instead of the current difference_cost/... functions (however, the latter
would probably lead to somewhat slower compilation time).  The patch should
also include a testcase for the problem.

Thanks for working on this,

Zdenek

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Fix PR/46200 -- ivopt bug in test condition cost computation
  2010-10-31  9:22 ` Zdenek Dvorak
@ 2010-11-01  6:59   ` Xinliang David Li
  2010-11-02 17:15     ` Xinliang David Li
  2010-11-03 10:28     ` Zdenek Dvorak
  0 siblings, 2 replies; 11+ messages in thread
From: Xinliang David Li @ 2010-11-01  6:59 UTC (permalink / raw)
  To: Zdenek Dvorak; +Cc: GCC Patches

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

On Sat, Oct 30, 2010 at 12:30 PM, Zdenek Dvorak <rakdver@kam.mff.cuni.cz> wrote:
> Hi,
>
>> Hi, please review the patch attached. Regression and some performance
>> test is under going.
>
> it would be more consistent to either avoid using aff_combination functions
> in get_computation_cost_at completely, or rewrite it to use aff_combination
> instead of the current difference_cost/... functions (however, the latter
> would probably lead to somewhat slower compilation time).  The patch should
> also include a testcase for the problem.

I agree -- the code for cost computation should match (or probably
share with) code in the rewrite functions -- however that is a much
larger task than is needed for this PR.

I added a test case (marked with x86 target as ivopt are very target
sensitive). Regression test and minimal perf testing went ok.

Ok to checkin?

Thanks,

David

(test case change log)

010-10-31  Xinliang David Li  <davidxl@google.com>

        PR target/46200
        * g++.dg/tree-ssa/ivopts-2.C: New test.






>
> Thanks for working on this,
>
> Zdenek
>

[-- Attachment #2: ivopt_46200_2.p --]
[-- Type: application/octet-stream, Size: 2294 bytes --]

Index: gcc/testsuite/g++.dg/tree-ssa/ivopts-2.C
===================================================================
--- gcc/testsuite/g++.dg/tree-ssa/ivopts-2.C	(revision 0)
+++ gcc/testsuite/g++.dg/tree-ssa/ivopts-2.C	(revision 0)
@@ -0,0 +1,11 @@
+/* { dg-do compile { target { i?86-*-* x86_64-*-*  } } } */
+/* { dg-options "-O2 -fdump-tree-ivopts-details" } */
+
+void test (int *b, int *e, int stride)
+  {
+    for (int *p = b; p != e; p += stride)
+      *p = 1;
+  }
+
+/* { dg-final { scan-tree-dump-times "PHI <p" 1 "ivopts"} } */
+/* { dg-final { cleanup-tree-dump "ivopts" } } */
Index: gcc/tree-ssa-loop-ivopts.c
===================================================================
--- gcc/tree-ssa-loop-ivopts.c	(revision 166032)
+++ gcc/tree-ssa-loop-ivopts.c	(working copy)
@@ -4027,6 +4027,8 @@ get_computation_cost_at (struct ivopts_d
   STRIP_NOPS (cbase);
   ctype = TREE_TYPE (cbase);
 
+  stmt_is_after_inc = stmt_after_increment (data->current_loop, cand, at);
+
   /* use = ubase + ratio * (var - cbase).  If either cbase is a constant
      or ratio == 1, it is better to handle this like
 
@@ -4045,8 +4047,24 @@ get_computation_cost_at (struct ivopts_d
     }
   else if (ratio == 1)
     {
+      tree real_cbase = cbase;
+
+      /* Check to see if any adjustment is needed.  */
+      if (cstepi == 0 && stmt_is_after_inc)
+        {
+          aff_tree real_cbase_aff;
+          aff_tree cstep_aff;
+
+          tree_to_aff_combination (cbase, TREE_TYPE (real_cbase),
+                                   &real_cbase_aff);
+          tree_to_aff_combination (cstep, TREE_TYPE (cstep), &cstep_aff);
+
+          aff_combination_add (&real_cbase_aff, &cstep_aff);
+          real_cbase = aff_combination_to_tree (&real_cbase_aff);
+        }
+
       cost = difference_cost (data,
-			      ubase, cbase,
+			      ubase, real_cbase,
 			      &symbol_present, &var_present, &offset,
 			      depends_on);
       cost.cost /= avg_loop_niter (data->current_loop);
@@ -4088,7 +4106,6 @@ get_computation_cost_at (struct ivopts_d
 
   /* If we are after the increment, the value of the candidate is higher by
      one iteration.  */
-  stmt_is_after_inc = stmt_after_increment (data->current_loop, cand, at);
   if (stmt_is_after_inc)
     offset -= ratio * cstepi;
 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Fix PR/46200 -- ivopt bug in test condition cost computation
  2010-11-01  6:59   ` Xinliang David Li
@ 2010-11-02 17:15     ` Xinliang David Li
  2010-11-03 10:28     ` Zdenek Dvorak
  1 sibling, 0 replies; 11+ messages in thread
From: Xinliang David Li @ 2010-11-02 17:15 UTC (permalink / raw)
  To: Zdenek Dvorak; +Cc: GCC Patches

Can I get an explicit OK :) ?

Thanks,

David

On Sun, Oct 31, 2010 at 11:59 PM, Xinliang David Li <davidxl@google.com> wrote:
> On Sat, Oct 30, 2010 at 12:30 PM, Zdenek Dvorak <rakdver@kam.mff.cuni.cz> wrote:
>> Hi,
>>
>>> Hi, please review the patch attached. Regression and some performance
>>> test is under going.
>>
>> it would be more consistent to either avoid using aff_combination functions
>> in get_computation_cost_at completely, or rewrite it to use aff_combination
>> instead of the current difference_cost/... functions (however, the latter
>> would probably lead to somewhat slower compilation time).  The patch should
>> also include a testcase for the problem.
>
> I agree -- the code for cost computation should match (or probably
> share with) code in the rewrite functions -- however that is a much
> larger task than is needed for this PR.
>
> I added a test case (marked with x86 target as ivopt are very target
> sensitive). Regression test and minimal perf testing went ok.
>
> Ok to checkin?
>
> Thanks,
>
> David
>
> (test case change log)
>
> 010-10-31  Xinliang David Li  <davidxl@google.com>
>
>        PR target/46200
>        * g++.dg/tree-ssa/ivopts-2.C: New test.
>
>
>
>
>
>
>>
>> Thanks for working on this,
>>
>> Zdenek
>>
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Fix PR/46200 -- ivopt bug in test condition cost computation
  2010-11-01  6:59   ` Xinliang David Li
  2010-11-02 17:15     ` Xinliang David Li
@ 2010-11-03 10:28     ` Zdenek Dvorak
  2010-11-03 23:10       ` Xinliang David Li
  1 sibling, 1 reply; 11+ messages in thread
From: Zdenek Dvorak @ 2010-11-03 10:28 UTC (permalink / raw)
  To: Xinliang David Li; +Cc: GCC Patches

Hi,

> >> Hi, please review the patch attached. Regression and some performance
> >> test is under going.
> >
> > it would be more consistent to either avoid using aff_combination functions
> > in get_computation_cost_at completely, or rewrite it to use aff_combination
> > instead of the current difference_cost/... functions (however, the latter
> > would probably lead to somewhat slower compilation time).  The patch should
> > also include a testcase for the problem.
> 
> I agree -- the code for cost computation should match (or probably
> share with) code in the rewrite functions -- however that is a much
> larger task than is needed for this PR.
> 
> I added a test case (marked with x86 target as ivopt are very target
> sensitive). Regression test and minimal perf testing went ok.

OK,

Zdenek


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Fix PR/46200 -- ivopt bug in test condition cost computation
  2010-11-03 10:28     ` Zdenek Dvorak
@ 2010-11-03 23:10       ` Xinliang David Li
  0 siblings, 0 replies; 11+ messages in thread
From: Xinliang David Li @ 2010-11-03 23:10 UTC (permalink / raw)
  To: Zdenek Dvorak; +Cc: GCC Patches

Submitted as r166280.

Thanks,

David

On Wed, Nov 3, 2010 at 3:27 AM, Zdenek Dvorak <rakdver@kam.mff.cuni.cz> wrote:
> Hi,
>
>> >> Hi, please review the patch attached. Regression and some performance
>> >> test is under going.
>> >
>> > it would be more consistent to either avoid using aff_combination functions
>> > in get_computation_cost_at completely, or rewrite it to use aff_combination
>> > instead of the current difference_cost/... functions (however, the latter
>> > would probably lead to somewhat slower compilation time).  The patch should
>> > also include a testcase for the problem.
>>
>> I agree -- the code for cost computation should match (or probably
>> share with) code in the rewrite functions -- however that is a much
>> larger task than is needed for this PR.
>>
>> I added a test case (marked with x86 target as ivopt are very target
>> sensitive). Regression test and minimal perf testing went ok.
>
> OK,
>
> Zdenek
>
>
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Fix PR/46200 -- ivopt bug in test condition cost computation
  2010-10-29 23:10 Fix PR/46200 -- ivopt bug in test condition cost computation Xinliang David Li
  2010-10-31  9:22 ` Zdenek Dvorak
@ 2010-11-05 20:40 ` H.J. Lu
  2010-11-05 20:42   ` H.J. Lu
                     ` (2 more replies)
  1 sibling, 3 replies; 11+ messages in thread
From: H.J. Lu @ 2010-11-05 20:40 UTC (permalink / raw)
  To: Xinliang David Li; +Cc: GCC Patches, Zdenek Dvorak

On Fri, Oct 29, 2010 at 1:28 PM, Xinliang David Li <davidxl@google.com> wrote:
> Hi, please review the patch attached. Regression and some performance
> test is under going.
>
> Thanks,
>
> David
>
>
> 2010-10-29  Xinliang David Li  <davidxl@google.com>
>
>        PR target/46200
>        * tree-ssa-loop-ivopts.c (get_computation_cost_at):
>        Adjust cbase if the use stmt is after iv update.
>

This patch may have caused:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46316

You need to build a 32bit gcc to reproduce it. I am using

CC="gcc -m32" CXX="g++ -m32"  configure  i686-linux

on Fedora 16/Intel64 to build 32bit GCC.


-- 
H.J.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Fix PR/46200 -- ivopt bug in test condition cost computation
  2010-11-05 20:40 ` H.J. Lu
@ 2010-11-05 20:42   ` H.J. Lu
  2010-11-05 21:00     ` H.J. Lu
  2010-11-06 11:08   ` Xinliang David Li
  2010-11-07 21:29   ` Xinliang David Li
  2 siblings, 1 reply; 11+ messages in thread
From: H.J. Lu @ 2010-11-05 20:42 UTC (permalink / raw)
  To: Xinliang David Li; +Cc: GCC Patches, Zdenek Dvorak

On Fri, Nov 5, 2010 at 1:32 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Fri, Oct 29, 2010 at 1:28 PM, Xinliang David Li <davidxl@google.com> wrote:
>> Hi, please review the patch attached. Regression and some performance
>> test is under going.
>>
>> Thanks,
>>
>> David
>>
>>
>> 2010-10-29  Xinliang David Li  <davidxl@google.com>
>>
>>        PR target/46200
>>        * tree-ssa-loop-ivopts.c (get_computation_cost_at):
>>        Adjust cbase if the use stmt is after iv update.
>>
>
> This patch may have caused:
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46316
>

I was wrong. Ignore it.

-- 
H.J.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Fix PR/46200 -- ivopt bug in test condition cost computation
  2010-11-05 20:42   ` H.J. Lu
@ 2010-11-05 21:00     ` H.J. Lu
  0 siblings, 0 replies; 11+ messages in thread
From: H.J. Lu @ 2010-11-05 21:00 UTC (permalink / raw)
  To: Xinliang David Li; +Cc: GCC Patches, Zdenek Dvorak

On Fri, Nov 5, 2010 at 1:40 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Fri, Nov 5, 2010 at 1:32 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Fri, Oct 29, 2010 at 1:28 PM, Xinliang David Li <davidxl@google.com> wrote:
>>> Hi, please review the patch attached. Regression and some performance
>>> test is under going.
>>>
>>> Thanks,
>>>
>>> David
>>>
>>>
>>> 2010-10-29  Xinliang David Li  <davidxl@google.com>
>>>
>>>        PR target/46200
>>>        * tree-ssa-loop-ivopts.c (get_computation_cost_at):
>>>        Adjust cbase if the use stmt is after iv update.
>>>
>>
>> This patch may have caused:
>>
>> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46316
>>
>
> I was wrong. Ignore it.

Ooops. I was right. This is the cause/


-- 
H.J.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Fix PR/46200 -- ivopt bug in test condition cost computation
  2010-11-05 20:40 ` H.J. Lu
  2010-11-05 20:42   ` H.J. Lu
@ 2010-11-06 11:08   ` Xinliang David Li
  2010-11-07 21:29   ` Xinliang David Li
  2 siblings, 0 replies; 11+ messages in thread
From: Xinliang David Li @ 2010-11-06 11:08 UTC (permalink / raw)
  To: H.J. Lu; +Cc: GCC Patches, Zdenek Dvorak

Sorry for the late reply -- reproduced. It is likely some bug
triggered by this change. I will take a look.

David

On Fri, Nov 5, 2010 at 1:32 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Fri, Oct 29, 2010 at 1:28 PM, Xinliang David Li <davidxl@google.com> wrote:
>> Hi, please review the patch attached. Regression and some performance
>> test is under going.
>>
>> Thanks,
>>
>> David
>>
>>
>> 2010-10-29  Xinliang David Li  <davidxl@google.com>
>>
>>        PR target/46200
>>        * tree-ssa-loop-ivopts.c (get_computation_cost_at):
>>        Adjust cbase if the use stmt is after iv update.
>>
>
> This patch may have caused:
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46316
>
> You need to build a 32bit gcc to reproduce it. I am using
>
> CC="gcc -m32" CXX="g++ -m32"  configure  i686-linux
>
> on Fedora 16/Intel64 to build 32bit GCC.
>
>
> --
> H.J.
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Fix PR/46200 -- ivopt bug in test condition cost computation
  2010-11-05 20:40 ` H.J. Lu
  2010-11-05 20:42   ` H.J. Lu
  2010-11-06 11:08   ` Xinliang David Li
@ 2010-11-07 21:29   ` Xinliang David Li
  2 siblings, 0 replies; 11+ messages in thread
From: Xinliang David Li @ 2010-11-07 21:29 UTC (permalink / raw)
  To: H.J. Lu; +Cc: GCC Patches, Zdenek Dvorak

I have no idea why my patch would have affected it, but this seems to
be a problem in double_int overflow in tree-vrp. I will send out a
patch shortly.

David

On Fri, Nov 5, 2010 at 1:32 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Fri, Oct 29, 2010 at 1:28 PM, Xinliang David Li <davidxl@google.com> wrote:
>> Hi, please review the patch attached. Regression and some performance
>> test is under going.
>>
>> Thanks,
>>
>> David
>>
>>
>> 2010-10-29  Xinliang David Li  <davidxl@google.com>
>>
>>        PR target/46200
>>        * tree-ssa-loop-ivopts.c (get_computation_cost_at):
>>        Adjust cbase if the use stmt is after iv update.
>>
>
> This patch may have caused:
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46316
>
> You need to build a 32bit gcc to reproduce it. I am using
>
> CC="gcc -m32" CXX="g++ -m32"  configure  i686-linux
>
> on Fedora 16/Intel64 to build 32bit GCC.
>
>
> --
> H.J.
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2010-11-07 21:08 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-29 23:10 Fix PR/46200 -- ivopt bug in test condition cost computation Xinliang David Li
2010-10-31  9:22 ` Zdenek Dvorak
2010-11-01  6:59   ` Xinliang David Li
2010-11-02 17:15     ` Xinliang David Li
2010-11-03 10:28     ` Zdenek Dvorak
2010-11-03 23:10       ` Xinliang David Li
2010-11-05 20:40 ` H.J. Lu
2010-11-05 20:42   ` H.J. Lu
2010-11-05 21:00     ` H.J. Lu
2010-11-06 11:08   ` Xinliang David Li
2010-11-07 21:29   ` Xinliang David Li

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).