------- Comment #107 from rguenther at suse dot de  2007-05-22 16:20 -------
Subject: Re:  [4.0/4.1/4.2/4.3 Regression] placement
 new does not change the dynamic type as it should

On Tue, 22 May 2007, mark at codesourcery dot com wrote:

> rguenth at gcc dot gnu dot org wrote:
> 
> >  - we _cannot_ sink loads across stores.
> > 
> >      x = *int;
> >      *double = 1.0;
> > 
> >    the store to double may change the dynamic type of what *int
> >    points to.
> 
> To be clear, you mean something like this, right:
> 
>   int i;
>   int *ip = &i;
>   double *dp = (double *)&i;
>   int x;
>   x = *ip;
>   *dp = 1.0;
> 
> ?
> 
> I think that considering this code valid, and, therefore, forbidding the
> interchange of the last two statements, requires a perverse reading of
> the standard.  Placement new allows you to change the dynamic type of
> storage; I don't think that just writing through a pointer does.  A key
> goal of C++ relative to C was better type-safety.  The placement new
> operator provides a facility for explicitly controlling object lifetime,
> for programmers that need this.

I just wanted to point out that even with a "perverse" reading of the
C++ standard we don't loose the most interesting memory operations
(respectively load hoisting and store sinking).

> Before we do anything to support the case above, we should have a
> crystal-clear ruling from the committee that says this is valid.
> Otherwise, this is exactly the kind of optimization that TBAA was
> designed to perform.

TBAA still performs the useful cases of load hoisting and store sinking.
The "perverse" reading of the standard is not making programs invalid
that are valid as of the strict TBAA interpretation - it just implements
(IMHO) a cheap way of making placement new work.

> For history, the reason I implemented TBAA in GCC was that the SGI
> MIPSPro C/C++ compiler did these kinds of optimizations ten years ago,
> and I was trying to catch us up when looking at POOMA performance on
> IRIX.  G++ has had the freedom to interchange those stores for a long
> time, and I believe it should continue to have that choice.

So, what kind of useful transformations rely on hoisting stores or
sinking loads?

Richard.


-- 


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

Reply via email to