public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* [tree-ssa] Write to global memory not hoisted out of loop
@ 2004-04-30 16:23 Richard Guenther
  2004-04-30 16:25 ` Steven Bosscher
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Guenther @ 2004-04-30 16:23 UTC (permalink / raw)
  To: gcc

Hi!

Writes to global memory are not hoisted out of a computation loop. F.e.

double tmp;
void foo(double * __restrict__ x, double * __restrict__ y, double *
__restrict__ z, int n)
{
  int i;
  for (i=0; i<n; ++i) {
    tmp = y[i]*z[i];
    x[i] = tmp;
  }
}

is compiled to (-O2 -fno-trapping-math):

...
.L4:
        leal    0(,%edx,8), %eax        #, tmp66
        incl    %edx    # i
        fldl    (%eax,%ebx)     #* z
        cmpl    %ecx, %edx      # n, i
        fmull   (%eax,%esi)     #* y
        fstl    tmp     # tmp
        fstpl   (%eax,%edi)     #* x
        jl      .L4     #,
...

note that the load from tmp is optimized, but the store is still inside
the loop.  The store would be necessary in case of trapping math
operations to make side-effects visible, but I thought, -fno-trapping-math
should get rid of it.  Making tmp static doesn't help either, while here
removing the store would be valid even in case of trapping math.  Turning
on points-to doesn't help either.  Intel compiler moves the store in any
case (which seems to be a bug).

Is there already a PR about this pessimization? (Couldn't find one)

Richard.

--
Richard Guenther <richard dot guenther at uni-tuebingen dot de>
WWW: http://www.tat.physik.uni-tuebingen.de/~rguenth/

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

* Re: [tree-ssa] Write to global memory not hoisted out of loop
  2004-04-30 16:23 [tree-ssa] Write to global memory not hoisted out of loop Richard Guenther
@ 2004-04-30 16:25 ` Steven Bosscher
  2004-04-30 16:26   ` Richard Guenther
  0 siblings, 1 reply; 7+ messages in thread
From: Steven Bosscher @ 2004-04-30 16:25 UTC (permalink / raw)
  To: Richard Guenther; +Cc: gcc

On Apr 30, 2004 01:14 PM, Richard Guenther <rguenth@tat.physik.uni-tuebingen.de> wrote:

> Writes to global memory are not hoisted out of a computation loop.

Try this with the LNO branch, iirc it can do this.


> Is there already a PR about this pessimization? (Couldn't find one)

Why is this a pessimization, does gcc 3.4.0 do what you want?  Looks
like just a missed opportunity.  I am more surprised that making tmp
static doesn't help...

Gr.
Steven



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

* Re: [tree-ssa] Write to global memory not hoisted out of loop
  2004-04-30 16:25 ` Steven Bosscher
@ 2004-04-30 16:26   ` Richard Guenther
  2004-04-30 22:25     ` Zdenek Dvorak
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Guenther @ 2004-04-30 16:26 UTC (permalink / raw)
  To: Steven Bosscher; +Cc: gcc

On Fri, 30 Apr 2004, Steven Bosscher wrote:

> On Apr 30, 2004 01:14 PM, Richard Guenther <rguenth@tat.physik.uni-tuebingen.de> wrote:
>
> > Writes to global memory are not hoisted out of a computation loop.
>
> Try this with the LNO branch, iirc it can do this.

Not as of gcc (GCC) 3.5-tree-ssa-lno 20040430 (merged 20040425) (-O2
-ftree-loop-optimize -ffast-math), neither with static nor without.

> > Is there already a PR about this pessimization? (Couldn't find one)
>
> Why is this a pessimization, does gcc 3.4.0 do what you want?  Looks
> like just a missed opportunity.  I am more surprised that making tmp
> static doesn't help...

Yes, I assumed tree-ssa can do this with some part of DOM - but
appearantly not.  No version of gcc can do this, but I think of
pessimization as of "worse than best possible", not as of a regression
towards an older release.

Richard.

--
Richard Guenther <richard dot guenther at uni-tuebingen dot de>
WWW: http://www.tat.physik.uni-tuebingen.de/~rguenth/

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

* Re: [tree-ssa] Write to global memory not hoisted out of loop
  2004-04-30 16:26   ` Richard Guenther
@ 2004-04-30 22:25     ` Zdenek Dvorak
  2004-04-30 22:26       ` Diego Novillo
  0 siblings, 1 reply; 7+ messages in thread
From: Zdenek Dvorak @ 2004-04-30 22:25 UTC (permalink / raw)
  To: Richard Guenther; +Cc: Steven Bosscher, gcc

Hello,

> > > Writes to global memory are not hoisted out of a computation loop.
> >
> > Try this with the LNO branch, iirc it can do this.
> 
> Not as of gcc (GCC) 3.5-tree-ssa-lno 20040430 (merged 20040425) (-O2
> -ftree-loop-optimize -ffast-math), neither with static nor without.

tree-ssa aliasing probably does not take restricted pointers into
account, since it decides that all the accesses in the loop may alias.
Consequently none of the optimizations that could cause the store
to be hoisted out detects the possibility.

Zdenek

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

* Re: [tree-ssa] Write to global memory not hoisted out of loop
  2004-04-30 22:25     ` Zdenek Dvorak
@ 2004-04-30 22:26       ` Diego Novillo
  0 siblings, 0 replies; 7+ messages in thread
From: Diego Novillo @ 2004-04-30 22:26 UTC (permalink / raw)
  To: Zdenek Dvorak; +Cc: Richard Guenther, Steven Bosscher, gcc

On Fri, 2004-04-30 at 16:57, Zdenek Dvorak wrote:

> tree-ssa aliasing probably does not take restricted pointers into
> account, since it decides that all the accesses in the loop may alias.
>
Correct.  We don't check restricted pointers.  This is another item in
my post merge todo.


Diego.

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

* Re: [tree-ssa] Write to global memory not hoisted out of loop
@ 2004-04-30 22:28 Richard Kenner
  2004-04-30 22:28 ` Diego Novillo
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Kenner @ 2004-04-30 22:28 UTC (permalink / raw)
  To: dnovillo; +Cc: gcc

    Correct.  We don't check restricted pointers.  This is another item in
    my post merge todo.

Do you call the normal get_alias_set code?  Is TYPE_REF_CAN_ALIAS_ALL
respected?

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

* Re: [tree-ssa] Write to global memory not hoisted out of loop
  2004-04-30 22:28 Richard Kenner
@ 2004-04-30 22:28 ` Diego Novillo
  0 siblings, 0 replies; 7+ messages in thread
From: Diego Novillo @ 2004-04-30 22:28 UTC (permalink / raw)
  To: Richard Kenner; +Cc: gcc

On Fri, 2004-04-30 at 17:17, Richard Kenner wrote:

> Do you call the normal get_alias_set code?  Is TYPE_REF_CAN_ALIAS_ALL
> respected?
>
Yes.  My mistake.  We base all the TBAA decisions on get_alias_set. 
It's in the flow-sensitive points-to code where we don't check
'restrict'.


Diego.

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

end of thread, other threads:[~2004-04-30 21:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-30 16:23 [tree-ssa] Write to global memory not hoisted out of loop Richard Guenther
2004-04-30 16:25 ` Steven Bosscher
2004-04-30 16:26   ` Richard Guenther
2004-04-30 22:25     ` Zdenek Dvorak
2004-04-30 22:26       ` Diego Novillo
2004-04-30 22:28 Richard Kenner
2004-04-30 22:28 ` Diego Novillo

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