public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* should MEM tracking be able to optimize this?
@ 2001-11-05  4:44 Dan Nicolaescu
  2001-11-05  8:16 ` degger
  2001-11-05 14:20 ` Zack Weinberg
  0 siblings, 2 replies; 24+ messages in thread
From: Dan Nicolaescu @ 2001-11-05  4:44 UTC (permalink / raw)
  To: gcc; +Cc: Richard Kenner


The following 2 functions should generate very similar assembly, right?

struct {
  float f[2048];
  float p[2048];
  float q[2048];
  float d[2048];
} A;


void
calc1 (void)
{
  int i;
  for (i = 0; i < 1024; ++i) {
    A.f[i]  = A.p[i] + A.q[i];
    A.d[i]  = A.p[i] + A.q[i]; 
    A.f[i]  = A.f[i] + A.p[i] + A.q[i];
  }
}

float f[2048];
float p[2048];
float q[2048];
float d[2048];

void
calc2 (void)
{
  int i;
  for (i = 0; i < 1024; ++i) {
    f[i]  = p[i] + q[i];
    d[i]  = p[i] + q[i]; 
    f[i]  = f[i] + p[i] + q[i];
  }
}


On sparc-sun-solaris2.8 using -O2 I get the following assembly:
(from a gcc updated about 1 hour ago when using -O2, just the loops
are shown)


calc1:
[snip]
.LL5:
	sll	%i5, 2, %i1	! i
	add	%i1, %o0, %i2
	add	%i1, %o7, %i3
	ld	[%i4+%i3], %f3	! A
	ld	[%i4+%i2], %f2	! A
	fadds	%f2, %f3, %f2
	st	%f2, [%i4+%i1]	! A
	ld	[%i4+%i3], %f2	! A
	ld	[%i4+%i2], %f3	! A
	fadds	%f3, %f2, %f3
	add	%i1, %g1, %i0
	st	%f3, [%i4+%i0]	! A
	ld	[%i4+%i2], %f4	! A
	ld	[%i4+%i1], %f2	! A
	ld	[%i4+%i3], %f3	! A
	fadds	%f2, %f4, %f2
	fadds	%f2, %f3, %f2
	add	%i5, 1, %i5	! i, i
	cmp	%i5, 1023	! i
	ble	.LL5
	st	%f2, [%i4+%i1]	! A
[snip]

calc2:
[snip]
.LL13:
	sll	%o2, 2, %o0	! i
	ld	[%o4+%o0], %f2	! p
	ld	[%o3+%o0], %f3	! q
	fadds	%f2, %f3, %f4
	fadds	%f4, %f2, %f2
	fadds	%f2, %f3, %f2
	add	%o2, 1, %o2	! i, i
	st	%f2, [%o5+%o0]	! f
	cmp	%o2, 1023	! i
	ble	.LL13
	st	%f4, [%o1+%o0]	! d



"calc1" one has too many loads and stores...  
Should MEM tracking be able to dissambiguate the non-dependend loads
and stores in "calc1"?



^ permalink raw reply	[flat|nested] 24+ messages in thread
* Re:  should MEM tracking be able to optimize this?
@ 2001-11-05  4:49 Richard Kenner
  2001-11-05  5:47 ` Dan Nicolaescu
  0 siblings, 1 reply; 24+ messages in thread
From: Richard Kenner @ 2001-11-05  4:49 UTC (permalink / raw)
  To: dann; +Cc: gcc

    "calc1" one has too many loads and stores...  Should MEM tracking be
    able to dissambiguate the non-dependend loads and stores in "calc1"?

No, only in calc2.  The point is that it can now disambiguate when you
have separate variables, like you do in calc2.  In calc1, what you
have are different *fields* of the same variable and that isn't what
is tracked.

^ permalink raw reply	[flat|nested] 24+ messages in thread
* Re: should MEM tracking be able to optimize this?
@ 2001-11-05  5:54 Richard Kenner
  2001-11-05 11:34 ` Dan Nicolaescu
  0 siblings, 1 reply; 24+ messages in thread
From: Richard Kenner @ 2001-11-05  5:54 UTC (permalink / raw)
  To: dann; +Cc: gcc

    Do you have any plans to do anything about tracking the fields too? 

No.

    Or it's not considered to be worth the effort? 

It's a hard problem because there's a limit to what you can keep track of.
It's not clear it's common enough to be worth the effort.

^ permalink raw reply	[flat|nested] 24+ messages in thread
* Re: should MEM tracking be able to optimize this?
@ 2001-11-05 12:09 Richard Kenner
  2001-11-05 12:52 ` guerby
  2001-11-08 15:28 ` Dan Nicolaescu
  0 siblings, 2 replies; 24+ messages in thread
From: Richard Kenner @ 2001-11-05 12:09 UTC (permalink / raw)
  To: dann; +Cc: gcc

    Would it be possible to put the fields in different alias sets at
    tree->rtl conversion time (or whenever the alias sets are first
    computed), as we should know they don't overlap?
 
Well there's no mechanism for fields to have alias sets and even if
they did, the alias set for the reference would be that of "float", not
of the field.  This is because of the addressing rules in C.

^ permalink raw reply	[flat|nested] 24+ messages in thread
* Re: should MEM tracking be able to optimize this?
@ 2001-11-05 12:55 Richard Kenner
  0 siblings, 0 replies; 24+ messages in thread
