This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: g++ optimizer and numerical computations
On Mon, Feb 16, 1998 at 09:51:06PM -0700, Jeffrey A Law wrote:
> In message <19980216125213.40642@dot.cygnus.com>you write:
> > On Mon, Feb 16, 1998 at 06:06:01PM +0100, Marc Espie wrote:
> > > - the refcnt test occurs inside the loop. It has not been moved outside
> > > the loop by the compiler.
> >
> > No, gcc is not able to notice test domination of that nature.
> > Jeff Law played around with that a bit I remember, but I don't
> > know how succesfulit was.
> I don't grok C++, so can someone describe exactly what test we think
> should have been eliminated?
Okay, basically, I try to implement copy-on-write semantics.
When I write
Vector w = v;
I don't want to copy the array, I just want the cnt++. (Vector is just
a `pointer' to the actual array, with special semantics).
When I try to write to the actual element, I want the copy to occur.
Specifically, w[i] occurs as a lvalue, hence invokes a specific operator,
which tells it will be overwritten (write requested). The `copy-on-write' looks
like (assuming a pointer to the InVector structure):
if (p->cnt != 1)
{
make p point to a copy of the old p;
p->cnt = 1; // now that we have a unique copy
}
This is the
if (p->cnt != 1)
{
make copy
p->cnt = 1;
}
which I would like moved outside of the loop, as
o p->cnt != 1 and p->cnt = 1 are the only two operations affecting p->cnt.
o this particular code is defined inside the class, not declared, which means
it should be inlined. Hence the compiler is supposed to know everything
about p->cnt at that point.
This might be very useful to get efficient copy-on-write semantics.
> And as Jason noted, dealing with aliases, particularly in the
> presense of function calls is a tough problem :-)
There is no function-call: everything is inline :-)
--
Marc Espie