From: Richard Kenner @ 2001-11-05 12:55 UTC (permalink / raw)
  To: guerby; +Cc: gcc

    Just curious, what about Ada?

Yes, it can be done for nonaliased fields and variables in Ada and we
in fact talked about it in the variable case.

^ permalink raw reply	[flat|nested] 24+ messages in thread
* Re: should MEM tracking be able to optimize this?
@ 2001-11-05 16:19 Richard Kenner
  2001-11-05 16:49 ` Daniel Berlin
  0 siblings, 1 reply; 24+ messages in thread
From: Richard Kenner @ 2001-11-05 16:19 UTC (permalink / raw)
  To: dan; +Cc: gcc

    It's not that simple to differentiate between field accesses, and 
    whether two given field accesses overlap.  

True in general, but you don't need to solve the general problem.  You
just need an algorithm that tells you when it's known they *don't*.
And it's not hard to find such an algorithm that will do that in the
vast majority of all the common cases.

The tricky part isn't in determining that two fields don't overlap,
but in all the all recordkeeping needed to have that information at
the right place.

^ permalink raw reply	[flat|nested] 24+ messages in thread
* Re: should MEM tracking be able to optimize this?
@ 2001-11-05 20:23 Richard Kenner
  2001-11-06  8:56 ` Alexandre Oliva
  2001-11-06 19:54 ` Daniel Berlin
  0 siblings, 2 replies; 24+ messages in thread
From: Richard Kenner @ 2001-11-05 20:23 UTC (permalink / raw)
  To: dan; +Cc: gcc

    Only if we are talking about interprocedural algorithms.
    Intraprocedural aliasing algorithms will never get the vast majority of 
    common cases.
    But assuming we are talking about interprocedural algorithms, you are 
    right of course.  aliasing algorithms generally are distinguished by how 
    much info they retain at a given program point, and their alias relation 
    representation.

No, that's way more complex than I mean.  The point is that there are
times (such as this case and many other similar ones) when you can
tell statically that certain types of references to field can never
conflict (because the bit positions don't overlap).  The problem is
representing this information in such a way that you can make that
statement about the references themselves.

Recall the example was:

	struct foo { float a[2048], b[2048]; }

It's obvious statically that X.a[i] and Y.b[j] can never conflict for any
expressions X and Y of type struct foo.  But there needs to be a way to
represent this.

^ permalink raw reply	[flat|nested] 24+ messages in thread
* Re: should MEM tracking be able to optimize this?
@ 2001-11-06  3:18 Richard Kenner
  0 siblings, 0 replies; 24+ messages in thread
From: Richard Kenner @ 2001-11-06  3:18 UTC (permalink / raw)
  To: dan; +Cc: gcc

Actually, I just saw how to do it.

Right now, there's a function that looks at a tree for the offset
computation and returns the highest power of two that it's known to
be a multiple of.  That can be replaced by a routine that returns the
highest known multiple (or we can have both routines).

We add a field to the mem attribute structure which we could call
MEM_STRIDE.  If it's nonzero, then MEM_OFFSET does not represent a
constant offset, but an assertion that the actual offset is 
MEM_OFFSET + J * MEM_STRIDE for some value of J.

Then if we have two MEMs with the same stride, we can take the offset
modulo the stride and if those (offset, size) pairs don't conflict, we know
the two MEMs can't.

Is anybody interested in doing this?

^ permalink raw reply	[flat|nested] 24+ messages in thread
* Re: should MEM tracking be able to optimize this?
@ 2001-11-08 16:50 Richard Kenner
  0 siblings, 0 replies; 24+ messages in thread
From: Richard Kenner @ 2001-11-08 16:50 UTC (permalink / raw)
  To: dann; +Cc: gcc

    It seems that ex1->a and ex1->c are put in the alias set 0 and it
    should not be necessary. 
    Can this be avoided? 

Perhaps, but it gets into very tricky C semantics, since char * is allowed
to be used to access *any* datatype.

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

end of thread, other threads:[~2001-11-19 22:38 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-05  4:44 should MEM tracking be able to optimize this? Dan Nicolaescu
2001-11-05  8:16 ` degger
2001-11-05 14:20 ` Zack Weinberg
2001-11-05 15:45   ` Daniel Berlin
2001-11-05  4:49 Richard Kenner
2001-11-05  5:47 ` Dan Nicolaescu
2001-11-05  5:54 Richard Kenner
2001-11-05 11:34 ` Dan Nicolaescu
2001-11-05 12:09 Richard Kenner
2001-11-05 12:52 ` guerby
2001-11-08 15:28 ` Dan Nicolaescu
2001-11-05 12:55 Richard Kenner
2001-11-05 16:19 Richard Kenner
2001-11-05 16:49 ` Daniel Berlin
2001-11-05 17:06   ` Paolo Carlini
2001-11-05 20:23 Richard Kenner
2001-11-06  8:56 ` Alexandre Oliva
2001-11-07  3:16   ` Zack Weinberg
2001-11-07  3:19     ` Alexandre Oliva
2001-11-07  3:58       ` Zack Weinberg
2001-11-07  4:00         ` Alexandre Oliva
2001-11-06 19:54 ` Daniel Berlin
2001-11-06  3:18 Richard Kenner
2001-11-08 16:50 Richard Kenner

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